Skip to content

Commit

Permalink
Additions and fixes for new version release
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedia committed Apr 1, 2015
1 parent aa61c97 commit 49d465d
Show file tree
Hide file tree
Showing 66 changed files with 275 additions and 134 deletions.
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ Imports:
fields,
MASS,
verification,
scales
scales,
ncdf4
Suggests:
ecomsUDG.Raccess,
R.VALUE
Type: Package
Title: Climate data manipulation and statistical downscaling
Version: 0.5-2
Date: 22-Jan-2015
Version: 0.6-0
Date: 01-Apr-2015
Authors@R: as.person(c(
"Joaquin Bedia <[email protected]> [ctb, cre]",
"Sixto Herrera <[email protected]> [ctb]",
"Maria Dolores Frias <[email protected]> [ctb]",
"Jesus Fernandez <[email protected]> [ctb]",
"Wietse Franssen <[email protected]> [ctb]",
"Max Tuni <[email protected]> [ctb]",
"Antonio Cofino <[email protected]> [ctb]",
"Santander Meteorology Group <http://meteo.unican.es> [aut]"))
Expand Down
9 changes: 8 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by roxygen2 (4.0.2): do not edit by hand
# Generated by roxygen2 (4.1.0): do not edit by hand

export(aggr6hToDailyMean)
export(analogs)
Expand All @@ -19,6 +19,7 @@ export(getLatLonDomain)
export(getSeason)
export(getTimeDomain)
export(getYearsAsINDEX)
export(grid2NetCDF)
export(hurs2huss)
export(interpGridData)
export(isimip)
Expand Down Expand Up @@ -55,6 +56,12 @@ importFrom(fields,image.plot)
importFrom(fields,interp.surface.grid)
importFrom(fields,rdist)
importFrom(fields,world)
importFrom(ncdf4,nc_close)
importFrom(ncdf4,nc_create)
importFrom(ncdf4,ncatt_put)
importFrom(ncdf4,ncdim_def)
importFrom(ncdf4,ncvar_def)
importFrom(ncdf4,ncvar_put)
importFrom(scales,alpha)
importFrom(utils,packageDescription)
importFrom(verification,roc.area)
8 changes: 4 additions & 4 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
downscaleR 0.5-2
downscaleR 0.6-0
================

* New features for bias correction:
* New options for multimember corrections
* New moving-window option for reference period definition
* Several improvements in bias correction methods
* New netCDF-4 export feature
* Minor bug fixes
130 changes: 67 additions & 63 deletions R/grid2Netcdf.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#' @title Write NetCDF
#' @description Export downscaleR object to NetCDF
#'
#' @import ncdf4
#' @importFrom ncdf4 ncdim_def
#' @importFrom ncdf4 ncvar_def
#' @importFrom ncdf4 nc_create
#' @importFrom ncdf4 ncatt_put
#' @importFrom ncdf4 ncvar_put
#' @importFrom ncdf4 nc_close
#'
#' @param data A grid data object coming from \code{\link{loadGridData}} or \code{\link{interpGridData}}
#' or the function \code{\link[ecomsUDG.Raccess]{loadECOMS}} of package \pkg{ecomsUDG.Raccess}.
Expand All @@ -14,8 +19,7 @@
#' @param shuffle Turns on (if TRUE) or off (if FALSE, the default) the shuffle filter. According to netcdf docs, turning the shuffle filter on can improve compression for integer variables. Turning the shuffle filter on forces the created file to be in netcdf version 4 format, which will not be compatible with older software that only reads netcdf version 3 files.
#'
#' @return A NetCDF-4 file with the variable and attributes defined in the inputs.
#'
#' @family
#'
#'
#' @references
#'
Expand Down Expand Up @@ -47,64 +51,64 @@
#' grid2NetCDF(prd.bc, NetCDFOutFile = fileName, missval = 1e20, prec = "float", globalAttributes = globalAttributes, varAttributes = varAttributes)
#' }

