Usage¶
Reading Data¶
We can either read mds data using
-
cubedsphere.open_ascii_dataset(outdir, iternumber, **kwargs)[source]¶ Wrapper that opens simulation outputs from standard mitgcm outputs.
- Parameters
- outdir: string
Output directory
- iternumber: List or integer or None
See xmitgcm iters, can be a iterationnumber or ‘all’
- **kwargs
everything else that is passed to xmitgcm
- Returns
- ds: xarray Dataset
Dataset of simulation output
We can also read NETCDF data which has been outputed from the mnc package
-
cubedsphere.open_mnc_dataset(outdir, iternumber, fname_list=['state', 'secmomDiag', 'dynDiag', 'surfDiag'])[source]¶ Wrapper that opens simulation outputs from mnc outputs.
- Parameters
- outdir: string
Output directory
- iternumber: integer
iteration number of output file
- fname_list: list
List of NetCDF file prefixes to read (no need to specify grid files here)
- Returns
- ds: xarray Dataset
Dataset of simulation output
Regridding¶
-
class
cubedsphere.Regridder(ds, d_lon=5, d_lat=4, input_grid=None, concat_mode=False, filename='weights', method='conservative', **kwargs)[source]¶ Class that wraps the xESMF regridder for cs geometry.
Only two methods are possible with the cs geometry: conservative when using concat_mode=False (requires lon_b to have different shape from lon and lat_b from lat) or nearest_s2d when using concat_mode=True. Conservative regridding should be used if possible!
Notes
You can find more examples in the examples directory
Examples
>>> import cubedsphere as cs # import cubedsphere >>> outdir = "../run" # specify output directory >>> ds = cs.open_mnc_dataset(outdir, 276480) # open dataset >>> regrid = cs.Regridder(ds) # init regridder >>> ds_regrid = regrid() # perform regridding of dataset
- Attributes
- regridder: list or xESMF regrid object
(contains) the initialized xESMF regridder
- grid: dict
output grid
-
__init__(ds, d_lon=5, d_lat=4, input_grid=None, concat_mode=False, filename='weights', method='conservative', **kwargs)[source]¶ Build the regridder. This step will create the output grid and weight files which will then be used to regrid the dataset.
- Parameters
- ds: xarray DataSet
Dataset to be regridded. Dataset must contain grid information.
- d_lon: integer
Longitude step size, i.e. grid resolution.
- d_lat: integer
Latitude step size, i.e. grid resolution.
- input_grid: xarray DataSet
use input grid different to ds. Caution with this practice!
- concat_mode: boolean
use one regridding instance instead of one regridder for each face
- filename: string
filename for weights (weights will be name filename(+ _tile{i}).nc)
- method: string
Regridding method. See xe.Regridder for options.
- kwargs :
Optional parameters that are passed to xe.Regridder (see xe.Regridder for options).
-
__call__(vector_names=None, **kwargs)[source]¶ Wrapper that carries out the regridding from cubedsphere to latlon.
- Parameters
- vector_names: list
names of vectors in ds, each list entry should follow ‘{}NAME’ format for ‘UNAME’ and ‘VNAME’. if not provided, will fallback to ‘[“{}VEL”, “{}”, “{}VELSQ”, “{}THMASS”]’
- Returns
- ds: xarray DataSet
regridded Dataset
Create XGCM grids¶
-
cubedsphere.init_grid_CS(ds=None, grid_dir=None, **kwargs)[source]¶ Init a xgcm grid for a cubedsphere dataset. Useful for raw datasets.
- Parameters
- grid_dir: string
direction where the grid can be found (optional)
- ds: xarray DataSet
dataset that contains the grid (optional)
- Returns
- grid: xgcm.grid
xgcm grid
-
cubedsphere.init_grid_LL(ds=None, grid_dir=None, **kwargs)[source]¶ Init a xgcm grid for a latlon dataset. Useful for regridded datasets
- Parameters
- grid_dir: string
direction where the grid can be found (optional)
- ds: xarray DataSet
dataset that contains the grid (optional)
- Returns
- grid: xgcm.grid
xgcm grid
Plotting¶
-
cubedsphere.plotCS(dr, ds, mask_size=None, **kwargs)[source]¶ A quick way to plot cubed-sphere data of resolution 6*N*N. Wrapping plotCS_quick_raw to work with xarray objects
- Parameters
- dr: xarray DataArray
The dimensions must be (y,x)
- ds: xarray DataSet (the parent DataSet of dr)
Must contain XC, YC as coordinate variables.
- mask_size: None or int
The overlap size of individual tiles. If None is chosen one might likely experience issues
- **kwargs
Other keyword arguments such as cmap will be passed to plotCS_quick_raw() and subsequently to plt.pcolormesh()
- Returns
- ph: list
List of mappabales