Skip to content

Commit

Permalink
generic function for getBiasFactor
Browse files Browse the repository at this point in the history
generic function for getBiasFactor, and applyBiasFactor. No input type
needed, R will detect.
  • Loading branch information
Yuanchao-Xu committed Nov 1, 2015
1 parent 0ae6182 commit 66a56b5
Show file tree
Hide file tree
Showing 42 changed files with 1,408 additions and 932 deletions.
1,014 changes: 507 additions & 507 deletions .Rhistory

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .Rproj.user/D53FD3E6/pcs/find-in-files.pper
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"filePatterns" : [
],
"path" : "E:/1/R/hyfo",
"query" : "invisible(",
"query" : "multi_biasCorrect",
"regex" : false
}
}
2 changes: 1 addition & 1 deletion .Rproj.user/D53FD3E6/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"activeTab" : 6
"activeTab" : 7
}
17 changes: 17 additions & 0 deletions .Rproj.user/D53FD3E6/sdb/per/t/2345FC5F
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"contents" : "# Generated by roxygen2 (4.1.1): do not edit by hand\n\nexport(applyBiasFactor)\nexport(biasCorrect)\nexport(checkBind)\nexport(collectData)\nexport(collectData_csv_anarbe)\nexport(collectData_excel_anarbe)\nexport(collectData_txt_anarbe)\nexport(downscaleNcdf)\nexport(extractPeriod)\nexport(fillGap)\nexport(getAnnual)\nexport(getBiasFactor)\nexport(getEnsem_comb)\nexport(getFrcEnsem)\nexport(getHisEnsem)\nexport(getLMom)\nexport(getMoment)\nexport(getNcdfVar)\nexport(getPreciBar)\nexport(getPreciBar_comb)\nexport(getSpatialMap)\nexport(getSpatialMap_comb)\nexport(getSpatialMap_mat)\nexport(list2Dataframe)\nexport(loadNcdf)\nexport(monDay)\nexport(plotTS)\nexport(plotTS_comb)\nexport(shp2cat)\nexport(writeNcdf)\nexportClasses(biasFactor)\nimport(ggplot2)\nimport(maps)\nimport(maptools)\nimport(ncdf)\nimport(plyr)\nimport(rgdal)\nimport(rgeos)\nimportFrom(MASS,fitdistr)\nimportFrom(grDevices,rainbow)\nimportFrom(lmom,samlmu)\nimportFrom(methods,new)\nimportFrom(methods,setClass)\nimportFrom(methods,setMethod)\nimportFrom(moments,kurtosis)\nimportFrom(moments,skewness)\nimportFrom(reshape2,melt)\nimportFrom(stats,aggregate)\nimportFrom(stats,coef)\nimportFrom(stats,cor)\nimportFrom(stats,ecdf)\nimportFrom(stats,lm)\nimportFrom(stats,median)\nimportFrom(stats,na.omit)\nimportFrom(stats,pgamma)\nimportFrom(stats,qgamma)\nimportFrom(stats,quantile)\nimportFrom(stats,rgamma)\nimportFrom(stats,var)\nimportFrom(utils,choose.dir)\nimportFrom(utils,combn)\nimportFrom(utils,packageDescription)\nimportFrom(utils,read.csv)\nimportFrom(utils,read.fwf)\nimportFrom(utils,tail)\nimportFrom(zoo,as.Date)\n",
"created" : 1446242206157.000,
"dirty" : false,
"encoding" : "ASCII",
"folds" : "",
"hash" : "2467207366",
"id" : "2345FC5F",
"lastKnownWriteTime" : 1446409855,
"path" : "E:/1/R/hyfo/NAMESPACE",
"project_path" : "NAMESPACE",
"properties" : {
},
"relative_order" : 10,
"source_on_save" : false,
"type" : "r_namespace"
}
8 changes: 4 additions & 4 deletions .Rproj.user/D53FD3E6/sdb/per/t/2F56DEAB

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions .Rproj.user/D53FD3E6/sdb/per/t/3D352F96

This file was deleted.

