eolearn.features.interpolation¶
Module for interpolating, smoothing and re-sampling features in EOPatch
-
eolearn.features.interpolation.
base_interpolation_function
(data, times, resampled_times)[source]¶ Interpolates data feature
- Parameters
data (numpy.ndarray) – Array in a shape of t x (h x w x n)
times – Array of reference times relative to the first timestamp
resampled_times (numpy.array) – Array of reference times relative to the first timestamp in initial timestamp array.
- Returns
Array of interpolated values
- Return type
numpy.ndarray
-
eolearn.features.interpolation.
interpolation_function
(data, times, resampled_times)¶ Interpolates data feature
- Parameters
data (numpy.ndarray) – Array in a shape of t x (h x w x n)
times – Array of reference times relative to the first timestamp
resampled_times (numpy.array) – Array of reference times relative to the first timestamp in initial timestamp array.
- Returns
Array of interpolated values
- Return type
numpy.ndarray
-
eolearn.features.interpolation.
interpolation_function_parallel
(data, times, resampled_times)¶ Interpolates data feature
- Parameters
data (numpy.ndarray) – Array in a shape of t x (h x w x n)
times – Array of reference times relative to the first timestamp
resampled_times (numpy.array) – Array of reference times relative to the first timestamp in initial timestamp array.
- Returns
Array of interpolated values
- Return type
numpy.ndarray
-
class
eolearn.features.interpolation.
InterpolationTask
(*args, **kwargs)[source]¶ Bases:
eolearn.core.eotask.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.
- Parameters
feature ((FeatureType, str) or (FeatureType, str, str)) – A feature to be interpolated with optional new feature name
interpolation_object (object) – Interpolation class which is initialized with
resample_range ((str, str, int) or list(str) or list(datetime.datetime) or None) – 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 ((float, float)) – Maximum and minimum of returned data
mask_feature ((FeatureType, str)) – A mask feature which will be used to mask certain features
copy_features (list((FeatureType, str) or (FeatureType, str, str))) – 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 or numpy.nan) – 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 – Flag to indicate pixel wise interpolation or fast interpolation that creates a single interpolation object for the whole image
:type interpolate_pixel_wise : bool :param interpolation_parameters: 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 (numpy.ndarray) – Array in a shape of t x nobs, where nobs = h x w x n
times (numpy.array) – Array of reference times relative to the first timestamp
resampled_times (numpy.array) – Array of reference times relative to the first timestamp in initial timestamp array.
- Returns
Array of interpolated values
- Return type
numpy.ndarray
-
get_interpolation_function
(times, series)[source]¶ Initializes interpolation model
- Parameters
times (numpy.array) – Array of reference times in second relative to the first timestamp
series (numpy.array) – One dimensional array of time series
- Returns
Initialized interpolation model class
-
get_resampled_timestamp
(timestamp)[source]¶ Takes a list of timestamps and generates new list of timestamps according to
resample_range
- Parameters
timestamp (list(datetime.datetime)) – list of timestamps
- Returns
new list of timestamps
- Return type
-
class
eolearn.features.interpolation.
LegacyInterpolation
(*args, **kwargs)[source]¶ Bases:
eolearn.features.interpolation.InterpolationTask
Implements eolearn.features.InterpolationTask by using scipy.interpolate.interp1d(kind=’linear’)
Stores initialization parameters and the order to the instance attribute init_args.
-
class
eolearn.features.interpolation.
LinearInterpolation
(*args, **kwargs)[source]¶ Bases:
eolearn.features.interpolation.InterpolationTask
Implements eolearn.features.InterpolationTask by using numpy.interp and @numb.jit(nopython=True)
- Parameters
parallel (bool) – interpolation is calculated in parallel using as many CPUs as detected by the multiprocessing module.
**kwargs –
parameters of InterpolationTask(EOTask)
Stores initialization parameters and the order to the instance attribute init_args.
-
interpolate_data
(data, times, resampled_times)[source]¶ Interpolates data feature
- Parameters
data (numpy.ndarray) – Array in a shape of t x nobs, where nobs = h x w x n
times (numpy.array) – Array of reference times in second relative to the first timestamp
resampled_times (numpy.array) – Array of reference times in second relative to the first timestamp in initial timestamp array.
- Returns
Array of interpolated values
- Return type
numpy.ndarray
-
class
eolearn.features.interpolation.
CubicInterpolation
(*args, **kwargs)[source]¶ Bases:
eolearn.features.interpolation.InterpolationTask
Implements eolearn.features.InterpolationTask by using scipy.interpolate.interp1d(kind=’cubic’)
Stores initialization parameters and the order to the instance attribute init_args.
-
class
eolearn.features.interpolation.
SplineInterpolation
(*args, **kwargs)[source]¶ Bases:
eolearn.features.interpolation.InterpolationTask
Implements eolearn.features.InterpolationTask by using scipy.interpolate.UnivariateSpline
Stores initialization parameters and the order to the instance attribute init_args.
-
class
eolearn.features.interpolation.
BSplineInterpolation
(*args, **kwargs)[source]¶ Bases:
eolearn.features.interpolation.InterpolationTask
Implements eolearn.features.InterpolationTask by using scipy.interpolate.BSpline
Stores initialization parameters and the order to the instance attribute init_args.
-
class
eolearn.features.interpolation.
AkimaInterpolation
(*args, **kwargs)[source]¶ Bases:
eolearn.features.interpolation.InterpolationTask
Implements eolearn.features.InterpolationTask by using scipy.interpolate.Akima1DInterpolator
Stores initialization parameters and the order to the instance attribute init_args.
-
class
eolearn.features.interpolation.
KrigingObject
(times, series, **kwargs)[source]¶ Bases:
object
Interpolation function like object for Kriging
-
class
eolearn.features.interpolation.
KrigingInterpolation
(*args, **kwargs)[source]¶ Bases:
eolearn.features.interpolation.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 (which may or may not be desirable).
Stores initialization parameters and the order to the instance attribute init_args.
-
class
eolearn.features.interpolation.
ResamplingTask
(*args, **kwargs)[source]¶ Bases:
eolearn.features.interpolation.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.
Stores initialization parameters and the order to the instance attribute init_args.
-
interpolate_data
(data, times, resampled_times)[source]¶ Interpolates data feature
- Parameters
data (numpy.ndarray) – Array in a shape of t x nobs, where nobs = h x w x n
times (numpy.array) – Array of reference times in second relative to the first timestamp
resampled_times (numpy.array) – Array of reference times in second relative to the first timestamp in initial timestamp array.
- Returns
Array of interpolated values
- Return type
numpy.ndarray
-
-
class
eolearn.features.interpolation.
NearestResampling
(*args, **kwargs)[source]¶ Bases:
eolearn.features.interpolation.ResamplingTask
Implements eolearn.features.ResamplingTask by using scipy.interpolate.interp1d(kind=’nearest’)
Stores initialization parameters and the order to the instance attribute init_args.
-
class
eolearn.features.interpolation.
LinearResampling
(*args, **kwargs)[source]¶ Bases:
eolearn.features.interpolation.ResamplingTask
Implements eolearn.features.ResamplingTask by using scipy.interpolate.interp1d(kind=’linear’)
Stores initialization parameters and the order to the instance attribute init_args.
-
class
eolearn.features.interpolation.
CubicResampling
(*args, **kwargs)[source]¶ Bases:
eolearn.features.interpolation.ResamplingTask
Implements eolearn.features.ResamplingTask by using scipy.interpolate.interp1d(kind=’cubic’)
Stores initialization parameters and the order to the instance attribute init_args.