eolearn.features.extra.interpolation

Module for interpolating, smoothing and re-sampling features in EOPatch

eolearn.features.extra.interpolation.base_interpolation_function(data, times, resampled_times)[source]

Interpolates data feature

Parameters:
  • data (ndarray) – Array in a shape of t x (h x w x n)

  • times (ndarray) – Array of reference times relative to the first timestamp

  • resampled_times (ndarray) – Array of reference times relative to the first timestamp in initial timestamp array.

Returns:

Array of interpolated values

Return type:

ndarray

eolearn.features.extra.interpolation.interpolation_function(data, times, resampled_times)

Interpolates data feature

Parameters:
  • data (np.ndarray) – Array in a shape of t x (h x w x n)

  • times (np.ndarray) – Array of reference times relative to the first timestamp

  • resampled_times (np.ndarray) – Array of reference times relative to the first timestamp in initial timestamp array.

Returns:

Array of interpolated values

Return type:

np.ndarray

eolearn.features.extra.interpolation.interpolation_function_parallel(data, times, resampled_times)

Interpolates data feature

Parameters:
  • data (np.ndarray) – Array in a shape of t x (h x w x n)

  • times (np.ndarray) – Array of reference times relative to the first timestamp

  • resampled_times (np.ndarray) – Array of reference times relative to the first timestamp in initial timestamp array.

Returns:

Array of interpolated values

Return type:

np.ndarray

class eolearn.features.extra.interpolation.InterpolationTask(feature, interpolation_object, *, resample_range=None, result_interval=None, mask_feature=None, copy_features=None, unknown_value=nan, filling_factor=10, scale_time=3600, interpolate_pixel_wise=False, **interpolation_parameters)[source]

Bases: EOTask

Main EOTask class for interpolation and resampling of time-series.

The task takes from EOPatch the specified data feature and timestamps. For each pixel in the spatial grid it creates an interpolation model using values that are not NaN or masked with eopatch.mask[‘VALID_DATA’]. Then it replaces invalid values using interpolation model. If resample_range parameter is used the values in time series will be resampled to new timestamps.

In the process the interpolated feature is overwritten and so are the timestamps. After the execution of the task the feature will contain interpolated and resampled values and corresponding new timestamps.

