Skip to content

Commit

Permalink
Viginette updated and some typo corrected.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuanchao-Xu committed Sep 10, 2015
1 parent a626a94 commit 8bbeb6a
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 67 deletions.
14 changes: 7 additions & 7 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
aaa <- biasCorrect(frc, hindcast, obs)
debug(biasCorrect)
aaa <- biasCorrect(frc, hindcast, obs)
as.POSIXlt(hindcast[, 1]) != as.POSIXlt(obs[, 1])
hindcast[, 1] != obs[, 1]
as.POSIXlt(hindcast[, 1]) != as.POSIXlt(obs[, 1])
as.POSIXlt(hindcast[, 1]) != as.POSIXlt(obs[, 1])
aaa <- biasCorrect(frc, hindcast, obs)
hindcast[, 1] != obs[, 1]
as.POSIXlt(hindcast[, 1]) != as.POSIXlt(obs[, 1])
obs
Expand Down Expand Up @@ -510,3 +503,10 @@ devtools::build()
install.packages("~/hyfo_1.1.9.tar.gz", repos = NULL, type = "source")
devtools::document()
devtools::check()
devtools::document()
devtools::check()
devtools::document()
devtools::check()
devtools::document()
devtools::check()
devtools::build()
2 changes: 1 addition & 1 deletion .Rproj.user/132DF987/pcs/files-pane.pper
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"path" : "~/hyfo",
"path" : "~/hyfo/R",
"sortOrder" : [
{
"ascending" : false,
Expand Down
2 changes: 1 addition & 1 deletion .Rproj.user/132DF987/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"activeTab" : 2
"activeTab" : 0
}
6 changes: 3 additions & 3 deletions .Rproj.user/132DF987/sdb/per/t/A9B56DE9

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions .Rproj.user/132DF987/sdb/per/t/B35F5C0C
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"contents" : "#' testdl\n#'\n#'A list containing different precipitation time series.\n#'\n#'\n#' @format A list consists of 3 different lists.\n#' \\describe{\n#' \\item{AAA}{AAA, a dataframe containing a date column and a value column. }\n#' \\item{BBB}{BBB, a dataframe containing a date column and a value column.}\n#' \\item{CCC}{CCC, a dataframe containing a date column and a value column.}\n#' ...\n#' }\n#' @references\n#' http:https://meteo.navarra.es/estaciones/mapadeestaciones.cfm\n#' http:https://www4.gipuzkoa.net/oohh/web/esp/02.asp\n#' @source\n#' http:https://meteo.navarra.es/estaciones/mapadeestaciones.cfm\n#' http:https://www4.gipuzkoa.net/oohh/web/esp/02.asp\n\"testdl\"\n\n\n#' tgridData\n#'\n#'A list containing different information getting from grid data file, e.g., netcdf file.\n#'\n#'\n#' @format A list containing different information.\n#' \\describe{\n#' \\item{Variables}{variable information. }\n#' \\item{Data}{Data.}\n#' \\item{xyCoords}{longitude and latitude of the data.}\n#' \\item{Dates}{Date information.}\n#' ...\n#' }\n#' @references Herrera, S., Ancell, R., Gutierrez, J. M., Pons, M. R., Frias, M. D., & Fernandez, J. \n#' (2012). Development and analysis of a 50-year high-resolution daily gridded precipitation dataset \n#' over Spain (Spain02). International Journal of Climatology \n#' (http:https://www.meteo.unican.es/datasets/spain02), 10.1002/joc.2256.\n#' \n#' @source http:https://www.meteo.unican.es/datasets/spain02\n\"tgridData\"\n\n\n\n#' testCat\n#' @format A catchment file generated by library rgdal.\n#' \\describe{\n#' \\item{class}{Formal class 'SpatialPolygonsDataFrame' [package \"sp\"] with 5 slots}\n#' ...\n#' }\n\"testCat\"",
"created" : 1441928983272.000,
"dirty" : false,
"encoding" : "ASCII",
"folds" : "",
"hash" : "3590903000",
"id" : "B35F5C0C",
"lastKnownWriteTime" : 1440688194,
"path" : "~/hyfo/R/dataDocument.R",
"project_path" : "R/dataDocument.R",
"properties" : {
"tempName" : "Untitled1"
},
"relative_order" : 4,
"source_on_save" : false,
"type" : "r_source"
}
10 changes: 9 additions & 1 deletion R/biasCorrect.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
#'
#' @examples
#'
#' # Use testdl as an example, we take frc, hindcast and obs fro testdl.
#' # Use testdl as an example, we take frc, hindcast and obs from testdl.
#' data(testdl)
#'
#' # common period has to be extracted in order to better train the forecast.
Expand All @@ -92,6 +92,14 @@
#' # If the variable is precipitation, it cannot be negative value, so use multi scale method
#' frc_new <- biasCorrect(frc, hindcast, obs, method = 'scaling', scaleType = 'multi')
#'
#' # If the forecasts you extracted only has incontinuous data for certain months and years, e.g.,
#' # for seasonal forecasting, forecasts only provide 3-6 months data, so the case can be
#' # for example Dec, Jan and Feb of every year from year 1999-2005.
#' # In such case, you need to extract certain months and years from observed time series.
#' # extractPeriod() can be then used.
#'
#'
#'
#' @references
#' Bias correction methods come from \code{biasCorrection} from \code{dowscaleR}
#'
Expand Down
5 changes: 3 additions & 2 deletions R/extractPeriod.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@
#'
#'
#' dataframe <- list2Dataframe(datalist_com1)
#' # now we have a dataframe to extract certain months.
#' dataframe_new <- extractPeriod(dataframe = dataframe, month = c(1,2,3) )
#' # now we have a dataframe to extract certain months and years.
#' dataframe_new <- extractPeriod(dataframe = dataframe, month = c(1,2,3))
#' dataframe_new <- extractPeriod(dataframe = dataframe, month = c(12,1,2), year = 1995)
#'
#'
#' @importFrom zoo as.Date
Expand Down
40 changes: 20 additions & 20 deletions R/getSpatialMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' is NULL, if no member assigned, and there is a "member" in dimensions, the mean value of the members will be
#' taken.
#' @param ... Check \code{?getSpatialMap_mat} for details, e.g., x, y, title, catchment,
#' points, output,
#' point, output,
#' @return A matrix representing the raster map is returned, and the map is plotted.
#' @details
#' There are following methods to be selected,
Expand All @@ -26,9 +26,9 @@
#'
#' getSpatialMap(tgridData, method = 'winter', catchment = testCat)
#'
#' file <- system.file("extdata", "points.txt", package = "hyfo")
#' points <- read.table(file, header = TRUE, sep = ',' )
#' getSpatialMap(tgridData, method = 'winter', catchment = testCat, points = points)
#' file <- system.file("extdata", "point.txt", package = "hyfo")
#' point <- read.table(file, header = TRUE, sep = ',' )
#' getSpatialMap(tgridData, method = 'winter', catchment = testCat, point = point)
#'
#' @export
getSpatialMap <- function(dataset, method = NULL, member = 'mean', ...) {
Expand Down Expand Up @@ -181,7 +181,7 @@ getSpatialMap <- function(dataset, method = NULL, member = 'mean', ...) {



#' rePlot raster matrix
#' Replot raster matrix
#'
#' replot the matrix output from \code{getSpatialMap}, when \code{output = 'data'} or output is default
#' value.
Expand All @@ -190,7 +190,7 @@ getSpatialMap <- function(dataset, method = NULL, member = 'mean', ...) {
#' or 'data'
#' @param title_d A string showing the title of the plot, defaut is NULL.
#' @param catchment A catchment file geting from \code{shp2cat()} in the package, if a catchment is available for background.
#' @param points A dataframe, showing other information, e.g., location of the gauging stations. The
#' @param point A dataframe, showing other information, e.g., location of the gauging stations. The
#' the data.frame should be with columes "name, lon, lat, z, value".
#' @param output A string showing the type of the output, if \code{output = 'ggplot'}, the returned
#' data can be used in ggplot and \code{getSpatialMap_comb()}; if \code{output = 'plot'}, the returned data is the plot containing all
Expand All @@ -200,9 +200,9 @@ getSpatialMap <- function(dataset, method = NULL, member = 'mean', ...) {
#' different outputs in the later multiplot using \code{getSpatialMap_comb}.
#' @param info A boolean showing whether the information of the map, e.g., max, mean ..., default is FALSE.
#' @param scale A string showing the plot scale, 'identity' or 'sqrt'.
#' @param colors Most of time you don't have to set this, but if you are not satisfied with the
#' default color, you can set your own palette here. e.g., \code{colors = c('red', 'blue')}, then
#' the value from lowest to highest, will have the color from red to blue. More info about colors,
#' @param color Most of time you don't have to set this, but if you are not satisfied with the
#' default color, you can set your own palette here. e.g., \code{color = c('red', 'blue')}, then
#' the value from lowest to highest, will have the color from red to blue. More info about color,
#' please check ?palette().
#' @param ... \code{title, x, y} showing the title and x and y axis of the plot. e.g. \code{title = 'aaa'}
#'default is about precipitation.
Expand Down Expand Up @@ -249,16 +249,16 @@ getSpatialMap <- function(dataset, method = NULL, member = 'mean', ...) {
#'
#'
#'
getSpatialMap_mat <- function(matrix, title_d = NULL, catchment = NULL, points = NULL, output = 'data',
name = NULL, info = FALSE, scale = 'identity', colors = NULL, ...) {
getSpatialMap_mat <- function(matrix, title_d = NULL, catchment = NULL, point = NULL, output = 'data',
name = NULL, info = FALSE, scale = 'identity', color = NULL, ...) {
#check input
checkWord <- c('lon', 'lat', 'z', 'value')
if (is.null(attributes(matrix)$dimnames)) {
stop('Input matrix is incorrect, check help to know how to get the matrix.')
} else if (!is.null(catchment) & class(catchment) != "SpatialPolygonsDataFrame") {
stop('Catchment format is incorrect, check help to get more details. ')
} else if (!is.null(points) & any(is.na(match(checkWord, attributes(points)$names)))) {
stop('Points should be a dataframe with colnames "lon, lat, z, value".')
} else if (!is.null(point) & any(is.na(match(checkWord, attributes(point)$names)))) {
stop('point should be a dataframe with colnames "lon, lat, z, value".')
}

#ggplot
Expand Down Expand Up @@ -294,15 +294,15 @@ getSpatialMap_mat <- function(matrix, title_d = NULL, catchment = NULL, points =
colnames(data_ggplot) <- c('lat', 'lon', 'value')
theme_set(theme_bw())

if (is.null(colors)) colors <- c('yellow', 'orange', 'red')
# if (is.null(colors)) colors <- rev(rainbow(n = 20, end = 0.7))
if (is.null(color)) color <- c('yellow', 'orange', 'red')
# if (is.null(color)) color <- rev(rainbow(n = 20, end = 0.7))

mainLayer <- with(data_ggplot, {

ggplot(data = data_ggplot) +
geom_tile(aes(x = lon, y = lat, fill = value)) +
#scale_fill_discrete()+
scale_fill_gradientn(colours = colors, na.value = 'transparent') +#usually scale = 'sqrt'
scale_fill_gradientn(colours = color, na.value = 'transparent') +#usually scale = 'sqrt'
#guide = guide_colorbar, colorbar and legend are not the same.
guides(fill = guide_colourbar(title='Rainfall (mm)', barheight = rel(9), trans = scale)) +#usually scale = 'sqrt'
geom_map(data = world_map, map = world_map, aes(map_id = region), fill = 'transparent',
Expand Down Expand Up @@ -346,10 +346,10 @@ getSpatialMap_mat <- function(matrix, title_d = NULL, catchment = NULL, points =

printLayer <- printLayer + catchmentLayer
}
#plot points
if (is.null(points) == FALSE) {
pointLayer <- with(points, {
geom_point(data = points, aes(x = lon, y = lat, size = value, colour = z),
#plot point
if (is.null(point) == FALSE) {
pointLayer <- with(point, {
geom_point(data = point, aes(x = lon, y = lat, size = value, colour = z),
guide = guide_legend(barheight = rel(3)))


Expand Down
File renamed without changes.
8 changes: 7 additions & 1 deletion man/biasCorrect.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ The additive version is preferably applicable to unbounded variables (e.g. tempe
and the multiplicative to variables with a lower bound (e.g. precipitation, because it also preserves the frequency).
}
\examples{
# Use testdl as an example, we take frc, hindcast and obs fro testdl.
# Use testdl as an example, we take frc, hindcast and obs from testdl.
data(testdl)

# common period has to be extracted in order to better train the forecast.
Expand All @@ -102,6 +102,12 @@ frc_new <- biasCorrect(frc, hindcast, obs)

# If the variable is precipitation, it cannot be negative value, so use multi scale method
frc_new <- biasCorrect(frc, hindcast, obs, method = 'scaling', scaleType = 'multi')

# If the forecasts you extracted only has incontinuous data for certain months and years, e.g.,
# for seasonal forecasting, forecasts only provide 3-6 months data, so the case can be
# for example Dec, Jan and Feb of every year from year 1999-2005.
# In such case, you need to extract certain months and years from observed time series.
# extractPeriod() can be then used.
}
\references{
Bias correction methods come from \code{biasCorrection} from \code{dowscaleR}
Expand Down
5 changes: 3 additions & 2 deletions man/extractPeriod.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ datalist_com1 <- extractPeriod(testdl, startDate = '1994-1-1', endDate = '1995-1


dataframe <- list2Dataframe(datalist_com1)
# now we have a dataframe to extract certain months.
dataframe_new <- extractPeriod(dataframe = dataframe, month = c(1,2,3) )
# now we have a dataframe to extract certain months and years.
dataframe_new <- extractPeriod(dataframe = dataframe, month = c(1,2,3))
dataframe_new <- extractPeriod(dataframe = dataframe, month = c(12,1,2), year = 1995)
}
\references{
Achim Zeileis and Gabor Grothendieck (2005). zoo: S3 Infrastructure for Regular and Irregular Time
Expand Down
8 changes: 4 additions & 4 deletions man/getSpatialMap.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ is NULL, if no member assigned, and there is a "member" in dimensions, the mean
taken.}

\item{...}{Check \code{?getSpatialMap_mat} for details, e.g., x, y, title, catchment,
points, output,}
point, output,}
}
\value{
A matrix representing the raster map is returned, and the map is plotted.
Expand All @@ -42,8 +42,8 @@ getSpatialMap(tgridData, method = 'winter')

getSpatialMap(tgridData, method = 'winter', catchment = testCat)

file <- system.file("extdata", "points.txt", package = "hyfo")
points <- read.table(file, header = TRUE, sep = ',' )
getSpatialMap(tgridData, method = 'winter', catchment = testCat, points = points)
file <- system.file("extdata", "point.txt", package = "hyfo")
point <- read.table(file, header = TRUE, sep = ',' )
getSpatialMap(tgridData, method = 'winter', catchment = testCat, point = point)
}

14 changes: 7 additions & 7 deletions man/getSpatialMap_mat.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
% Please edit documentation in R/getSpatialMap.R
\name{getSpatialMap_mat}
\alias{getSpatialMap_mat}
\title{rePlot raster matrix}
\title{Replot raster matrix}
\usage{
getSpatialMap_mat(matrix, title_d = NULL, catchment = NULL, points = NULL,
getSpatialMap_mat(matrix, title_d = NULL, catchment = NULL, point = NULL,
output = "data", name = NULL, info = FALSE, scale = "identity",
colors = NULL, ...)
color = NULL, ...)
}
\arguments{
\item{matrix}{A matrix raster, should be the result of \code{getSpatialMap()}, output should be default
Expand All @@ -16,7 +16,7 @@ or 'data'}

\item{catchment}{A catchment file geting from \code{shp2cat()} in the package, if a catchment is available for background.}

\item{points}{A dataframe, showing other information, e.g., location of the gauging stations. The
\item{point}{A dataframe, showing other information, e.g., location of the gauging stations. The
the data.frame should be with columes "name, lon, lat, z, value".}

\item{output}{A string showing the type of the output, if \code{output = 'ggplot'}, the returned
Expand All @@ -31,9 +31,9 @@ different outputs in the later multiplot using \code{getSpatialMap_comb}.}
\item{scale}{A string showing the plot scale, 'identity' or 'sqrt'.}
\item{colors}{Most of time you don't have to set this, but if you are not satisfied with the
default color, you can set your own palette here. e.g., \code{colors = c('red', 'blue')}, then
the value from lowest to highest, will have the color from red to blue. More info about colors,
\item{color}{Most of time you don't have to set this, but if you are not satisfied with the
default color, you can set your own palette here. e.g., \code{color = c('red', 'blue')}, then
the value from lowest to highest, will have the color from red to blue. More info about color,
please check ?palette().}

\item{...}{\code{title, x, y} showing the title and x and y axis of the plot. e.g. \code{title = 'aaa'}
Expand Down
Loading

0 comments on commit 8bbeb6a

Please sign in to comment.