grid_process.data_model#
Module with utility functions to deal with the numerous supported data models
Attributes#
Functions#
|
Returns name of temporal dimension according to the possible options defined |
|
Returns names of temporal dimensions according to the possible options defined |
|
Returns names of temporal coordinates according to the possible options defined |
|
Returns name of forecast reference time dimension or coordinate according to |
Returns name of valid time dimension or coordinate according to the possible |
|
|
Returns name of lead time dimension or coordinate according to the possible |
|
Returns name of ensemble members dimension according to the possible options |
|
Set grid_mapping attribute according to internal conventions when the input |
|
Returns names of spatial dimensions according to the possible options defined |
|
Returns names of non-dimension spatial coordinates according to the |
|
Returns spatial dimension name for an unstructured grid according to the |
|
Returns names of latitude and longitude coordinates if they exist according |
|
Returns names of latitude and longitude dimensions if they exist according |
|
Returns name of the surface altitude coordinate variable according to the |
|
Returns POIs altitudes from |
|
Get correct CRS according to supported conventions. |
|
Parse internal grid database style "grid_mapping" attribute and decode it with Pyproj. |
|
Get correct coordinate names and CRS according to supported conventions. When |
|
Whether 1 dimensional |
|
Checks whether |
Module Contents#
- logger#
- F#
- DATA_MODEL#
- FLAT_DIM: list[str]#
- YX: tuple[tuple[str, str], ...]#
- LATLON: tuple[tuple[str, str], ...]#
- SURF_ALT: list[str]#
- REFTIME: list[str]#
- VALIDTIME: list[str]#
- LEADTIME: list[str]#
- ENS_DIM: list[str]#
- POI_ALT_COL: list[str]#
- get_t_dim(ds: xarray.Dataset) str[source]#
Returns name of temporal dimension according to the possible options defined in the config (could be overwritten by setting appropriate env variable). Temporal dimension could be expressed as valid time or lead time.
- get_temporal_dims(data: xarray.Dataset | xarray.DataArray) tuple[str | None, str | None, str | None][source]#
Returns names of temporal dimensions according to the possible options defined in the config (could be overwritten by setting appropriate env variable) or according to CF standard name. The returned tuple contains dimension names in the following order: (reftime, leadtime, validtime).
- get_temporal_coords(data: xarray.Dataset | xarray.DataArray) tuple[str | None, str | None, str | None][source]#
Returns names of temporal coordinates according to the possible options defined in the config (could be overwritten by setting appropriate env variable) or according to CF standard name. The returned tuple contains coordinate names in the following order: (reftime, leadtime, validtime).
- get_reftime(data: xarray.Dataset | xarray.DataArray, kind: Literal['dim', 'coord'] = 'dim') str | None[source]#
Returns name of forecast reference time dimension or coordinate according to the possible options defined in the config (could be overwritten by setting appropriate env variable) or according to CF standard name.
- get_validtime(data: xarray.Dataset | xarray.DataArray, kind: Literal['dim', 'coord'] = 'dim', raise_notfound: Literal[True] = True) str[source]#
- get_validtime(data: xarray.Dataset | xarray.DataArray, kind: Literal['dim', 'coord'] = 'dim', raise_notfound: Literal[False] = False) str | None
Returns name of valid time dimension or coordinate according to the possible options defined in the config (could be overwritten by setting appropriate env variable) or according to CF standard name. When raise_notfound is set to True, raise a ValueError if a valid time dimension/coordinate can not be found.
- get_leadtime(data: xarray.Dataset | xarray.DataArray, kind: Literal['dim', 'coord'] = 'dim') str | None[source]#
Returns name of lead time dimension or coordinate according to the possible options defined in the config (could be overwritten by setting appropriate env variable) or according to CF standard name.
- get_ensemble_dim(data: xarray.Dataset | xarray.DataArray) str[source]#
Returns name of ensemble members dimension according to the possible options defined in the config (could be overwritten by setting appropriate env variable) or according to CF standard name.
- set_grid_mapping(ds: xarray.Dataset) xarray.Dataset[source]#
Set grid_mapping attribute according to internal conventions when the input grid follow CF conventions (grid mapping encoded as a data variable). The data variable encoding the grid mapping is removed.
- get_spatial_dims(grid: xarray.Dataset | xarray.DataArray) tuple[str, ...][source]#
Returns names of spatial dimensions according to the possible options defined in the config (could be overwritten by setting appropriate env variable) or according to CF conventions. The returned tuple has size one in case of unstructured grid otherwise contains dimension names in the order (y, x).
- get_spatial_coords(grid: xarray.Dataset | xarray.DataArray) tuple[str, str][source]#
Returns names of non-dimension spatial coordinates according to the possible options defined in the config (could be overwritten by setting appropriate env variable) or according to CF conventions. The returned tuple contains coordinate names in the order (y, x).
- get_flat_dim(grid: xarray.Dataset | xarray.DataArray) str | None[source]#
Returns spatial dimension name for an unstructured grid according to the possible options defined in the config (could be overwritten by setting appropriate env variable).
- get_latlon_coords(grid: xarray.Dataset | xarray.DataArray, nondim: bool = True) tuple[str, str] | None[source]#
Returns names of latitude and longitude coordinates if they exist according to the possible options defined in the config (could be overwritten by setting appropriate env variable) or according to CF conventions. The returned tuple contains coordinate names in the order (latitude, longitude). When
nondimis True (default), only checks coordinates that are non-dimensional.
- get_latlon_dims(grid: xarray.Dataset | xarray.DataArray) tuple[str, str] | None[source]#
Returns names of latitude and longitude dimensions if they exist according to the possible options defined in the config (could be overwritten by setting appropriate env variable) or according to CF conventions. The returned tuple contains coordinate names in the order (latitude, longitude).
- get_surf_alt(grid: xarray.Dataset | xarray.DataArray) str[source]#
Returns name of the surface altitude coordinate variable according to the possible options defined in the config (could be overwritten by setting appropriate env variable).
- get_poi_alt(poi_info: geopandas.GeoDataFrame) numpy.typing.NDArray[numpy.float32][source]#
Returns POIs altitudes from
poi_infoaccording to the column names defined in the config (could be overwritten by setting appropriate env variable) or from a “z” geometry. Altitude data is expected to be in meters above sea level.
- get_grid_crs(grid: xarray.Dataset | xarray.DataArray) pyproj.CRS[source]#
Get correct CRS according to supported conventions.
- Parameters:
grid (xarray Dataset or DataArray) – contains spatial horizontal coordinates. Must have a “grid_mapping” or “crs” attribute referencing the spatial dimensions unless longitude and latitude (or configured equivalents) are dimensions.
- Returns:
pyproj representation of input grid coordinate reference system
- Return type:
pyproj CRS
See also
set_grid_mapping()
- parse_grid_mapping(grid_mapping: str | dict[str, Any]) pyproj.CRS[source]#
Parse internal grid database style “grid_mapping” attribute and decode it with Pyproj.
- Parameters:
grid_mapping (dict or dict encapsulated in a string) – contains CF conventions attributes parsable by pyproj.CRS.from_cf() or the key “epsg_code” with value being an authority string (e.g. EPSG:4326)
- Returns:
pyproj representation of input grid_mapping
- Return type:
pyproj CRS
See also
- get_coords_name_crs(grid: xarray.Dataset | xarray.DataArray, spatial_dims: tuple[str, ...] | None = None) tuple[str, str, pyproj.CRS][source]#
Get correct coordinate names and CRS according to supported conventions. When non-dimensional longitude and latitude coordinates arrays are present, these are used instead of the native spatial dimension coordinates.
- Parameters:
grid (xarray Dataset or DataArray) – contains spatial horizontal coordinates. Must have a “grid_mapping” or “crs” attribute referencing the spatial dimensions unless longitude and latitude coordinates are present.
spatial_dims (tuple of string(s), optional) – name of the
gridspatial dimension(s). Has size one in case of unstructured grid otherwise contains dimension names in the order (y, x). If not provided, callsget_spatial_dims()
- Returns:
grid_y (str) – name of the northward coordinate. Usually ‘x’ or ‘longitude’
grid_x (str) – name of the eastward coordinate. Usually ‘y’ or ‘latitude’’
grid_crs (pyproj CRS) – pyproj representation of input grid coordinate reference system