API reference#
earthcarekit.utils.xarray
Utilities based on xarray.
Notes#
This module does not depend on other internal modules.
concat_datasets
#
Concatenates two xarray.Dataset objects along a specified dimension, padding other dimensions to match.
Pads non-concatenation dimensions to the maximum size (if they differ) before concatenating. Integer variables are padded with -9999 or dtype-specific minimum (e.g., -128 for int8); non-integer variables are padded with NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds1
|
Dataset
|
First dataset to concatenate. |
required |
ds2
|
Dataset
|
Second dataset to concatenate. |
required |
dim
|
str
|
Dimension along which to concatenate. |
required |
Returns:
| Type | Description |
|---|---|
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 into an xarray.Dataset at a specified position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Original dataset. |
required |
var
|
str
|
Name of the new variable. |
required |
data
|
Any
|
Data for the new variable. |
required |
index
|
int | None
|
Insertion index; ignored if |
None
|
before_var
|
str | None
|
Insert before this variable. |
None
|
after_var
|
str | None
|
Insert after this variable; ignored if |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
The 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.