rotpole_nc_point_to_dt {eurocordexr} | R Documentation |
Extract time series of a single grid cell of a rot-pole daily netcdf to data.table
Description
Creates a data.table
from a rotated pole netcdf (as
usually found in RCMs), which includes values and date. Useful for extracting
e.g. the series for a station. Requires that dimension variables in netcdf
file contain rlon and rlat, and that it contains daily data.
Usage
rotpole_nc_point_to_dt(
filename,
variable,
point_lon,
point_lat,
interpolate_to_standard_calendar = FALSE,
verbose = FALSE,
add_grid_coord = FALSE
)
Arguments
filename |
Complete path to .nc file. |
variable |
Name of the variable to extract from |
point_lon |
Numeric longitude of the point to extract (decimal degrees). |
point_lat |
Numeric latitude of the point to extract (decimal degrees). |
interpolate_to_standard_calendar |
Boolean, if |
verbose |
Boolean, if |
add_grid_coord |
Boolean, if |
Details
Calculates the euclidean distance, and takes the grid cell with minimal
distance to point_lon
and point_lat
. Requires that the .nc file
contains variables lon[rlon, rlat] and lat[rlon, rlat].
Value
A data.table
with two columns: the dates in
date, and the values in a variable named after input variable
. The
date column is of class Date
, unless the .nc
file has a non-standard calendar (360, noleap) and
interpolate_to_standard_calendar
is set to FALSE
, in which it
will be character. If add_grid_coord
is set to TRUE
, then
two more columns named grid_lon and grid_lat.
Examples
# example data from EURO-CORDEX (cropped for size)
# standard calendar
fn1 <- system.file("extdata", "test1.nc", package = "eurocordexr")
dt1 <- rotpole_nc_point_to_dt(
filename = fn1,
variable = "tasmin",
point_lon = 11.31,
point_lat = 46.5,
verbose = TRUE
)
# non-standard calendar (360)
fn2 <- system.file("extdata", "test2.nc", package = "eurocordexr")
# read as is
dt2 <- rotpole_nc_point_to_dt(fn2, "tasmin", 11.31, 46.5)
str(dt2) # chr date
dt2[86:94, ] # e.g. 30th of February in 360 calendar
# interpolate to standard
dt3 <- rotpole_nc_point_to_dt(fn2, "tasmin", 11.31, 46.5,
interpolate_to_standard_calendar = TRUE)
str(dt3) # class Date
dt3[86:94, ] # standard calender