A function to import a variable from a generic raster file, including datasets with more than one time deadline.
Usage
importRaster(
file = file.choose(),
k = 1,
kz = 1,
dx = 0,
dy = 0,
destaggering = FALSE,
variable = NULL,
level = NULL,
verbose = FALSE
)Arguments
- file
character. Path to the raster file.
- k
numeric. Factor applied to x and y coordinates (default = 1). For example, it can be used to convert the grid coordinates from km to m (k = 1000).
- kz
numeric. Factor applied to the variable values (default = 1).
- dx, dy
numeric. Constant to shift x and y coordinates (default = 0).
- destaggering
Use
TRUEto apply destaggering to X and Y coordinates (default = FALSE). See theDetailssection.- variable
character. The name of the variable to be imported. If missing, the function stops with an error message printing the list of available variables.
- level
numeric. Vertical level to import for variables with more than one level. If missing, the function stops with an error message printing the list of available vertical levels.
- verbose
logical. If
TRUE, prints out basic statistics (default = FALSE).
Value
A data.frame with x, y and z columns for the grid cells coordinates
and the variable value. If the raster has more than one time deadline, the columns are
x, y, variable, z, time where variable is the layer name and z is the cell value.
Details
This function is based on the terra package and it can import any format managed by it, such as NetCDF.
Destaggering applies a shift equal to half grid size in both horizontal directions. It is useful for importing data from the SPRAY air quality dispersion model and it is not applied by default.
An optional summary output can be printed out by setting the verbose parameter
to TRUE. For datasets with time deadlines, statistics are printed for each time step.
Examples
if (FALSE) { # \dontrun{
# Import binary (netcdf) file and convert coordinates from km to m,
# without destaggering. Variable name is "NOx".
mydata <- importRaster(
file = "/path_to_file/filename.nc",
variable = "NOx",
k = 1000,
destaggering = FALSE
)
# Select wind speed at 10m height
mydata <- importRaster(
file = "/path_to_file/filename.nc",
variable = "ws",
level = 10
)
# Import binary (netcdf) file and convert coordinates from km to m,
# with shift of 100 m in both directions:
mydata <- importRaster(
file = "/path_tofile/filename.nc",
variable = "pm10",
k = 1000,
dx = 100,
dy = 100
)
} # }
