my_code_base.core.xarray_utils¶
Classes¶
A class for accessing and manipulating the 'history' attribute of an xarray object. |
Functions¶
|
Compress |
|
Get the index of a dimension in a DataArray. |
Module Contents¶
- class my_code_base.core.xarray_utils.HistoryAccessor(xr_obj)[source]¶
A class for accessing and manipulating the ‘history’ attribute of an xarray object.
- Parameters:¶
- xr_obj : xarray.Dataset or xarray.DataArray¶
The xarray object to be accessed.
- my_code_base.core.xarray_utils.compress_xarray(data: xarray.Dataset | xarray.DataArray, complevel: int) xarray.Dataset | xarray.DataArray[source]¶
Compress
xarray.Datasetorxarray.DataArray.- Parameters:¶
- data : xarray.Dataset | xarray.DataArray¶
Data to compress.
- complevel : int¶
Compression level.
- Returns:¶
Compressed data.
- Return type:¶
xr.Dataset | xr.DataArray
- my_code_base.core.xarray_utils.get_dim_index(da: xarray.DataArray, dim: str) int[source]¶
Get the index of a dimension in a DataArray.
Deprecated since version 0.1.0: Will be removed in a future version. Use
xarray.DataArray.get_axis_num()instead.- Parameters:¶
- da : xarray.DataArray¶
DataArray to get the dimension index from.
- dim : str¶
Dimension name.
- Return type:¶
Index of the dimension in the DataArray. Can be used for specifying the axis in a numpy operation.
Examples
>>> da = xr.DataArray(np.random.rand(2, 3, 4), dims=['time', 'lat', 'lon']) >>> get_dim_index(da, 'lat') 1