zooc.dsp.filters
Digital filters for single dimensional data processing in time domain.
- class zooc.dsp.filters.Filter(*, data_values)
Bases:
ABCMathematical filter to output a value based in single dimensional input data.
- Parameters:
data_values (FloatArray) – Input data values.
- abstractmethod describe()
Describe the filter output.
- abstractmethod get_output()
Get the output value of the filter.
- Returns:
Filtered output value.
- Return type:
- class zooc.dsp.filters.FilterExpDecay(*, data_values, data_t, max_linalg=20000000.0)
Bases:
FilterMathExponentially decaying filter.
- Parameters:
- Raises:
ValueError – When data is not valid for exponential decay filter.
- classmethod create(data)
Create a FilterExpDecay from dictionary data.
- static model_func(t, a, k, c)
Mathematical function for exponential decay used by this filter.
- Parameters:
t (FloatArray) – Time.
a (Float) – Amplitude constant.
k (Float) – Exponent constant.
c (Float) – Constant where the function decays to, i.e. the limit value.
- Returns:
Value of the function at time t.
- Return type:
FloatArray
- describe()
Describe the filter output.
- find_worst_outlier()
Get the worst outlier from the data.
- forecast(t_future)
Calculate the future value of the function starting from the last time point.
- Parameters:
t_future (FloatAny) – Time after the latest data point [s].
- Returns:
Value at t_future.
- Return type:
FloatArray
- get_amplitude()
Get the amplitude constant, i.e., the difference of the first sample and the final value.
- Returns:
Amplitude.
- Return type:
- get_output()
Get the final limit value into which the function approaches.
- get_time_constant()
Get the time constant of the exponential decay function.
- Returns:
Time constant [s].
- Return type:
- get_value_tc(value)
Get time as a multiple of the time constant for given value.
Example: A value at 63.5% of the final value would result 1.0 (1 time constant).
- has_enough_data()
Was enough data points provided to solve the exponential decay function.
- Returns:
True is enough data points.
- Return type:
- is_pos_or_neg()
Check whether the function is rising or decreasing.
- Returns:
True if rising.
- Return type:
- is_valid(max_linalg=None)
Validate the data resembles exponentially decaying function.
At least 4 data points.
Numpy evaluates the data as valid.
- solve(t)
Calculate the value of the function at the given time point.
- Parameters:
t (FloatArray) – Time point [s].
- Returns:
Value at t.
- Return type:
FloatArray
- solve_float(t)
Calculate the value of the function at the given time point.
- Parameters:
t (FloatAny) – Time point [s].
- Returns:
Value at t.
- Return type:
- solve_t0(t)
Calculate the value of the function starting from the first time point.
- Parameters:
t (FloatAny) – Time after the first data point [s].
- Returns:
Value at t_0 + t.
- Return type:
FloatArray
- a: float64
Amplitude constant.
- property bounds: tuple[list[float], list[float]]
Get bounds for the model.
- Returns:
Tuple of (lower_bounds, upper_bounds) for [a, k, c].
- c: float64
Constant where the function decays to, i.e. the limit value.
- k: float64
Exponent constant. Absolute value. Negative value is used in
model_func()
- parm_cov: FloatArray
Numpy covariance matrix of the parameters.
- t_range: float64
Time range for normalized time.
- t_zero: float64
Zero time point.
- class zooc.dsp.filters.FilterExpDecayZ(*, data_values, data_t, max_linalg=20000000.0, tau_min_th, tau_max_th, noise_rel_range_th, noise_abs_range_th)
Bases:
FilterExpDecayExponentially decaying filter combined with min/max time constant and monotonic data validation.
- Parameters:
data_values (FloatArray) – See parent class:
FilterExpDecay.data_t (FloatArray) – See parent class:
FilterExpDecay.a – See parent class:
FilterExpDecay.k – See parent class:
FilterExpDecay.c – See parent class:
FilterExpDecay.parm_cov – See parent class:
FilterExpDecay.t_zero – See parent class:
FilterExpDecay.t_range – See parent class:
FilterExpDecay.max_linalg (Final[float]) – See parent class:
FilterExpDecay.tau_min_th (float) – Minimum time constant [s].
tau_max_th (float) – Maximum time constant [s].
noise_rel_range_th (float) – See
FilterMonotonic.noise_abs_range_th (float) – See
FilterMonotonic.
- Raises:
ValueError – When data is not valid for exponential decay filter.
- classmethod create(data)
Create a FilterExpDecay from dictionary data.
- static model_func(t, a, k, c)
Mathematical function for exponential decay used by this filter.
- Parameters:
t (FloatArray) – Time.
a (Float) – Amplitude constant.
k (Float) – Exponent constant.
c (Float) – Constant where the function decays to, i.e. the limit value.
- Returns:
Value of the function at time t.
- Return type:
FloatArray
- describe()
Describe the filter output.
- find_worst_outlier()
Get the worst outlier from the data.
- forecast(t_future)
Calculate the future value of the function starting from the last time point.
- Parameters:
t_future (FloatAny) – Time after the latest data point [s].
- Returns:
Value at t_future.
- Return type:
FloatArray
- get_amplitude()
Get the amplitude constant, i.e., the difference of the first sample and the final value.
- Returns:
Amplitude.
- Return type:
- get_output()
Get the final limit value into which the function approaches.
- get_time_constant()
Get the time constant of the exponential decay function.
- Returns:
Time constant [s].
- Return type:
- get_value_tc(value)
Get time as a multiple of the time constant for given value.
Example: A value at 63.5% of the final value would result 1.0 (1 time constant).
- has_enough_data()
Was enough data points provided to solve the exponential decay function.
- Returns:
True is enough data points.
- Return type:
- is_pos_or_neg()
Check whether the function is rising or decreasing.
- Returns:
True if rising.
- Return type:
- is_valid(max_linalg=None)
Validate the data resembles exponentially decaying function.
At least 4 data points.
Numpy evaluates the data as valid.
- solve(t)
Calculate the value of the function at the given time point.
- Parameters:
t (FloatArray) – Time point [s].
- Returns:
Value at t.
- Return type:
FloatArray
- solve_float(t)
Calculate the value of the function at the given time point.
- Parameters:
t (FloatAny) – Time point [s].
- Returns:
Value at t.
- Return type:
- solve_t0(t)
Calculate the value of the function starting from the first time point.
- Parameters:
t (FloatAny) – Time after the first data point [s].
- Returns:
Value at t_0 + t.
- Return type:
FloatArray
- a: float64
Amplitude constant.
- property bounds: tuple[list[float], list[float]]
Get bounds for the model.
- Returns:
Tuple of (lower_bounds, upper_bounds) for [a, k, c].
- c: float64
Constant where the function decays to, i.e. the limit value.
- k: float64
Exponent constant. Absolute value. Negative value is used in
model_func()
- parm_cov: FloatArray
Numpy covariance matrix of the parameters.
- t_range: float64
Time range for normalized time.
- t_zero: float64
Zero time point.
- class zooc.dsp.filters.FilterMath(*, data_values, data_t)
Bases:
FilterAbstract filter for forecasting future values.
- Parameters:
data_t (FloatArray) – Time data.
data_values (FloatArray)
- abstractmethod describe()
Describe the filter output.
- forecast(t_future)
Calculate the future value of the function starting from the last time point.
- Parameters:
t_future (FloatAny) – Time after the latest data point [s].
- Returns:
Value at t_future.
- Return type:
FloatArray
- abstractmethod get_output()
Get the output value of the filter.
- Returns:
Filtered output value.
- Return type:
- abstractmethod is_valid()
Check whether the data is valid for the filter.
- Returns:
True if valid.
- Return type:
- abstractmethod solve(t)
Calculate the value of the function at the given time point.
- Parameters:
t (FloatArray) – Time point [s].
- Returns:
Value at t.
- Return type:
FloatArray
- solve_float(t)
Calculate the value of the function at the given time point.
- Parameters:
t (FloatAny) – Time point [s].
- Returns:
Value at t.
- Return type:
- solve_t0(t)
Calculate the value of the function starting from the first time point.
- Parameters:
t (FloatAny) – Time after the first data point [s].
- Returns:
Value at t_0 + t.
- Return type:
FloatArray
- class zooc.dsp.filters.FilterMedian(*, data_values, MIN_SAMPLES_STDDEV=2, max_abs_input_range)
Bases:
FilterMedian output filter for 1D data with min/max input noise tolerance.
- Parameters:
- describe()
Describe the filter output.
- get_output()
Get the output value of the filter.
- Returns:
Filtered output value.
- Return type:
- is_valid()
Check whether the data is valid for the filter.
- Returns:
True if valid.
- Return type:
- property filtered_series: FloatArray
Get the median filtered output.
- Returns:
Filtered output.
- class zooc.dsp.filters.FilterMedianLinear(*, data_values, MIN_SAMPLES_STDDEV=2, max_abs_input_range, data_t)
Bases:
FilterMath,FilterMedianMedian output filter for data with time dimension and linear regression.
- Parameters:
- static create(data, max_abs_input_range)
Create a FilterLinear from dictionary data.
- Parameters:
- Returns:
FilterMedianLinear.
- Return type:
- describe()
Describe the filter output.
- forecast(t_future)
Calculate the future value of the function starting from the last time point.
- Parameters:
t_future (FloatAny) – Time after the latest data point [s].
- Returns:
Value at t_future.
- Return type:
FloatArray
- get_output()
Get the output value of the filter.
- Returns:
Filtered output value.
- Return type:
- is_valid()
Check whether the data is valid for the filter.
- Returns:
True if valid.
- Return type:
- solve(t)
Calculate the value of the function at the given time point.
- Parameters:
t (FloatArray) – Time point [s].
- Returns:
Value at t.
- Return type:
FloatArray
- solve_float(t)
Calculate the value of the function at the given time point.
- Parameters:
t (FloatAny) – Time point [s].
- Returns:
Value at t.
- Return type:
- solve_t0(t)
Calculate the value of the function starting from the first time point.
- Parameters:
t (FloatAny) – Time after the first data point [s].
- Returns:
Value at t_0 + t.
- Return type:
FloatArray
- property correlation: float
Get the linear regression correlation of the data.
Note, correlation of constant (flat) data is 0.
- Returns:
Correlation as r-value.
- property filtered_series: FloatArray
Get the median filtered output.
- Returns:
Filtered output.
- property intercept: float
Get the linear regression. y-intercept of the data.
- Returns:
y-intercept at t=0.
- class zooc.dsp.filters.FilterMonotonic(*, data_values, noise_rel_range_th, noise_abs_range_th)
-
Abstract filter for monotonically increasing or decreasing data with noise tolerance.
- Parameters:
- describe()
Describe the filter output.
- get_noise_th()
Get allowed noise threshold, larger of relative and absolute noise thresholds.
- Returns:
Noise threshold as absolute value.
- Return type:
- abstractmethod get_output()
Get the output value of the filter.
- Returns:
Filtered output value.
- Return type:
- is_monotonic()
Is input data monotonic within the noise tolerance.
- Returns:
True if monotonic.
- Return type:
- is_monotonic_dec(noise)
Check whether the input data is decreasing monotonically within noise tolerance.
- is_monotonic_inc(noise)
Check whether the input data is increasing monotonically within the noise tolerance.
- class zooc.dsp.filters.FilterMonotonicImpl(*, data_values, noise_rel_range_th, noise_abs_range_th)
Bases:
FilterMonotonicDummy implementation of FilterMonotonic.
- Parameters:
- describe()
Describe the filter output.
- get_noise_th()
Get allowed noise threshold, larger of relative and absolute noise thresholds.
- Returns:
Noise threshold as absolute value.
- Return type:
- get_output()
Get the output value of the filter.
- Returns:
Filtered output value.
- Return type:
- is_monotonic()
Is input data monotonic within the noise tolerance.
- Returns:
True if monotonic.
- Return type:
- is_monotonic_dec(noise)
Check whether the input data is decreasing monotonically within noise tolerance.
- is_monotonic_inc(noise)
Check whether the input data is increasing monotonically within the noise tolerance.
- class zooc.dsp.filters.FilterStable(*, data_values, MIN_SAMPLES_STDDEV=2, max_abs_input_range, data_t, max_slope, max_rse, max_stddev)
Bases:
FilterMedianLinearStable filter for 2D data.
Data is determined as stable (valid) when the slope is small and correlation high.
- Parameters:
data_values (FloatArray) – Input data values.
max_abs_input_range (float) – Allowed absolute noise threshold over the input range.
data_t (FloatArray) – Time data.
max_slope (float) – Maximum allowed slope in given unit / time [x/y].
max_rse (float) – Maximum relative standard error of the slope when slope is high [n].
max_stddev (float) – Maximum standard deviation when slope is low [y].
- static create(data, max_abs_input_range)
Create a FilterLinear from dictionary data.
- Parameters:
- Returns:
FilterMedianLinear.
- Return type:
- describe()
Describe the filter output.
- forecast(t_future)
Calculate the future value of the function starting from the last time point.
- Parameters:
t_future (FloatAny) – Time after the latest data point [s].
- Returns:
Value at t_future.
- Return type:
FloatArray
- get_output()
Get the output value of the filter.
- Returns:
Filtered output value.
- Return type:
- is_valid()
Check whether the data is valid for the filter.
- Returns:
True if valid.
- Return type:
- solve(t)
Calculate the value of the function at the given time point.
- Parameters:
t (FloatArray) – Time point [s].
- Returns:
Value at t.
- Return type:
FloatArray
- solve_float(t)
Calculate the value of the function at the given time point.
- Parameters:
t (FloatAny) – Time point [s].
- Returns:
Value at t.
- Return type:
- solve_t0(t)
Calculate the value of the function starting from the first time point.
- Parameters:
t (FloatAny) – Time after the first data point [s].
- Returns:
Value at t_0 + t.
- Return type:
FloatArray
- property correlation: float
Get the linear regression correlation of the data.
Note, correlation of constant (flat) data is 0.
- Returns:
Correlation as r-value.
- property filtered_series: FloatArray
Get the median filtered output.
- Returns:
Filtered output.
- property intercept: float
Get the linear regression. y-intercept of the data.
- Returns:
y-intercept at t=0.