xarray_regrid.regrid ==================== .. py:module:: xarray_regrid.regrid Classes ------- .. autoapisummary:: xarray_regrid.regrid.Regridder Functions --------- .. autoapisummary:: xarray_regrid.regrid.validate_input Module Contents --------------- .. py:class:: Regridder(xarray_obj: xarray.DataArray | xarray.Dataset) 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 .. py:attribute:: _obj .. py:method:: linear(ds_target_grid: xarray.Dataset, time_dim: str | None = 'time') -> xarray.DataArray | xarray.Dataset Regrid to the coords of the target dataset with linear interpolation. :param ds_target_grid: Dataset containing the target coordinates. :param 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. .. py:method:: nearest(ds_target_grid: xarray.Dataset, time_dim: str | None = 'time') -> xarray.DataArray | xarray.Dataset Regrid to the coords of the target with nearest-neighbor interpolation. :param ds_target_grid: Dataset containing the target coordinates. :param 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. .. py:method:: cubic(ds_target_grid: xarray.Dataset, time_dim: str | None = 'time') -> xarray.DataArray | xarray.Dataset Regrid to the coords of the target dataset with cubic interpolation. :param ds_target_grid: Dataset containing the target coordinates. :param 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. .. py:method:: 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 Regrid to the coords of the target dataset with a conservative scheme. :param ds_target_grid: Dataset containing the target coordinates. :param 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". :param time_dim: Name of the time dimension. Defaults to "time". Use `None` to force regridding over the time dimension. :param 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. :param 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. :param 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. .. py:method:: most_common(ds_target_grid: xarray.Dataset, values: numpy.ndarray, time_dim: str | None = 'time', fill_value: None | Any = None) -> xarray.DataArray 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. :param ds_target_grid: Target grid dataset :param 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. :param time_dim: Name of the time dimension. Defaults to "time". Use `None` to force regridding over the time dimension. :param 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. .. py:method:: least_common(ds_target_grid: xarray.Dataset, values: numpy.ndarray, time_dim: str | None = 'time', fill_value: None | Any = None) -> xarray.DataArray 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. :param ds_target_grid: Target grid dataset :param 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. :param time_dim: Name of the time dimension. Defaults to "time". Use `None` to force regridding over the time dimension. :param 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. .. py:method:: 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 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 :param ds_target_grid: Target grid dataset :param method: One of the following reduction methods: "sum", "mean", "var", "std", "median", "min", or "max". :param time_dim: Name of the time dimension. Defaults to "time". Use `None` to force regridding over the time dimension. :param skipna: If NaN values should be ignored. :param 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. .. py:function:: validate_input(data: xarray.Dataset, ds_target_grid: xarray.Dataset, time_dim: str | None) -> xarray.Dataset validate_input(data: xarray.DataArray, ds_target_grid: xarray.Dataset, time_dim: str | None) -> xarray.Dataset