mass_balance_module.helpers

Utility functions for use across mass_balance_module modules.

Functions

get_dataset_crs(dataset)

Retrieve the CRS details from the dataset.

path_or_web_url_validator(type_, path_or_url)

Validate that the provided path is either a valid local path or a web URL.

prepare_time_data_array(time_data_array)

Convert a time coordinate to seconds and apply its CF metadata.

type mass_balance_module.helpers.ZarrType = Annotated[str, Parameter(validator=(<function path_or_web_url_validator at 0x7f79f4b52980>,))]
mass_balance_module.helpers.get_dataset_crs(dataset: Dataset) → CRS | None

Retrieve the CRS details from the dataset.

This function has been taken from the Data Download Module. It first checks for CRS written with rioxarray. Next, it checks the dataset for a grid mapping attribute If the CRS is not found in the grid mapping, it checks the dataset attributes for a _CRS attribute containing the WKT. If the CRS is still not found, it checks one of the data variable’s attributes for a _CRS attribute with a wkt key (to match the current format of S1 ice velocity data on EODS).

Parameters:

dataset (xr.Dataset) – The dataset from which to retrieve the CRS.

Returns:

The CRS of the dataset.

Return type:

pyproj.CRS | None

mass_balance_module.helpers.path_or_web_url_validator(type_: object, path_or_url: Path | str) → str

Validate that the provided path is either a valid local path or a web URL.

NOTE: Path(“”) resolves to the current directory (“.”) - which is considered a valid path.

Parameters:
  • type (object) – The type of the argument being validated - unused, purely required for cyclopts validator compatibility.

  • path_or_url (Path | str) – The candidate path or URL to validate.

Returns:

The validated path or URL as a string.

Return type:

str

Raises:

ValueError – If the provided path is neither a valid local path nor a web URL.

mass_balance_module.helpers.prepare_time_data_array(time_data_array: DataArray) → DataArray

Convert a time coordinate to seconds and apply its CF metadata.