| Title: | Easy Access to NetCDF Files with CF Metadata Conventions |
|---|---|
| Description: | Network Common Data Form ('netCDF') files are widely used for scientific data. Library-level access in R is provided through packages 'RNetCDF' and 'ncdf4'. Package 'ncdfCF' is built on top of 'RNetCDF' and makes the data and its attributes available as a set of R6 classes that are informed by the Climate and Forecasting Metadata Conventions. Access to the data uses standard R subsetting operators and common function forms. |
| Authors: | Patrick Van Laake [aut, cre, cph] |
| Maintainer: | Patrick Van Laake <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.8.2.9000 |
| Built: | 2026-06-07 16:15:22 UTC |
| Source: | https://github.com/r-cf/ncdfcf |
Extract data from a CFVariable instance, optionally sub-setting the
axes to load only data of interest.
## S3 method for class 'CFVariable' x[i, j, ..., drop = FALSE]## S3 method for class 'CFVariable' x[i, j, ..., drop = FALSE]
x |
An |
i, j, ...
|
Expressions, one for each axis of |
drop |
Logical, ignored. Axes are never dropped. Any degenerate dimensions of the array are returned as such, with dimnames and appropriate attributes set. |
If all the data of the variable in x is to be extracted, simply use []
(unlike with regular arrays, this is required, otherwise the details of the
variable are printed on the console).
The indices into the axes to be subset can be specified in a variety of
ways; in practice it should (resolve to) be a vector of integers. A range
(e.g. 100:200), an explicit vector (c(23, 46, 3, 45, 17), a sequence
(seq(from = 78, to = 100, by = 2), all work. Note, however, that only a
single range is generated from the vector so these examples resolve to
100:200, 3:46, and 78:100, respectively. It is also possible to use a
custom function as an argument.
This method works with "bare" indices into the axes of the array. If
you want to use domain values of the axes (e.g. longitude values or
timestamps) to extract part of the variable array, use the
CFVariable$subset() method.
Scalar axes should not be included in the indexing as they do not represent a dimension into the data array.
An array with dimnames and other attributes set.
fn <- system.file("extdata", "pr_day_EC-Earth3-CC_ssp245_r1i1p1f1_gr_20230101-20231231_vncdfCF.nc", package = "ncdfCF") ds <- open_ncdf(fn) pr <- ds[["pr"]] # How are the dimensions organized? dimnames(pr) # Precipitation data for March for a single location x <- pr[5, 12, 61:91] str(x) # Summer precipitation over the full spatial extent summer <- pr[, , 173:263] str(summer)fn <- system.file("extdata", "pr_day_EC-Earth3-CC_ssp245_r1i1p1f1_gr_20230101-20231231_vncdfCF.nc", package = "ncdfCF") ds <- open_ncdf(fn) pr <- ds[["pr"]] # How are the dimensions organized? dimnames(pr) # Precipitation data for March for a single location x <- pr[5, 12, 61:91] str(x) # Summer precipitation over the full spatial extent summer <- pr[, , 173:263] str(summer)
Extract data from a CFVariableL3b instance, optionally sub-setting the
axes to load only data of interest.
## S3 method for class 'CFVariableL3b' x[i, j, ..., drop = FALSE]## S3 method for class 'CFVariableL3b' x[i, j, ..., drop = FALSE]
x |
An |
i, j, ...
|
Expressions, one for each of the two axes of |
drop |
Logical, ignored. Axes are never dropped. Any degenerate dimensions of the array are returned as such, with dimnames and appropriate attributes set. |
If all the data of the variable in x is to be extracted, simply use []
(unlike with regular arrays, this is required, otherwise the details of the
variable are printed on the console).
The indices into the axes to be subset can be specified in a variety of
ways; in practice it should (resolve to) be a vector of integers. A range
(e.g. 100:200), an explicit vector (c(23, 46, 3, 45, 17), a sequence
(seq(from = 78, to = 100, by = 2), all work. Note, however, that only a
single range is generated from the vector so these examples resolve to
100:200, 3:46, and 78:100, respectively. It is also possible to use a
custom function as an argument.
This method works with "bare" indices into the axes of the array. If
you want to use domain values of the axes (e.g. longitude values or
timestamps) to extract part of the variable array, use the
CFVariableL3b$subset() method.
Scalar axes should not be included in the indexing as they do not represent a dimension into the data array.
An array with dimnames and other attributes set.
fn <- system.file("extdata", "pr_day_EC-Earth3-CC_ssp245_r1i1p1f1_gr_20230101-20231231_vncdfCF.nc", package = "ncdfCF") ds <- open_ncdf(fn) pr <- ds[["pr"]] # How are the dimensions organized? dimnames(pr) # Precipitation data for March for a single location x <- pr[5, 12, 61:91] str(x) # Summer precipitation over the full spatial extent summer <- pr[, , 173:263] str(summer)fn <- system.file("extdata", "pr_day_EC-Earth3-CC_ssp245_r1i1p1f1_gr_20230101-20231231_vncdfCF.nc", package = "ncdfCF") ds <- open_ncdf(fn) pr <- ds[["pr"]] # How are the dimensions organized? dimnames(pr) # Precipitation data for March for a single location x <- pr[5, 12, 61:91] str(x) # Summer precipitation over the full spatial extent summer <- pr[, , 173:263] str(summer)
This method can be used to retrieve a variable or axis from the data set by name.
## S3 method for class 'CFDataset' x[[i]]## S3 method for class 'CFDataset' x[[i]]
x |
An |
i |
The name of a variable or axis in |
If the data set has groups, the name i of the variable or axis should be
fully qualified with the path to the group where the object is located. This
fully qualified name can be retrieved with the names() and dimnames()
functions, respectively.
An instance of CFVariable or an CFAxis descendant class, or
NULL if the name is not found.
fn <- system.file("extdata", "ERA5land_Rwanda_20160101.nc", package = "ncdfCF") ds <- open_ncdf(fn) v1 <- ds$var_names[1] var <- ds[[v1]] varfn <- system.file("extdata", "ERA5land_Rwanda_20160101.nc", package = "ncdfCF") ds <- open_ncdf(fn) v1 <- ds$var_names[1] var <- ds[[v1]] var
This function constructs the area of interest of an analysis. It consists of an extent and a resolution of longitude and latitude, all in decimal degrees.
The AOI is used to define the subset of data to be extracted from a data variable that has an auxiliary longitude-latitude grid (see the CFAuxiliaryLongLat class) at a specified resolution. The data variable thus has a primary coordinate system where the horizontal components are not a geographic system of longitude and latitude coordinates.
aoi(lonMin, lonMax, latMin, latMax, resX, resY)aoi(lonMin, lonMax, latMin, latMax, resX, resY)
lonMin, lonMax, latMin, latMax
|
The minimum and maximum values of the
longitude and latitude of the AOI, in decimal degrees. The longitude values
must agree with the range of the longitude in the data variable to which
this AOI will be applied, e.g. |
resX, resY
|
The separation between adjacent grid cell, in the longitude
and latitude directions respectively, in decimal degrees. The recommended
values lie within the range |
Following the CF Metadata Conventions, axis coordinates represent
the center of grid cells. So when specifying aoi(20, 30, -10, 10, 1, 2),
the south-west grid cell coordinate is at (20.5, -9). If the axes of the
longitude-latitude grid have bounds, then the bounds will coincide with the
AOI and the CFVariable$subset() method that uses the AOI will attach
those bounds as attributes to the resulting array.
If no resolution is specified, it will be determined from the separation
between adjacent grid cells in both longitude and latitude directions in
the middle of the area of interest. If no extent is specified (meaning,
none of the values; if some but not all values are specified an error will
be thrown), then the whole extent of the variable is used, extended
outwards by the bounds if they are set or half the resolution otherwise.
Thus, to get the entire extent of the variable but in a longitude-latitude
grid and with a resolution comparable to the resolution at the original
Cartesian coordinate system of the variable, simply pass aoi() as an
argument to CFVariable$subset(). Note that any missing
arguments are calculated internally and stored in the returned object, but
only after the call to CFVariable$subset().
In data collections that are composed of multiple data variables in a
single netCDF resource, a single auxiliary longitude-latitude grid may be
referenced by multiple data variables, such as in
ROMS data which may have dozens of data variables
using a shared grid. When subsetting with an AOI, the instance of this
class is cached to improve performance. The successive calls to
CFVariable$subset() should use the same object returned from a single
call to this function for this caching to work properly.
The return value of the function is an R6 object which uses
reference semantics. Making changes to the returned object will be visible
in all copies made of the object.
(aoi <- aoi(20, 60, -40, -20, 0.5))(aoi <- aoi(20, 60, -40, -20, 0.5))
CFDataset or CFVariable instance from an R objectWith this function you can convert an R object into a CFDataset or
CFVariable, depending on the characteristics of the argument obj. The
object to convert can be an array, matrix or vector of type logical,
integer, numeric or character, or a terra::SpatRaster.
as_CF(name, obj) ## Default S3 method: as_CF(name, obj) ## S3 method for class 'SpatRaster' as_CF(name, obj)as_CF(name, obj) ## Default S3 method: as_CF(name, obj) ## S3 method for class 'SpatRaster' as_CF(name, obj)
name |
The name of the |
obj |
The object to convert. This can be an array, matrix or vector of
type |
Dimnames on the R object will be converted to instances of a CFAxis
descendant class, depending on their values. If the dimnames along a
dimension of the R object can be converted to numeric, then it will be an
instance of CFAxisNumeric. If the dimnames are character, a first attempt
is made to create a CFAxisTime (i.e. the dimnames have to represent
timestamps), failing that a CFAxisCharacter will be created. If no dimnames
are set, an instance of CFAxisDiscrete is generated.
The axes of the CFVariable instance(s) are oriented as in the object. Note
that this is different from standard practice in the netCDF community and the
portability of saved data sets is thus limited. You can improve this
situation by setting the orientation of the axes and by adding attributes.
After creation of the CFDataset or CFVariable, it is recommended to set
other properties, such as attributes or a coordinate reference system.
An instance of class CFDataset or CFVariable.
This class represents the longitude and latitude variables that compose auxiliary coordinate variable axes for X-Y grids that are not longitude-latitude.
The class provides access to the data arrays for longitude and latitude from the netCDF resource, as well as all the details that have been associated with both axes. Additionally, this class can generate the index to extract values on a long-lat grid of the associated X-Y grid data variable using a user-selectable extent and resolution.
Auxiliary longitude-latitude grids are only supported for reading from a netCDF resource. Creating an instance of this class manually therefore has no practical purpose.
friendlyClassName(read-only) A nice description of the class.
name(read-only) The name of the auxiliary lon-lat grid.
grid_names(read-only) Read the names of the longitude and latitude grid as a vector of length 2.
dimids(read-only) Retrieve the dimension ids used by the longitude and latitude grids.
aoiSet or retrieve the AOI for the long-lat grid.
lon(read-only) Retrieve the longitude grid.
lat(read-only) Retrieve the latitude grid.
lon_bounds(read-only) Retrieve the boundary values of the longitude grid.
lat_bounds(read-only) Retrieve the boundary values of the latitude grid.
extent(read-only) Retrieve the extent of the longitude and latitude grids, including bounds if they have been set. The extent is reported as a numeric vector of the four elements minimum and maximum longitude and minimum and maximum latitude.
dim(read-only) The dimensions of the longitude and latitude grids.
new()
Creating a new instance. It should normally not be useful to create an instance of this class other than upon reading a netCDF resource.
CFAuxiliaryLongLat$new(varLong, varLat, boundsLong = NULL, boundsLat = NULL)
varLong, varLatThe CFVariable instances with the longitude and latitude grid values, respectively.
boundsLong, boundsLatThe CFBounds instances of the grid cells
for the longitude and latitude, respectively, if set. Defaults to
NULL.
print()
Summary of the auxiliary longitude-latitude variable printed to the console.
CFAuxiliaryLongLat$print()
brief()
Some details of the auxiliary longitude-latitude grid.
CFAuxiliaryLongLat$brief()
A 2-row data.frame with some details of the grid components.
sample_index()
Return the indexes into the X (longitude) and Y (latitude) axes of the original data grid of the points closest to the supplied longitudes and latitudes, up to a maximum distance.
CFAuxiliaryLongLat$sample_index(x, y, maxDist = NULL)
x, yVectors of longitude and latitude values in decimal degrees, respectively.
maxDistNumeric value in decimal degrees of the maximum distance between the sampling point and the closest grid cell. If omitted (default), the distance is calculated from the nominal resolution of the grids.
A matrix with two columns X and Y and as many rows as
arguments x and y. The X and Y columns give the index into the
grid of the sampling points, or c(NA, NA) is no grid point is located
within the maxDist distance from the sampling point.
grid_index()
Compute the indices for the AOI into the data grid.
CFAuxiliaryLongLat$grid_index()
An integer matrix with the dimensions of the AOI, where each grid cell gives the linear index value into the longitude and latitude grids.
clear_cache()
Clears the cache of pre-computed grid index values if an AOI has been set.
CFAuxiliaryLongLat$clear_cache()
attach_to_group()
Attach the auxiliary long-lat grids and any bounds to a group. If there is another object with the same name in this group an error is thrown.
CFAuxiliaryLongLat$attach_to_group(grp, locations = list())
grpAn instance of CFGroup.
locationsOptional. A list whose named elements correspond to
the names of objects associated with these auxiliary grids. Each list
element has a single character string indicating the group in the
hierarchy where the object should be stored. As an example, if the
variable has axes "lon" and "lat" and they should be stored in the
parent group of grp, then specify locations = list(lon = "..", lat = ".."). Locations can use absolute paths or relative paths from group
grp. The auxiliary grids and bounds that are not in the list will be
stored in group grp. If the argument locations is not provided, all
objects will be stored in this group.
Self, invisibly.
detach()
Detach the latitude and longitude from an underlying netCDF resource.
CFAuxiliaryLongLat$detach()
Self, invisibly.
clone()
The objects of this class are cloneable with this method.
CFAuxiliaryLongLat$clone(deep = FALSE)
deepWhether to make a deep clone.
This class is a basic ancestor to all classes that represent CF axes. More useful classes use this class as ancestor.
This super-class does manage the "coordinates" of the axis, i.e. the values along the axis. This could be the values of the axis as stored on file, but it can also be the values from an auxiliary coordinate set, in the form of a CFLabel instance. The coordinate set to use in display, selection and processing is selectable through methods and fields in this class.
ncdfCF::CFObject -> ncdfCF::CFData -> CFAxis
friendlyClassName(read-only) A nice description of the class.
dimidThe netCDF dimension id of this axis. Setting this value to anything other than the correct value will lead to disaster.
length(read-only) The declared length of this axis.
orientationSet or retrieve the orientation of the axis, a single character with a value of "X", "Y", "Z", "T". Setting the orientation of the axis should only be done when the current orientation is unknown. Setting a wrong value may give unexpected errors in processing of data variables.
values(read-only) Retrieve the raw values of the axis. In general
you should use the coordinates field rather than this one.
coordinates(read-only) Retrieve the coordinate values of the active coordinate set from the axis.
boundsSet or retrieve the bounds of this axis as a CFBounds object. When setting the bounds, the bounds values must agree with the coordinates of this axis.
auxiliarySet or retrieve auxiliary coordinates for the axis. On
assignment, the value must be an instance of CFLabel or a CFAxis
descendant, which is added to the end of the list of coordinate sets.
On retrieval, the active CFLabel or CFAxis instance or NULL when
the active coordinate set is the primary axis coordinates.
coordinate_names(read-only) Retrieve the names of the coordinate sets defined for the axis, as a character vector. The first element in the vector is the name of the axis and it refers to the values of the coordinates of this axis. Following elements refer to auxiliary coordinates.
coordinate_range(read-only) Retrieve the range of the coordinates of the axis as a vector of two values. The mode of the result depends on the sub-type of the axis.
active_coordinatesSet or retrieve the name of the coordinate set
to use with the axis for printing to the console as well as for
processing methods such as subset().
unlimitedLogical to indicate if the axis is unlimited. The setting can only be changed if the axis has not yet been written to file.
time(read-only) Retrieve the CFTime object associated with the
axis. Always returns NULL but CFAxisTime overrides this field.
is_parametric(read-only) Logical flag that indicates if the axis
has parametric coordinates. Always FALSE for all axes except for
CFAxisVertical which overrides this method.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()new()
Create a new CF axis instance from a dimension and a
variable in a netCDF resource. This method is called upon opening a
netCDF resource by the initialize() method of a descendant class
suitable for the type of axis.
Creating a new axis is more easily done with the makeAxis() function.
CFAxis$new( var, group, values, start = 1L, count = NA, orientation = "", attributes = data.frame() )
varThe name of the axis when creating a new axis. When reading an axis from file, the NCVariable object that describes this instance.
groupThe CFGroup that this instance will live in.
valuesOptional. The values of the axis in a vector. Ignored when
argument var is a NCVariable object.
startOptional. Integer index where to start reading axis data
from file. The index may be NA to start reading data from the start.
countOptional. Number of elements to read from file. This may be
NA to read to the end of the data.
orientationOptional. The orientation of the axis: "X", "Y", "Z" "T", or "" (default) when not known or relevant.
attributesOptional. A data.frame with the attributes of the
axis. When an empty data.frame (default) and argument var is an
NCVariable instance, attributes of the axis will be taken from the
netCDF resource.
A basic CFAxis object.
print()
Prints a summary of the axis to the console. This method is
typically called by the print() method of descendant classes.
CFAxis$print(...)
...Arguments passed on to other functions. Of particular interest
is width = to indicate a maximum width of attribute columns.
self, invisibly.
brief()
Some details of the axis.
CFAxis$brief()
A 1-row data.frame with some details of the axis.
shard()
Very concise information on the axis. The information returned by this function is very concise and most useful when combined with similar information from other axes.
CFAxis$shard()
Character string with very basic axis information.
peek()
Retrieve interesting details of the axis.
CFAxis$peek()
A 1-row data.frame with details of the axis.
detach()
Detach the axis from its underlying netCDF resource, including any dependent CF objects.
CFAxis$detach()
Self, invisibly.
copy_terms()
Copy the parametric terms of a vertical axis. This method is
only useful for CFAxisVertical instances having a parametric
formulation. This stub is here to make the call to this method succeed
with no result for the other descendant classes.
CFAxis$copy_terms(from, original_axes, new_axes)
fromA CFAxisVertical instance that will receive references to the parametric terms.
original_axesList of CFAxis instances from the CF object that
these parametric terms are copied from.
new_axesList of CFAxis instances to use with the formula term
objects.
NULL
configure_terms()
Configure the function terms of a parametric vertical axis.
This method is only useful for CFAxisVertical instances having a
parametric formulation. This stub is here to make the call to this
method succeed with no result for the other descendant classes.
CFAxis$configure_terms(axes)
axesList of CFAxis instances.
NULL
identical()
Tests if the axis passed to this method is identical to
self. This only tests for generic properties - class, length, name
and attributes - with further assessment done in sub-classes.
CFAxis$identical(axis, with_attributes = FALSE)
axisThe CFAxis instance to test.
with_attributesLogical that indicates if the attributes are
assessed for equality too. Default is FALSE.
TRUE if the two axes are identical, FALSE if not.
can_append()
Tests if the axis passed to this method can be appended to
self. This only tests for generic properties - class, mode of the
values and name - with further assessment done in sub-classes.
CFAxis$can_append(axis)
axisThe CFAxis descendant instance to test.
TRUE if the passed axis can be appended to self, FALSE if
not.
copy()
Create a copy of this axis. This method is "virtual" in the
sense that it does not do anything other than return NULL. This stub
is here to make the call to this method succeed with no result for the
CFAxis descendants that do not implement this method.
CFAxis$copy(name = "", group)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
NULL
copy_with_values()
Create a copy of this axis but using the supplied values.
This method is "virtual" in the sense that it does not do anything
other than return NULL. This stub is here to make the call to this
method succeed with no result for the CFAxis descendants that do not
implement this method.
CFAxis$copy_with_values(name = "", group, values)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
valuesThe values to the used with the copy of this axis.
NULL
subset()
Return an axis spanning a smaller coordinate range. This
method is "virtual" in the sense that it does not do anything other
than return self. This stub is here to make the call to this method
succeed with no result for the CFAxis descendants that do not
implement this method.
CFAxis$subset(name = "", group, rng = NULL)
nameThe name for the new axis if the rng argument is provided.
groupThe CFGroup where the copy of this axis will live.
rngThe range of indices whose values from this axis to include in
the returned axis. If the value of the argument is NULL, return a
copy of the axis.
NULL
indexOf()
Find indices in the axis domain. Given a vector of
numerical, timestamp or categorical coordinates x, find their indices
in the coordinates of the axis.
This is a virtual method. For more detail, see the corresponding method in descendant classes.
CFAxis$indexOf(x, method = "constant", rightmost.closed = TRUE)
xVector of numeric, timestamp or categorial coordinates to find axis indices for. The timestamps can be either character, POSIXct or Date vectors. The type of the vector has to correspond to the type of the axis values.
methodSingle character value of "constant" or "linear".
rightmost.closedWhether or not to include the upper limit.
Default is TRUE.
Numeric vector of the same length as x.
attach_to_group()
Attach this axis to a group. If there is another object with the same name in this group an error is thrown. For associated objects (such as bounds, etc), if another object with the same name is otherwise identical to the associated object then that object will be linked from the variable, otherwise an error is thrown.
CFAxis$attach_to_group(grp, locations = list())
grpAn instance of CFGroup.
locationsOptional. A list whose named elements correspond to
the names of objects associated with this axis, possibly including the
axis itself. Each list element has a single character string indicating
the group in the hierarchy where the object should be stored. As an
example, if the variable has axes "lon" and "lat" and they should be
stored in the parent group of grp, then specify locations = list(lon = "..", lat = ".."). Locations can use absolute paths or relative
paths from group grp. The axis and associated objects that are not in
the list will be stored in group grp. If the argument locations is
not provided, all associated objects will be stored in this group.
Self, invisibly.
write()
Write the axis to a netCDF file, including its attributes.
CFAxis$write()
Self, invisibly.
This class represent CF axes that use categorical character labels as coordinate values. Note that this is different from a CFLabel, which is associated with an axis but not an axis itself.
This is an extension to the CF Metadata Conventions. As per CF, axes are required to have numerical values, which is relaxed here.
ncdfCF::CFObject -> ncdfCF::CFData -> ncdfCF::CFAxis -> CFAxisCharacter
friendlyClassName(read-only) A nice description of the class.
dimnames(read-only) The coordinates of the axis as a character vector.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()ncdfCF::CFAxis$attach_to_group()ncdfCF::CFAxis$can_append()ncdfCF::CFAxis$configure_terms()ncdfCF::CFAxis$copy_terms()ncdfCF::CFAxis$detach()ncdfCF::CFAxis$peek()ncdfCF::CFAxis$print()ncdfCF::CFAxis$shard()ncdfCF::CFAxis$write()new()
Create a new instance of this class.
Creating a new character axis is more easily done with the
makeCharacterAxis() function.
CFAxisCharacter$new( var, group, values, start = 1L, count = NA, attributes = data.frame() )
varThe name of the axis when creating a new axis. When reading an axis from file, the NCVariable object that describes this instance.
groupThe CFGroup that this instance will live in.
valuesOptional. The values of the axis in a vector. These must be
character values. Ignored when argument var is a NCVariable object.
startOptional. Integer index where to start reading axis data
from file. The index may be NA to start reading data from the start.
countOptional. Number of elements to read from file. This may be
NA to read to the end of the data.
attributesOptional. A data.frame with the attributes of the
axis. When an empty data.frame (default) and argument var is an
NCVariable instance, attributes of the axis will be taken from the
netCDF resource.
brief()
Some details of the axis.
CFAxisCharacter$brief()
A 1-row data.frame with some details of the axis.
copy()
Create a copy of this axis. The copy is completely separate from this axis, meaning that the new axis and all of its components are made from new instances. If this axis is backed by a netCDF resource, the copy will retain the reference to the resource.
CFAxisCharacter$copy(name = "", group)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
The newly created axis.
copy_with_values()
Create a copy of this axis but using the supplied values. The attributes are copied to the new axis. Boundary values and auxiliary coordinates are not copied.
After this operation the attributes of the newly created axes may not be accurate, except for the "actual_range" attribute. The calling code should set, modify or delete attributes as appropriate.
CFAxisCharacter$copy_with_values(name = "", group, values)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
valuesThe values to the used with the copy of this axis.
The newly created axis.
slice()
Given a range of domain coordinate values, returns the indices into the axis that fall within the supplied range.
CFAxisCharacter$slice(rng)
rngA character vector whose extreme (alphabetic) values indicate the indices of coordinates to return.
An integer vector of length 2 with the lower and higher indices
into the axis that fall within the range of coordinates in argument
rng. Returns NULL if no values of the axis fall within the range of
coordinates.
subset()
Return an axis spanning a smaller coordinate range. This
method returns an axis which spans the range of indices given by the
rng argument.
CFAxisCharacter$subset(name = "", group, rng = NULL)
nameThe name for the new axis. If an empty string is passed (default), will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
rngThe range of indices whose values from this axis to include in
the returned axis. If the value of the argument is NULL, return a
copy of the axis.
A new CFAxisCharacter instance covering the indicated range of
indices. If the value of the argument rng is NULL, return a copy of
this axis as the new axis.
identical()
Tests if the axis passed to this method is identical to
self.
CFAxisCharacter$identical(axis)
axisThe CFAxisCharacter instance to test.
TRUE if the two axes are identical, FALSE if not.
append()
Append a vector of values at the end of the current values of the axis.
CFAxisCharacter$append(from, group)
fromAn instance of CFAxisCharacter whose values to append to
the values of self.
groupThe CFGroup where the copy of this axis will live.
A new CFAxisCharacter instance with values from self and the
from axis appended.
indexOf()
Find indices in the axis domain. Given a vector of character
strings x, find their indices in the coordinates of the axis.
CFAxisCharacter$indexOf(x, method = "constant", rightmost.closed = TRUE)
xVector of character strings to find axis indices for.
methodIgnored.
rightmost.closedIgnored.
Numeric vector of the same length as x. Values of x that are
not equal to a coordinate of the axis are returned as NA.
This class represent discrete CF axes, i.e. those axes whose coordinate values do not represent a physical property. The coordinate values are ordinal values equal to the index into the axis.
ncdfCF::CFObject -> ncdfCF::CFData -> ncdfCF::CFAxis -> CFAxisDiscrete
friendlyClassName(read-only) A nice description of the class.
dimnames(read-only) The coordinates of the axis as an integer vector, or labels for every axis element if they have been set.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()ncdfCF::CFAxis$attach_to_group()ncdfCF::CFAxis$can_append()ncdfCF::CFAxis$configure_terms()ncdfCF::CFAxis$copy_terms()ncdfCF::CFAxis$copy_with_values()ncdfCF::CFAxis$detach()ncdfCF::CFAxis$identical()ncdfCF::CFAxis$peek()ncdfCF::CFAxis$shard()new()
Create a new instance of this class. The values of this axis are always a sequence, but the sequence may start with any positive value such that the length of this instance falls within the length of the axis on file, if there is one.
Creating a new discrete axis is more easily done with the
makeDiscreteAxis() function.
CFAxisDiscrete$new(var, group, start = 1L, count)
varThe name of the axis when creating a new axis. When reading an axis from file, the NCVariable object that describes this instance.
groupThe CFGroup that this instance will live in.
startOptional. Integer value that indicates the starting value of
this axis. Defults to 1L.
countNumber of elements in the axis.
print()
Summary of the axis printed to the console.
CFAxisDiscrete$print(...)
...Arguments passed on to other functions. Of particular interest
is width = to indicate a maximum width of attribute columns.
self, invisibly.
brief()
Some details of the axis.
CFAxisDiscrete$brief()
A 1-row data.frame with some details of the axis.
copy()
Create a copy of this axis. The copy is completely separate from this axis, meaning that both this axis and all of its components are made from new instances.
CFAxisDiscrete$copy(name = "", group)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
The newly created axis.
indexOf()
Find indices in the axis domain. Given a vector of numerical
values x, find their indices in the values of the axis. Outside
values will be dropped.
CFAxisDiscrete$indexOf(x, method = "constant", rightmost.closed = TRUE)
xVector of numeric values to find axis indices for.
methodIgnored.
rightmost.closedIgnored.
Numeric vector of the same length as x. Values of x outside
of the range of the values in the axis are returned as NA.
slice()
Given a range of coordinate values, returns the indices into the axis that fall within the supplied range. If the axis has auxiliary coordinates selected then these will be used for the identification of the indices to return.
CFAxisDiscrete$slice(rng)
rngA vector whose extreme values indicate the indices of coordinates to return. The mode of the vector has to be integer or agree with any auxiliary coordinates selected.
An integer vector of length 2 with the lower and higher indices
into the axis that fall within the range of coordinates in argument
rng. Returns NULL if no (boundary) values of the axis fall within
the range of coordinates.
subset()
Return an axis spanning a smaller coordinate range. This
method returns an axis which spans the range of indices given by the
rng argument.
CFAxisDiscrete$subset(name = "", group, rng = NULL)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
rngThe range of indices whose values from this axis to include in
the returned axis. If the value of the argument is NULL, return a
copy of the axis.
A new CFAxisDiscrete instance covering the indicated range of
indices. If the value of the argument is NULL, return a copy of
self as the new axis.
append()
Append a vector of values at the end of the current values of the axis.
CFAxisDiscrete$append(from)
fromAn instance of CFAxisDiscrete whose length to add to this
axis.
groupThe CFGroup where the copy of this axis will live.
A new CFAxisDiscrete instance with a length that is the sum of
the lengths of this axis and the from axis.
write()
Write the axis to a netCDF file. A discrete axis does not have any attributes or values to write.
CFAxisDiscrete$write()
Self, invisibly.
This class represents a latitude axis. Its values are numeric. This class adds some logic that is specific to latitudes, such as their range, orientation and meaning.
ncdfCF::CFObject -> ncdfCF::CFData -> ncdfCF::CFAxis -> ncdfCF::CFAxisNumeric -> CFAxisLatitude
friendlyClassName(read-only) A nice description of the class.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()ncdfCF::CFAxis$attach_to_group()ncdfCF::CFAxis$can_append()ncdfCF::CFAxis$configure_terms()ncdfCF::CFAxis$copy_terms()ncdfCF::CFAxis$detach()ncdfCF::CFAxis$peek()ncdfCF::CFAxis$shard()ncdfCF::CFAxis$write()ncdfCF::CFAxisNumeric$brief()ncdfCF::CFAxisNumeric$identical()ncdfCF::CFAxisNumeric$indexOf()ncdfCF::CFAxisNumeric$print()ncdfCF::CFAxisNumeric$range()ncdfCF::CFAxisNumeric$slice()new()
Create a new instance of this class.
Creating a new latitude axis is more easily done with the
makeLatitudeAxis() function.
CFAxisLatitude$new( var, group, values, start = 1L, count = NA, attributes = data.frame() )
varThe name of the axis when creating a new axis. When reading an axis from file, the NCVariable object that describes this instance.
groupThe CFGroup that this instance will live in.
valuesOptional. The values of the axis in a vector. The values
have to be numeric within the range (-90, 90) and monotonic. Ignored
when argument var is a NCVariable object.
startOptional. Integer index where to start reading axis data
from file. The index may be NA to start reading data from the start.
countOptional. Number of elements to read from file. This may be
NA to read to the end of the data.
attributesOptional. A data.frame with the attributes of the
axis. When an empty data.frame (default) and argument var is an
NCVariable instance, attributes of the axis will be taken from the
netCDF resource.
copy()
Create a copy of this axis. The copy is completely separate
from self, meaning that both self and all of its components are made
from new instances.
CFAxisLatitude$copy(name = "", group)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
The newly created axis.
copy_with_values()
Create a copy of this axis but using the supplied values. The attributes are copied to the new axis. Boundary values and auxiliary coordinates are not copied.
After this operation the attributes of the newly created axes may not be accurate, except for the "actual_range" attribute. The calling code should set, modify or delete attributes as appropriate.
CFAxisLatitude$copy_with_values(name = "", group, values)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
valuesThe values to the used with the copy of this axis.
The newly created axis.
subset()
Return a latitude axis spanning a smaller coordinate range.
This method returns an axis which spans the range of indices given by
the rng argument.
CFAxisLatitude$subset(name = "", group, rng = NULL)
nameThe name for the new axis. If an empty string is passed (default), will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
rngThe range of indices whose values from this axis to include in
the returned axis. If the value of the argument is NULL, return a
copy of the axis.
A new CFAxisLatitude instance covering the indicated range of
indices. If the value of the argument rng is NULL, return a copy of
self as the new axis.
append()
Append a vector of values at the end of the current values
of the axis. Boundary values are appended as well but if either this
axis or the from axis does not have boundary values, neither will the
resulting axis.
CFAxisLatitude$append(from)
fromAn instance of CFAxisLatitude whose values to append to the
values of this axis.
groupThe CFGroup where the copy of this axis will live.
A new CFAxisLatitude instance with values from this axis and
the from axis appended.
This class represents a longitude axis. Its values are numeric. This class is used for axes that represent longitudes. This class adds some logic that is specific to longitudes, such as their range, orientation and their meaning. (In the near future, it will also support selecting data that crosses the 0-360 degree boundary.)
ncdfCF::CFObject -> ncdfCF::CFData -> ncdfCF::CFAxis -> ncdfCF::CFAxisNumeric -> CFAxisLongitude
friendlyClassName(read-only) A nice description of the class.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()ncdfCF::CFAxis$attach_to_group()ncdfCF::CFAxis$can_append()ncdfCF::CFAxis$configure_terms()ncdfCF::CFAxis$copy_terms()ncdfCF::CFAxis$detach()ncdfCF::CFAxis$peek()ncdfCF::CFAxis$shard()ncdfCF::CFAxis$write()ncdfCF::CFAxisNumeric$brief()ncdfCF::CFAxisNumeric$identical()ncdfCF::CFAxisNumeric$indexOf()ncdfCF::CFAxisNumeric$print()ncdfCF::CFAxisNumeric$range()ncdfCF::CFAxisNumeric$slice()new()
Create a new instance of this class.
Creating a new longitude axis is more easily done with the
makeLongitudeAxis() function.
CFAxisLongitude$new( var, group, values, start = 1L, count = NA, attributes = data.frame() )
varThe name of the axis when creating a new axis. When reading an axis from file, the NCVariable object that describes this instance.
groupThe CFGroup that this instance will live in.
valuesOptional. The values of the axis in a vector. The values
have to be numeric with the maximum value no larger than the minimum
value + 360, and monotonic. Ignored when argument var is a NCVariable
object.
startOptional. Integer index where to start reading axis data
from file. The index may be NA to start reading data from the start.
countOptional. Number of elements to read from file. This may be
NA to read to the end of the data.
attributesOptional. A data.frame with the attributes of the
axis. When an empty data.frame (default) and argument var is an
NCVariable instance, attributes of the axis will be taken from the
netCDF resource.
copy()
Create a copy of this axis. The copy is completely separate
from self, meaning that both self and all of its components are made
from new instances.
CFAxisLongitude$copy(name = "", group)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
The newly created axis.
copy_with_values()
Create a copy of this axis but using the supplied values. The attributes are copied to the new axis. Boundary values and auxiliary coordinates are not copied.
After this operation the attributes of the newly created axes may not be accurate, except for the "actual_range" attribute. The calling code should set, modify or delete attributes as appropriate.
CFAxisLongitude$copy_with_values(name = "", group, values)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
valuesThe values to the used with the copy of this axis.
The newly created axis.
subset()
Return a longitude axis spanning a smaller coordinate range.
This method returns an axis which spans the range of indices given by
the rng argument.
CFAxisLongitude$subset(name = "", group, rng = NULL)
nameThe name for the new axis. If an empty string is passed (default), will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
rngThe range of indices whose values from this axis to include in
the returned axis. If the value of the argument is NULL, return a
copy of the axis.
A new CFAxisLongitude instance covering the indicated range of
indices. If the value of the argument rng is NULL, return a copy of
self as the new axis.
append()
Append a vector of values at the end of the current values
of the axis. Boundary values are appended as well but if either this
axis or the from axis does not have boundary values, neither will the
resulting axis.
CFAxisLongitude$append(from)
fromAn instance of CFAxisLongitude whose values to append to
the values of this axis.
groupThe CFGroup where the copy of this axis will live.
A new CFAxisLongitude instance with values from this axis and
the from axis appended.
This class represents a numeric axis. Its values are numeric. This class is used for axes with numeric values but without further knowledge of their nature. More specific classes descend from this class.
ncdfCF::CFObject -> ncdfCF::CFData -> ncdfCF::CFAxis -> CFAxisNumeric
friendlyClassName(read-only) A nice description of the class.
dimnames(read-only) The coordinates of the axis as a vector. These are by default the values of the axis, but it could also be a set of auxiliary coordinates, if they have been set.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()ncdfCF::CFAxis$attach_to_group()ncdfCF::CFAxis$can_append()ncdfCF::CFAxis$configure_terms()ncdfCF::CFAxis$copy_terms()ncdfCF::CFAxis$detach()ncdfCF::CFAxis$peek()ncdfCF::CFAxis$shard()ncdfCF::CFAxis$write()new()
Create a new instance of this class.
Creating a new axis is more easily done with the makeAxis() function.
CFAxisNumeric$new( var, group, values, start = 1L, count = NA, orientation = "", attributes = data.frame() )
varThe name of the axis when creating a new axis. When reading an axis from file, the NCVariable object that describes this instance.
groupThe CFGroup that this instance will live in.
valuesOptional. The values of the axis in a vector. The values
have to be numeric with the maximum value no larger than the minimum
value + 360, and monotonic. Ignored when argument var is a
NCVariable object.
startOptional. Integer index where to start reading axis data
from file. The index may be NA to start reading data from the start.
countOptional. Number of elements to read from file. This may be
NA to read to the end of the data.
orientationOptional. The orientation of the axis: "X", "Y", "Z" "T", or "" (default) when not known or relevant.
attributesOptional. A data.frame with the attributes of the
axis. When an empty data.frame (default) and argument var is an
NCVariable instance, attributes of the axis will be taken from the
netCDF resource.
print()
Summary of the axis printed to the console.
CFAxisNumeric$print(...)
...Arguments passed on to other functions. Of particular interest
is width = to indicate a maximum width of attribute columns.
self, invisibly.
brief()
Some details of the axis.
CFAxisNumeric$brief()
A 1-row data.frame with some details of the axis.
range()
Retrieve the range of coordinate values in the axis.
CFAxisNumeric$range()
A numeric vector with two elements with the minimum and maximum values in the axis, respectively.
indexOf()
Retrieve the indices of supplied coordinates on the axis. If the axis has boundary values then the supplied coordinates must fall within the boundaries of an axis coordinate to be considered valid.
CFAxisNumeric$indexOf(x, method = "constant", rightmost.closed = TRUE)
xA numeric vector of coordinates whose indices into the axis to extract.
methodExtract index values without ("constant", the default) or with ("linear") fractional parts.
rightmost.closedWhether or not to include the upper limit. This
parameter is ignored for this class, it always is TRUE.
A vector giving the indices in x of valid coordinates provided.
Values of x outside of the range of the coordinates in the axis are
returned as NA. If the axis has boundary values, then values of x
that do not fall on or between the boundaries of an axis coordinate are
returned as NA.
slice()
Given a range of domain coordinate values, returns the indices into the axis that fall within the supplied range. If the axis has bounds, any coordinate whose boundary values fall entirely or partially within the supplied range will be included in the result.
CFAxisNumeric$slice(rng)
rngA numeric vector whose extreme values indicate the indices of coordinates to return.
An integer vector of length 2 with the lower and higher indices
into the axis that fall within the range of coordinates in argument
rng. Returns NULL if no (boundary) values of the axis fall within
the range of coordinates.
copy()
Create a copy of this axis. The copy is completely separate
from self, meaning that both self and all of its components are made
from new instances.
CFAxisNumeric$copy(name = "", group)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
The newly created axis.
copy_with_values()
Create a copy of this axis but using the supplied values. The attributes are copied to the new axis. Boundary values and auxiliary coordinates are not copied.
After this operation the attributes of the newly created axes may not be accurate, except for the "actual_range" attribute. The calling code should set, modify or delete attributes as appropriate.
CFAxisNumeric$copy_with_values(name = "", group, values)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
valuesThe values to the used with the copy of this axis.
The newly created axis.
identical()
Tests if the axis passed to this method is identical to
self.
CFAxisNumeric$identical(axis)
axisThe CFAxisNumeric or sub-class instance to test.
TRUE if the two axes are identical, FALSE if not.
append()
Append a vector of values at the end of the current values
of the axis. Boundary values are appended as well but if either this
axis or the from axis does not have boundary values, neither will the
resulting axis.
CFAxisNumeric$append(from, group)
fromAn instance of CFAxisNumeric whose values to append to the
values of this axis.
groupThe CFGroup where the copy of this axis will live.
A new CFAxisNumeric instance with values from this axis and the
from axis appended.
subset()
Return an axis spanning a smaller coordinate range. This
method returns an axis which spans the range of indices given by the
rng argument.
CFAxisNumeric$subset(name = "", group, rng = NULL)
nameThe name for the new axis. If an empty string is passed (default), will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
rngThe range of indices whose values from this axis to include in
the returned axis. If the value of the argument is NULL, return a
copy of the axis.
A new CFAxisNumeric instance covering the indicated range of
indices. If the value of the argument rng is NULL, return a copy of
this axis as the new axis.
This class represents a time axis. The functionality is provided
by the CFTime class in the CFtime package.
ncdfCF::CFObject -> ncdfCF::CFData -> ncdfCF::CFAxis -> CFAxisTime
friendlyClassName(read-only) A nice description of the class.
time(read-only) Retrieve the CFTime instance that manages the
values of this axis.
dimnames(read-only) The coordinates of the axis as a character vector.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()ncdfCF::CFAxis$attach_to_group()ncdfCF::CFAxis$can_append()ncdfCF::CFAxis$configure_terms()ncdfCF::CFAxis$copy_terms()ncdfCF::CFAxis$detach()ncdfCF::CFAxis$peek()ncdfCF::CFAxis$shard()ncdfCF::CFAxis$write()new()
Create a new instance of this class, including its boundary
values. A CFTime or CFClimatology instance will also be created to
manage the time magic.
Creating a new time axis is more easily done with the makeTimeAxis()
function.
CFAxisTime$new( var, group, values, start = 1L, count = NA, attributes = data.frame() )
varThe name of the axis when creating a new axis. When reading an axis from file, the NCVariable object that describes this instance.
groupThe CFGroup that this instance will live in.
valuesEither the numeric values of this axis, in which case
argument var must be a NCVariable, or an instance of CFTime or
CFClimatology with bounds set, and then argument var must be a name
for the axis.
startOptional. Integer index where to start reading axis data
from file. The index may be NA to start reading data from the start.
countOptional. Number of elements to read from file. This may be
NA to read to the end of the data.
attributesOptional. A data.frame with the attributes of the
axis. When an empty data.frame (default) and argument var is an
NCVariable instance, attributes of the axis will be taken from the
netCDF resource.
print()
Summary of the time axis printed to the console.
CFAxisTime$print(...)
...Arguments passed on to other functions. Of particular interest
is width = to indicate a maximum width of attribute columns.
brief()
Some details of the axis.
CFAxisTime$brief()
A 1-row data.frame with some details of the axis.
identical()
Tests if the axis passed to this method is identical to
self.
CFAxisTime$identical(axis)
axisThe CFAxisTime instance to test.
TRUE if the two axes are identical, FALSE if not.
copy()
Create a copy of this axis. The copy is completely separate
from self, meaning that both self and all of its components are made
from new instances.
CFAxisTime$copy(name = "", group)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
The newly created axis.
copy_with_values()
Create a copy of this axis but using the supplied values. The attributes are copied to the new axis. Boundary values and auxiliary coordinates are not copied.
After this operation the attributes of the newly created axes may not be accurate, except for the "actual_range" attribute. The calling code should set, modify or delete attributes as appropriate.
CFAxisTime$copy_with_values(name = "", group, values)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
valuesThe values to the used with the copy of this axis. This can
be a CFTime instance, a vector of numeric values, a vector of
character timestamps in ISO8601 or UDUNITS format, or a vector of
POSIXct or Date values. If not a CFTime instance, the values
will be converted into a CFTime instance using the definition and
calendar of this axis.
The newly created axis.
append()
Append a vector of time values at the end of the current values of the axis.
CFAxisTime$append(from, group)
fromAn instance of CFAxisTime whose values to append to the
values of this axis.
groupThe CFGroup where the copy of this axis will live.
A new CFAxisTime instance with values from this axis and the
from axis appended.
indexOf()
Retrieve the indices of supplied values on the time axis.
CFAxisTime$indexOf(x, method = "constant", rightmost.closed = FALSE)
xA vector of timestamps whose indices into the time axis to extract.
methodExtract index values without ("constant", the default) or with ("linear") fractional parts.
rightmost.closedWhether or not to include the upper limit.
Default is FALSE.
A vector giving the indices in the time axis of valid
values in x, or NA if the value is not valid.
slice()
Retrieve the indices of the time axis falling between two extreme values.
CFAxisTime$slice(x, rightmost.closed = FALSE)
xA vector of two timestamps in between of which all indices into the time axis to extract.
rightmost.closedWhether or not to include the upper limit.
Default is FALSE.
An integer vector giving the indices in the time axis between
values in x, or NULL if none of the values are valid.
subset()
Return an axis spanning a smaller coordinate range. This
method returns an axis which spans the range of indices given by the
rng argument.
CFAxisTime$subset(name = "", group, rng = NULL)
nameThe name for the new axis. If an empty string is passed (default), will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
rngThe range of indices whose values from this axis to include in
the returned axis. If the value of the argument is NULL, return a
copy of the axis.
A new CFAxisTime instance covering the indicated range of
indices. If the value of the argument rng is NULL, return a copy of
self as the new axis.
This class represents a vertical axis, which may be parametric. A regular vertical axis behaves like any other numeric axis. A parametric vertical axis, on the other hand, is defined through an index value that is contained in the axis coordinates, with additional data variables that hold ancillary "formula terms" with which to calculate physical axis coordinates. It is used in atmosphere and ocean data sets.
Parametric vertical axes can only be read from file, not created from scratch.
ncdfCF::CFObject -> ncdfCF::CFData -> ncdfCF::CFAxis -> ncdfCF::CFAxisNumeric -> CFAxisVertical
friendlyClassName(read-only) A nice description of the class.
formula_terms(read-only) A data.frame with the "formula_terms"
to calculate the parametric axis values.
is_parametric(read-only) Logical flag that indicates if the coordinates of the axis are parametric.
parametric_coordinates(read-only) Retrieve the parametric coordinates of this vertical axis as a CFVariable.
computed_name(read-only) The name of the computed parameterised coordinates. If the parameterised coordinates have not been computed yet the computed name is an empty string.
computed_units(read-only) Return the units of the computed
parameterised coordinates, if computed, otherwise return NULL. This
will access the standard names table.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()ncdfCF::CFAxis$can_append()ncdfCF::CFAxis$configure_terms()ncdfCF::CFAxis$copy_terms()ncdfCF::CFAxis$peek()ncdfCF::CFAxis$shard()ncdfCF::CFAxis$write()ncdfCF::CFAxisNumeric$brief()ncdfCF::CFAxisNumeric$identical()ncdfCF::CFAxisNumeric$indexOf()ncdfCF::CFAxisNumeric$print()ncdfCF::CFAxisNumeric$range()ncdfCF::CFAxisNumeric$slice()new()
Create a new instance of this class.
CFAxisVertical$new( var, group, values, start = 1L, count = NA, attributes = data.frame() )
varThe name of the axis when creating a new axis. When reading an axis from file, the NCVariable object that describes this instance.
groupThe CFGroup that this instance will live in.
valuesOptional. The values of the axis in a vector. The values have to be numeric and monotonic.
startOptional. Integer index where to start reading axis data
from file. The index may be NA to start reading data from the start.
countOptional. Number of elements to read from file. This may be
NA to read to the end of the data.
attributesOptional. A data.frame with the attributes of the
axis. When an empty data.frame (default) and argument var is an
NCVariable instance, attributes of the axis will be taken from the
netCDF resource.
attach_to_group()
Attach this verical axis to a group, including any parameteric terms. If there is another object with the same name in this group an error is thrown. For associated objects (such as bounds, etc), if another object with the same name is otherwise identical to the associated object then that object will be linked from the variable, otherwise an error is thrown.
CFAxisVertical$attach_to_group(grp, locations = list())
grpAn instance of CFGroup.
locationsOptional. A list whose named elements correspond to
the names of objects associated with this axis, possibly including the
axis itself. Each list element has a single character string indicating
the group in the hierarchy where the object should be stored. As an
example, if the variable has axes "lon" and "lat" and they should be
stored in the parent group of grp, then specify locations = list(lon = "..", lat = ".."). Locations can use absolute paths or relative
paths from group grp. The axis and associated objects that are not in
the list will be stored in group grp. If the argument locations is
not provided, all associated objects will be stored in this group.
Self, invisibly.
detach()
Detach the parametric terms from an underlying netCDF resource.
CFAxisVertical$detach()
Self, invisibly.
copy()
Create a copy of this axis. The copy is completely separate from this instance, meaning that the copies of both this instance and all of its components are made as new instances.
CFAxisVertical$copy(name = "", group)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
The newly created axis.
copy_with_values()
Create a copy of this axis but using the supplied values. The attributes are copied to the new axis. Boundary values, parametric coordinates and auxiliary coordinates are not copied.
After this operation the attributes of the newly created axes may not be accurate, except for the "actual_range" attribute. The calling code should set, modify or delete attributes as appropriate.
CFAxisVertical$copy_with_values(name = "", group, values)
nameThe name for the new axis. If an empty string is passed, will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
valuesThe values to the used with the copy of this axis.
The newly created axis.
set_parametric_terms()
Set the parametric terms for this axis. The name and the terms have to fully describe a CF parametric vertical axis.
The terms must also agree with the other axes used by any data variable that refers to this axis. That is not checked here so the calling code must make that assertion.
CFAxisVertical$set_parametric_terms(sn, terms)
snThe "standard_name" of the parametric formulation. See the CF documentation for details.
termsA data.frame with columns term, variable and
param containing the terms of the formula to calculate the axis
values. Column param has the references to the variables that
hold the data for each term.
append()
Append a vector of values at the end of the current values
of the axis. Boundary values are appended as well but if either this
axis or the from axis does not have boundary values, neither will the
resulting axis.
This method is not recommended for parametric vertical axes. Any
parametric terms will be deleted. If appending of parametric axes is
required, the calling code should first read out the parametric terms
and merge them with the parametric terms of the from axis before
setting them back for this axis.
CFAxisVertical$append(from)
fromAn instance of CFAxisVertical whose values to append to the
values of this axis.
groupThe CFGroup where the copy of this axis will live.
A new CFAxisVertical instance with values from this axis and
the from axis appended.
subset()
Return an axis spanning a smaller coordinate range. This
method returns an axis which spans the range of indices given by the
rng argument. If this axis has parametric terms, these are not subset
here - they should be separately treated once all associated axes in
the terms have been subset. That happens automatically in CFVariable
methods which call the subset_parametric_terms() method.
CFAxisVertical$subset(name = "", group, rng = NULL)
nameThe name for the new axis. If an empty string is passed (default), will use the name of this axis.
groupThe CFGroup where the copy of this axis will live.
rngThe range of indices whose values from this axis to include in
the returned axis. If the value of the argument is NULL, return a
copy of the axis.
A new CFAxisVertical instance covering the indicated range of
indices. If the value of the argument rng is NULL, return a copy of
this axis as the new axis.
subset_parametric_terms()
Subset the parametric terms of this axis.
CFAxisVertical$subset_parametric_terms( original_axis_names, new_axes, start, count, aux = NULL, ZT_dim = NULL )
original_axis_namesCharacter vector of names of the axes prior to a modifying operation in the owning data variable
new_axesList of CFAxis instances to use for the subsetting.
startThe indices to start reading data from the file, as an integer vector at least as long as the number of axis for the term.
countThe number of values to read from the file, as an integer vector at least as long as the number of axis for the term.
auxOptional. List with the parameters for an auxiliary grid
transformation. Default is NULL.
ZT_dimOptional. Dimensions of the non-grid axes when an auxiliary grid transformation is specified.
Self, invisibly. The parametric terms will have been subset in this axis.
https://cfconventions.org/Data/cf-conventions/cf-conventions.html#parametric-vertical-coordinate https://www.myroms.org/wiki/Vertical_S-coordinate
This class represents the boundaries of an axis or an auxiliary longitude-latitude grid.
The class manages the boundary information for an axis (2 vertices per element) or an auxiliary longitude-latitude grid (4 vertices per element).
ncdfCF::CFObject -> ncdfCF::CFData -> CFBounds
friendlyClassName(read-only) A nice description of the class.
length(read-only) The length of the second dimension of the data, i.e. the number of boundary values.
vertices(read-only) The length of the first dimension of the data, i.e. the number of vertices that make up a boundary.
valuesSet or retrieve the boundary values of this object. Upon retrieval, values are read from the netCDF resource, if there is one, upon first access and cached thereafter. Upon setting values, if there is a linked netCDF resource, this object will be detached from it.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attach_to_group()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$detach()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()new()
Create an instance of this class.
CFBounds$new( var, group, values, start = NA, count = NA, attributes = data.frame(), owner_dims = 1L )
varThe name of the boundary variable when creating a new boundary variable. When reading a boundary variable from file, the NCVariable object that describes this instance.
groupThe CFGroup that this instance will live in.
valuesOptional. The values of the boundary variable. This must be
a numeric matrix whose first dimension has a length equal to the number
of vertices for each boundary, and the second dimension is as long as
the CFObject instances that use these boundary values. Ignored when
argument var is a NCVariable object.
startOptional. Vector of indices where to start reading boundary
data along the dimensions of the data. The vector must be NA to read
all data, otherwise it must have a length equal to the dimensionality
of the owning object + 1.
countOptional. Vector of number of elements to read along each
dimension of the boundary data. The vector must be NA to read to the
end of each dimension, otherwise it must have a length equal to the
dimensionality of the owning object + 1.
attributesOptional. A data.frame with the attributes of the
boundary object. When an empty data.frame (default) and argument
var is an NCVariable instance, attributes of the bounds object will
be taken from the netCDF resource.
owner_dimsOptional, the number of dimensions of the object that these boundary values pertain to. Default is 1.
A new instance of this class.
print()
Print a summary of the object to the console.
CFBounds$print(attributes = TRUE, ...)
attributesDefault TRUE, flag to indicate if the attributes of
the boundary values should be printed.
...Arguments passed on to other functions. Of particular interest
is width = to indicate a maximum width of attribute columns.
print_boundary_values()
Print the boundary values to the console. This method is not
very useful to call directly - instead, call $print(), which will
call this method. These boundary values are also printed when printing
an axis that has boundary values associated with it.
CFBounds$print_boundary_values()
range()
Retrieve the lowest and highest value in the bounds.
CFBounds$range()
copy()
Create a copy of this bounds object The copy is completely
separate from self, meaning that both self and all of its
components are made from new instances.
CFBounds$copy(name = "", group)
nameThe name for the new bounds object. If an empty string is passed, will use the name of this bounds object.
groupThe CFGroup where the copy of this axis will live.
The newly created bounds object.
subset()
Return a boundary variable spanning a smaller coordinate range. This currently only applies to 1-D axes.
This method returns boundary values which span the range of indices
given by the rng argument.
CFBounds$subset(group, rng)
groupThe CFGroup where the copy of these bounds will live.
rngThe range of values from this bounds object to include in the returned object.
A CFBounds instance covering the indicated range of indices.
append()
Append boundary values at the end of the current values of the boundary variable.
CFBounds$append(from, group)
fromAn instance of CFBounds whose values to append to the
values of this boundary variable.
groupThe CFGroup where the copy of these bounds will live.
A new CFBounds instance with values from this boundary variable
and the from boundary variable appended. If argument from is
NULL, return NULL.
write()
Write the boundary variable to a netCDF file. This method
should not be called directly; instead, CFVariable$save() will call
this method automatically.
CFBounds$write(object_id)
object_idThe integer dimid of the object that uses these boundary values, usually an axis but could also be an auxiliary CV.
This class represents a CF cell measure variable, the object that indicates the area or volume of every grid cell in referencing data variables.
If a cell measure variable is external to the current file, an instance will still be created for it, but the user must link the external file to this instance before it can be used in analysis.
measure(read-only) Retrieve the measure of this instance. Either "area" or "volume".
nameThe name of this instance, which must refer to a NC variable or an external variable.
new()
Create an instance of this class.
CFCellMeasure$new(measure, name, nc_var = NULL, axes = NULL)
measureThe measure of this object. Must be either of "area" or "volume".
nameThe name of the cell measure variable. Ignored if argument
nc_var is specified.
nc_varThe netCDF variable that defines this CF cell measure
object. NULL for an external variable.
axesList of CFAxis instances that describe the dimensions of
the cell measure object. NULL for an external variable.
An instance of this class.
print()
Print a summary of the cell measure variable to the console.
CFCellMeasure$print(...)
...Arguments passed on to other functions. Of particular interest
is width = to indicate a maximum width of attribute columns.
data()
Retrieve the values of the cell measure variable.
CFCellMeasure$data()
The values of the cell measure as a CFVariable instance.
register()
Register a CFVariable which is using this cell measure variable. A check is performed on the compatibility between the data variable and this cell measure variable.
CFCellMeasure$register(var)
varA CFVariable instance to link to this instance.
Self, invisibly.
link()
Link the cell measure variable to an external netCDF resource. The resource will be opened and the appropriate data variable will be linked to this instance. If the axes or other properties of the external resource are not compatible with this instance, an error will be raised.
CFCellMeasure$link(resource)
resourceThe name of the netCDF resource to open, either a local file name or a remote URI.
Self, invisibly.
detach()
Detach the internal data variable from an underlying netCDF resource.
CFCellMeasure$detach()
Self, invisibly.
clone()
The objects of this class are cloneable with this method.
CFCellMeasure$clone(deep = FALSE)
deepWhether to make a deep clone.
This class is a basic ancestor to all classes that contain data from a netCDF resource, specifically data variables and axes. More useful classes use this class as ancestor.
ncdfCF::CFObject -> CFData
data_typeSet or retrieve the data type of the data in the object. Setting the data type to a wrong value can have unpredictable and mostly catastrophic consequences.
ndims(read-only) Retrieve the dimensionality of the data in the array.
NC_mapReturns a list with columns "start" and "count" giving the indices for reading the data of this object from a netCDF resource. The list is empty if this object is not backed by a netCDF resource.
new()
Create a new CFData instance. This method is called upon
creating CF objects, such as when opening a netCDF resource or creating
a new CF object. It is rarely, if ever, useful to call this constructor
directly. Instead, use the methods from higher-level classes such as
CFVariable.
CFData$new( obj, group, values, start = 1L, count = NA, attributes = data.frame() )
objThe NCVariable instance upon which this CF object is based when read from a netCDF resource, or the name for the new CF object to be created.
groupThe CFGroup that this instance will live in.
valuesOptional. The values of the object in an array. Ignored
when argument obj is an NCVariable instance.
startOptional. Vector of indices where to start reading data
along the dimensions of the array on file. The vector must be NA to
read all data, otherwise it must have agree with the dimensions of the
array on file. Default value is 1, i.e. start from the beginning of
the 1-D NC variable. Ignored when argument obj is not an NCVariable
instance.
countOptional. Vector of number of elements to read along each
dimension of the array on file. The vector must be NA to read to the
end of each dimension, otherwise its value must agree with the
corresponding start value and the dimension of the array on file.
Default is NA. Ignored when argument obj is not an NCVariable
instance.
attributesOptional. A data.frame with the attributes of the
object.
A CFData instance.
detach()
Detach the current object from its underlying netCDF resource. If necessary, data is read from the resource before detaching.
CFData$detach()
dim()
Retrieve the dimensions of the data of this object.
CFData$dim(dimension)
dimensionOptional. The index of the dimension to retrieve the length for. If omitted, retrieve the lengths of all dimensions.
Integer vector with the length of each requested dimension.
Read the data of the CF object from the NC file. The data is cached by
self so repeated calls do not access the netCDF resource, unless
argument refresh is TRUE. This method will not assess how big the
data is before reading it so there is a chance that memory will be
exhausted. The calling code should check for this possibility and break
up the reading of data into chunks.
read_data()
CFData$read_data(refresh = FALSE)
refreshShould the data be read from file if the object is linked?
This will replace current values, if previously loaded. Default
FALSE.
An array of data, invisibly, as prescribed by the start and
count values used to create this object. If the object is not backed
by a netCDF resource, returns NULL.
Read a chunk of raw data of the CF object, as defined by the start and
count vectors. Note that these vectors are relative to any subset of
the data variable that this CF object refers to. The data read by this
method will not be stored in self so the calling code must take a
reference to it.
read_chunk()
CFData$read_chunk(start, count)
startVector of indices where to start reading data along the
dimensions of the array. The vector must be NA to read all data,
otherwise it must agree with the dimensions of the array.
countVector of number of elements to read along each dimension of
the array. The vector must be NA to read to the end of each
dimension, otherwise its value must agree with the corresponding
start value and the dimension of the array.
An array of data, as prescribed by the start and count
arguments, or NULL if there is no data.
This class represents a CF data set, the object that
encapsulates a netCDF resource. You should never instantiate this class
directly; instead, call open_ncdf() which will return an instance that
has all properties read from the netCDF resource, or create_ncdf() for a
new, empty instance. Class methods can then be called, or the base R
functions called with this instance.
The CF data set instance provides access to all the objects in the netCDF resource, organized in groups.
nameThe name of the netCDF resource. This is extracted from the URI (file name or URL).
rootRoot of the group hierarchy through which all elements of the netCDF resource are accessed. It is strongly discouraged to manipulate the objects in the group hierarchy directly. Use the provided access methods instead.
file_typeThe type of data in the netCDF resource, if identifiable. In terms of the CF Metadata Conventions, this includes discrete sampling geometries (DSG). Other file types that can be identified include L3b files used by NASA and NOAA for satellite imagery (these data sets need special processing), and CMIP5, CMIP6 and CORDEX climate projection data.
friendlyClassName(read-only) A nice description of the class.
resource(read-only) The connection details of the netCDF resource. This is for internal use only.
uri(read-only) The connection string to the netCDF resource.
conventions(read-only) Returns the conventions that this netCDF resource conforms to.
var_names(read-only) Vector of names of variables in this data set.
axis_names(read-only) Vector of names of axes in this data set.
new()
Create an instance of this class. Do not instantiate this
class directly; instead, call open_ncdf() which will return an
instance that has all properties read from the netCDF resource, or
create_ncdf() for a new, empty instance.
CFDataset$new(resource, format)
resourceAn instance of NCResource that links to the netCDF
resource, or a character string with the name of a new data set.
formatCharacter string with the format of the netCDF resource as
reported by the call opening the resource. Ignored when argument
resource is a character string.
print()
Summary of the data set printed to the console.
CFDataset$print(...)
...Arguments passed on to other functions. Of particular interest
is width = to indicate a maximum width of attribute columns.
hierarchy()
Print the group hierarchy to the console.
CFDataset$hierarchy()
objects_by_standard_name()
Get objects by standard_name. Several conventions define standard vocabularies for physical properties. The standard names from those vocabularies are usually stored as the "standard_name" attribute with variables or axes. This method retrieves all variables or axes that list the specified "standard_name" in its attributes.
CFDataset$objects_by_standard_name(standard_name)
standard_nameOptional, a character string to search for a specific "standard_name" value in variables and axes.
If argument standard_name is provided, a character vector of
variable or axis names. If argument standard_name is missing or an
empty string, a named list with all "standard_name" attribute values in
the the netCDF resource; each list item is named for the variable or
axis.
has_subgroups()
Does the netCDF resource have subgroups? Newer versions of
the netcdf library, specifically netcdf4, can organize dimensions
and variables in groups. This method will report if the data set is
indeed organized with subgroups.
CFDataset$has_subgroups()
Logical to indicate that the netCDF resource uses subgroups.
find_by_name()
Find an object by its name. Given the name of a CF data variable or axis, possibly preceded by an absolute group path, return the object to the caller.
CFDataset$find_by_name(name)
nameThe name of a CF data variable or axis, with an optional absolute group path.
The object with the provided name. If the object is not found,
returns NULL.
variables()
This method lists the CF data variables located in this netCDF resource, including those in subgroups.
CFDataset$variables()
A list of CFVariable instances.
axes()
This method lists the axes located in this netCDF resource, including axes in subgroups.
CFDataset$axes()
A list of CFAxis descendants.
attributes()
List all the attributes of a group. This method returns a
data.frame containing all the attributes of the indicated group.
CFDataset$attributes(group)
groupThe name of the group whose attributes to return. If the argument is missing, the global attributes will be returned.
A data.frame of attributes.
attribute()
Retrieve global attributes of the data set.
CFDataset$attribute(att, field = "value")
attVector of character strings of attributes to return.
fieldThe field of the attribute to return values from. This must be "value" (default) or "type".
If the field argument is "type", a character string. If field
is "value", a single value of the type of the attribute, or a vector
when the attribute has multiple values. If no attribute is named with a
value of argument att NA is returned.
set_attribute()
Add an attribute to the global attributes. If an attribute
name already exists, it will be overwritten.
CFDataset$set_attribute(name, type, value)
nameThe name of the attribute. The name must begin with a letter and be composed of letters, digits, and underscores, with a maximum length of 255 characters. UTF-8 characters are not supported in attribute names.
typeThe type of the attribute, as a string value of a netCDF data type.
valueThe value of the attribute. This can be of any supported type, including a vector or list of values. Matrices, arrays and like compound data structures should be stored as a data variable, not as an attribute and they are thus not allowed. In general, an attribute should be a character value, a numeric value, a logical value, or a short vector or list of any of these. Values passed in a list will be coerced to their common mode.
Self, invisibly.
append_attribute()
Append the text value of a global attribute. If an attribute
name already exists, the value will be appended to the existing
value of the attribute. If the attribute name does not exist it will
be created. The attribute must be of "NC_CHAR" or "NC_STRING" type; in
the latter case having only a single string value.
CFDataset$append_attribute(name, value, sep = "; ", prepend = FALSE)
nameThe name of the attribute. The name must begin with a letter and be composed of letters, digits, and underscores, with a maximum length of 255 characters. UTF-8 characters are not supported in attribute names.
valueThe character value of the attribute to append. This must be a character string.
sepThe separator to use. Default is "; ".
prependLogical to flag if the supplied value should be placed
before the existing value. Default is FALSE.
Self, invisibly.
delete_attribute()
Delete attributes. If an attribute name is not present
this method simply returns.
CFDataset$delete_attribute(name)
nameVector of names of the attributes to delete.
Self, invisibly.
add_variable()
Add a CFVariable object to the data set. If there is another object with the same name in the group where the data variable should be placed an error is thrown. For objects associated with the data variable (such as axes, CRS, boundary variables, etc), if another object with the same name is otherwise identical to the associated object then that object will be linked from the variable, otherwise an error is thrown.
CFDataset$add_variable(var, group, locations = list())
varAn instance of CFVariable or any of its descendants.
groupOptional. An instance of CFGroup where the data variable should be located. If omitted, the data variable will be stored in the root group.
locationsOptional. A list whose named elements correspond to
the names of objects associated with the data variable in argument
var. Each list element has a single character string indicating the
group in the hierarchy where the object should be stored. As an
example, if the data variable has axes "lon" and "lat" and they should
be stored in the parent group of group, then specify locations = list(lon = "..", lat = ".."). Locations can use absolute paths or
relative paths from the group. Associated objects that are not in the
list will be stored in group. If the argument locations is not
provided, all associated objects will be stored in group.
Argument var, invisibly.
save()
Save the data set to file, including its subordinate objects such as attributes, data variables, axes, CRS, etc.
CFDataset$save(fn = NULL, pack = FALSE)
fnOptional. Fully-qualified file name indicating where to save the data set to. This argument must be provided if the data set is virtual. If the argument is provided on a data set that was read from a netCDF file and it does not point to that netCDF file, a new netCDF file will be written to the indicated location. If the argument is the same file name as before, the existing netCDF file will be updated.
packOptional. Logical to indicate if the data should be packed;
default is FALSE. Packing is only useful for numeric data; packing is
not performed on integer values. Packing is always to the "NC_SHORT"
data type, i.e. 16-bits per value.
Self, invisibly.
clone()
The objects of this class are cloneable with this method.
CFDataset$clone(deep = FALSE)
deepWhether to make a deep clone.
This class contains the details for a coordinate reference system, or grid mapping in CF terms, of a data variable.
When reporting the coordinate reference system to the caller, a character string in WKT2 format is returned, following the OGC standard.
ncdfCF::CFObject -> CFGridMapping
friendlyClassName(read-only) A nice description of the class.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attach_to_group()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$detach()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()new()
Create a new instance of this class.
Note that when a new grid mapping object is created (as opposed to
reading from a netCDF resource), only the grid_mapping_name attribute
will be set. The caller must set all other parameters through their
respective attributes, following the CF Metadata Conventions.
CFGridMapping$new(var, group, grid_mapping_name)
varWhen creating a new grid mapping object, the name of the object. When reading from a netCDF resource, the netCDF variable that describes this instance.
groupThe CFGroup that this instance will live in.
grid_mapping_nameOptional. When creating a new grid mapping
object, the formal name of the grid mapping, as specified in the CF
Metadata Conventions. This value is stored in the new object as
attribute "grid_mapping_name". Ignored when argument var is a NC
object.
print()
Prints a summary of the grid mapping to the console.
CFGridMapping$print()
brief()
Retrieve a 1-row data.frame with some information on this
grid mapping.
CFGridMapping$brief()
wkt2()
Retrieve the CRS string for a specific variable.
CFGridMapping$wkt2(axis_info)
axis_infoA list with information that describes the axes of the
CFVariable instance to describe.
A character string with the CRS in WKT2 format.
write()
Write the CRS object to a netCDF file.
CFGridMapping$write()
Self, invisibly.
https://docs.ogc.org/is/18-010r11/18-010r11.pdf https://cfconventions.org/cf-conventions/cf-conventions.html#appendix-grid-mappings
This class represents a CF group, the object that holds elements like dimensions and variables of a CFDataset.
Direct access to groups is usually not necessary. The principal objects held by the group, CF data variables and axes, are accessible via other means. Only for access to the group attributes is a reference to a group required. Changing the properties of a group other than its name may very well invalidate the CF objects or even the netCDF file.
ncdfCF::CFObject -> CFGroup
parent(read-only) The parent group of the current group, or its owning data set for the root node.
nameSet or retrieve the name of the group. Note that the name is always relative to the location in the hierarchy that the group is in and it should thus not be qualified by backslashes. The name has to be a valid CF name. The name of the root group cannot be changed.
fullname(read-only) The fully qualified absolute path of the group.
root(read-only) Retrieve the root group.
data_set(read-only) Retrieve the CFDataset that the group
belongs to. If the group is not attached to a CFDataset, returns
NULL.
has_subgroups(read-only) Does the current group have subgroups?
subgroups(read-only) Retrieve the list of the subgroups of the current group.
CFobjects(read-only) Retrieve the list of CF objects of the current group.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attach_to_group()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$detach()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()new()
Create a new CF group instance.
CFGroup$new(grp, parent)
grpEither a NCGroup instance when opening a netCDF resource, or a character string with a name for the group when creating a new CF group in memory. When a character string, it should be the local name, without any slash "/" characters. For the root group, specify an empty string "".
parentThe parent group for this group, or a CFDataset for the
root group.
An instance of this class.
print()
Summary of the group printed to the console.
CFGroup$print(stand_alone = TRUE, ...)
stand_aloneLogical to indicate if the group should be printed as
an object separate from other objects (TRUE, default), or print as part
of an enclosing object (FALSE).
...Passed on to other methods.
hierarchy()
Prints the hierarchy of the group and its subgroups to the console, with a summary of contained objects. Usually called from the root group to display the full group hierarchy.
CFGroup$hierarchy(idx = 1L, total = 1L)
idx, totalArguments to control indentation. Should both be 1 (the default) when called interactively. The values will be updated during recursion when there are groups below the current group.
subgroup_names()
Retrieve the names of the subgroups of the current group.
CFGroup$subgroup_names(recursive = TRUE)
recursiveLogical, default is TRUE. If TRUE, include names of
recursively through the group hierarchy.
A character vector with the names of the subgroups of the current
group. If recursive = TRUE, the names will be fully qualified with
their path.
create_subgroup()
Create a new group as a subgroup of the current group.
CFGroup$create_subgroup(name)
nameThe name of the new subgroup. This must be a valid CF name, so not contain any slash '/' characters among other restrictions, and it cannot be already present in the group.
The newly created group, or an error.
add_subgroups()
Add subgroups to the current group. These subgroups must be
fully formed, including having set their parent to this group. Use the
create_subgroup() method to add a group from scratch.
CFGroup$add_subgroups(grps)
grpsA CFGroup, or list thereof.
Self, invisibly.
add_CF_object()
Add one or more CF objects to the current group. This is an
internal method that should not be invoked by the user. The objects to
be added are considered atomic and not assessed for any contained
objects. Use a method like add_variable() to add a CF variable to
this group as well as its composing sub-objects such as axes.
CFGroup$add_CF_object(obj, silent = TRUE)
objAn instance of a CFObject descendant class, or a list
thereof. If it is a list, the list elements must be named after the
CF object they contain.
silentLogical. If TRUE (default), CF objects in argument obj
whose name is already present in the list of CF objects and whose
class is identical to the already present object are silently dropped;
otherwise or when the argument is FALSE an error is thrown.
Self, invisibly, or an error.
remove_CF_object()
Remove a CF objects from the current group. This is an internal method that should not be invoked by the user. The objects to be removed are considered atomic and not assessed for any contained objects.
CFGroup$remove_CF_object(obj)
objThe integer id property of the CF object to remove from this group.
Self, invisibly.
objects()
This method lists the CF objects of a certain class located in this group, optionally including objects in subgroups.
CFGroup$objects(cls, recursive = TRUE)
clsCharacter vector of classes whose objects to retrieve. Note
that subclasses are automatically retrieved as well, so specifying
cls = "CFAxis" will retrieve all axes defined in this group.
recursiveShould subgroups be scanned for CF objects too
(default is TRUE)?
A list of CFObject instances.
find_by_name()
Find an object by its name. Given the name of an object,
possibly preceded by an absolute or relative group path, return the
object to the caller. Typically, this method is called
programmatically; similar interactive use is provided through the
[[.CFDataset operator.
CFGroup$find_by_name(name)
nameThe name of an object, with an optional absolute or relative group path from the calling group. The object must be an CF construct: group, data variable, axis, auxiliary axis, label, grid mapping, etc.
The object with the provided name. If the object is not found,
returns NULL.
add_variable()
Add a CFVariable object to the group. If there is another object with the same name in this group an error is thrown. For associated objects (such as axes, CRS, boundary variables, etc), if another object with the same name is otherwise identical to the associated object then that object will be linked from the variable, otherwise an error is thrown.
CFGroup$add_variable(var, locations = list())
varAn instance of CFVariable or any of its descendants.
locationsOptional. A list whose named elements correspond to
the names of objects associated with the variable in argument var.
Each list element has a single character string indicating the group in
the hierarchy where the object should be stored. As an example, if the
variable has axes "lon" and "lat" and they should be stored in the
parent group of this group, then specify locations = list(lon = "..", lat = ".."). Locations can use absolute paths or relative paths from
the current group. Associated objects that are not in the list will be
stored in this group. If the argument locations is not provided, all
associated objects will be stored in this group.
Argument var, invisibly.
write()
Write the group to file, including its attributes, if it doesn't already exist.
CFGroup$write(recursive = TRUE)
recursiveIf TRUE (default), write sub-groups as well.
Self, invisibly.
write_variables()
Write data variables in the group to file, including its associated objects, if it doesn't already exist.
CFGroup$write_variables(pack = FALSE, recursive = TRUE)
packLogical to indicate if the data should be packed. Packing is only useful for numeric data; packing is not performed on integer values. Packing is always to the "NC_SHORT" data type, i.e. 16-bits per value.
recursiveIf TRUE (default), write data variables in sub-groups
as well.
Self, invisibly.
This class represent CF labels, i.e. a variable of character type that provides a textual label for a discrete or general numeric axis. See also CFAxisCharacter, which is an axis with character labels.
ncdfCF::CFObject -> ncdfCF::CFData -> CFLabel
friendlyClassName(read-only) A nice description of the class.
valuesSet or retrieve the labels of this object. In general you
should use the coordinates field rather than this one. Upon setting
values, if there is a linked netCDF resource, this object will be
detached from it.
coordinates(read-only) Retrieve the labels of this object. Upon retrieval, label values are read from the netCDF resource, if there is one, upon first access and cached thereafter.
length(read-only) The number of labels in the set.
dimidThe netCDF dimension id of this label set. Setting this value to anything other than the correct value will lead to disaster.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attach_to_group()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$detach()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()new()
Create a new instance of this class.
CFLabel$new(var, group, values = NA, start = NA, count = NA)
varThe NCVariable instance upon which this CF object is based when read from a netCDF resource, or the name for the object new CF object to be created.
groupThe CFGroup that this instance will live in.
valuesOptional. The labels of the CF object. Ignored when
argument var is a NCVariable object.
startOptional. Integer index value indicating where to start
reading data from the file. The value may be NA (default) to read all
data, otherwise it must not be larger than the number of labels.
Ignored when argument var is not an NCVariable instance.
countOptional. Integer value indicating the number of labels to
read from file. The value may be NA to read to the end of the labels,
otherwise its value must agree with the corresponding start value and
the number of labels on file. Ignored when argument var is not an
NCVariable instance.
A CFLabel instance.
print()
Prints a summary of the labels to the console.
CFLabel$print(...)
...Arguments passed on to other functions. Of particular interest
is width = to indicate a maximum width of attribute columns.
identical()
Tests if the object passed to this method is identical to
self.
CFLabel$identical(lbl)
lblThe CFLabel instance to test.
TRUE if the two label sets are identical, FALSE if not.
copy()
Create a copy of this label set. The copy is completely
separate from self, meaning that both self and all of its
components are made from new instances.
CFLabel$copy(name = "", group)
nameThe name for the new label set. If an empty string is passed, will use the name of this label set.
groupThe CFGroup where the copy of this axis will live.
The newly created label set.
slice()
Given a range of domain coordinate values, returns the indices into the axis that fall within the supplied range.
CFLabel$slice(rng)
rngA character vector whose extreme (alphabetic) values indicate the indices of coordinates to return.
An integer vector of length 2 with the lower and higher indices
into the axis that fall within the range of coordinates in argument
rng. Returns NULL if no values of the axis fall within the range of
coordinates.
subset()
Retrieve a subset of the labels.
CFLabel$subset(name, group, rng)
nameThe name for the new label set, optional.
groupThe CFGroup where the copy of this label set will live.
rngThe range of indices whose values from this axis to include in the returned axis.
A CFLabel instance, or NULL if the rng values are invalid.
write()
Write the labels to a netCDF file, including its attributes.
CFLabel$write()
Self, invisibly.
This class is a basic ancestor to all classes that represent CF objects. More useful classes use this class as ancestor.
friendlyClassName(read-only) A nice description of the class.
id(read-only) Retrieve the identifier of the CF object.
nameSet or retrieve the name of the CF object. The name must be a valid netCDF name: start with a character, use only characters, numbers and the underscore, and be at most 255 characters long.
fullname(read-only) The fully-qualified name of the CF object.
groupSet or retrieve the CFGroup that this object is
located in, possibly NULL.
attributes(read-only) Retrieve a data.frame with the attributes
of the CF object.
has_resource(read-only) Flag that indicates if this object has an underlying netCDF resource.
NC(read-only) The NC object that links to an underlying netCDF
resource, or NULL if not linked.
is_dirtyFlag to indicate if the object has any unsaved changes.
new()
Create a new CFobject instance in memory or from an object
in a netCDF resource when this method is called upon opening a netCDF
resource. It is rarely, if ever, useful to call this constructor
directly. Instead, use the methods from higher-level classes such as
CFVariable.
CFObject$new(obj, attributes = data.frame(), group = NULL)
objThe NCObject instance upon which this CF object is based when read from a netCDF resource, or the name for the new CF object to be created.
attributesOptional. A data.frame with the attributes of the
object. When argument obj is an NCGroup instance and this argument
is an empty data.frame (default), arguments will be read from the
resource.
groupThe CFGroup instance that this object will live in. The
default is NULL but this is only useful for CFGroup instance.
A CFObject instance.
attach_to_group()
Attach this CF object to a group. If there is another object with the same name in this group an error is thrown. This is the basic method that may be overridden by descendant classes.
CFObject$attach_to_group(grp, locations = list())
grpAn instance of CFGroup.
locationsOptional. A list whose named elements correspond to
the names of objects, possibly including this object. Each list element
has a single character string indicating the group in the hierarchy
where the object should be stored. As an example, if a data variable
has axes "lon" and "lat" and they should be stored in the parent group
of grp, then specify locations = list(lon = "..", lat = "..").
Locations can use absolute paths or relative paths from group grp. If
the argument locations is not provided or the name of the object is
not in the list, the object will be stored in group grp.
Self, invisibly.
detach()
Detach the current object from its underlying netCDF resource.
CFObject$detach()
attribute()
Retrieve an attribute of a CF object.
CFObject$attribute(att, field = "value")
attSingle character string of attribute to return.
fieldThe field of the attribute to return values from. This must be "value" (default) or "type".
If the field argument is "type", a character string. If field
is "value", a single value of the type of the attribute, or a vector
when the attribute has multiple values. If no attribute is named with a
value of argument att NA is returned.
print_attributes()
Print the attributes of the CF object to the console.
CFObject$print_attributes(width = 30L)
widthThe maximum width of each column in the data.frame when
printed to the console.
set_attribute()
Add an attribute. If an attribute name already exists, it
will be overwritten.
CFObject$set_attribute(name, type, value)
nameThe name of the attribute. The name must begin with a letter and be composed of letters, digits, and underscores, with a maximum length of 255 characters. UTF-8 characters are not supported in attribute names.
typeThe type of the attribute, as a string value of a netCDF data type.
valueThe value of the attribute. This can be of any supported type, including a vector or list of values. Matrices, arrays and like compound data structures should be stored as a data variable, not as an attribute and they are thus not allowed. In general, an attribute should be a character value, a numeric value, a logical value, or a short vector or list of any of these. Values passed in a list will be coerced to their common mode.
Self, invisibly.
attributes_identical()
Test if the supplied attributes are identical to the attributes of this instance. The order of the attributes may differ but the names, types and values must coincide.
CFObject$attributes_identical(cmp)
cmpdata.frame with attributes to compare to the attributes of
this instance.
TRUE if attributes in argument cmp are identical to the
attributes of this instance, FALSE otherwise.
append_attribute()
Append the text value of an attribute. If an attribute
name already exists, the value will be appended to the existing
value of the attribute. If the attribute name does not exist it will
be created. The attribute must be of "NC_CHAR" or "NC_STRING" type; in
the latter case having only a single string value.
CFObject$append_attribute(name, value, sep = "; ", prepend = FALSE)
nameThe name of the attribute. The name must begin with a letter and be composed of letters, digits, and underscores, with a maximum length of 255 characters. UTF-8 characters are not supported in attribute names.
valueThe character value of the attribute to append. This must be a character string.
sepThe separator to use. Default is "; ".
prependLogical to flag if the supplied value should be placed
before the existing value. Default is FALSE.
Self, invisibly.
delete_attribute()
Delete attributes. If an attribute name is not present
this method simply returns.
CFObject$delete_attribute(name)
nameVector of names of the attributes to delete.
Self, invisibly.
write_attributes()
Write the attributes of this object to a netCDF file.
CFObject$write_attributes()
Self, invisibly.
clone()
The objects of this class are cloneable with this method.
CFObject$clone(deep = FALSE)
deepWhether to make a deep clone.
The CF Metadata Conventions define a large number of standard names for physical parameters, including axes and data variables. This class accesses the standard names table. For each of the entries in the table two properties are provided: the canonical unit and a description. These properties are retrieved when searching for a given name.
Access to this class is through the CF environment. Use the
CF$standard_names$find("name_of_interest") method to access a particular
standard name. It is strongly recommended not to instantiate this class
manually as that may introduce problems with accessing the underlying XML
file.
The XML table is retrieved from the CF Metadata Conventions web site
here and stored locally in
the cache of the ncdfCF package. A check is performed periodically for an
updated version, which will then be downloaded automatically. The frequency
of the update check can be controlled with the
CF.options$cache_stale_days option.
is_loaded(read-only) Flag to determine if the standard names table is available.
new()
Initialize an instance of this class. This is done automatically when the package is loaded.
CFStandardNames$new()
print()
Print the version number of the standard names table in use, if it is loaded. The table is loaded automatically when it is first used.
CFStandardNames$print()
find()
Retrieve the information on the specified names.
CFStandardNames$find(names)
namesA character vector with the names to search the standard names table for.
If an entry with a value in names is found, returns a
data.frame with with with the canonical units and a description of
the name. If no names are found in the table NULL is returned.
load()
Load the standard names table so that it's contents may be used in display and analysis. Note that the table may be downloaded (4.3MB at version 91) if not available or stale.
CFStandardNames$load()
Self, invisibly.
clone()
The objects of this class are cloneable with this method.
CFStandardNames$clone(deep = FALSE)
deepWhether to make a deep clone.
https://cfconventions.org/cf-conventions/cf-conventions.html#standard-name
This class represents a CF data variable, the object that provides access to an array of data.
The CF data variable instance provides access to all the details that have been associated with the data variable, such as axis information, grid mapping parameters, etc.
ncdfCF::CFObject -> ncdfCF::CFData -> CFVariable
friendlyClassName(read-only) A nice description of the class.
axes(read-only) List of instances of classes descending from CFAxis that are the axes of the data object.
ancillary_variablesA list of ancillary data variables associated with this data variable.
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_measures(read-only) List of the CFCellMeasure objects of this variable, if defined.
dimids(read-only) Retrieve the dimension ids used by the NC variable used by this variable.
dimnames(read-only) Retrieve dimnames of the data variable.
auxiliary_names(read-only) Retrieve the names of the auxiliary
longitude and latitude grids as a vector of two character strings, in
that order. If no auxiliary grids are defined, returns NULL.
values(read-only) Retrieve the raw values of the data variable.
In general you should use the raw() function rather than this method
because the raw() function will attach dimnames to the array that
is returned.
gridLongLatRetrieve or set the grid of longitude and latitude values of every grid cell when the main variable grid has a different coordinate system.
crs_wkt2(read-only) Retrieve the coordinate reference system description of the variable as a WKT2 string.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()new()
Create an instance of this class.
CFVariable$new( var, group, axes, values = values, start = NA, count = NA, attributes = data.frame() )
varThe NCVariable instance upon which this CF variable is based when read from a netCDF resource, or the name for the new CF variable to be created.
groupThe CFGroup that this instance will live in.
axesList of instances of CFAxis to use with this variable.
valuesOptional. The values of the variable in an array.
startOptional. Vector of indices where to start reading data
along the dimensions of the NC variable on file. The vector must be
NA to read all data, otherwise it must have agree with the dimensions
of the NC variable. Ignored when argument var is not an NCVariable
instance.
countOptional. Vector of number of elements to read along each
dimension of the NC variable on file. The vector must be NA to read
to the end of each dimension, otherwise its value must agree with the
corresponding start value and the dimension of the NC variable.
Ignored when argument var is not an NCVariable instance.
attributesOptional. A data.frame with the attributes of the
object. When argument var is an NCVariable instance and this
argument is an empty data.frame (default), arguments will be read
from the netCDF resource.
A CFVariable instance.
print()
Print a summary of the data variable to the console.
CFVariable$print(...)
...Arguments passed on to other functions. Of particular interest
is width = to indicate a maximum width of attribute columns.
brief()
Some details of the data variable.
CFVariable$brief()
A 1-row data.frame with some details of the data variable.
shard()
The information returned by this method is very concise and most useful when combined with similar information from other variables.
CFVariable$shard()
Character string with very basic variable information.
peek()
Retrieve interesting details of the data variable.
CFVariable$peek()
A 1-row data.frame with details of the data variable.
detach()
Detach the various properties of this variable from an underlying netCDF resource.
CFVariable$detach()
Self, invisibly.
time()
Return the time object from the axis representing time.
CFVariable$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.
raw()
Retrieve the data in the object exactly as it was read from a netCDF resource or produced by an operation.
CFVariable$raw()
An array, matrix or vector with (dim)names set.
array()
Retrieve the data in the object in the form of an R array, with axis ordering Y-X-others and Y values going from the top down.
CFVariable$array()
An array or matrix of data in R ordering, or a vector if
the data has only a single dimension.
subset()
This method extracts a subset of values from the array of the variable, with the range along each axis to extract expressed in coordinate values of the domain of each axis.
CFVariable$subset(..., rightmost.closed = FALSE, .resolution = NULL)
...One or more arguments of the form axis = range. The "axis"
part should be the name of an axis or its orientation X, Y, Z or
T. The "range" part is a vector of values representing coordinates
along the axis where to extract data. Axis designators and names are
case-sensitive and can be specified in any order. If values for the
range per axis fall outside of the extent of the axis, the range is
clipped to the extent of the axis.
rightmost.closedSingle logical value to indicate if the upper
boundary of range in each axis should be included. You must use the
argument name when specifying this, like rightmost.closed = TRUE, to
avoid the argument being treated as an axis name.
.resolutionFor interpolation with auxiliary coordinates, the resolution in longitude and latitude directions as numeric values in decimal degrees, optional. If a single value is given, it will apply in both directions. If not supplied, the resolution in the center of the requested area will be calculated and applied over the entire area.
The range of values along each axis to be subset is expressed in
coordinates of the domain of the axis. Any axes for which no selection
is made in the ... argument are extracted in whole. Coordinates can
be specified in a variety of ways that are specific to the nature of
the axis. For numeric axes it should (resolve to) be a vector of real
values. A range (e.g. 100:200), a vector (c(23, 46, 3, 45, 17), a
sequence (seq(from = 78, to = 100, by = 2), all work. Note, however,
that only a single range is generated from the vector so these examples
resolve to (100, 200), (3, 46), and (78, 100), respectively. For
time axes a vector of character timestamps, POSIXct or Date values
must be specified. As with numeric values, only the two extreme values
in the vector will be used.
If the range of coordinate values for an axis in argument ... extends
the valid range of the axis, the extracted data will start at the
beginning for smaller values and extend to the end for larger values.
If the values envelope the valid range the entire axis will be
extracted in the result. If the range of coordinate values for any axis
are all either smaller or larger than the valid range of the axis then
nothing is extracted and NULL is returned.
The extracted data has the same dimensional structure as the data in
the variable, with degenerate dimensions preserved. The order of the
axes in argument ... does not reorder the axes in the result; use the
array() method for this.
As an example, to extract values of a variable for Australia for the
year 2020, where the first axis in x is the longitude, the second
axis is the latitude, both in degrees, and the third (and final) axis
is time, the values are extracted by x$subset(X = c(112, 154), Y = c(-9, -44), T = c("2020-01-01", "2021-01-01")). Note that this works
equally well for projected coordinate reference systems - the key is
that the specification in argument ... uses the same domain of values
as the respective axes in x use.
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 for longitude and latitude that are
two grids with the same dimension as the horizontal axes of the data
variable where each pixel gives the corresponding value for the
longitude and latitude. If the variable has such auxiliary coordinate
variables then you can specify their names (instead of specifying the
names of the primary planar axes). The resolution of the grid that is
produced by this method is automatically calculated. If you want to
subset those axes then specify values in decimal degrees; if you want
to extract the full extent, specify NA for both axes.
A CFVariable instance, having the axes and attributes of the
variable, or NULL if one or more of the selectors in the ...
argument fall entirely outside of the range of the axis.
If self is linked to a netCDF resource then the result will be linked
to the same netCDF resource as well, except when auxiliary coordinate
variables have been selected for the planar axes. In all cases the
result will be attached to a private group.
summarise()
Summarise the temporal domain of the data, if present, to a lower resolution, using a user-supplied aggregation function.
CFVariable$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, quite possibly 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.
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 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 CFVariable$set_attribute() on the result of this
method to set or update attributes as appropriate.
A CFVariable object, or a list thereof with as many
CFVariable objects as fun returns values, or NULL if the era
argument falls entirely outside of the range of the time axis.
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.
CFVariable$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 resulting CFVariable 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 CFVariable
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 CFVariable
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 variable has such auxiliary coordinate variables then you can specify their names (instead of specifying the names of the primary planar axes).
If .as_table == FALSE, a CFVariable 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.
append()
Append the data from another CFVariable instance to the
current instance, along one of the axes. The operation will only
succeed if the axes other than the one to append along have the same
coordinates and the coordinates of the axis to append along have to be
monotonically increasing or decreasing after appending. The attributes
are not assessed.
CFVariable$append(from, along)
fromThe CFVariable instance to append to this data variable.
alongThe name of the axis to append along. This must be a single
character string and the named axis has to be present both in this data
variable and in the CFVariable instance in argument from.
Self, invisibly, with the arrays from this data variable and
from appended, in a new private group.
is_coincident()
Tests if the other object is coincident with this data
variable: identical axes.
CFVariable$is_coincident(other)
otherA CFVariable instance to compare to this data variable.
TRUE if the data variables are coincident, FALSE otherwise.
add_cell_measure()
Add a cell measure variable to this variable.
CFVariable$add_cell_measure(cm)
cmAn instance of CFCellMeasure.
Self, invisibly.
add_auxiliary_coordinate()
Add an auxiliary coordinate to the appropriate axis of this variable. The length of the axis must be the same as the length of the auxiliary labels.
CFVariable$add_auxiliary_coordinate(aux, axis)
Self, invisibly.
add_ancillary_variable()
Add an ancillary variable to this variable.
CFVariable$add_ancillary_variable(var)
varAn instance of CFVariable.
Self, invisibly.
attach_to_group()
Attach this variable to a group. If there is another object with the same name in this group an error is thrown. For associated objects (such as axes, CRS, boundary variables, etc), if another object with the same name is otherwise identical to the associated object then that object will be linked from the variable, otherwise an error is thrown.
CFVariable$attach_to_group(grp, locations = list())
grpAn instance of CFGroup.
locationsOptional. A list whose named elements correspond to
the names of objects associated with this variable (but not the
variable itself). Each list element has a single character string
indicating the group in the hierarchy where the object should be
stored. As an example, if the variable has axes "lon" and "lat" and
they should be stored in the parent group of grp, then specify
locations = list(lon = "..", lat = ".."). Locations can use absolute
paths or relative paths from the group. Associated objects that are not
in the list will be stored in group grp. If the argument locations
is not provided, all associated objects will be stored in this group.
Self, invisibly.
terra()
Convert the data to a terra::SpatRaster (3D) or a
terra::SpatRasterDataset (4D) object. The data will be oriented to
North-up. The 3rd dimension in the data will become layers in the
resulting SpatRaster, any 4th dimension the data sets. The terra
package needs to be installed for this method to work.
CFVariable$terra()
A terra::SpatRaster or terra::SpatRasterDataset instance.
data.table()
Retrieve the data variable in the object in the form of a
data.table. The data.table package needs to be installed for this
method to work.
The attributes associated with this data variable will be mostly lost.
If present, attributes 'long_name' and 'units' are attached to the
data.table as attributes, but all others are lost.
CFVariable$data.table(var_as_column = FALSE)
var_as_columnLogical to flag if the name of the variable should
become a column (TRUE) or be used as the name of the column with the
data values (FALSE, default). Including the name of the variable as a
column is useful when multiple data.tables are merged by rows into
one.
A data.table with all data points in individual rows. All axes
will become columns. Two attributes are added: name indicates the
long name of this data variable, units indicates the physical unit of
the data values.
write()
Write the data variable to a netCDF file, including all of its dependent objects, such as axes and attributes.
Axes with length == 1L are written as a "scalar axis", unless they
are unlimited.
CFVariable$write(pack)
packOptional. Logical to indicate if the data should be packed
for a CFVariable first written to file. Packing is only useful for
numeric data; packing is not performed on integer values. Packing is
always to the "NC_SHORT" data type, i.e. 16-bits per value. If the
variable has been written before, the packing state of the variable on
file will be used.
Self, invisibly.
save()
Save the data variable to a netCDF file, including its subordinate objects such as axes, CRS, etc. Note that saving a data variable will create a "bare-bones" netCDF file and its associated CFDataset.
CFVariable$save(fn, pack = FALSE)
fnThe name of the netCDF file to create.
packLogical to indicate if the data should be packed. Packing is only useful for numeric data; packing is not performed on integer values. Packing is always to the "NC_SHORT" data type, i.e. 16-bits per value.
The newly create CFDataset, invisibly.
This class represents a CF data variable that provides access to data sets in NASA level-3 binned format, used extensively for satellite imagery.
ncdfCF::CFObject -> ncdfCF::CFData -> ncdfCF::CFVariable -> CFVariableL3b
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()ncdfCF::CFVariable$add_ancillary_variable()ncdfCF::CFVariable$add_auxiliary_coordinate()ncdfCF::CFVariable$add_cell_measure()ncdfCF::CFVariable$append()ncdfCF::CFVariable$array()ncdfCF::CFVariable$attach_to_group()ncdfCF::CFVariable$brief()ncdfCF::CFVariable$data.table()ncdfCF::CFVariable$detach()ncdfCF::CFVariable$is_coincident()ncdfCF::CFVariable$peek()ncdfCF::CFVariable$print()ncdfCF::CFVariable$profile()ncdfCF::CFVariable$raw()ncdfCF::CFVariable$save()ncdfCF::CFVariable$shard()ncdfCF::CFVariable$summarise()ncdfCF::CFVariable$terra()ncdfCF::CFVariable$time()ncdfCF::CFVariable$write()new()
Create an instance of this class.
CFVariableL3b$new(grp, units)
grpThe group that this CF variable lives in. Must be called "/level-3_binned_data".
unitsVector of two character strings with the variable name and the physical units of the data variable in the netCDF resource.
An instance of this class.
subset()
This method extracts a subset of values from the data of the variable, with the range along both axes expressed in decimal degrees.
CFVariableL3b$subset(..., rightmost.closed = FALSE)
...One or more arguments of the form axis = range. The "axis"
part should be the name of axis longitude or latitude or its
orientation X or Y. The "range" part is a vector of values
representing coordinates along the axis where to extract data. Axis
designators and names are case-sensitive and can be specified in any
order. If values for the range of an axis fall outside of the extent of
the axis, the range is clipped to the extent of the axis.
rightmost.closedSingle logical value to indicate if the upper boundary of range in each axis should be included.
The range of values along both axes of latitude and longitude is
expressed in decimal degrees. Any axes for which no information is
provided in the subset argument are extracted in whole. Values can be
specified in a variety of ways that should (resolve to) be a vector of
real values. A range (e.g. 100:200), a vector (c(23, 46, 3, 45, 17), a sequence (seq(from = 78, to = 100, by = 2), all work. Note,
however, that only a single range is generated from the vector so these
examples resolve to (100, 200), (3, 46), and (78, 100),
respectively.
If the range of values for an axis in argument subset extend the
valid range of the axis in x, the extracted slab will start at the
beginning for smaller values and extend to the end for larger values.
If the values envelope the valid range the entire axis will be
extracted in the result. If the range of subset values for any axis
are all either smaller or larger than the valid range of the axis in
x then nothing is extracted and NULL is returned.
The extracted data has the same dimensional structure as the data in
the variable, with degenerate dimensions dropped. The order of the axes
in argument subset does not reorder the axes in the result; use the
CFVariable$array() method for this.
A CFVariable instance, having an array with axes and attributes of
the variable, or NULL if one or more of the elements in the ...
argument falls entirely outside of the range of the axis. Note that
degenerate dimensions (having length(.) == 1) are dropped from the
array but the corresponding axis is maintained in the result as a
scalar axis.
https://oceancolor.gsfc.nasa.gov/resources/docs/technical/ocean_level-3_binned_data_products.pdf
This class represents a formula term for a parametric vertical axis.
ncdfCF::CFObject -> ncdfCF::CFData -> ncdfCF::CFVariable -> CFVerticalParametricTerm
has_dataLogical flag that indicates of the instance has an
associated data variable. If not, the instance will report 0 as its
data.
values(read-only) The values of the parametric term. Depending on
the definition of the term, this could be a large array or a simple
scalar. Specifically, if the term is defined but no data is included in
the netCDF resource, this method will return 0, as per the CF
Metadata Conventions.
ncdfCF::CFObject$append_attribute()ncdfCF::CFObject$attribute()ncdfCF::CFObject$attributes_identical()ncdfCF::CFObject$delete_attribute()ncdfCF::CFObject$print_attributes()ncdfCF::CFObject$set_attribute()ncdfCF::CFObject$write_attributes()ncdfCF::CFData$dim()ncdfCF::CFData$read_chunk()ncdfCF::CFData$read_data()ncdfCF::CFVariable$add_ancillary_variable()ncdfCF::CFVariable$add_auxiliary_coordinate()ncdfCF::CFVariable$add_cell_measure()ncdfCF::CFVariable$append()ncdfCF::CFVariable$array()ncdfCF::CFVariable$attach_to_group()ncdfCF::CFVariable$brief()ncdfCF::CFVariable$data.table()ncdfCF::CFVariable$detach()ncdfCF::CFVariable$is_coincident()ncdfCF::CFVariable$peek()ncdfCF::CFVariable$profile()ncdfCF::CFVariable$raw()ncdfCF::CFVariable$save()ncdfCF::CFVariable$shard()ncdfCF::CFVariable$summarise()ncdfCF::CFVariable$terra()ncdfCF::CFVariable$time()ncdfCF::CFVariable$write()new()
Create an instance of this class.
CFVerticalParametricTerm$new( var, group, axes, values = values, start = NA, count = NA, attributes = data.frame() )
varThe NCVariable instance upon which this CF variable is based when read from a netCDF resource, or the name for the new CF variable to be created.
groupThe CFGroup that this instance will live in.
axesA list of CFAxis descendant instances that describe the
axes of the data object.
valuesOptional. The values of the variable in an array.
startOptional. Vector of indices where to start reading data
along the dimensions of the array on file. The vector must be NA to
read all data, otherwise it must have agree with the dimensions of the
array on file. Ignored when argument var is not an NCVariable
instance.
countOptional. Vector of number of elements to read along each
dimension of the array on file. The vector must be NA to read to the
end of each dimension, otherwise its value must agree with the
corresponding start value and the dimension of the array on file.
Ignored when argument var is not an NCVariable instance.
attributesOptional. A data.frame with the attributes of the
object. When argument var is an NCVariable instance and this
argument is an empty data.frame (default), arguments will be read
from the resource.
An instance of this class.
print()
Prints a summary of the parametric formula term to the console.
CFVerticalParametricTerm$print(...)
...Arguments passed on to other functions. Of particular interest
is width = to indicate a maximum width of attribute columns.
self, invisibly.
subset()
Subset the indices to read a smaller portion of the data from the netCDF file. The passed indices should be named after the axes that they refer to. There may be more indices than axes and they may be in a different order than the axes of the term.
CFVerticalParametricTerm$subset( original_axis_names, new_axes, start, count, aux = NULL, ZT_dim = NULL )
original_axis_namesCharacter vector of names of the axes prior to a modifying operation in the owning data variable.
new_axesList of CFAxis instances to use for the subsetting.
startThe indices to start reading data from the file, as an integer vector at least as long as the number of axis for the term.
countThe number of values to read from the file, as an integer vector at least as long as the number of axis for the term.
auxOptional. List with the parameters for an auxiliary grid
transformation. Default is NULL.
ZT_dimOptional. Dimensions of the non-grid axes when an auxiliary grid transformation is specified.
The new parametric term object.
This function creates a new, empty data set in memory. You can add groups,
data variables and attributes to this data set as appropriate. The data set
can be saved with CFDataset$save(), if so desired.
create_ncdf()create_ncdf()
This method returns the dimensions of the grid that would be created for the AOI.
## S3 method for class 'AOI' dim(x)## S3 method for class 'AOI' dim(x)
x |
An instance of the |
A vector of two values giving the longitude and latitude dimensions of the grid that would be created for the AOI.
a <- aoi(30, 40, 10, 30, 0.1) dim(a)a <- aoi(30, 40, 10, 30, 0.1) dim(a)
This method returns the lengths of the axes of a variable or axis.
## S3 method for class 'CFAxis' dim(x)## S3 method for class 'CFAxis' dim(x)
x |
A |
For a CFVariable instance in argument x, a named vector of axis
lengths, excluding any scalar axes. For a CFAxis descendant instance in
argument x, the length of the axis.
fn <- system.file("extdata", "ERA5land_Rwanda_20160101.nc", package = "ncdfCF") ds <- open_ncdf(fn) t2m <- ds[["t2m"]] dim(t2m) dim(t2m$axes[["time"]])fn <- system.file("extdata", "ERA5land_Rwanda_20160101.nc", package = "ncdfCF") ds <- open_ncdf(fn) t2m <- ds[["t2m"]] dim(t2m) dim(t2m$axes[["time"]])
CFVariable
This is a basic function to support plotting of ncdfCF data
with the ggplot2 package. Specifically, this function creates a geo_ncdf
object which can be used like a geom_raster. The geom_ncdf takes a
CFVariable instance as its data. The CFVariable should be properly
pre-processed to make it suitable for plotting. The $subset() method is
well suited for this task. Note that currently only map plotting works, e.g.
the CFVariable should have X and Y axes.
geom_ncdf(mapping = NULL, data, ...)geom_ncdf(mapping = NULL, data, ...)
mapping |
As in geom_raster. If the argument
is not provided, a mapping is constructed from the properties of the |
data |
A CFVariable instance. This will override any |
... |
Arguments passed on to |
A geom_* object that can be used in ggplot2 plot composition.
library(ggplot2) fn <- system.file("extdata", "tasmax_NAM-44_day_20410701-vncdfCF.nc", package = "ncdfCF") ds <- open_ncdf(fn) tasmax <- ds[["tasmax"]] ggplot() + geom_ncdf(data = tasmax) + coord_equal() + scale_fill_viridis_c()library(ggplot2) fn <- system.file("extdata", "tasmax_NAM-44_day_20410701-vncdfCF.nc", package = "ncdfCF") ds <- open_ncdf(fn) tasmax <- ds[["tasmax"]] ggplot() + geom_ncdf(data = tasmax) + coord_equal() + scale_fill_viridis_c()
List the groups in the CF object, recursively.
groups(x) ## S3 method for class 'CFDataset' groups(x)groups(x) ## S3 method for class 'CFDataset' groups(x)
x |
A |
A character vector with group names in the object.
fn <- system.file("extdata", "ERA5land_Rwanda_20160101.nc", package = "ncdfCF") ds <- open_ncdf(fn) groups(ds)fn <- system.file("extdata", "ERA5land_Rwanda_20160101.nc", package = "ncdfCF") ds <- open_ncdf(fn) groups(ds)
With this function you can create an axis to use with new CFVariable
instances. Depending on the orientation argument and the type of the
values argument an instance of a class descending from CFAxis will be
returned.
makeAxis( name, orientation, values, bounds = NULL, attributes = data.frame(), group = NULL )makeAxis( name, orientation, values, bounds = NULL, attributes = data.frame(), group = NULL )
name |
Name of the axis. |
orientation |
The orientation of the axis. Must be one of "X", "Y", "Z", or "T" for longitude, latitude, height or depth, and time axes, respectively. For any other axis, indicate an empty string "" |
values |
The coordinate values. In the case of an axis with |
bounds |
The boundary values of the coordinates, or |
attributes |
|
group |
CFGroup instance where the axis will be located. If |
There are several restrictions on the combination of orientation and
values arguments. Longitude, latitude and depth axes (orientation of "X",
"Y" or "Z") must have numeric values. For a time axis (orientation of
"T") the values argument must be an instance of CFTime or
CFClimatology.
An instance of a class descending from CFAxis.
makeLongitudeAxis(), makeLatitudeAxis(), makeTimeAxis(),
makeDiscreteAxis()
With this method you can create a character axis to use with new CFVariable instances.
makeCharacterAxis(name, values, attributes = data.frame(), group = NULL)makeCharacterAxis(name, values, attributes = data.frame(), group = NULL)
name |
Name of the axis. |
values |
The character coordinate values of the axis. |
attributes |
|
group |
CFGroup instance where the axis will be located. If |
A CFAxisCharacter instance.
With this method you can create a discrete axis to use with new CFVariable instances.
makeDiscreteAxis(name, length, group = NULL)makeDiscreteAxis(name, length, group = NULL)
name |
Name of the axis. |
length |
The length of the axis. |
group |
CFGroup instance where the axis will be located. If |
A CFAxisDiscrete instance. The values will be a sequence of size
length.
This function creates a new group for CF objects. Groups are organized in an
hierarchy, starting with a root node. A root node is specified by an empty
string for a name and with argument parent_group = NULL.
makeGroup(name = "", parent_group = NULL)makeGroup(name = "", parent_group = NULL)
name |
A name for the group. This must be a valid name for CF objects. The default value is the empty string "". |
parent_group |
Optionally, a parent for the current group. This must be
an instance of |
A new instance of CFGroup.
root <- makeGroup() sub_group <- makeGroup("sub", root)root <- makeGroup() sub_group <- makeGroup("sub", root)
With this method you can create a latitude axis to use with new CFVariable instances.
makeLatitudeAxis( name, values, bounds = NULL, attributes = data.frame(), group = NULL )makeLatitudeAxis( name, values, bounds = NULL, attributes = data.frame(), group = NULL )
name |
Name of the axis. |
values |
The coordinate values. |
bounds |
The bounds of the coordinate values, or |
attributes |
|
group |
CFGroup instance where the axis will be located. If |
A CFAxisLatitude instance.
With this method you can create a longitude axis to use with new CFVariable instances.
makeLongitudeAxis( name, values, bounds = NULL, attributes = data.frame(), group = NULL )makeLongitudeAxis( name, values, bounds = NULL, attributes = data.frame(), group = NULL )
name |
Name of the axis. |
values |
The coordinate values. |
bounds |
The bounds of the coordinate values, or |
attributes |
|
group |
CFGroup instance where the axis will be located. If |
A CFAxisLongitude instance.
With this method you can create a time axis to use with new CFVariable instances.
makeTimeAxis(name, values, attributes = data.frame(), group = NULL)makeTimeAxis(name, values, attributes = data.frame(), group = NULL)
name |
Name of the axis. |
values |
A |
attributes |
|
group |
CFGroup instance where the axis will be located. If |
A CFAxisTime instance.
With this method you can create a vertical axis to use with new CFVariable instances. Note that you should set the "positive" attribute after creating the axis to indicate if values are increasing going upwards (positive = "up") or downwards (positive = "down").
makeVerticalAxis( name, values, bounds = NULL, attributes = data.frame(), group = NULL )makeVerticalAxis( name, values, bounds = NULL, attributes = data.frame(), group = NULL )
name |
Name of the axis. |
values |
The coordinate values. |
bounds |
The bounds of the coordinate values, or |
attributes |
|
group |
CFGroup instance where the axis will be located. If |
A CFAxisVertical instance.
Retrieve the variable or axis names of an ncdfCF object. The
names() function gives the names of the variables in the data set,
preceded by the path to the group if the resource uses groups. The return
value of the dimnames() function differs depending on the type of object:
CFDataset, CFVariable: The dimnames are returned as a vector of the
names of the axes of the data set or variable, preceded with the path to
the group if the resource uses groups. Note that this differs markedly from
the base::dimnames() functionality.
CFAxisNumeric, CFAxisLongitude, CFAxisLatitude, CFAxisVertical: The
coordinate values along the axis as a numeric vector.
CFAxisTime: The coordinate values along the axis as a
character vector containing timestamps in ISO8601 format. This could be
dates or date-times if time information is available in the axis.
CFAxisCharacter: The coordinate values along the axis as
a character vector.
CFAxisDiscrete: The index values of the axis, either along the entire
axis, or a portion thereof.
## S3 method for class 'CFDataset' names(x)## S3 method for class 'CFDataset' names(x)
x |
An |
A vector as described in the Description section.
fn <- system.file("extdata", "pr_day_EC-Earth3-CC_ssp245_r1i1p1f1_gr_20230101-20231231_vncdfCF.nc", package = "ncdfCF") ds <- open_ncdf(fn) # Names of data variables names(ds) # CFDataset dimnames(ds) # CFVariable pr <- ds[["pr"]] dimnames(pr) # CFAxisNumeric lon <- ds[["lon"]] dimnames(lon) # CFAxisTime t <- ds[["time"]] dimnames(t)fn <- system.file("extdata", "pr_day_EC-Earth3-CC_ssp245_r1i1p1f1_gr_20230101-20231231_vncdfCF.nc", package = "ncdfCF") ds <- open_ncdf(fn) # Names of data variables names(ds) # CFDataset dimnames(ds) # CFVariable pr <- ds[["pr"]] dimnames(pr) # CFAxisNumeric lon <- ds[["lon"]] dimnames(lon) # CFAxisTime t <- ds[["time"]] dimnames(t)
This class represents an netCDF dimension. It contains the information on a dimension that is stored in an netCDF file. Consequently, the properties of this class are all read-only. The length of the dimension may change if data is written to an unlimited dimension, but that is managed internally.
This class is not very useful for interactive use. Use the CFAxis descendent classes instead.
ncdfCF::NCObject -> NCDimension
length(read-only) The length of the dimension. If field unlim = TRUE, this field indicates the length of the data in this dimension
written to file.
unlim(read-only) Logical flag to indicate if the dimension is unlimited, i.e. that additional data may be written to file incrementing this dimension.
new()
Create a new netCDF dimension. This class should not be instantiated directly, create CF objects instead. This class is instantiated when opening a netCDF resource.
NCDimension$new(id, name, length = 1L, unlim = FALSE, group)
idNumeric identifier of the netCDF dimension.
nameCharacter string with the name of the netCDF dimension.
lengthLength of the dimension. Default is 1.
unlimIs the dimension unlimited? Default is FALSE.
groupThe NC group where the dimension is located.
A NCDimension instance.
print()
Summary of the NC dimension printed to the console.
NCDimension$print(...)
...Passed on to other methods.
write()
Write the dimension to a netCDF file.
NCDimension$write(h)
hThe handle to the netCDF file to write.
Self, invisibly.
clone()
The objects of this class are cloneable with this method.
NCDimension$clone(deep = FALSE)
deepWhether to make a deep clone.
This class represents a netCDF group, the object that holds elements like dimensions and variables of a netCDF file.
Direct access to groups is usually not necessary. The principal objects of interest, CF data variables and axes, are accessible via CFGroup. Changing the properties of a netCDF group other than its name may very well invalidate the CF objects or even the netCDF file.
ncdfCF::NCObject -> NCGroup
parentParent group of this group, the owning CFDataset for the
root group.
subgroupsList of child NCGroup instances of this group.
NCvarsList of netCDF variables that are located in this group.
NCdimsList of netCDF dimensions that are located in this group.
NCudtsList of netCDF user-defined types that are located in this group.
friendlyClassName(read-only) A nice description of the class.
resource(read-only) The RNetCDF object to the underlying netCDF resource.
handle(read-only) Get the handle to the netCDF resource for the group
can_write(read-only) Is the resource writable?
nameSet or retrieve the name of the group. Note that the name is always relative to the location in the hierarchy that the group is in and it should thus not be qualified by backslashes. The name has to be a valid CF name. The name of the root group cannot be changed.
fullname(read-only) The fully qualified absolute path of the group.
root(read-only) Retrieve the root group.
CFSet or retrieve the CFGroup that is associated with this NC group.
new()
Create a new instance of this class.
NCGroup$new(id, name, attributes = data.frame(), parent, resource)
idThe identifier of the group. If NA, the new group will be
created in the netCDF resource, unless argument parent == NULL, i.e.
the root group which already exists.
nameThe name of the group.
attributesOptional, a data.frame with group attributes.
parentThe parent group of this group. If NULL then argument
resource must be a valid instance of NCResource.
resourceOptional. Reference to the NCResource instance that provides access to the netCDF resource.
An instance of this class.
print()
Summary of the group printed to the console.
NCGroup$print(stand_alone = TRUE, ...)
stand_aloneLogical to indicate if the group should be printed as
an object separate from other objects (TRUE, default), or print as part
of an enclosing object (FALSE).
...Passed on to other methods.
find_by_name()
Find an object by its name. Given the name of an object, possibly preceded by an absolute or relative group path, return the object to the caller. Usually this method is called programmatically.
NCGroup$find_by_name(name)
nameThe name of an object, with an optional absolute or relative group path from the calling group. The object must be an NC group, dimension or variable.
The object with the provided name. If the object is not found,
returns NULL.
find_dim_by_id()
Find an NC dimension object by its id. Given the id of a dimension, return the NCDimension object to the caller. The dimension has to be found in the current group or any of its parents.
NCGroup$find_dim_by_id(id)
idThe id of the dimension.
The NCDimension object with an identifier equal to the id
argument. If the object is not found, returns NULL.
has_name()
Has a given name been defined in this group already?
NCGroup$has_name(name)
nameCharacter string. The name will be searched for, regardless of case.
TRUE if name is present in the group, FALSE otherwise.
set_name()
Change the name of the NC group. The new name must be valid and should not duplicate a sibling group.
NCGroup$set_name(new_name)
new_nameThe new name for the NC group.
Self, invisibly.
unused()
Find NC variables that are not referenced by CF objects. For debugging purposes only.
NCGroup$unused()
List of NCVariable.
create_group()
Create a new group as a sub-group of the current group. This writes the new group to the netCDF resource, but only if it is open for writing.
NCGroup$create_group(CFgroup)
CFgroupThe CFGroup associated with this NC group.
The newly created group as a NCGroup instance, invisibly.
append()
Append an object to this group.
NCGroup$append(obj)
objThe object to append. This must be an NCVariable or
NCDimension instance. Any other type of object will generate a
warning.
Self, invisible.
fullnames()
This method lists the fully qualified name of this group, optionally including names in subgroups.
NCGroup$fullnames(recursive = TRUE)
recursiveShould subgroups be scanned for names too (default is
TRUE)?
A character vector with group names.
dimensions()
List all the dimensions that are visible from this group, possibly including those that are defined in parent groups (by names not defined by any of their child groups in direct lineage to the current group).
NCGroup$dimensions(scope = "all")
scopeCharacter string that indicates if only dimensions in the
current group should be reported (local) or visible dimensions in
parent groups as well (all, default).
A vector of NCDimension objects.
clone()
The objects of this class are cloneable with this method.
NCGroup$clone(deep = FALSE)
deepWhether to make a deep clone.
This class is a basic ancestor to all classes that represent netCDF objects, specifically groups, dimensions, variables and the user-defined types in a netCDF file. More useful classes use this class as ancestor.
The fields in this class are common among all netCDF objects. In addition, this class manages the attributes for its descendent classes.
id(read-only) Retrieve the identifier of the netCDF object.
nameSet or retrieve the name of the NC object. The netCDF file must be open for writing to change the name.
attributes(read-only) Read the attributes of the object. When
there are no attributes, an empty data.frame will be returned.
CFRegister CF object that uses this netCDF object, or retrieve the list of registered CF objects.
new()
Create a new netCDF object. This class should not be instantiated directly, create descendant objects instead.
NCObject$new(id, name, attributes = data.frame())
idNumeric identifier of the netCDF object.
nameCharacter string with the name of the netCDF object.
attributesOptional, data.frame with attributes of the object.
print_attributes()
This function prints the attributes of the netCDF object to the console.
NCObject$print_attributes(width = 50L)
widthThe maximum width of each column in the data.frame when
printed to the console.
attribute()
Retrieve an attribute of a NC object.
NCObject$attribute(att, field = "value")
attSingle character string of attribute to return.
fieldThe field of the attribute to return values from. This must be "value" (default) or "type".
If the field argument is "type", a character string. If field
is "value", a single value of the type of the attribute, or a vector
when the attribute has multiple values. If no attribute is named with a
value of argument att NA is returned.
write_attributes()
Write the attributes of this object to a netCDF file. This will retain existing attributes, update modified attributes, and delete and add missing attributes from the passed in argument.
NCObject$write_attributes(nm, new_atts)
nmThe NC variable name or "NC_GLOBAL" to write the attributes to.
new_attsThe attributes to write.
Self, invisibly.
clone()
The objects of this class are cloneable with this method.
NCObject$clone(deep = FALSE)
deepWhether to make a deep clone.
This class contains the connection details to a netCDF resource.
There is a single instance of this class for every netCDF resource, owned by the CFDataset instance. The instance is shared by other objects, specifically NCGroup instances, for access to the underlying resource for reading of data.
This class should never have to be accessed directly. All access is handled by higher-level methods.
errorError message, or empty string.
friendlyClassName(read-only) A nice description of the class.
handle(read-only) The handle to the netCDF resource.
uri(read-only) The URI of the netCDF resource, either a local filename or the location of an online resource.
can_write(read-only) Is the resource writable?
new()
Create a connection to a netCDF resource. This is called by
open_ncdf() when opening a netCDF resource or when saving a dataset
to file. You should never have to call this directly.
NCResource$new(uri, write)
uriThe URI to the netCDF resource.
writeLogical flag to indicate if the resource should be read-write.
An instance of this class.
print()
Print a summary of the netCDF resource to the console.
NCResource$print()
Self, invisibly.
create()
Create a new file on disk for the netCDF resource.
NCResource$create()
Self, invisibly.
close()
Closing an open netCDF resource. It should rarely be necessary to call this method directly.
NCResource$close()
group_handle()
Every group in a netCDF file has its own handle, with the "root" group having the handle for the entire netCDF resource. The handle returned by this method is valid only for the named group.
NCResource$group_handle(group_name)
group_nameThe absolute path to the group.
The handle to the group.
clone()
The objects of this class are cloneable with this method.
NCResource$clone(deep = FALSE)
deepWhether to make a deep clone.
This class represents a netCDF variable, the object that holds the properties and data of elements like dimensions and variables of a netCDF file.
Direct access to netCDF variables is usually not necessary. NetCDF variables are linked from CF data variables and axes and all relevant properties are thus made accessible.
ncdfCF::NCObject -> NCVariable
group(read-only) NetCDF group where this variable is located.
handle(read-only) Get the handle to the netCDF resource for the variable.
vtype(read-only) The netCDF data type of this variable. This could be the packed type. Don't check this field but use the appropriate method in the class of the object whose data type you are looking for.
ndims(read-only) Number of dimensions that this variable uses.
dimids(read-only) Vector of dimension identifiers that this NCVariable uses.
netcdf4(read-only) Additional properties for a netcdf4 resource.
CFRegister CF objects that use this netCDF variable, or retrieve the list of registered CF objects.
fullname(read-only) Name of this netCDF variable including the group path from the root group.
is_packed(read-only) Flag that indicates if the data on file is packed.
new()
Create a new netCDF variable. This class should not be instantiated directly, they are created automatically when opening a netCDF resource.
NCVariable$new( id, name, group, vtype, dimids, attributes = data.frame(), netcdf4 = list() )
idNumeric identifier of the netCDF object.
nameCharacter string with the name of the netCDF object.
groupThe NCGroup this variable is located in.
vtypeThe netCDF data type of the variable.
dimidsThe integer identifiers of the dimensions this variable uses.
attributesOptional, data.frame with the attributes of the
object.
netcdf4Optional, netcdf4-specific arguments in the format of
RNetCDF.
An instance of this class.
print()
Summary of the NC variable printed to the console.
NCVariable$print(...)
...Passed on to other methods.
shard()
Very concise information on the variable. The information returned by this function is very concise and most useful when combined with similar information from other variables.
NCVariable$shard()
Character string with very basic variable information.
detach()
Detach the passed object from this NC variable.
NCVariable$detach(obj)
objThe CFObject instance to detach from this NC variable.
obj, invisibly.
get_data()
Read (a chunk of) data from the netCDF file. Degenerate dimensions are maintained and data is always returned in its smallest type.
NCVariable$get_data(start = NA, count = NA)
startA vector of indices specifying the element where reading
starts along each dimension of the data. When NA, all data are read
from the start of the array.
countAn integer vector specifying the number of values to read
along each dimension of the data. Any NA value in vector count
indicates that the corresponding dimension should be read from the
start index to the end of the dimension.
An array, matrix or vector with the requested data, or an error object.
write_data()
Write (a chunk of) data to the netCDF file.
NCVariable$write_data(d, start = NA, count = NA, ...)
dThe data to write. This must have appropriate dimensions.
startA vector of indices specifying the element where writing
starts along each dimension of the data. When NA, all data are
written from the start of the array.
countAn integer vector specifying the number of values to write
along each dimension of the data. Any NA value in vector count
indicates that the corresponding dimension should be written from the
start index to the end of the dimension.
...Other parameters passed on to RNetCDF::var.put.nc().
Self, invisibly.
set_name()
Change the name of the NC variable. The new name must be valid in the indicated group, it can not already exist in the group. The netCDF file must be open for writing to change the name.
NCVariable$set_name(new_name)
new_nameThe new name for the NC variable
Self, invisibly.
dimension()
Get the NCDimension object(s) that this variable uses.
NCVariable$dimension(id)
idThe index of the dimension. If missing, all dimensions of this variable are returned.
A NCDimension object or a list thereof. If no NCDimensions
were found, return NULL.
dim()
The lengths of the data dimensions of this object.
NCVariable$dim(dimension)
dimensionOptional. The index of the dimension to retrieve the length for. If omitted, retrieve the lengths of all dimensions.
clone()
The objects of this class are cloneable with this method.
NCVariable$clone(deep = FALSE)
deepWhether to make a deep clone.
This function will read the metadata of a netCDF resource and interpret the netCDF dimensions, variables and attributes to generate the corresponding CF objects. The data for the CF variables is not read, please see CFVariable for methods to read the variable data.
open_ncdf(resource, write = FALSE)open_ncdf(resource, write = FALSE)
resource |
The name of the netCDF resource to open, either a local file name or a remote URI. |
write |
|
An CFDataset instance, or an error if the resource was not found or
errored upon reading.
fn <- system.file("extdata", "pr_day_EC-Earth3-CC_ssp245_r1i1p1f1_gr_20230101-20231231_vncdfCF.nc", package = "ncdfCF") (ds <- open_ncdf(fn))fn <- system.file("extdata", "pr_day_EC-Earth3-CC_ssp245_r1i1p1f1_gr_20230101-20231231_vncdfCF.nc", package = "ncdfCF") (ds <- open_ncdf(fn))
Basic arithmetic, mathematical and logical operations can be applied on the data of CFVariable objects having a suitable data type, specifically the base R functions from the Ops and Math groups of the S3 groupGeneric functions.
## S3 method for class 'CFVariable' Ops(e1, e2) ## S3 method for class 'CFVariable' Math(x, ...)## S3 method for class 'CFVariable' Ops(e1, e2) ## S3 method for class 'CFVariable' Math(x, ...)
e1, e2
|
|
x |
A CFVariable object. |
... |
Additional arguments passed on to the math functions. |
The functions always return a new CFVariable object. Functions can thus be
concatenated to create more complex expressions. The data type of the new
object is determined by the base R function; its name is concatenated from
the names in the argument object(s). The result will be assigned to a private
group and is thus completely disjoint from other CF objects.
For the Ops functions with two arguments, if both arguments are a
CFVariable object they have to be compatible: same shape, axis coordinate
values and coordinate reference system. The resulting CFVariable object
will use the same axes as the CFVariable object(s) used as argument.
The attributes of the resulting CFVariable object should be updated to
reflect its contents, in particular the "name", "long_name", "standard_name"
and "units" attributes. Attributes are not copied over from the CFVariable
objects in the arguments.
A new CFVariable object. The object will have the same coordinate
space as the CFVariable object used as argument. Arguments are not copied
and the new object will only have the "actual_range" attribute set.
Results that are logical (see the examples) are stored using the NC_SHORT
data type because netCDF does not have a native logical data type.
fn <- system.file("extdata", "ERA5land_Rwanda_20160101.nc", package = "ncdfCF") ds <- open_ncdf(fn) # Temperature data in K t2m <- ds[["t2m"]] # Convert to degrees_Celsius t2mC <- t2m - 273.15 t2mC$name <- "t2m_Celsius" t2mC$set_attribute("units", "NC_CHAR", "degrees_Celsius") t2mC hot <- t2mC > 20 hot$name <- "t2m_Celsius_over_20" hot$set_attribute("long_name", "NC_CHAR", "Flag to indicate where temperature is 20C or hotter") hot$set_attribute("units", "NC_CHAR", "1") hotfn <- system.file("extdata", "ERA5land_Rwanda_20160101.nc", package = "ncdfCF") ds <- open_ncdf(fn) # Temperature data in K t2m <- ds[["t2m"]] # Convert to degrees_Celsius t2mC <- t2m - 273.15 t2mC$name <- "t2m_Celsius" t2mC$set_attribute("units", "NC_CHAR", "degrees_Celsius") t2mC hot <- t2mC > 20 hot$name <- "t2m_Celsius_over_20" hot$set_attribute("long_name", "NC_CHAR", "Flag to indicate where temperature is 20C or hotter") hot$set_attribute("units", "NC_CHAR", "1") hot
This function will read a netCDF resource and return a list of identifying information, including data variables, axes and global attributes. Upon returning the netCDF resource is closed.
peek_ncdf(resource)peek_ncdf(resource)
resource |
The name of the netCDF resource to open, either a local file name or a remote URI. |
If you find that you need other information to be included in the result, open an issue.
A list with elements "variables", "axes" and global "attributes",
each a data.frame.
fn <- system.file("extdata", "pr_day_EC-Earth3-CC_ssp245_r1i1p1f1_gr_20230101-20231231_vncdfCF.nc", package = "ncdfCF") peek_ncdf(fn)fn <- system.file("extdata", "pr_day_EC-Earth3-CC_ssp245_r1i1p1f1_gr_20230101-20231231_vncdfCF.nc", package = "ncdfCF") peek_ncdf(fn)