API reference
earthcarekit.utils.xarray
Utilities based on xarray.
Notes
This module does not depend on other internal modules.
concat_datasets
Concatenate two xarray.Dataset objects along a specified dimension, padding other dimensions to match.
Pads all non-concatenation dimensions in both datasets to the maximum size among them (if they differ) before concatenating. Integer variables are padded with -9999 or data type-specific minimum value (e.g., -128 for int8), non-interger variables are padded with NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds1
|
Dataset
|
The first dataset to concatenate. |
required |
ds2
|
Dataset
|
The second dataset to concatenate. |
required |
dim
|
str
|
The name of the dimension to concatenate along. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
A new dataset resulting from the concatenation. |
Source code in earthcarekit/utils/xarray/_concat.py
convert_scalar_var_to_str
Converts a given scalar variable inside a xarray.Dataset to string.
Source code in earthcarekit/utils/xarray/_scalars.py
demote_coords
Converts a coordinate to a variable and renames the related dimension.
Source code in earthcarekit/utils/xarray/_demote_coordinate_dimension.py
insert_var
insert_var(
ds: Dataset,
var: str,
data: Any,
index: int | None = None,
before_var: str | None = None,
after_var: str | None = None,
) -> Dataset
Inserts a new variable in a xarray.Dataset before or after a given variable or at a given index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
The original dataset to which the variable will be added. |
required |
var
|
str
|
Name of the new variable to be added. |
required |
data
|
Any
|
Data stored in the new variable. |
required |
index
|
int | None
|
Index at which the new variable will be added. Will be ignored when either |
None
|
before_var
|
str | None
|
Name of the variable before which the new variable should be inserted. Defaults to None. |
None
|
after_var
|
str | None
|
Name of the variable after which the new variable should be inserted. Will be ignored
when |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Dataset
|
The original dataset with the new variable inserted. |
Source code in earthcarekit/utils/xarray/_insert_var.py
merge_datasets
Merges two datasets while keeping all global attributes from one dataset.
Source code in earthcarekit/utils/xarray/_merge.py
remove_dims
Drop a list of dimensions and all associated variables and coordinates from a given xarray.dataset.