sea_level_response.selrem.selrem_input_prep
Prepare mass balance data for the SELREM entrypoint.
SELREM expects a (time, point) dataset with lat/lon coordinates and annual timesteps. This module converts from a gridded (time, y, x) dataset with CF metadata and a CRS (e.g., as written by rioxarray) to the SELREM schema, handling coordinate reprojection and annual resampling as needed. If the input is already in (time, point) format, it will be passed through after ensuring annual resolution and appropriate coordinate variables are present.
Functions
|
Convert gridded data to the (time, point) schema SELREM expects. |
|
Resample to annual resolution if sub-annual timesteps are present. |
- prepare_gridded_ds_for_selrem(ds: Dataset, coarsen_factor: int = 1) Dataset
Convert gridded data to the (time, point) schema SELREM expects.
Resamples to annual resolution if sub-annual timesteps are detected.
Converts to geographic coordinates (if the input CRS is not already geographic), stacks and drops all-NaN points.
Coarsens spatially by the given factor if coarsen_factor > 1, using mass-conserving sum for the mass balance
variable and averaging for coordinates.
- Parameters:
ds (xr.Dataset) – Gridded dataset with x, y, time coords and mass balance and (optionally) mass balance error variables.
coarsen_factor (int) – Spatial coarsening factor applied before flattening. Mass is summed (mass-conserving); coordinates are averaged. Default 1 (no coarsening).
- Returns:
Dataset with (time, point) dimensions and y = latitude, x = longitude coordinate variables.
- Return type:
xr.Dataset
- Raises:
ValueError – If the dataset does not have the required dimensions or variables, or if the coarsen_factor is invalid.
- to_annual(da: DataArray, is_uncertainty: bool = False) DataArray
Resample to annual resolution if sub-annual timesteps are present.
- Parameters:
da (xr.DataArray) – DataArray with a time dimension.
is_uncertainty (bool) – If True, resample using RSS/N, use mean otherwise. Default False.
- Returns:
Annually resampled DataArray; same as input if already at annual resolution.
- Return type:
xr.DataArray