Extract data from ERDDAP dataset by bounding box and/or polygon. This function provides the following enhancements to rerddap::griddap():

  1. 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.

  2. Mask the grids by Area of Interest (aoi) (using terra::mask()).

  3. Summarize grids over time by aoi, including sub-geometries, into a CSV (using terra::zonal()).

  4. 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,
  ...
)

Arguments

ed

ERDDAP info object, of class rerddap::info as returned by ed_info)

var

variable to extract

sf_zones

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.

bbox

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.

zonal_csv

output zonal statistics as CSV from terra::zonal(rast_tif, aoi)

zonal_fun

function to summarize the data over time by sf_zones. Default:

rast_tif

optional output as GeoTIFF masked to sf_zones from NetCDF

mask_tif

mask the GeoTIFF by sf_zones. Default: TRUE

dir_nc

optional output directory to keep NetCDF files written to disk by rerddap::griddap()

n_max_vals_per_req

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

fld_zones

character vector of unique field name(s) in sf_zones to include in extracted zonal statistics

Value

true if successful or false if unsuccessful #

Examples

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