xarray_regrid.regrid
Classes
Regridding xarray datasets and dataarrays. |
Functions
Module Contents
- class xarray_regrid.regrid.Regridder(xarray_obj: xarray.DataArray | xarray.Dataset)[source]
Regridding xarray datasets and dataarrays.
- Available methods:
linear: linear, bilinear, or higher dimensional linear interpolation nearest: nearest-neighbor regridding cubic: cubic spline regridding conservative: conservative regridding most_common: most common value regridder stat: area statistics regridder
- linear(ds_target_grid: xarray.Dataset, time_dim: str | None = 'time') xarray.DataArray | xarray.Dataset[source]
Regrid to the coords of the target dataset with linear interpolation.
- Parameters:
ds_target_grid – Dataset containing the target coordinates.
time_dim – Name of the time dimension. Defaults to “time”. Use None to force regridding over the time dimension.
- Returns:
Data regridded to the target dataset coordinates.
- nearest(ds_target_grid: xarray.Dataset, time_dim: str | None = 'time') xarray.DataArray | xarray.Dataset[source]
Regrid to the coords of the target with nearest-neighbor interpolation.
- Parameters:
ds_target_grid – Dataset containing the target coordinates.
time_dim – Name of the time dimension. Defaults to “time”. Use None to force regridding over the time dimension.
- Returns:
Data regridded to the target dataset coordinates.
- cubic(ds_target_grid: xarray.Dataset, time_dim: str | None = 'time') xarray.DataArray | xarray.Dataset[source]
Regrid to the coords of the target dataset with cubic interpolation.
- Parameters:
ds_target_grid – Dataset containing the target coordinates.
time_dim – Name of the time dimension. Defaults to “time”. Use None to force regridding over the time dimension.
- Returns:
Data regridded to the target dataset coordinates.
- conservative(ds_target_grid: xarray.Dataset, latitude_coord: str | None = None, time_dim: str | None = 'time', skipna: bool = True, nan_threshold: float = 1.0, output_chunks: dict[collections.abc.Hashable, int] | None = None) xarray.DataArray | xarray.Dataset[source]
Regrid to the coords of the target dataset with a conservative scheme.
- Parameters:
ds_target_grid – Dataset containing the target coordinates.
latitude_coord – Name of the latitude coord, to be used for applying the spherical correction. By default, attempt to infer a latitude coordinate as either “latitude” or “lat”.
time_dim – Name of the time dimension. Defaults to “time”. Use None to force regridding over the time dimension.
skipna – If True, enable handling for NaN values. This adds only a small amount of overhead, but can be disabled for optimal performance on data without any NaNs.
nan_threshold – Threshold value that will retain any output points containing at least this many non-null input points. The default value is 1.0, which will keep output points containing any non-null inputs, while a value of 0.0 will only keep output points where all inputs are non-null.
output_chunks – Optional dictionary of explicit chunk sizes for the output data. If not provided, the output will be chunked the same as the input data.
- Returns:
Data regridded to the target dataset coordinates.
- most_common(ds_target_grid: xarray.Dataset, values: numpy.ndarray, time_dim: str | None = 'time', fill_value: None | Any = None) xarray.DataArray[source]
Regrid by taking the most common value within the new grid cells.
To be used for regridding data to a much coarser resolution, not for regridding when the source and target grids are of a similar resolution.
Note that in the case of two unqiue values with the same count, the behaviour is not deterministic, and the resulting “most common” one will randomly be either of the two.
- Parameters:
ds_target_grid – Target grid dataset
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.
- Returns:
Regridded data.
- least_common(ds_target_grid: xarray.Dataset, values: numpy.ndarray, time_dim: str | None = 'time', fill_value: None | Any = None) xarray.DataArray[source]
Regrid by taking the least common value within the new grid cells.
To be used for regridding data to a much coarser resolution, not for regridding when the source and target grids are of a similar resolution.
Note that in the case of two unqiue values with the same count, the behaviour is not deterministic, and the resulting “least common” one will randomly be either of the two.
- Parameters:
ds_target_grid – Target grid dataset
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.
- Returns:
Regridded data.
- stat(ds_target_grid: xarray.Dataset, method: str, time_dim: str | None = 'time', skipna: bool = False, fill_value: None | Any = None) xarray.DataArray | xarray.Dataset[source]
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:
ds_target_grid – Target grid dataset
method – One of the following reduction methods: “sum”, “mean”, “var”, “std”, “median”, “min”, or “max”.
time_dim – Name of the time dimension. Defaults to “time”. Use None to force regridding over the time dimension.
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.regrid.validate_input(data: xarray.Dataset, ds_target_grid: xarray.Dataset, time_dim: str | None) xarray.Dataset[source]
- xarray_regrid.regrid.validate_input(data: xarray.DataArray, ds_target_grid: xarray.Dataset, time_dim: str | None) xarray.Dataset