grid2NetCDF <- function(data, NetCDFOutFile = "out.nc4", missval = 1e20, globalAttributes = NULL, varAttributes = NULL, prec = "float", add = FALSE, compression=4, shuffle = TRUE) {
data(vocabulary)
ntime<-length(data$Dates$start)
tmpStdName<-as.character(vocabulary$standard_name[pmatch(vocabulary$identifier,data$Variable$varName, nomatch=0) > 0])
tmpUnits<-as.character(vocabulary$units[pmatch(vocabulary$identifier,data$Variable$varName, nomatch=0) > 0])
time.index <- grep("^time$", attr(data$Data, "dimensions"))
lon.index <- grep("^lon$", attr(data$Data, "dimensions"))
lat.index <- grep("^lat$", attr(data$Data, "dimensions"))
member.index <- grep("^member$", attr(data$Data, "dimensions"))
datesList <- as.POSIXct(data$Dates$start, tz="GMT", format="%Y-%m-%d %H:%M:%S")
times <- (as.double(datesList)-as.double(datesList[1]))/86400
dimtime <- ncdim_def( "time", paste0("days since ", data$Dates$start[1]), times, unlim=FALSE, calendar="gregorian", create_dimvar = TRUE)
dimlon <- ncdim_def( "lon", units="degrees_east", data$xyCoords$x, longname="longitude", create_dimvar = TRUE)
dimlat <- ncdim_def( "lat", units="degrees_north", data$xyCoords$y, longname="latitude", create_dimvar = TRUE)
if (length(member.index)>0){
dimens <- ncdim_def( "member", units="member", 0:(dim(data$Data)[member.index]-1), longname="realization", create_dimvar = TRUE)
perOrdered <- c(lon.index,lat.index,member.index,time.index)
dimOrdered <- list(dimlon,dimlat,dimens,dimtime)
}else{
perOrdered <- c(lon.index,lat.index,time.index)
dimOrdered <- list(dimlon,dimlat,dimtime)
}
dataOrdered <- aperm(data$Data, perOrdered)
var <- ncvar_def(data$Variable$varName, units=tmpUnits, dim=dimOrdered, missval, longname=tmpStdName, compression=compression, shuffle = shuffle)
ncnew <- nc_create(NetCDFOutFile, var )
ncatt_put(ncnew, "time", "standard_name","time")
ncatt_put(ncnew, "time", "axis","T")
ncatt_put(ncnew, "time", "_CoordinateAxisType","Time")
ncatt_put(ncnew, "time", "_ChunkSize",1)
ncatt_put(ncnew, "lon", "standard_name","longitude")
ncatt_put(ncnew, "lon", "_CoordinateAxisType","Lon")
ncatt_put(ncnew, "lat", "standard_name","latitude")
ncatt_put(ncnew, "lat", "_CoordinateAxisType","Lat")
if (length(member.index)>0){
ncatt_put(ncnew, "member", "standard_name","realization")
ncatt_put(ncnew, "member", "_CoordinateAxisType","Ensemble")
ncatt_put(ncnew, "member", "ref","http://www.uncertml.org/samples/realisation")
}
ncatt_put(ncnew, data$Variable$varName, "missing_value",missval)
for (v in 1:length(varAttributes)){
ncatt_put(ncnew, data$Variable$varName, names(varAttributes)[v],as.character(varAttributes[v]))
}
for (v in 1:length(globalAttributes)){
ncatt_put(ncnew, 0, names(globalAttributes)[v],as.character(globalAttributes[v]))
}
if (length(attr(data$Data, "correction"))>0){
ncatt_put(ncnew, 0, "product","Bias-Correction")
ncatt_put(ncnew, 0, "bc_method",attr(data$Data, "correction"))
}
if (length(attr(data, "dataset"))>0){
ncatt_put(ncnew, 0, "dataset",attr(data, "dataset"))
}
if (length(attr(data, "source"))>0){
ncatt_put(ncnew, 0, "source",attr(data, "source"))
}
ncatt_put(ncnew, 0, "description","NetCDF file created by downscaleR: https://github.com/SantanderMetGroup/downscaleR")
ncatt_put(ncnew, 0, "Conventions","CF-1.4")
ncvar_put(ncnew, var, dataOrdered )
nc_close(ncnew)
message(paste0("NetCDF file written: ", NetCDFOutFile))
grid2NetCDF <- function(data, NetCDFOutFile = "out.nc4", missval = 1e20, globalAttributes = NULL, varAttributes = NULL, prec = "float", compression=4, shuffle = TRUE) {
data(vocabulary)
ntime<-length(data$Dates$start)
tmpStdName<-as.character(vocabulary$standard_name[pmatch(vocabulary$identifier,data$Variable$varName, nomatch=0) > 0])
tmpUnits<-as.character(vocabulary$units[pmatch(vocabulary$identifier,data$Variable$varName, nomatch=0) > 0])
time.index <- grep("^time$", attr(data$Data, "dimensions"))
lon.index <- grep("^lon$", attr(data$Data, "dimensions"))
lat.index <- grep("^lat$", attr(data$Data, "dimensions"))
member.index <- grep("^member$", attr(data$Data, "dimensions"))
datesList <- as.POSIXct(data$Dates$start, tz="GMT", format="%Y-%m-%d %H:%M:%S")
times <- (as.double(datesList)-as.double(datesList[1]))/86400
dimtime <- ncdim_def( "time", paste0("days since ", data$Dates$start[1]), times, unlim=FALSE, calendar="gregorian", create_dimvar = TRUE)
dimlon <- ncdim_def( "lon", units="degrees_east", data$xyCoords$x, longname="longitude", create_dimvar = TRUE)
dimlat <- ncdim_def( "lat", units="degrees_north", data$xyCoords$y, longname="latitude", create_dimvar = TRUE)
if (length(member.index)>0){
dimens <- ncdim_def( "member", units="member", 0:(dim(data$Data)[member.index]-1), longname="realization", create_dimvar = TRUE)
perOrdered <- c(lon.index,lat.index,member.index,time.index)
dimOrdered <- list(dimlon,dimlat,dimens,dimtime)
}else{
perOrdered <- c(lon.index,lat.index,time.index)
dimOrdered <- list(dimlon,dimlat,dimtime)
}
dataOrdered <- aperm(data$Data, perOrdered)
var <- ncvar_def(data$Variable$varName, units=tmpUnits, dim=dimOrdered, missval, longname=tmpStdName, compression=compression, shuffle = shuffle)
ncnew <- nc_create(NetCDFOutFile, var )
ncatt_put(ncnew, "time", "standard_name","time")
ncatt_put(ncnew, "time", "axis","T")
ncatt_put(ncnew, "time", "_CoordinateAxisType","Time")
ncatt_put(ncnew, "time", "_ChunkSize",1)
ncatt_put(ncnew, "lon", "standard_name","longitude")
ncatt_put(ncnew, "lon", "_CoordinateAxisType","Lon")
ncatt_put(ncnew, "lat", "standard_name","latitude")
ncatt_put(ncnew, "lat", "_CoordinateAxisType","Lat")
if (length(member.index)>0){
ncatt_put(ncnew, "member", "standard_name","realization")
ncatt_put(ncnew, "member", "_CoordinateAxisType","Ensemble")
ncatt_put(ncnew, "member", "ref","http://www.uncertml.org/samples/realisation")
}
ncatt_put(ncnew, data$Variable$varName, "missing_value",missval)
for (v in 1:length(varAttributes)){
ncatt_put(ncnew, data$Variable$varName, names(varAttributes)[v],as.character(varAttributes[v]))
}
for (v in 1:length(globalAttributes)){
ncatt_put(ncnew, 0, names(globalAttributes)[v],as.character(globalAttributes[v]))
}
if (length(attr(data$Data, "correction"))>0){
ncatt_put(ncnew, 0, "product","Bias-Correction")
ncatt_put(ncnew, 0, "bc_method",attr(data$Data, "correction"))
}
if (length(attr(data, "dataset"))>0){
ncatt_put(ncnew, 0, "dataset",attr(data, "dataset"))
}
if (length(attr(data, "source"))>0){
ncatt_put(ncnew, 0, "source",attr(data, "source"))
}
ncatt_put(ncnew, 0, "description","NetCDF file created by downscaleR: https://github.com/SantanderMetGroup/downscaleR")
ncatt_put(ncnew, 0, "Conventions","CF-1.4")
ncvar_put(ncnew, var, dataOrdered )
nc_close(ncnew)
message(paste0("NetCDF file written: ", NetCDFOutFile))
}
3 changes: 2 additions & 1 deletion man/aggr6hToDailyMean.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/aggr6hToDailyMean.R
\name{aggr6hToDailyMean}
\alias{aggr6hToDailyMean}
\title{Performs the aggregation of 6 hourly data to daily mean}
Expand Down
3 changes: 2 additions & 1 deletion man/analogs.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/analogs.R
\name{analogs}
\alias{analogs}
\title{Analog downscaling}
Expand Down
3 changes: 2 additions & 1 deletion man/array3Dto2Dmat.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/array3Dto2Dmat.R
\name{array3Dto2Dmat}
\alias{array3Dto2Dmat}
\title{Conversion of a 3D array to a 2D matrix}
Expand Down
3 changes: 2 additions & 1 deletion man/biasCorrection.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/biasCorrection.R
\name{biasCorrection}
\alias{biasCorrection}
\title{Bias correction methods}
Expand Down
3 changes: 2 additions & 1 deletion man/bubbleValidation.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/bubbleValidation.R
\name{bubbleValidation}
\alias{bubbleValidation}
\title{Bubble plot for visualization of the skill of an ensemble forecast prediction}
Expand Down
3 changes: 2 additions & 1 deletion man/calibrateProj.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/biasCorrection.R
\name{calibrateProj}
\alias{calibrateProj}
\title{Bias correction methods}
Expand Down
3 changes: 2 additions & 1 deletion man/dataInventory.ASCII.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/dataInventory.R
\name{dataInventory.ASCII}
\alias{dataInventory.ASCII}
\title{Data inventory of standard ASCII station datasets}
Expand Down
3 changes: 2 additions & 1 deletion man/dataInventory.NetCDF.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/dataInventory.R
\name{dataInventory.NetCDF}
\alias{dataInventory.NetCDF}
\title{Inventory of a gridded dataset}
Expand Down
3 changes: 2 additions & 1 deletion man/dataInventory.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/dataInventory.R
\name{dataInventory}
\alias{dataInventory}
\title{Dataset inventory}
Expand Down
3 changes: 2 additions & 1 deletion man/dateReplacement.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/misc.R
\name{dateReplacement}
\alias{dateReplacement}
\title{Compute dates of a downscaled observational dataset}
Expand Down
3 changes: 2 additions & 1 deletion man/deaccum.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/deaccum.R
\name{deaccum}
\alias{deaccum}
\title{Performs deaccumulation}
Expand Down
3 changes: 2 additions & 1 deletion man/dictionaryLookup.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/dictionaryLookup.R
\name{dictionaryLookup}
\alias{dictionaryLookup}
\title{Searches variable string in the dictionary}
Expand Down
3 changes: 2 additions & 1 deletion man/dictionaryTransform.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/dictionaryTransform.R
\name{dictionaryTransform}
\alias{dictionaryTransform}
\title{Performs variable transformation}
Expand Down
3 changes: 2 additions & 1 deletion man/dictionaryTransformGrid.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/dictionaryTransformGrid.R
\name{dictionaryTransformGrid}
\alias{dictionaryTransformGrid}
\title{Performs variable transformation}
Expand Down
3 changes: 2 additions & 1 deletion man/fieldFromPCs.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/fieldFromPCs.R
\name{fieldFromPCs}
\alias{fieldFromPCs}
\title{Reconstruct a Field from EOFs and principal components}
Expand Down
3 changes: 2 additions & 1 deletion man/findPointXYindex.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/findPointXYindex.R
\name{findPointXYindex}
\alias{findPointXYindex}
\title{Define user-defined geolocation parameters}
Expand Down
3 changes: 2 additions & 1 deletion man/findVerticalLevel.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/findVerticalLevel.R
\name{findVerticalLevel}
\alias{findVerticalLevel}
\title{Finds vertical level from variable definition}
Expand Down
3 changes: 2 additions & 1 deletion man/getCoordinates.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/misc.R
\name{getCoordinates}
\alias{getCoordinates}
\title{Get geographical coordinates of a climate data object}
Expand Down
3 changes: 2 additions & 1 deletion man/getGrid.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/getGrid.R
\name{getGrid}
\alias{getGrid}
\title{Get regular grid definition}
Expand Down
3 changes: 2 additions & 1 deletion man/getLatLonDomain.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/getLatLonDomain.R
\name{getLatLonDomain}
\alias{getLatLonDomain}
\title{Determine the geo-location parameters of an arbitrary user selection}
Expand Down
3 changes: 2 additions & 1 deletion man/getLatLonDomainStations.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/getLatLonDomainStations.R
\name{getLatLonDomainStations}
\alias{getLatLonDomainStations}
\title{Define geolocation of station datasets}
Expand Down
3 changes: 2 additions & 1 deletion man/getSeason.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/misc.R
\name{getSeason}
\alias{getSeason}
\title{Get season from a station or field object}
Expand Down
3 changes: 2 additions & 1 deletion man/getTimeDomain.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/getTimeDomain.R
\name{getTimeDomain}
\alias{getTimeDomain}
\title{Selection of time slices of gridded datasets}
Expand Down
3 changes: 2 additions & 1 deletion man/getTimeDomainStations.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/getTimeDomainStations.R
\name{getTimeDomainStations}
\alias{getTimeDomainStations}
\title{Time index positions for station dataset selections}
Expand Down
3 changes: 2 additions & 1 deletion man/getVerticalLevelPars.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/getVerticalLevelPars.R
\name{getVerticalLevelPars}
\alias{getVerticalLevelPars}
\title{Definition of vertical dimension slices}
Expand Down
3 changes: 2 additions & 1 deletion man/getYearsAsINDEX.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
% Generated by roxygen2 (4.0.2): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/misc.R
\name{getYearsAsINDEX}
\alias{getYearsAsINDEX}
\title{Get years as a factor}
Expand Down
Loading

0 comments on commit 49d465d

Please sign in to comment.