openAndMatchNcdfData: Extract NetCDF data

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Extract NetCDF data

Usage

1
2
openAndMatchNcdfData(filePath, method = c("ncdf4", "raster"), dayFilter,
  coordinates, ...)

Arguments

filePath

A path to a NetCDF file.

method

Method (package) of extraction. Currently supports either ncdf4 or raster. See Details below.

dayFilter

Optional. A vector containing Date objects with dates of interest.

coordinates

Optional, only used if method is raster. A data.frame containing columns Longitude and Latitude (in this order) indicating the coordinates of interest.

...

Additional arguments to extract (used internally).

Details

Method ncdf4 uses the package to extract all layers using all coordinates. Method raster allows the user to specify arguments to the raster function extract together with a table of coordinates of interest.

Value

An array (longitude, latitude, time) containing variable of interest.

Author(s)

Diego Barneche.

See Also

noaaErddapFiles.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
library(noaaErddap)
library(plyr)

nppFiles  <-  noaaErddapFiles('productivity', full.name = TRUE)

# extract NPP values for a given subset of coordinates (median value within a buffer of 20 km) across all files and take the mean
nppValues  <-  abind::abind(lapply(nppFiles, openAndMatchNcdfData, method = 'raster', coordinates = data.frame(Longitude = c(330, 335, 340), #' Latitude = c(-27, -19, 0)), buffer = 2e4, fun = median, na.rm = TRUE), along = 3)
apply(nppValues, c(1, 2), mean, na.rm = TRUE)

# extract the average NPP values for the globe in 1998
nppValues1998  <-  abind::abind(lapply(nppFiles[grep('-1998.nc', nppFiles, fixed = TRUE)], openAndMatchNcdfData, method = 'ncdf4'), along = 3)
meanNPP1998    <-  apply(nppValues1998, c(1, 2), mean, na.rm = TRUE)

dbarneche/noaaErddap documentation built on May 16, 2020, 11:37 a.m.