xarray_regrid.methods.flox_reduce
Implementation of flox reduction based regridding methods.
Functions
Upsampling of data using statistical methods (e.g. the mean or variance). |
|
Find the smallest integer datatype that can cover the given array. |
|
|
Upsample the input data using a "most common label" (mode) approach. |
Module Contents
- xarray_regrid.methods.flox_reduce.statistic_reduce(data: xarray.DataArray, target_ds: xarray.Dataset, time_dim: str | None, method: str, skipna: bool = False, fill_value: None | Any = None) xarray.DataArray[source]
- xarray_regrid.methods.flox_reduce.statistic_reduce(data: xarray.Dataset, target_ds: xarray.Dataset, time_dim: str | None, method: str, skipna: bool = False, fill_value: None | Any = None) xarray.Dataset
Upsampling of data using statistical methods (e.g. the mean or variance).
We use flox Aggregations to perform a “groupby” over multiple dimensions, which we reduce using the specified method. https://flox.readthedocs.io/en/latest/aggregations.html
- Parameters:
data – Input dataset. It is assumed that the coordinates of this data are sorted.
target_ds – Dataset which coordinates the input dataset should be regrid to.
time_dim – Name of the time dimension. Defaults to “time”. Use None to force regridding over the time dimension.
method – One of the following reduction methods: “sum”, “mean”, “var”, “std”, or “median.
skipna – If NaN values should be ignored.
fill_value – What value to fill uncovered parts of the target grid. By default this will be NaN, and integer type data will be cast to float to accomodate this.
- Returns:
xarray.dataset with regridded land cover categorical data.
- xarray_regrid.methods.flox_reduce.find_matching_int_dtype(a: numpy.ndarray) type[numpy.signedinteger] | type[numpy.unsignedinteger][source]
Find the smallest integer datatype that can cover the given array.
- xarray_regrid.methods.flox_reduce.compute_mode(data: xarray.DataArray, target_ds: xarray.Dataset, values: numpy.ndarray, time_dim: str | None, fill_value: None | Any = None, anti_mode: bool = False) xarray.DataArray[source]
Upsample the input data using a “most common label” (mode) approach.
- Parameters:
data – Input DataArray, with an integer data type. If your data does not consist of integer type values, you will have to encode them to integer types. It is assumed that the coordinates of this data are sorted.
target_ds – Dataset which coordinates the input dataset should be regrid to.
values – Numpy array containing all labels expected to be in the input data. For example, np.array([0, 2, 4]), if the data only contains the values 0, 2 and 4.
time_dim – Name of the time dimension. Defaults to “time”. Use None to force regridding over the time dimension.
fill_value – What value to fill uncovered parts of the target grid. By default this will be NaN, and integer type data will be cast to float to accomodate this.
anti_mode – Find the least-common-value (anti-mode).
- Raises:
ValueError – if the input data is not of an integer dtype.
- Returns:
xarray.DataArray with regridded categorical data.