Interpolation Functions

Functions

class xr_fresh.interpolate_series.interpolate_nan(missing_value=None, interp_type='linear', count=1, dates=None)[source]

Interpolate missing values in a geospatial time series. Without dates set this class assumes a regular time interval between observations. With dates set this class can handle irregular time, based on the DOY as an index.

Parameters:
  • missing_value (int or float, optional) – The value to be replaced by NaNs. Default is None.

  • interp_type (str, optional) – The type of interpolation algorithm to use. Options include “linear”, “nearest”, “zero”, “slinear”, “quadratic”, “cubic”, “previous”, “next”, “cubicspline”, “spline”, and “UnivariateSpline”. Default is “linear”.

  • dates (list[datetime]) – List of datetime objects corresponding to each time slice.

  • count (int, optional) – Overrides the default output band count. Default is 1.

calculate(array)[source]

Applies the interpolation on the input array.

Example Usage:

pth = "/home/mmann1123/Dropbox/Africa_data/Temperature/"
files = sorted(glob(f"{pth}*.tif"))[0:10]
strp_glob = f"{pth}RadT_tavg_%Y%m.tif"
dates = sorted(datetime.strptime(string, strp_glob) for string in files)
date_strings = [date.strftime("%Y-%m-%d") for date in dates]

# window size controls RAM usage, transfer lab can be jax if using GPU
with gw.series(files, window_size=[640, 640], transfer_lib="numpy") as src:
    src.apply(
        func=interpolate_nan(
            missing_value=0,
            count=len(src.filenames),
            dates=dates,
        ),
        outfile="/home/mmann1123/Downloads/test.tif",
        num_workers=min(12, src.nchunks),
        bands=1,
    )

Methods

__call__(w, array, band_dict)

Call self as a function.

calculate(array)

Calculates the user function.

calculate(array)[source]

Calculates the user function.

Parameters:

| (data (numpy.ndarray) – jax.Array | torch.Tensor | tensorflow.Tensor): The input array, shaped [time x bands x rows x columns].

Returns:

numpy.ndarray | jax.Array | torch.Tensor | tensorflow.Tensor:

Shaped (time|bands x rows x columns)