Extract data from ERDDAP dataset by bounding box and/or polygon. This function
provides the following enhancements to rerddap::griddap()
:
Throttle request to rerddap::griddap()
by chunks of time, so
the ERDDAP server does not become unresponsive with too big a request while
minimizing the number of requests.
Mask the grids by Area of Interest (aoi
) (using terra::mask()
).
Summarize grids over time by aoi
, including sub-geometries, into a CSV (using terra::zonal()
).
Preserve intermediary NetCDF and/or GeoTIFF files for raster visualization.
ed_extract(
ed,
var,
sf_zones = NULL,
bbox = NULL,
zonal_csv,
zonal_fun = "mean",
rast_tif = NULL,
mask_tif = TRUE,
dir_nc = NULL,
n_max_vals_per_req = 1e+05,
time_min = NULL,
time_max = NULL,
...
)
ERDDAP info object, of class rerddap::info
as returned by ed_info
)
variable to extract
spatial feature object (sf
) with zones to extract zonal
statistics from ERDDAP gridded data. If sf_zones
is left
to the default NULL
value, then the bbox
is used.
bounding box (e.g.,
c(xmin = -83.0, ymin = 27.3, xmax = -81.8, ymax= 28.5)
), used to extract
the grid (i.e., as longitude
and latitude
arguments to rerddap::griddap()
).
If bbox
is left to the default NULL
value, then the bounding box is derived from the bounding box of the
sf_zones
.
output zonal statistics as CSV from terra::zonal(rast_tif, aoi)
function to summarize the data over time by sf_zones
. Default:
optional output as GeoTIFF masked to sf_zones
from NetCDF
mask the GeoTIFF by sf_zones
. Default: TRUE
optional output directory to keep NetCDF files written to disk
by rerddap::griddap()
maximum number of values to request from ERDDAP server at a time. Default: 100,000
arguments to pass along to rerddap::griddap()
, such as to
filter the request by dimensions
character vector of unique field name(s) in sf_zones
to
include in extracted zonal statistics
true if successful or false if unsuccessful #
ed <- ed_info("https://coastwatch.pfeg.noaa.gov/erddap/griddap/jplMURSST41.html")
(vars <- ed_vars(ed))
#> variable_name data_type actual_range
#> 1 analysed_sst double
#> 2 analysis_error double
#> 3 mask byte
#> 4 sea_ice_fraction double
ed_extract(
ed,
"analysed_sst",
bbox = c(xmin = -83.0, ymin = 27.3, xmax = -81.8, ymax= 28.5))
#> Error in ed_extract(ed, "analysed_sst", bbox = c(xmin = -83, ymin = 27.3, xmax = -81.8, ymax = 28.5)): object 'fld_zones' not found