Skip to content
Snippets Groups Projects
Commit 81a891d2 authored by David Schäfer's avatar David Schäfer
Browse files

Merge branch 'residues' into 'develop'

residues: type hints

See merge request !200
parents cf2a1d10 275b6cd9
No related branches found
No related tags found
1 merge request!200residues: type hints
Pipeline #14403 passed with warnings with stages
in 12 minutes and 20 seconds
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from typing import Tuple, Union, Optional, Callable
from typing_extensions import Literal
import numpy as np
from dios import DictOfSeries
from saqc.core.register import register
from saqc.flagger.baseflagger import BaseFlagger
from saqc.funcs.rolling import roll
from saqc.funcs.curvefit import fitPolynomial
@register(masking='field')
def calculatePolynomialResidues(data, field, flagger, winsz, polydeg, numba="auto", eval_flags=True, min_periods=0,
**kwargs):
def calculatePolynomialResidues(
data: DictOfSeries, field: str, flagger: BaseFlagger,
winsz: Union[str, int], polydeg: int,
numba: Literal[True, False, "auto"]="auto",
eval_flags: bool=True,
min_periods: Optional[int]=0,
**kwargs) -> Tuple[DictOfSeries, BaseFlagger]:
"""
Function fits a polynomial model to the data and returns the residues.
......@@ -67,7 +79,7 @@ def calculatePolynomialResidues(data, field, flagger, winsz, polydeg, numba="aut
eval_flags : bool, default True
Wheather or not to assign new flags to the calculated residuals. If True, a residual gets assigned the worst
flag present in the interval, the data for its calculation was obtained from.
min_periods : {int, np.nan}, default 0
min_periods : {int, None}, default 0
The minimum number of periods, that has to be available in every values fitting surrounding for the polynomial
fit to be performed. If there are not enough values, np.nan gets assigned. Default (0) results in fitting
regardless of the number of values present (results in overfitting for too sparse intervals). To automatically
......@@ -84,16 +96,22 @@ def calculatePolynomialResidues(data, field, flagger, winsz, polydeg, numba="aut
"""
data, flagger = fitPolynomial(data, field, flagger, winsz, polydeg, numba=numba, eval_flags=eval_flags,
min_periods=min_periods, _return_residues=True, **kwargs)
min_periods=min_periods, return_residues=True, **kwargs)
return data, flagger
@register(masking='field')
def calculateRollingResidues(data, field, flagger, winsz, func=np.mean, eval_flags=True, min_periods=0, center=True,
**kwargs):
def calculateRollingResidues(
data: DictOfSeries, field: str, flagger: BaseFlagger,
winsz: Union[str, int],
func: Callable[[np.array], np.array]=np.mean,
eval_flags: bool=True,
min_periods: Optional[int]=0,
center: bool=True,
**kwargs) -> Tuple[DictOfSeries, BaseFlagger]:
data, flagger = roll(data, field, flagger, winsz, func=func, eval_flags=eval_flags,
min_periods=min_periods, center=center, _return_residues=True, **kwargs)
return data, flagger
\ No newline at end of file
return data, flagger
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment