grid_process.helpers#

Module for general helper functions and decorators

Attributes#

Functions#

timefn(→ collections.abc.Callable[..., Any])

Generic decorator to log function processing times

make_accessor(…)

Generic decorator to turn functions operating on xarray objects into

keepattrs(→ collections.abc.Callable[..., xarray.Dataset])

Decorator to keep dataset and data variables attributes for functions

update_vars_attrs(→ None)

Updates data variables attributes in a xarray.Dataset. The operation is

replace_vars_attrs(→ None)

Replaces data variables attributes in a xarray.Dataset. The operation is

reproject(…)

Reprojects x and y coordinates from a source CRS to a new specified

Module Contents#

logger#
timefn(func: collections.abc.Callable[..., Any]) → collections.abc.Callable[..., Any][source]#

Generic decorator to log function processing times

make_accessor(func: collections.abc.Callable[..., xarray.Dataset], accessor_class: type) → collections.abc.Callable[..., xarray.Dataset][source]#
make_accessor(func: collections.abc.Callable[..., xarray.DataArray], accessor_class: type) → collections.abc.Callable[..., xarray.DataArray]

Generic decorator to turn functions operating on xarray objects into accessors based on a registered dataset or dataarray accessor_class

keepattrs(func: collections.abc.Callable[..., xarray.Dataset]) → collections.abc.Callable[..., xarray.Dataset][source]#

Decorator to keep dataset and data variables attributes for functions operating on xarray.Datasets

update_vars_attrs(ds: xarray.Dataset, vars_attrs: dict[collections.abc.Hashable, dict[collections.abc.Hashable, Any]]) → None[source]#

Updates data variables attributes in a xarray.Dataset. The operation is done “in-place”.

Parameters:
  • ds (xarray.Dataset) – can contain one or several data variables

  • vars_attrs (dict) – contains the attributes of each data variables in the input dataset

replace_vars_attrs(ds: xarray.Dataset, vars_attrs: dict[str, dict]) → None[source]#

Replaces data variables attributes in a xarray.Dataset. The operation is done “in-place”.

Parameters:
  • ds (xarray.Dataset) – can contain one or several data variables

  • vars_attrs (dict) – contains the new attributes of each data variables in the input dataset to be replaced

reproject(x_coords: numpy.typing.NDArray[numpy.floating], y_coords: numpy.typing.NDArray[numpy.floating], src_crs: pyproj.CRS | str, dst_crs: pyproj.CRS | str) → tuple[numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.float64]][source]#
reproject(x_coords: list[float], y_coords: list[float], src_crs: pyproj.CRS | str, dst_crs: pyproj.CRS | str) → tuple[list[float], list[float]]
reproject(x_coords: tuple[float, ...], y_coords: tuple[float, ...], src_crs: pyproj.CRS | str, dst_crs: pyproj.CRS | str) → tuple[tuple[float, ...], tuple[float, ...]]

Reprojects x and y coordinates from a source CRS to a new specified one.

Parameters:
  • x_coords (numpy.ndarray, list or tuple) – contains x coordinates.

  • y_coords (numpy.ndarray, list or tuple) – contains y coordinates

  • src_crs (pyproj.CRS of the source or equivalent string) – The value can be anything accepted by pyproj.CRS.from_user_input, such as an authority string (e.g. “EPSG:4326”) or a WKT string

  • dst_crs (pyproj.CRS of the destination or equivalent string) – The value can be anything accepted by pyproj.CRS.from_user_input, such as an authority string (eg “EPSG:4326”) or a WKT string

Returns:

  • x_coords_new (numpy.ndarray, list or tuple of float64) – same as input x_coords in the new CRS and cast as float64

  • y_coords_new (numpy.ndarray, list or tuple of float64) – same as input y_coords in the new CRS and cast as float64