17 changes: 17 additions & 0 deletions .Rproj.user/D53FD3E6/sdb/per/t/46447358

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions .Rproj.user/D53FD3E6/sdb/per/t/76FD9DF7

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions .Rproj.user/D53FD3E6/sdb/per/t/7C472C81

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions .Rproj.user/D53FD3E6/sdb/per/t/7FAF7171
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"contents" : "# \n# print <- function(object, ...) {\n# UseMethod('print')\n# }\n# \n# print.biasFactor <- function(object, ...) {\n# msg <- paste('biasFactor of method ', object@method)\n# if (length(object@memberDim)) msgM <- paste('There are', object@memberDim, 'members existing in the forecasting data.')\n# return(c(msg, msgM))\n# }\n\n#' #### Generics of biasFactor\n# @param object biasFactor object\n# @export\n# setGeneric('print', function(object) {\n# standardGeneric('print')\n# })\n# \n# \n# setMethod('print', signature('biasFactor'), function(object) {\n# msg <- paste('biasFactor of method ', object@method)\n# if (length(object@memberDim)) msgM <- paste('There are', object@memberDim, 'members existing in the forecasting data.')\n# return(c(msg, msgM))\n# })\n\n# #' @export\n# #' @param a biasFactor object\n# size <- function(x, ...) {\n# UseMethod('size', x)\n# }\n# \n# #' @describeIn size\n# size.biasFactor <-function(object) {\n# if (length(object@lonLatDim) == 0) {\n# return (1)\n# } else {\n# lonLat <- object@lonLatDim\n# msg <- paste('Grid file with', lonLat[1], 'grids in longitude, ', lonLat[2], 'grids in latitude.')\n# return(msg)\n# }\n# }\n\n##### hyfo\n\n# hyfo, TS and datalist should be three kinds of objects, so that many functions in hyfo can be split\n# into different generic methods, then no need to set up input = TS or input = hyfo.\n# But too much work to re-construct all the functions.\n\n# For new methods, it should set up different generic methods for hyfo, TS, and grid file from \n# downscaleR.\n",
"created" : 1446239993498.000,
"dirty" : false,
"encoding" : "ASCII",
"folds" : "",
"hash" : "782457068",
"id" : "7FAF7171",
"lastKnownWriteTime" : 1446409776,
"path" : "E:/1/R/hyfo/R/generics.R",
"project_path" : "R/generics.R",
"properties" : {
"tempName" : "Untitled1"
},
"relative_order" : 9,
"source_on_save" : false,
"type" : "r_source"
}
18 changes: 0 additions & 18 deletions .Rproj.user/D53FD3E6/sdb/per/t/9507A061

This file was deleted.

