This class is a basic ancestor to CFVariable and CFArray. It should not be instantiated directly, use the descendant classes instead.
This class provides access to common properties of data variables and the data they contain.
ncdfCF::CFObject -> CFVariableBase
axesList of instances of classes descending from CFAxis that
are the axes of the data object. If there are any scalar axes, they are
listed after the axes that associate with the dimensions of the data.
(In other words, axes 1..n describe the 1..n data dimensions, while
any axes n+1..m are scalar axes.)
crsThe coordinate reference system of this variable, as an
instance of CFGridMapping. If this field is NULL, the horizontal
component of the axes are in decimal degrees of longitude and latitude.
cell_measureThe CFCellMeasure object of this variable, if defined.
new()Create an instance of this class.
CFVariableBase$new(var, axes, crs)varThe NC variable that describes this data object.
axesA list of CFAxis descendant instances that describe the
axes of the data object.
crsThe CFGridMapping instance of this data object, or NULL
when no grid mapping is available.
An instance of this class.
time()Return the time object from the axis representing time.
CFVariableBase$time(want = "time")wantCharacter string with value "axis" or "time", indicating what is to be returned.
If want = "axis" the CFAxisTime axis; if want = "time" the
CFTime instance of the axis, or NULL if the variable does not have a
"time" axis.
summarise()Summarise the temporal domain of the data, if present, to a lower resolution, using a user-supplied aggregation function.
Attributes are copied from the input data variable or data array. Note
that after a summarisation the attributes may no longer be accurate.
This method tries to sanitise attributes (such as removing
scale_factor and add_offset, when present, as these will no longer
be appropriate in most cases) but the onus is on the calling code (or
yourself as interactive coder). Attributes like standard_name and
cell_methods likely require an update in the output of this method,
but the appropriate new values are not known to this method. Use
CFArray$set_attribute() on the result of this method to set or update
attributes as appropriate.
CFVariableBase$summarise(name, fun, period, era = NULL, ...)nameCharacter vector with a name for each of the results that
fun returns. So if fun has 2 return values, this should be a vector
of length 2. Any missing values are assigned a default name of
"result_#" (with '#' being replaced with an ordinal number).
funA function or a symbol or character string naming a function
that will be applied to each grouping of data. The function must return
an atomic value (such as sum() or mean()), or a vector of atomic
values (such as range()). Lists and other objects are not allowed and
will throw an error that may be cryptic as there is no way that this
method can assert that fun behaves properly so an error will pop up
somewhere, most probably in unexpected ways. The function may also be
user-defined so you could write a wrapper around a function like lm()
to return values like the intercept or any coefficients from the object
returned by calling that function.
periodThe period to summarise to. Must be one of either "day", "dekad", "month", "quarter", "season", "year". A "quarter" is the standard calendar quarter such as January-March, April-June, etc. A "season" is a meteorological season, such as December-February, March-May, etc. (any December data is from the year preceding the January data). The period must be of lower resolution than the resolution of the time axis.
eraOptional, integer vector of years to summarise over by the
specified period. The extreme values of the years will be used. This
can also be a list of multiple such vectors. The elements in the list,
if used, should have names as these will be used to label the results.
...Additional parameters passed on to fun.
A CFData object, or a list thereof with as many CFData
objects as fun returns values.
profile()This method extracts profiles of values from the array of the variable, with the location along each axis to extract expressed in coordinate values of each axis.
CFVariableBase$profile(..., .names = NULL, .as_table = FALSE)...One or more arguments of the form axis = location. The
"axis" part should be the name of an axis or its orientation X, Y,
Z or T. The "location" part is a vector of values representing
coordinates along the axis where to profile. A profile will be
generated for each of the elements of the "location" vectors in all
arguments.
.namesA character vector with names for the results. The names
will be used for the CFArray instances, or as values for the
"location" column of the data.table if argument .as_table is
TRUE. If the vector is shorter than the longest vector of locations
in the ... argument, a name "location_#" will be used, with the #
replaced by the ordinal number of the vector element.
.as_tableLogical to flag if the results should be CFArray
instances (FALSE, default) or a single data.table (TRUE). If
TRUE, all ... arguments must have the same number of elements, use
the same axes and the data.table package must be installed.
The coordinates along each axis to be sampled are expressed in
values of the domain of the axis. Any axes which are not passed as
arguments are extracted in whole to the result. If bounds are set on
the axis, the coordinate whose bounds envelop the requested coordinate
is selected. Otherwise, the coordinate along the axis closest to the
supplied value will be used. If the value for a specified axis falls
outside the valid range of that axis, NULL is returned.
A typical case is to extract the temporal profile as a 1D array for a
given location. In this case, use arguments for the latitude and
longitude on an X-Y-T data variable: profile(lat = -24, lon = 3).
Other profiling options are also possible, such as a 2D zonal
atmospheric profile at a given longitude for an X-Y-Z data variable:
profile(lon = 34).
Multiple profiles can be extracted in one call by supplying vectors for
the indicated axes: profile(lat = c(-24, -23, -2), lon = c(5, 5, 6)).
The vectors need not have the same length, unless .as_table = TRUE.
With unequal length vectors the result will be a list of CFArray
instances with different dimensionality and/or different axes.
A special case exists for variables where the horizontal dimensions (X
and Y) are not in longitude and latitude coordinates but in some other
coordinate system. In this case the netCDF resource may have so-called
auxiliary coordinate variables. If the data variable has such
auxiliary coordinate variables then they will be used automatically
if, and only if, the axes are specified as X and Y. Note that
if you want to profile the data in the original grid units, you should
specify the horizontal axis names.
If .as_table = FALSE, a CFArray instance, or a list thereof
with each having one profile for each of the elements in the "location"
vectors of argument ... and named with the respective .names value.
If .as_table = TRUE, a data.table with a row for each element along
all profiles, with a ".variable" column using the values from the
.names argument.
clone()The objects of this class are cloneable with this method.
CFVariableBase$clone(deep = FALSE)deepWhether to make a deep clone.