primap2.csg.GlobalLSStrategy

primap2.csg.GlobalLSStrategy#

class primap2.csg.GlobalLSStrategy(allow_shift: bool = True, allow_negative: bool = False)[source]#

Fill missing data by global least square matching.

The NaNs in the first timeseries \(\textrm{ts}(t)\) are filled using harmonized data from the lower priority timeseries \(\textrm{fill_ts}(t)\). For harmonization we use

\[\textrm{fill_ts}_h(t) = \textrm{fill_ts}(t) \times a + b,\]

where \(\textrm{fill_ts}_h(t)\) is the harmonized dataset and \(a\) and \(b\) are determined by minimizing the least squares distance between \(\textrm{ts}(t)\) and \(\textrm{fill_ts}_h(t)\).

If the class is initialized with allow_shift = True the faster scipy.linalg.lstsq() function is used and \(b\) can be arbitrary. For the case allow_shift = False (\(b = 0\)) scipy.optimize.least_squares() is used.

If there is no overlap in non-NaN data between \(\textrm{ts}(t)\) and \(\textrm{fill_ts}(t)\) a StrategyUnableToProcess error will be raised.

If allow_negative = False and the harmonized time-series \(\textrm{fill_ts}_h(t)\) contains negative data a StrategyUnableToProcess error will be raised.

Attributes:
allow_shift: bool, default True

Allow the filling time series to shift up and down using the additive constant \(b \neq 0\).

allow_negative: bool, default False

Allow the filling time series to contain negative data initially.

Methods

fill(*, ts, fill_ts, fill_ts_repr)

Fill missing data by global least square matching.

__init__(allow_shift: bool = True, allow_negative: bool = False) None#

Method generated by attrs for class GlobalLSStrategy.

Methods

__init__([allow_shift, allow_negative])

Method generated by attrs for class GlobalLSStrategy.

fill(*, ts, fill_ts, fill_ts_repr)

Fill missing data by global least square matching.

Attributes

allow_shift

allow_negative

type