Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • berntm/saqc
  • rdm-software/saqc
  • schueler/saqc
3 results
Show changes
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from typing import Optional from typing import Optional, Union
from typing_extensions import Literal from typing_extensions import Literal
from saqc.lib.tools import toSequence from saqc.lib.tools import toSequence
import pandas as pd import pandas as pd
...@@ -46,7 +46,7 @@ def makeFig( ...@@ -46,7 +46,7 @@ def makeFig(
flags: Flags, flags: Flags,
level: float, level: float,
max_gap: Optional[str] = None, max_gap: Optional[str] = None,
history: Optional[Literal["valid", "complete"]] = "valid", history: Union[Optional[Literal["valid", "complete"]], list] = "valid",
xscope: Optional[slice] = None, xscope: Optional[slice] = None,
phaseplot: Optional[str] = None, phaseplot: Optional[str] = None,
ax_kwargs: Optional[dict] = None, ax_kwargs: Optional[dict] = None,
...@@ -75,13 +75,16 @@ def makeFig( ...@@ -75,13 +75,16 @@ def makeFig(
below `max_gap` get connected via the plotting line. below `max_gap` get connected via the plotting line.
history : {"valid", "complete", None}, default "valid" history : {"valid", "complete", None, list of strings}, default "valid"
Discriminate the plotted flags with respect to the tests they originate from. Discriminate the plotted flags with respect to the tests they originate from.
* "valid" - Only plot those flags, that do not get altered or "unflagged" by subsequent tests. Only list tests * "valid" - Only plot those flags, that do not get altered or "unflagged" by subsequent tests. Only list tests
in the legend, that actually contributed flags to the overall resault. in the legend, that actually contributed flags to the overall resault.
* "complete" - plot all the flags set and list all the tests ran on a variable. Suitable for debugging/tracking. * "complete" - plot all the flags set and list all the tests ran on a variable. Suitable for debugging/tracking.
* "clear" - clear plot from all the flagged values * "clear" - clear plot from all the flagged values
* None - just plot the resulting flags for one variable, without any historical meta information. * None - just plot the resulting flags for one variable, without any historical meta information.
* list of strings - for any string ``s`` in the list, plot the flags set by test labeled, ``s`` - if ``s`` is
not present in the history labels, plot any flags, set by a test labeled ``s``
xscope : slice or Offset, default None xscope : slice or Offset, default None
Parameter, that determines a chunk of the data to be plotted / Parameter, that determines a chunk of the data to be plotted /
...@@ -97,6 +100,8 @@ def makeFig( ...@@ -97,6 +100,8 @@ def makeFig(
""" """
if ax_kwargs is None:
ax_kwargs = {}
# data retrieval # data retrieval
d = data[field] d = data[field]
# data slicing: # data slicing:
...@@ -110,6 +115,9 @@ def makeFig( ...@@ -110,6 +115,9 @@ def makeFig(
default = plt.rcParams["font.size"] default = plt.rcParams["font.size"]
plt.rcParams["font.size"] = ax_kwargs.pop("fontsize", None) or default plt.rcParams["font.size"] = ax_kwargs.pop("fontsize", None) or default
# set shapecycle start:
cyclestart = ax_kwargs.pop("cycleskip", 0)
na_mask = d.isna() na_mask = d.isna()
d = d[~na_mask] d = d[~na_mask]
if phaseplot: if phaseplot:
...@@ -147,6 +155,7 @@ def makeFig( ...@@ -147,6 +155,7 @@ def makeFig(
plot_kwargs, plot_kwargs,
ax_kwargs, ax_kwargs,
SCATTER_KWARGS, SCATTER_KWARGS,
cyclestart,
) )
plt.rcParams["font.size"] = default plt.rcParams["font.size"] = default
...@@ -165,6 +174,7 @@ def _plotVarWithFlags( ...@@ -165,6 +174,7 @@ def _plotVarWithFlags(
plot_kwargs, plot_kwargs,
ax_kwargs, ax_kwargs,
scatter_kwargs, scatter_kwargs,
cyclestart,
): ):
scatter_kwargs = scatter_kwargs.copy() scatter_kwargs = scatter_kwargs.copy()
ax.set_title(datser.name) ax.set_title(datser.name)
...@@ -176,8 +186,25 @@ def _plotVarWithFlags( ...@@ -176,8 +186,25 @@ def _plotVarWithFlags(
"color", plt.rcParams["axes.prop_cycle"].by_key()["color"] "color", plt.rcParams["axes.prop_cycle"].by_key()["color"]
) )
color_cycle = itertools.cycle(toSequence(color_cycle)) color_cycle = itertools.cycle(toSequence(color_cycle))
for k in range(0, cyclestart):
next(color_cycle)
next(shape_cycle)
if history: if history:
for i in flags_hist.columns: for i in flags_hist.columns:
if isinstance(history, list):
meta_field = "label" if "label" in flags_meta[i].keys() else "func"
to_plot = (
flags_meta[i][meta_field]
if flags_meta[i][meta_field] in history
else None
)
if not to_plot:
continue
else:
hist_key = "valid"
else:
hist_key = history
# catch empty but existing history case (flags_meta={}) # catch empty but existing history case (flags_meta={})
if len(flags_meta[i]) == 0: if len(flags_meta[i]) == 0:
continue continue
...@@ -187,12 +214,12 @@ def _plotVarWithFlags( ...@@ -187,12 +214,12 @@ def _plotVarWithFlags(
) )
scatter_kwargs.update({"label": label}) scatter_kwargs.update({"label": label})
flags_i = flags_hist[i].astype(float) flags_i = flags_hist[i].astype(float)
if history == "complete": if hist_key == "complete":
scatter_kwargs.update( scatter_kwargs.update(
{"color": next(color_cycle), "marker": next(shape_cycle)} {"color": next(color_cycle), "marker": next(shape_cycle)}
) )
_plotFlags(ax, datser, flags_i, na_mask, level, scatter_kwargs) _plotFlags(ax, datser, flags_i, na_mask, level, scatter_kwargs)
if history == "valid": if hist_key == "valid":
# only plot those flags, that do not get altered later on: # only plot those flags, that do not get altered later on:
mask = flags_i.eq(flags_vals) mask = flags_i.eq(flags_vals)
flags_i[~mask] = np.nan flags_i[~mask] = np.nan
...@@ -219,6 +246,7 @@ def _plotVarWithFlags( ...@@ -219,6 +246,7 @@ def _plotVarWithFlags(
level, level,
scatter_kwargs, scatter_kwargs,
) )
ax.legend() ax.legend()
else: else:
scatter_kwargs.update({"color": next(color_cycle), "marker": next(shape_cycle)}) scatter_kwargs.update({"color": next(color_cycle), "marker": next(shape_cycle)})
......
...@@ -430,11 +430,11 @@ def estimateFrequency( ...@@ -430,11 +430,11 @@ def estimateFrequency(
min_energy = delta_f[0] * min_energy min_energy = delta_f[0] * min_energy
# calc/assign low/high freq cut offs (makes life easier): # calc/assign low/high freq cut offs (makes life easier):
min_rate_i = int( min_rate_i = int(
len_f / (pd.Timedelta(min_rate).total_seconds() * (10 ** delta_precision)) len_f / (pd.Timedelta(min_rate).total_seconds() * (10**delta_precision))
) )
delta_f[:min_rate_i] = 0 delta_f[:min_rate_i] = 0
max_rate_i = int( max_rate_i = int(
len_f / (pd.Timedelta(max_rate).total_seconds() * (10 ** delta_precision)) len_f / (pd.Timedelta(max_rate).total_seconds() * (10**delta_precision))
) )
hf_cutoff = min(max_rate_i, len_f // 2) hf_cutoff = min(max_rate_i, len_f // 2)
delta_f[hf_cutoff:] = 0 delta_f[hf_cutoff:] = 0
......
...@@ -415,7 +415,7 @@ def _coeffMat(x, deg): ...@@ -415,7 +415,7 @@ def _coeffMat(x, deg):
mat_[:, 1] = x mat_[:, 1] = x
if deg > 1: if deg > 1:
for n in range(2, deg + 1): for n in range(2, deg + 1):
mat_[:, n] = x ** n mat_[:, n] = x**n
return mat_ return mat_
......
...@@ -98,7 +98,6 @@ import numpy as np ...@@ -98,7 +98,6 @@ import numpy as np
from saqc.constants import * from saqc.constants import *
""" """
# -- Other options ----------------------------------------------------------- # -- Other options -----------------------------------------------------------
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"] templates_path = ["_templates"]
......
...@@ -107,7 +107,7 @@ def test_arithmeticOperators(data): ...@@ -107,7 +107,7 @@ def test_arithmeticOperators(data):
("var1 * 100 > 200", data * 100 > 200), ("var1 * 100 > 200", data * 100 > 200),
("var1 / 100 > .1", data / 100 > 0.1), ("var1 / 100 > .1", data / 100 > 0.1),
("var1 % 2 == 1", data % 2 == 1), ("var1 % 2 == 1", data % 2 == 1),
("var1 ** 2 == 0", data ** 2 == 0), ("var1 ** 2 == 0", data**2 == 0),
] ]
for test, expected in tests: for test, expected in tests:
......
...@@ -32,7 +32,7 @@ def test_modelling_polyFit_forRegular(dat): ...@@ -32,7 +32,7 @@ def test_modelling_polyFit_forRegular(dat):
flags = initFlagsLike(data) flags = initFlagsLike(data)
result1, _ = calculatePolynomialResidues(data, "data", flags, 11, 2, numba=False) result1, _ = calculatePolynomialResidues(data, "data", flags, 11, 2, numba=False)
result2, _ = calculatePolynomialResidues(data, "data", flags, 11, 2, numba=True) result2, _ = calculatePolynomialResidues(data, "data", flags, 11, 2, numba=True)
assert (result1["data"] - result2["data"]).abs().max() < 10 ** -10 assert (result1["data"] - result2["data"]).abs().max() < 10**-10
result3, _ = calculatePolynomialResidues( result3, _ = calculatePolynomialResidues(
data, "data", flags, "110min", 2, numba=False data, "data", flags, "110min", 2, numba=False
) )
...@@ -40,7 +40,7 @@ def test_modelling_polyFit_forRegular(dat): ...@@ -40,7 +40,7 @@ def test_modelling_polyFit_forRegular(dat):
result4, _ = calculatePolynomialResidues( result4, _ = calculatePolynomialResidues(
data, "data", flags, 11, 2, numba=True, min_periods=11 data, "data", flags, 11, 2, numba=True, min_periods=11
) )
assert (result4["data"] - result2["data"]).abs().max() < 10 ** -10 assert (result4["data"] - result2["data"]).abs().max() < 10**-10
data.iloc[13:16] = np.nan data.iloc[13:16] = np.nan
result5, _ = calculatePolynomialResidues( result5, _ = calculatePolynomialResidues(
data, "data", flags, 11, 2, numba=True, min_periods=9 data, "data", flags, 11, 2, numba=True, min_periods=9
......