sea_level_response.helpers

Utility functions for use across sea_level_response modules.

Module Attributes

ZarrType

A local path or web URL, represented as a string.

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.

type ZarrType

A local path or web URL, represented as a string.

Validated by path_or_web_url_validator().

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

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.