API Reference#
Overview#
Most public xcdat APIs operate on xarray.Dataset objects. xcdat follows this design pattern because coordinate variable bounds are often required to perform robust calculations.
Currently, coordinate variable bounds can only be stored on Dataset objects and not DataArray objects. Refer to this issue for more information.
Top-level API Functions#
Below is a list of top-level API functions that are available in xcdat.
|
Wraps |
|
Wraps |
|
Centers time coordinates using the midpoint between time bounds. |
|
Decodes CF and non-CF time coordinates and time bounds using |
|
Swaps the orientation of a dataset's longitude axis. |
|
Compares the keys and values of two datasets. |
|
Gets the dimension coordinates for an axis. |
|
Gets the dimension key(s) for an axis. |
|
Retrieve the coordinate variable based on its name. |
|
Creates bounds for an axis using coordinate points as midpoints. |
|
Creates an axis and optional bounds. |
|
Create a mask as an xarray.DataArray based on the specified dimensions. |
|
Create a mask as an xarray.DataArray with NaN values based on source data. |
|
Creates a grid with Gaussian latitudes and uniform longitudes. |
|
Creates a global mean grid. |
|
Creates a grid dataset using the specified axes. |
|
Creates a uniform rectilinear grid and sets appropriate the attributes for the lat/lon axis. |
|
Creates a zonal grid. |
|
Open a dataset from the online repository (requires internet). |
Module-level API Functions#
Below is a list of module-level API functions that are available in xcdat.
|
Generate a land-sea mask using the PCMDI method. |
Accessors#
What are accessors?#
xcdat provides Dataset accessors, which are implicit namespaces for custom functionality that clearly identifies it as separate from built-in xarray methods.
xcdat implements accessors to extend xarray with custom functionality because it is the officially recommended and most common practice (over sub-classing).
In the example below, custom spatial functionality is exposed by chaining the spatial accessor attribute to the Dataset object.
This chaining enables access to the underlying spatial average() method.
How do I use xcdat accessors?#
First, import the package:
>>> from xcdat
Then open up a dataset file as a Dataset object:
>>> ds = xcdat.open_dataset("path/to/file", data_var="ts")
Now chain the accessor attribute to the Dataset to expose the accessor class attributes, methods, or properties:
>>> ds = ds.spatial.average("ts", axis=["X", "Y"])
Note
Accessors are created once per Dataset instance. New instances, like those created from arithmetic operations will have new accessors created.
Classes#
|
An accessor class that provides bounds attributes and methods on xarray Datasets through the |
|
An accessor class that provides spatial attributes and methods on xarray Datasets through the |
|
An accessor class that provides temporal attributes and methods on xarray Datasets through the |
|
An accessor class that provides regridding attributes and methods for xarray Datasets through the |
|
|
|
|
|
Attributes#
Returns a map of axis and coordinates keys to their bounds. |
|
Returns a list of keys for the bounds data variables in the Dataset. |
|
Extract the X, Y, and Z axes from the Dataset and return a new |
Methods#
Add bounds for an axis using its coordinates as midpoints. |
|
|
Add bounds for an axis using its coordinate points. |
|
Gets coordinate bounds. |
Adds missing coordinate bounds for supported axes in the Dataset. |
|
|
Calculates the spatial average for a rectilinear grid over an optionally specified regional domain. |
|
Masks a data variable by land. |
|
Masks a data variable by sea. |
Generate a land-sea mask. |
|
|
Returns a Dataset with the average of a data variable and the time dimension removed. |
|
Returns a Dataset with average of a data variable by time group. |
|
Returns a Dataset with the climatology of a data variable. |
|
Returns a Dataset with the climatological departures (anomalies) for a data variable. |
|
Transform |
|
Transform |
CDAT Mapping Table#
The table below maps the supported xCDAT operations to the equivalent CDAT and xCDAT APIs. It is especially useful for those who are transitioning over from CDAT to xarray/xCDAT.
How do I… |
xCDAT |
CDAT |
|---|---|---|
Open dataset files? |
|
|
Get coordinate bounds? |
|
|
Set coordinate bounds for a single axis? |
|
|
Set coordinate bounds for all axes with missing bounds? |
|
N/A |
Center time coordinates using time bounds? |
|
N/A |
Swap the longitude axis orientation between (-180 to 180) and (0 to 360)? |
|
N/A |
Spatially average over an optionally specified rectilinear grid? |
|
|
Decode time coordinates with CF/Non-CF units? |
|
|
Temporally averaging with a single time-averaged snapshot and time coordinates removed? |
|
|
Temporally average by time group? |
|
|
Calculate climatologies? |
|
|
Calculate climatological departures? |
|
|
Regrid horizontally? |
|
|