Skip to content
Snippets Groups Projects
Commit 7c21afad authored by Bert Palm's avatar Bert Palm 🎇 Committed by David Schäfer
Browse files

Dfilter constants

parent 670aa8e7
No related branches found
No related tags found
2 merge requests!370Release 2.0,!368Dfilter constants
......@@ -6,6 +6,8 @@ __all__ = [
"BAD",
"GOOD",
"ENVIRONMENT",
"FILTER_ALL",
"FILTER_NONE",
]
......@@ -13,6 +15,9 @@ import numpy as np
import scipy.stats as st
import saqc.lib.ts_operators as ts_ops
# ----------------------------------------------------------------------
# global flag constants
# ----------------------------------------------------------------------
#: A :py:mod:`flag level constant <saqc.constants>`
#: , evaluating to the level, that indicates, no flag has been assigned to yet.
......@@ -31,6 +36,23 @@ DOUBTFUL = 25.0
#: , evaluating to the highest (internal) flag level available.
BAD = 255.0
# ----------------------------------------------------------------------
# global dfilter constants
# ----------------------------------------------------------------------
#: A :py:mod:`dfilter constant <saqc.constants>`
#: , mask/filter all flagged data.
FILTER_ALL = -np.inf
#: A :py:mod:`dfilter constant <saqc.constants>`
#: , mask/filter no data at all.
FILTER_NONE = np.inf
# ----------------------------------------------------------------------
# other
# ----------------------------------------------------------------------
#: A :py:mod:`flag level constant <saqc.constants>`
ENVIRONMENT = {
# Not A number Constant.
......
......@@ -2,13 +2,13 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
from saqc.constants import BAD, UNFLAGGED
from saqc.constants import BAD, FILTER_ALL
import saqc
class Breaks:
def flagMissing(
self, field: str, flag: float = BAD, dfilter: float = UNFLAGGED, **kwargs
self, field: str, flag: float = BAD, dfilter: float = FILTER_ALL, **kwargs
) -> saqc.SaQC:
return self._defer("flagMissing", locals())
......
......@@ -5,7 +5,7 @@ from __future__ import annotations
from typing import Sequence, Union
import saqc
from saqc.constants import UNFLAGGED, BAD
from saqc.constants import UNFLAGGED, BAD, FILTER_ALL
from saqc.lib.types import GenericFunction
......@@ -16,7 +16,7 @@ class Generic:
func: GenericFunction,
target: str | Sequence[str] = None,
flag: float = UNFLAGGED,
dfilter: float = UNFLAGGED,
dfilter: float = FILTER_ALL,
**kwargs,
) -> saqc.SaQC:
return self._defer("processGeneric", locals())
......@@ -27,7 +27,7 @@ class Generic:
func: GenericFunction,
target: Union[str, Sequence[str]] = None,
flag: float = BAD,
dfilter: float = UNFLAGGED,
dfilter: float = FILTER_ALL,
**kwargs,
) -> saqc.SaQC:
return self._defer("flagGeneric", locals())
......@@ -8,6 +8,8 @@ from typing_extensions import Literal
import saqc
import numpy as np
from saqc.constants import FILTER_NONE
class Tools:
def copyField(self, field: str, target: str, **kwargs) -> saqc.SaQC:
......@@ -42,7 +44,7 @@ class Tools:
phaseplot: Optional[str] = None,
stats_dict: Optional[dict] = None,
store_kwargs: Optional[dict] = None,
dfilter: Optional[float] = np.inf,
dfilter: Optional[float] = FILTER_NONE,
**kwargs,
) -> saqc.SaQC:
return self._defer("plot", locals())
......@@ -9,7 +9,7 @@ import numpy as np
import pandas as pd
import dios
from saqc.constants import UNFLAGGED
from saqc.constants import UNFLAGGED, FILTER_ALL
from saqc.core.flags import Flags, History
from saqc.lib.tools import squeezeSequence, toSequence
......@@ -224,12 +224,11 @@ class FunctionWrapper:
Notes
-----
If ``dfilter`` is **not** in the kwargs, the threshold defaults to
- ``-np.inf``
If a floatish ``dfilter`` is found in the kwargs, this value is taken as the threshold.
If ``dfilter`` is **not** in the kwargs, the threshold defaults to `FILTER_ALL`.
For any floatish value, it is taken as the threshold.
"""
if "dfilter" not in self.kwargs:
return UNFLAGGED
return FILTER_ALL
return float(self.kwargs["dfilter"]) # handle int
def _createMeta(self) -> dict:
......@@ -478,7 +477,7 @@ def _isflagged(flagscol: np.ndarray | pd.Series, thresh: float) -> np.array | pd
if not isinstance(thresh, (float, int)):
raise TypeError(f"thresh must be of type float, not {repr(type(thresh))}")
if thresh == UNFLAGGED:
if thresh == FILTER_ALL:
return flagscol > UNFLAGGED
return flagscol >= thresh
......@@ -9,13 +9,14 @@ import numpy as np
import pandas as pd
from dios import DictOfSeries
from saqc.core.flags import (
Flags,
from saqc.constants import (
FILTER_ALL,
UNFLAGGED,
BAD,
GOOD,
)
from saqc.core.flags import Flags
from saqc.lib.types import ExternalFlag
......@@ -48,7 +49,7 @@ class TranslationScheme:
"""
# (internal) threshold flag above which values will be masked
DFILTER_DEFAULT: float = UNFLAGGED
DFILTER_DEFAULT: float = FILTER_ALL
# additional arguments and default values the translation scheme accepts
ARGUMENTS: Dict[str, Any] = {}
......@@ -198,7 +199,7 @@ class SimpleScheme(TranslationScheme):
"""
_FORWARD = {
"UNFLAGGED": -np.inf,
"UNFLAGGED": UNFLAGGED,
"BAD": BAD,
"OK": GOOD,
}
......
......@@ -30,7 +30,7 @@ def flagMissing(
field: str,
flags: Flags,
flag: float = BAD,
dfilter: float = UNFLAGGED,
dfilter: float = FILTER_ALL,
**kwargs
) -> Tuple[DictOfSeries, Flags]:
"""
......
......@@ -9,7 +9,7 @@ import pandas as pd
from dios import DictOfSeries
from saqc.constants import BAD, UNFLAGGED, ENVIRONMENT
from saqc.constants import BAD, UNFLAGGED, ENVIRONMENT, FILTER_ALL
from saqc.core.history import History
from saqc.lib.tools import toSequence
from saqc.lib.types import GenericFunction, PandasLike
......@@ -31,7 +31,7 @@ def _execGeneric(
flags: Flags,
data: PandasLike,
func: GenericFunction,
dfilter: float = UNFLAGGED,
dfilter: float = FILTER_ALL,
) -> DictOfSeries:
globs = {
......@@ -62,7 +62,7 @@ def processGeneric(
func: GenericFunction,
target: str | Sequence[str] = None,
flag: float = UNFLAGGED,
dfilter: float = UNFLAGGED,
dfilter: float = FILTER_ALL,
**kwargs,
) -> Tuple[DictOfSeries, Flags]:
"""
......@@ -99,7 +99,7 @@ def processGeneric(
The quality flag to set. The default ``UNFLAGGED`` states the general idea, that
``processGeneric`` generates 'new' data without direct relation to the potentially
already present flags.
dfilter: float, default ``UNFLAGGED``
dfilter: float, default ``FILTER_ALL``
Threshold flag. Flag values greater than ``dfilter`` indicate that the associated
data value is inappropiate for further usage.
......@@ -176,7 +176,7 @@ def flagGeneric(
func: GenericFunction,
target: Union[str, Sequence[str]] = None,
flag: float = BAD,
dfilter: float = UNFLAGGED,
dfilter: float = FILTER_ALL,
**kwargs,
) -> Tuple[DictOfSeries, Flags]:
"""
......@@ -209,7 +209,7 @@ def flagGeneric(
The quality flag to set. The default ``UNFLAGGED`` states the general idea, that
``processGeneric`` generates 'new' data without direct relation to the potentially
already present flags.
dfilter: float, default ``UNFLAGGED``
dfilter: float, default ``FILTER_ALL``
Threshold flag. Flag values greater than ``dfilter`` indicate that the associated
data value is inappropiate for further usage.
......
......@@ -231,15 +231,15 @@ def maskTime(
datcol_idx = data[field].index
if mode == "periodic":
dfilter = periodicMask(datcol_idx, start, end, closed)
mask = periodicMask(datcol_idx, start, end, closed)
elif mode == "mask_field":
idx = data[mask_field].index.intersection(datcol_idx)
dfilter = data.loc[idx, mask_field]
mask = data.loc[idx, mask_field]
else:
raise ValueError("Keyword passed as masking mode is unknown ({})!".format(mode))
data.aloc[dfilter, field] = np.nan
flags[dfilter, field] = UNFLAGGED
data.aloc[mask, field] = np.nan
flags[mask, field] = UNFLAGGED
return data, flags
......@@ -256,7 +256,7 @@ def plot(
phaseplot: Optional[str] = None,
stats_dict: Optional[dict] = None,
store_kwargs: Optional[dict] = None,
dfilter: float = np.inf,
dfilter: float = FILTER_ALL,
**kwargs,
):
"""
......
......@@ -9,7 +9,7 @@ import pandas as pd
import pytest
from saqc.constants import UNFLAGGED, BAD, DOUBTFUL
from saqc.constants import UNFLAGGED, BAD, DOUBTFUL, FILTER_NONE
from saqc.core.translation import (
PositionalScheme,
TranslationScheme,
......@@ -225,8 +225,8 @@ def _buildupSaQCObjects():
out = []
for _ in range(2):
saqc = SaQC(data=data, flags=flags)
saqc = saqc.flagRange(field=col, min=5, max=6, dfilter=np.inf).flagRange(
col, min=3, max=10, dfilter=np.inf
saqc = saqc.flagRange(field=col, min=5, max=6, dfilter=FILTER_NONE).flagRange(
col, min=3, max=10, dfilter=FILTER_NONE
)
flags = saqc._flags
out.append(saqc)
......
......@@ -5,7 +5,7 @@ import pytest
import pandas as pd
from dios.dios.dios import DictOfSeries
from saqc.constants import BAD, UNFLAGGED
from saqc.constants import BAD, UNFLAGGED, FILTER_ALL
from saqc.core.flags import Flags
from saqc import SaQC
from saqc.lib.tools import toSequence
......@@ -35,7 +35,7 @@ def test_writeTargetFlagGeneric(data):
"func": func.__name__,
"target": targets,
"flag": BAD,
"dfilter": UNFLAGGED,
"dfilter": FILTER_ALL,
},
}
......@@ -67,7 +67,7 @@ def test_overwriteFieldFlagGeneric(data):
"target": fields,
"func": func.__name__,
"flag": flag,
"dfilter": UNFLAGGED,
"dfilter": FILTER_ALL,
},
}
......
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