17 changes: 17 additions & 0 deletions .Rproj.user/D53FD3E6/sdb/per/t/B0B6357D
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"contents" : "#' Get a catchment object from selected shape file.\n#' @param filePath A string representing the path of the shape file.\n#' @return A catchment object can be used in \\code{getSpatialMap()}.\n#' @export\n#' @details This function is based on the package \\code{rgdal} and \\code{sp}, and the output comes from the package \n#' \\code{sp}\n#' @examples\n#' #open internal file\n#' file <- system.file(\"extdata\", \"testCat.shp\", package = \"hyfo\")\n#' catchment <- shp2cat(file)\n#' \n#' # More examples can be found in the user manual on http:https://yuanchao-xu.github.io/hyfo/\n#' \n#' @import rgdal\n#' @importFrom utils tail\n#' @references \n#' \n#' \\itemize{\n#' \\item Roger Bivand, Tim Keitt and Barry Rowlingson (2015). rgdal: Bindings for the Geospatial Data\n#' Abstraction Library. R package version 1.0-4. http:https://CRAN.R-project.org/package=rgdal\n#' \n#' \\item R Core Team (2015). R: A language and environment for statistical computing. R Foundation for\n#' Statistical Computing, Vienna, Austria. URL http:https://www.R-project.org/.\n#' }\n#' \n#' \nshp2cat <- function(filePath) {\n #if the path <- file.choose(), the seperator is '\\\\'\n if (grepl('\\\\\\\\', filePath)) {\n catName <- tail(strsplit(filePath,'\\\\\\\\')[[1]], 1)#needs to be four \\, caused by some window system problem\n catName1 <- strsplit(catName, '\\\\.')[[1]][1]\n catName2 <- paste('\\\\\\\\', catName, sep = '')\n folderName <- strsplit(filePath, catName2)[[1]]\n n <- list.files(folderName, pattern = catName1)\n if (length(n) == 1) stop('Please place the shp file in the folder containing \n full related files, not only the shape file')\n #the other seperator is '/' \n } else if (grepl('/', filePath)) {\n catName <- tail(strsplit(filePath,'/')[[1]], 1)#needs to be four \\, caused by some window system problem\n catName1 <- strsplit(catName, '\\\\.')[[1]][1]\n catName2 <- paste('/', catName, sep = '')\n folderName <- strsplit(filePath, catName2)[[1]]\n n <- list.files(folderName, pattern = catName1)\n if (length(n) == 1) stop('Please place the shp file in the folder containing \n full related files, not only the shape file')\n }\n \n if (length(folderName) == 0) stop('No shape file found, make sure the shp file is selected.')\n catchment <- readOGR(folderName, catName1)\n return(catchment)\n}\n",
"created" : 1446247741641.000,
"dirty" : false,
"encoding" : "ASCII",
"folds" : "",
"hash" : "3019466614",
"id" : "B0B6357D",
"lastKnownWriteTime" : 1443830746,
"path" : "E:/1/R/hyfo/R/shp2cat.R",
"project_path" : "R/shp2cat.R",
"properties" : {
},
"relative_order" : 11,
"source_on_save" : false,
"type" : "r_source"
}
18 changes: 18 additions & 0 deletions .Rproj.user/D53FD3E6/sdb/per/t/D4CCEE99
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"contents" : "# \n#' An S4 class, representing the biasFactor of single time series biasCorrection.\n#' @slot biasFactor list of biasFactor, containing all the information for computing.\n#' @slot method the biascorrection method\n#' @slot preci if the data is precipitation\n#' @slot scaleType 'Valid when 'scaling' method is selected, 'multi' or 'add'.\n#' @slot extrapolate Valid when 'eqm' method is selected, 'constant' or 'no'\n#' @slot memberDim members contained.\n#' @slot prThreshold precipitation threshold, under which the precipitation is considered as 0.\n#' @exportClass biasFactor\n#' @importFrom methods setClass\nsetClass(\"biasFactor\", representation(biasFactor = 'list', method = 'character', preci = 'logical', prThreshold = 'numeric',\n scaleType = 'character', extrapolate = 'character', memberDim = 'numeric'), \n validity = checkBiasFactor, \n prototype(memberDim = 1))\n# \n# \n#' An S4 class, representing the biasFactor of hyfo file.\n#' @slot lonLatDim lists of biasFactor\n#' @inheritParams biasFactor\nsetClass(\"biasFactor.hyfo\", representation(lonLatDim = 'integer'), contains = 'biasFactor', \n validity = checkBiasFactor.hyfo)\n\n\n\n\n\n\n# aa <- new('biasFactor', biasFactor = biasFactor[[1]], method = biasFactor$method, preci = biasFactor$preci, prThreshold = biasFactor$prThreshold,\n# scaleType = biasFactor$scaleType, extrapolate = biasFactor$extrapolate)\n\n# a <- new('biasFactor.multiMember', biasFactor = biasFactor[[1]], memberDim = biasFactor$memberDim,\n# method = biasFactor$method, preci = biasFactor$preci, prThreshold = biasFactor$prThreshold,\n# scaleType = biasFactor$scaleType, extrapolate = biasFactor$extrapolate, input = biasFactor$input)\n# \n# a <- new('biasFactor.hyfo.multiMember', biasFactor = biasFactor[[1]], memberDim = biasFactor$memberDim, lonLatDim = biasFactor$lonLatDim,\n# method = biasFactor$method, preci = biasFactor$preci, prThreshold = biasFactor$prThreshold,\n# scaleType = biasFactor$scaleType, extrapolate = biasFactor$extrapolate, input = biasFactor$input)\n# \n\n\n\n\n\n\n\n##### For hyfo class\n\n###### hyfo\n\n# Since hyfo has to inateract with other packages like downscaleR,\n# If particular class is defined, other packages may not be able to use the object.\n# So, for grid file, just keep it the list file. In future, if interpolate is added,\n# grid file may become a special class.\n\n# \n# \n# \n# checkHyfo <- function(object) {\n# errors <- character()\n# if (length(object@varName) == 0) {\n# msg <- 'hyfo must have a varName.'\n# errors <- c(errors, msg)\n# }\n# \n# if (length(object@xyCoords) != 2) {\n# msg <- 'hyfo must have x and y coordinats, stored in xyCooords.'\n# errors <- c(errors, msg)\n# }\n# \n# if (length(object@Data) == 0) {\n# msg <- 'hyfo must have a Data part, storing data.'\n# errors <- c(errors, msg)\n# } else {\n# validDim <- na.omit(match(c('lon', 'lat', 'time'),attributes(object@Data)$dimensions))\n# if (length(validDim) != 3) {\n# msg <- paste('Data should have at least dimensions \"lon\", \"lat\", \"time\".', '\\n',\n# 'Your input data has dimensions ', attributes(object@Data)$dimensions, sep = '')\n# errors <- c(errors, msg)\n# }\n# }\n# if (length(errors) == 0) TRUE else errors\n# }\n# \n# checkHyfo.multiMember <- function(object) {\n# errors <- character()\n# if (length(object@Members) == 0) {\n# msg <- 'Members names missing.'\n# errors <- c(errors, msg)\n# }\n# \n# memDim <- match('member', attributes(object@Data)$dimensions)\n# if (is.na(memDim)) {\n# msg <- 'Members dimension missing.'\n# errors <- c(errors, msg)\n# }\n# \n# if (length(errors) == 0) TRUE else errors\n# }\n\n\n\n\n\n# #' An S4 class representing the grid file loaded from netCDF file.\n# #' @slot varName the name of the varialbe of the hyfo object.\n# #' @slot xyCoords A list file containing longitude and latitude coordinates.\n# #' @slot Dates A list containing Date information.\n# #' @slot Data An array containing the data.\n# #' @slot Loaded An character showing the loading information. \n# #' @exportClass \n# setClass(\"hyfo\", representation(varName = \"character\", xyCoords = 'list', Dates = 'list',\n# Data = 'array', Loaded = 'character'),\n# prototype(Loaded = 'by hyfo package, http:https://yuanchao-xu.github.io/hyfo/'),\n# validity = checkHyfo)\n# \n# \n# #' An S4 class representing the multi-member grid file loaded from netCDF file.\n# #' @slot Members showing the name of the members.\n# #' @exportClass \n# setClass('hyfo.multiMember', representation(Members = 'array'), contains = 'hyfo',\n# validity = checkHyfo.multiMember)\n\n\n\n\n# \n# a <- new(\"hyfo\", varName = \"pr\", xyCoords = tgridData$xyCoords, Dates = tgridData$Dates, Data = tgridData$Data)\n# \n# a <- new(\"hyfo.multiMember\", varName = \"pr\", xyCoords = nc$xyCoords, Dates = nc$Dates, Data = nc$Data,\n# Members = nc$Members, Loaded = nc$Loaded)\n\n",
"created" : 1446229350238.000,
"dirty" : false,
"encoding" : "ASCII",
"folds" : "",
"hash" : "3466314913",
"id" : "D4CCEE99",
"lastKnownWriteTime" : 1446235115,
"path" : "E:/1/R/hyfo/R/classes.R",
"project_path" : "R/classes.R",
"properties" : {
"tempName" : "Untitled1"
},
"relative_order" : 9,
"source_on_save" : false,
"type" : "r_source"
}
8 changes: 4 additions & 4 deletions .Rproj.user/D53FD3E6/sdb/per/t/DEBB5BC6
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"contents" : "Package: hyfo\nType: Package\nTitle: Hydrology and Climate Forecasting R Package for Data Analysis and Visualization\nVersion: 1.2.8\nDate: 2015-10-02\nAuthors@R: person(\"Yuanchao\", \"Xu\", email = \"[email protected]\",\n role = c(\"aut\", \"cre\"))\nDescription: This package can be used as a tool for hydrology and climate forecasting. \n There are several tools including data processing, data visualization and data analysis. \n For hydrological and hydraulic modellers, hyfo can be a good pre-processing and post-processing \n tool for you.\n hyfo has been tested stable on windows platform.\nLicense: GPL-2\nDepends: R (>= 3.1.0), stats (>= 3.1.3), utils(>= 3.1.3)\nImports: ggplot2 (>= 1.0.1),\n reshape2 (>= 1.4.1),\n zoo (>= 1.7-12),\n rgdal (>= 0.9-3),\n plyr (>= 1.8.3),\n moments (>= 0.14),\n lmom (>= 2.5),\n maps(>= 2.3-9),\n maptools (>= 0.8-36),\n rgeos (>= 0.3-8),\n ncdf (>= 1.6.8),\n MASS (>= 7.3-39)\nSuggests: gridExtra,\n knitr\nVignetteBuilder: knitr\nLazyData: true\nURL: http:https://yuanchao-xu.github.io/hyfo/\nBugReports: https://github.com/Yuanchao-Xu/hyfo/issues\nrepository: github",
"contents" : "Package: hyfo\nType: Package\nTitle: Hydrology and Climate Forecasting R Package for Data Analysis and\n Visualization\nVersion: 1.2.9\nDate: 2015-10-30\nAuthors@R: person(\"Yuanchao\", \"Xu\", email = \"[email protected]\",\n role = c(\"aut\", \"cre\"))\nDescription: This package can be used as a tool for hydrology and climate\n forecasting. There are several tools including data processing, data\n visualization and data analysis. For hydrological and hydraulic modellers, hyfo\n can be a good pre-processing and post-processing tool for you. hyfo has been\n tested stable on windows platform.\nLicense: GPL-2\nDepends:\n R (>= 3.1.0),\n stats (>= 3.1.3),\n utils(>= 3.1.3),\nImports:\n ggplot2 (>= 1.0.1),\n reshape2 (>= 1.4.1),\n zoo (>= 1.7-12),\n rgdal (>= 0.9-3),\n plyr (>= 1.8.3),\n moments (>= 0.14),\n lmom (>= 2.5),\n maps(>= 2.3-9),\n maptools (>= 0.8-36),\n rgeos (>= 0.3-8),\n ncdf (>= 1.6.8),\n MASS (>= 7.3-39),\n methods\nSuggests:\n gridExtra,\n knitr\nVignetteBuilder: knitr\nLazyData: true\nURL: http:https://yuanchao-xu.github.io/hyfo/\nBugReports: https://github.com/Yuanchao-Xu/hyfo/issues\nrepository: github\n",
"created" : 1444011910438.000,
"dirty" : false,
"encoding" : "ASCII",
"folds" : "",
"hash" : "867422461",
"hash" : "2232663633",
"id" : "DEBB5BC6",
"lastKnownWriteTime" : 1445803897,
"lastKnownWriteTime" : 1446239861,
"path" : "E:/1/R/hyfo/DESCRIPTION",
"project_path" : "DESCRIPTION",
"properties" : {
},
"relative_order" : 8,
"relative_order" : 6,
"source_on_save" : false,
"type" : "dcf"
}
2 changes: 1 addition & 1 deletion .Rproj.user/D53FD3E6/sdb/per/t/ECF59ED6
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"project_path" : "R/startup.R",
"properties" : {
},
"relative_order" : 8,
"relative_order" : 7,
"source_on_save" : false,
"type" : "r_source"
}
Loading

0 comments on commit 66a56b5

Please sign in to comment.