Examples of interpolation_object: - `scipy.interpolate.interp1d, supply the kind as a kwarg, e.g. kind=”cubic” - scipy.interpolate.UnivariateSpline - scipy.interpolate.make_interp_spline - scipy.interpolate.Akima1DInterpolator

Parameters:
  • feature (SingleFeatureSpec) – A feature to be interpolated with optional new feature name

  • interpolation_object (Callable) – Interpolation class which is initialized with interpolation_parameters

  • resample_range (ResampleRangeType) – If None the data will be only interpolated over existing timestamps and NaN values will be replaced with interpolated values (if possible) in the existing EOPatch. Otherwise, resample_range can be set to tuple in a form of (start_date, end_date, step_days), e.g. (‘2018-01-01’, ‘2018-06-01’, 16). This will create a new EOPatch with resampled values for times start_date, start_date + step_days, start_date + 2 * step_days, … . End date is excluded from timestamps. Additionally, resample_range can be a list of dates or date-strings where the interpolation will be evaluated.

  • result_interval (tuple[float, float] | None) – Maximum and minimum of returned data

  • mask_feature (SingleFeatureSpec | None) – A mask feature which will be used to mask certain features

  • copy_features (FeaturesSpecification | None) – List of tuples of type (FeatureType, str) or (FeatureType, str, str) that are copied over into the new EOPatch. The first string is the feature name, and the second one (optional) is a new name to be used for the feature

  • unknown_value (float) – Value which will be used for timestamps where interpolation cannot be calculated

  • filling_factor (int) – Multiplication factor used to create temporal gap between consecutive observations. Value has to be greater than 1. Default is 10

  • scale_time (int) – Factor used to scale the time difference in seconds between acquisitions. If scale_time=60, returned time is in minutes, if scale_time=3600 in hours. Default is 3600

  • interpolate_pixel_wise (bool) – Flag to indicate pixel wise interpolation or fast interpolation that creates a single interpolation object for the whole image

  • interpolation_parameters (Any) – Parameters which will be propagated to interpolation_object

Stores initialization parameters and the order to the instance attribute init_args.

interpolate_data(data, times, resampled_times)[source]

Interpolates data feature

Parameters:
  • data (ndarray) – Array in a shape of t x num_obs, where num_obs = h x w x n

  • times (ndarray) – Array of reference times relative to the first timestamp

  • resampled_times (ndarray) – Array of reference times relative to the first timestamp in initial timestamp array.

Returns:

Array of interpolated values

Return type:

ndarray

get_interpolation_function(times, series)[source]

Initializes interpolation model

Parameters:
  • times (ndarray) – Array of reference times in second relative to the first timestamp

  • series (ndarray) – One dimensional array of time series

Returns:

Initialized interpolation model class

Return type:

Callable

get_resampled_timestamp(timestamps)[source]

Takes a list of timestamps and generates new list of timestamps according to resample_range

Parameters:

timestamps (list[datetime.datetime]) –

Return type:

list[datetime.datetime]

execute(eopatch)[source]

Execute method that processes EOPatch and returns EOPatch

Parameters:

eopatch (EOPatch) –

Return type:

EOPatch

class eolearn.features.extra.interpolation.LinearInterpolationTask(feature, parallel=False, **kwargs)[source]

Bases: InterpolationTask

Implements eolearn.features.InterpolationTask by using numpy.interp and @numba.jit(nopython=True)

Parameters:
  • parallel (bool) – interpolation is calculated in parallel by numba.

  • kwargs (Any) – parameters of InterpolationTask(EOTask)

  • feature (SingleFeatureSpec) –

Stores initialization parameters and the order to the instance attribute init_args.

interpolate_data(data, times, resampled_times)[source]

Interpolates data feature

Parameters:
  • data (ndarray) – Array in a shape of t x num_obs, where num_obs = h x w x n

  • times (ndarray) – Array of reference times in second relative to the first timestamp

  • resampled_times (ndarray) – Array of reference times relative to the first timestamp in initial timestamp array.

Returns:

Array of interpolated values

Return type:

ndarray

class eolearn.features.extra.interpolation.CubicInterpolationTask(feature, **kwargs)[source]

Bases: InterpolationTask

[DEPRECATED] Implements eolearn.features.InterpolationTask by using scipy.interpolate.interp1d(kind=’cubic’)

Stores initialization parameters and the order to the instance attribute init_args.

Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Self

class eolearn.features.extra.interpolation.SplineInterpolationTask(feature, *, spline_degree=3, smoothing_factor=0, **kwargs)[source]

Bases: InterpolationTask

[DEPRECATED] Implements eolearn.features.InterpolationTask by using scipy.interpolate.UnivariateSpline

Stores initialization parameters and the order to the instance attribute init_args.

Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Self

class eolearn.features.extra.interpolation.BSplineInterpolationTask(feature, *, spline_degree=3, **kwargs)[source]

Bases: InterpolationTask

[DEPRECATED] Implements eolearn.features.InterpolationTask by using scipy.interpolate.BSpline

Stores initialization parameters and the order to the instance attribute init_args.

Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Self

class eolearn.features.extra.interpolation.AkimaInterpolationTask(feature, **kwargs)[source]

Bases: InterpolationTask

[DEPRECATED] Implements eolearn.features.InterpolationTask by using scipy.interpolate.Akima1DInterpolator

Stores initialization parameters and the order to the instance attribute init_args.

Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Self

class eolearn.features.extra.interpolation.KrigingObject(times, series, **kwargs)[source]

Bases: object

Interpolation function like object for Kriging

Parameters:
  • times (np.ndarray) –

  • series (np.ndarray) –

  • kwargs (Any) –

class eolearn.features.extra.interpolation.KrigingInterpolationTask(feature, **kwargs)[source]

Bases: InterpolationTask

Implements eolearn.features.InterpolationTask by using sklearn.gaussian_process.GaussianProcessRegressor

Gaussian processes (superset of kriging) are especially used in geological missing data estimation. Compared to spline interpolation, gaussian processes produce much more smoothed results (might be desirable).

Stores initialization parameters and the order to the instance attribute init_args.

Parameters:
  • feature (SingleFeatureSpec) –

  • kwargs (Any) –

class eolearn.features.extra.interpolation.ResamplingTask(feature, interpolation_object, resample_range, *, result_interval=None, unknown_value=nan, **interpolation_parameters)[source]

Bases: InterpolationTask

A subclass of InterpolationTask task that works only with data with no missing, masked or invalid values.

It always resamples timeseries to different timestamps.

For example, to perform interpolation with the ‘nearest’ resampling use the values interpolation_object=scipy.interpolate.interp1d with kind=”nearest”.

Stores initialization parameters and the order to the instance attribute init_args.

Parameters:
  • feature (SingleFeatureSpec) –

  • interpolation_object (Callable) –

  • resample_range (ResampleRangeType) –

  • result_interval (tuple[float, float] | None) –

  • unknown_value (float) –

  • interpolation_parameters (Any) –

interpolate_data(data, times, resampled_times)[source]

Interpolates data feature

Parameters:
  • data (ndarray) – Array in a shape of t x num_obs, where num_obs = h x w x n

  • times (ndarray) – Array of reference times in second relative to the first timestamp

  • resampled_times (ndarray) – Array of reference times relative to the first timestamp in initial timestamp array.

Returns:

Array of interpolated values

Return type:

ndarray

get_interpolation_function(times, series)[source]

Initializes interpolation model

Parameters:
  • times (ndarray) – Array of reference times in second relative to the first timestamp

  • series (ndarray) – One dimensional array of time series

Returns:

Initialized interpolation model class

Return type:

Callable

class eolearn.features.extra.interpolation.NearestResamplingTask(feature, resample_range, **kwargs)[source]

Bases: ResamplingTask

[DEPRECATED] Implements eolearn.features.ResamplingTask by using scipy.interpolate.interp1d(kind=’nearest’)

Stores initialization parameters and the order to the instance attribute init_args.

Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Self

class eolearn.features.extra.interpolation.LinearResamplingTask(feature, resample_range, **kwargs)[source]

Bases: ResamplingTask

[DEPRECATED] Implements eolearn.features.ResamplingTask by using scipy.interpolate.interp1d(kind=’linear’)

Stores initialization parameters and the order to the instance attribute init_args.

Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Self

class eolearn.features.extra.interpolation.CubicResamplingTask(feature, resample_range, **kwargs)[source]

Bases: ResamplingTask

[DEPRECATED] Implements eolearn.features.ResamplingTask by using scipy.interpolate.interp1d(kind=’cubic’)

Stores initialization parameters and the order to the instance attribute init_args.

Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Self