This function reads a set of NetCDF files (one per variable) and extracts data for a set of NetCDF cells that are specified using a boundary box (in lon/lat format) or a set of (x,y) grid indices.
extractNetCDF(ncdf_files, bbox = NULL, offset = 0, cells = NULL, export = TRUE,
exportDir = getwd(), exportFormat = "meteoland/txt", mpfilename = "MP.txt")
Character vector containing files to read
Boundary box (2 x 2 matrix) specifying the limit coordinates of a study area (in lon/lat format).
A buffer to include NetCDF cells that are at a certain distance around the boundary box.
A (n x 2) matrix specifying the x and y indices of n cells in a grid.
If export = FALSE
the extracted data is stored in memory. Otherwise the result is written in the disk (using the format specified in exportFormat
).
Export format for meteorological data (see writemeteorologypoint
).
Output directory for extracted meteorology.
The name of the file that will store the meta data describing all written files.
If export = FALSE
, the function returns an object of class SpatialPointsMeteorology-class
with the meteorological series for each cell (represented by a spatial point). Otherwise the function returns an object of class SpatialPointsDataFrame-class
containing the meta data of the files written in the disk.
Function extractNetCDF
first identifies which cells in NetCDF data should be extracted according to bbox
(or the cells are indicated by the user using cells
), and the overall period (days). If neither bbox
or cells
is supplied, then all NetCDF cells will be processed. For each cell to be processed, the function loops over all files (which can describe different variables and time periods) and extracts the corresponding data. The function transforms units to the units used in meteoland
. If specific humidity and mean temperature are available, the function calculates mean relative humidity.
Extracted meteorological data (a data frame with days in rows and meteorological variables in columns) can be stored in an object SpatialPointsMeteorology-class
or it can be written in the disk (one file per cell). In the latter case, the output format can be chosen and the function also writes a supplementary file containing the meta data (i.e. the coordinates and filename of each file).
Humidity in climate model files is given as specific humidity. This is converted to relative humidity and the conversion may produce values above saturation (>100%) (see also defaultCorrectionParams
for the same issue when performing bias correction).
correctionpoints
, writemeteorologypointfiles
, SpatialPointsMeteorology-class