hyper_filter {tidync} | R Documentation |
Subset NetCDF variable by expression
Description
The hyper_filter()
acts on a tidync object by matching one or more
filtering expressions like with dplyr::filter
. This allows us to lazily
specify a subset from a NetCDF array without pulling any data. The modified
object may be printed to see the effects of subsetting, or saved for further
use.
Usage
hyper_filter(.x, ...)
## S3 method for class 'tidync'
hyper_filter(.x, ...)
Arguments
.x |
NetCDF file, connection object, or |
... |
currently ignored |
Details
The function hyper_filter()
will act on an existing tidync object or a
source string.
Filter arguments must be named as per the dimensions in the variable in form
dimname = dimname < 10
. This is a restrictive variant of dplyr::filter()
,
with a syntax more like dplyr::mutate()
. This ensures that each element is
named, so we know which dimension to apply this to, but also that the
expression evaluated against can do some extra work for a nuanced test.
There are special columns provided with each axis, one is 'index' so that
exact matching can be done by position, or to ignore the actual value of the
coordinate. That means we can use a form like dimname = index < 10
to
subset by position in the array index, without necessarily knowing the
values along that dimension.
Value
data frame
Examples
f <- "S20080012008031.L3m_MO_CHL_chlor_a_9km.nc"
l3file <- system.file("extdata/oceandata", f, package= "tidync")
## filter by value
tidync(l3file) %>% hyper_filter(lon = lon < 100)
## filter by index
tidync(l3file) %>% hyper_filter(lon = index < 100)
## be careful that multiple comparisons must occur in one expression
tidync(l3file) %>% hyper_filter(lon = lon < 100 & lon > 50)
## filter in combination/s
tidync(l3file) %>% hyper_filter(lat = abs(lat) < 10, lon = index < 100)