Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SaQC
Manage
Activity
Members
Labels
Plan
Issues
35
Issue boards
Milestones
Wiki
Code
Merge requests
7
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rdm-software
SaQC
Commits
37d283c9
Commit
37d283c9
authored
3 years ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Plain Diff
Merge branch 'plotInHistory' into cookBux
parents
58eeb836
19b7fcfe
No related branches found
No related tags found
7 merge requests
!685
Release 2.4
,
!684
Release 2.4
,
!567
Release 2.2.1
,
!566
Release 2.2
,
!501
Release 2.1
,
!372
fix doctest snippets
,
!369
Current documentation
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
saqc/core/modules/tools.py
+2
-1
2 additions, 1 deletion
saqc/core/modules/tools.py
saqc/funcs/tools.py
+25
-14
25 additions, 14 deletions
saqc/funcs/tools.py
saqc/lib/plotting.py
+41
-25
41 additions, 25 deletions
saqc/lib/plotting.py
tests/funcs/test_tools.py
+3
-5
3 additions, 5 deletions
tests/funcs/test_tools.py
with
71 additions
and
45 deletions
saqc/core/modules/tools.py
+
2
−
1
View file @
37d283c9
...
...
@@ -38,7 +38,8 @@ class Tools(ModuleBase):
path
:
Optional
[
str
]
=
None
,
max_gap
:
Optional
[
FreqString
]
=
None
,
stats
:
bool
=
False
,
plot_kwargs
:
Optional
[
dict
]
=
None
,
history
:
Optional
[
Literal
[
"
valid
"
,
"
complete
"
]]
=
"
valid
"
,
ax_kwargs
:
Optional
[
dict
]
=
None
,
fig_kwargs
:
Optional
[
dict
]
=
None
,
scatter_kwargs
:
Optional
[
dict
]
=
None
,
stats_dict
:
Optional
[
dict
]
=
None
,
...
...
This diff is collapsed.
Click to expand it.
saqc/funcs/tools.py
+
25
−
14
View file @
37d283c9
...
...
@@ -252,7 +252,9 @@ def plot(
path
:
Optional
[
str
]
=
None
,
max_gap
:
Optional
[
FreqString
]
=
None
,
stats
:
bool
=
False
,
plot_kwargs
:
Optional
[
dict
]
=
None
,
history
:
Optional
[
Literal
[
"
valid
"
,
"
complete
"
]]
=
"
valid
"
,
s
:
Optional
[
slice
]
=
None
,
ax_kwargs
:
Optional
[
dict
]
=
None
,
fig_kwargs
:
Optional
[
dict
]
=
None
,
scatter_kwargs
:
Optional
[
dict
]
=
None
,
stats_dict
:
Optional
[
dict
]
=
None
,
...
...
@@ -294,20 +296,26 @@ def plot(
stats : bool, default False
Whether to include statistics table in plot.
plot_kwargs : dict, default None
history : {
"
valid
"
,
"
complete
"
, None}, default
"
valid
"
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
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.
* None - just plot the resulting flags for one variable, without any historical meta information.
s : slice or Offset, default None
Parameter, that determines a chunk of the data to be plotted /
processed. `s` can be anything, that is a valid argument to the ``pandas.Series.__getitem__`` method.
ax_kwargs : dict, default None
ax_kwargs : dict, default None
Keyword arguments controlling plot generation. Will be passed on to the
``Matplotlib.axes.Axes.set()`` property batch setter for the axes showing the
data plot. The most relevant of those properties might be
"
ylabel
"
,
"
title
"
and
"
ylim
"
. In Addition, following options are available:
* {
'
slice
'
: s} property, that determines a chunk of the data to be plotted /
processed. `s` can be anything, that is a valid argument to the
``pandas.Series.__getitem__`` method.
* {
'
history
'
: str}
* str=
"
all
"
: All the flags are plotted with colored dots, refering to the
tests they originate from
* str=
"
valid
"
: - same as
'
all
'
- but only plots those flags, that are not
removed by later tests
data plot. The most relevant of those properties might be
"
ylabel
"
,
"
title
"
and in addition:
"
ylim
"
.
The
"
ylim
"
keyword can be passed a slice object with date offset entries to controll figure
scope.
fig_kwargs : dict, default None
Keyword arguments controlling figure generation. In interactive mode,
...
...
@@ -318,6 +326,8 @@ def plot(
Keyword arguments controlling the appearance of the dots, marking flagged values.
Dict just gets passed on to the matplotlib.pyplot.scatter method. Keywords of interest may be:
``
"
alpha
"
`` (transparancy), ``
"
marker
"
`` (marker appearance) and ``
"
s
"
`` (dot size).
The ``
"
marker
"
`` and ``
"
color
"
`` keywords can also be passed lists, that the plotting routine will then cycle
through.
store_kwargs : dict, default {}
Keywords to be passed on to the ``matplotlib.pyplot.savefig`` method, handling
...
...
@@ -376,7 +386,8 @@ def plot(
level
=
kwargs
.
get
(
"
flag
"
,
BAD
),
max_gap
=
max_gap
,
stats
=
stats
,
plot_kwargs
=
plot_kwargs
,
history
=
history
,
ax_kwargs
=
ax_kwargs
,
fig_kwargs
=
fig_kwargs
,
scatter_kwargs
=
scatter_kwargs
,
stats_dict
=
stats_dict
,
...
...
This diff is collapsed.
Click to expand it.
saqc/lib/plotting.py
+
41
−
25
View file @
37d283c9
...
...
@@ -2,9 +2,13 @@
# -*- coding: utf-8 -*-
from
typing
import
Optional
from
typing_extensions
import
Literal
from
saqc.lib.tools
import
toSequence
import
pandas
as
pd
import
numpy
as
np
import
matplotlib
as
mpl
import
itertools
import
matplotlib.pyplot
as
plt
from
saqc.constants
import
*
from
saqc.core
import
Flags
...
...
@@ -27,7 +31,8 @@ def makeFig(
level
:
float
,
max_gap
:
Optional
[
FreqString
]
=
None
,
stats
:
bool
=
False
,
plot_kwargs
:
Optional
[
dict
]
=
None
,
history
:
Optional
[
Literal
[
"
valid
"
,
"
complete
"
]]
=
"
valid
"
,
ax_kwargs
:
Optional
[
dict
]
=
None
,
fig_kwargs
:
Optional
[
dict
]
=
None
,
scatter_kwargs
:
Optional
[
dict
]
=
None
,
stats_dict
:
Optional
[
dict
]
=
None
,
...
...
@@ -58,21 +63,13 @@ def makeFig(
stats : bool, default False
Whether to include statistics table in plot.
plot
_kwargs : dict, default None
ax
_kwargs : dict, default None
Keyword arguments controlling plot generation. Will be passed on to the
``Matplotlib.axes.Axes.set()`` property batch setter for the axes showing the
data plot. The most relevant of those properties might be
"
ylabel
"
,
"
title
"
and
"
ylim
"
.
In Addition, following options are available:
* {
'
slice
'
: s} property, that determines a chunk of the data to be plotted /
processed. `s` can be anything,
that is a valid argument to the ``pandas.Series.__getitem__`` method.
* {
'
history
'
: str}
* str=
"
all
"
: All the flags are plotted with colored dots, refering to the
tests they originate from
* str=
"
valid
"
: - same as
'
all
'
- but only plots those flags, that are not
removed by later tests
"
title
"
and in addition:
"
ylim
"
.
The
"
ylim
"
keyword can be passed a slice object with date offset entries.
fig_kwargs : dict, default None
Keyword arguments controlling figure generation. None defaults to
{
"
figsize
"
: (16, 9)}
...
...
@@ -112,8 +109,8 @@ def makeFig(
>>>
func
=
lambda
x
,
y
,
z
:
round
((
x
.
isna
().
sum
())
/
len
(
x
),
2
)
"""
if
plot
_kwargs
is
None
:
plot
_kwargs
=
{
"
history
"
:
False
}
if
ax
_kwargs
is
None
:
ax
_kwargs
=
{}
if
fig_kwargs
is
None
:
fig_kwargs
=
{}
if
scatter_kwargs
is
None
:
...
...
@@ -124,7 +121,7 @@ def makeFig(
# data retrieval
d
=
data
[
field
]
# data slicing:
s
=
plot
_kwargs
.
pop
(
"
s
li
ce
"
,
slice
(
None
))
s
=
ax
_kwargs
.
pop
(
"
y
li
m
"
,
slice
(
None
))
d
=
d
[
s
]
flags_vals
=
flags
[
field
][
s
]
flags_hist
=
flags
.
history
[
field
].
hist
.
loc
[
s
]
...
...
@@ -157,8 +154,9 @@ def makeFig(
flags_vals
,
flags_hist
,
flags_meta
,
history
,
level
,
plot
_kwargs
,
ax
_kwargs
,
scatter_kwargs
,
na_mask
,
)
...
...
@@ -193,25 +191,43 @@ def _plotVarWithFlags(
flags_vals
,
flags_hist
,
flags_meta
,
history
,
level
,
plot
_kwargs
,
ax
_kwargs
,
scatter_kwargs
,
na_mask
,
):
ax
.
set_title
(
datser
.
name
)
ax
.
plot
(
datser
)
history
=
plot_kwargs
.
pop
(
"
history
"
,
False
)
ax
.
set
(
**
plot_kwargs
)
ax
.
plot
(
datser
,
color
=
"
black
"
)
ax
.
set
(
**
ax_kwargs
)
if
history
:
shape_cycle
=
scatter_kwargs
.
pop
(
"
marker
"
,
"
o
"
)
shape_cycle
=
itertools
.
cycle
(
toSequence
(
shape_cycle
))
color_cycle
=
scatter_kwargs
.
pop
(
"
color
"
,
plt
.
rcParams
[
"
axes.prop_cycle
"
].
by_key
()[
"
color
"
]
)
color_cycle
=
itertools
.
cycle
(
toSequence
(
color_cycle
))
for
i
in
flags_hist
.
columns
:
scatter_kwargs
.
update
({
"
label
"
:
flags_meta
[
i
][
"
func
"
].
split
(
"
.
"
)[
-
1
]})
if
history
==
"
all
"
:
_plotFlags
(
ax
,
datser
,
flags_hist
[
i
],
na_mask
,
level
,
scatter_kwargs
)
flags_i
=
flags_hist
[
i
].
astype
(
float
)
if
history
==
"
complete
"
:
_plotFlags
(
ax
,
datser
,
flags_i
,
na_mask
,
level
,
scatter_kwargs
)
if
history
==
"
valid
"
:
# only plot those flags, that do not get altered later on:
mask
=
flags_i
.
eq
(
flags_vals
)
flags_i
[
~
mask
]
=
np
.
nan
# Skip plot, if the test did not have no effect on the all over flagging result. This avoids
# legend overflow
if
~
(
flags_i
>=
level
).
any
():
continue
scatter_kwargs
.
update
(
{
"
color
"
:
next
(
color_cycle
),
"
marker
"
:
next
(
shape_cycle
)}
)
_plotFlags
(
ax
,
datser
,
flags_
hist
[
i
].
combine
(
flags_vals
,
min
)
,
flags_
i
,
na_mask
,
level
,
scatter_kwargs
,
...
...
This diff is collapsed.
Click to expand it.
tests/funcs/test_tools.py
+
3
−
5
View file @
37d283c9
...
...
@@ -28,11 +28,9 @@ def test_makeFig():
d_saqc
=
d_saqc
.
tools
.
plot
(
field
=
"
data
"
,
path
=
""
)
d_saqc
=
d_saqc
.
tools
.
plot
(
field
=
"
data
"
,
path
=
dummy_path
,
plot_kwargs
=
{
"
history
"
:
"
valid
"
}
,
stats
=
True
field
=
"
data
"
,
path
=
dummy_path
,
history
=
"
valid
"
,
stats
=
True
)
d_saqc
=
d_saqc
.
tools
.
plot
(
field
=
"
data
"
,
path
=
dummy_path
,
history
=
"
complete
"
)
d_saqc
=
d_saqc
.
tools
.
plot
(
field
=
"
data
"
,
path
=
dummy_path
,
plot_kwargs
=
{
"
history
"
:
"
all
"
}
)
d_saqc
=
d_saqc
.
tools
.
plot
(
field
=
"
data
"
,
path
=
dummy_path
,
plot_kwargs
=
{
"
slice
"
:
"
2000-10
"
},
stats
=
True
field
=
"
data
"
,
path
=
dummy_path
,
ax_kwargs
=
{
"
ylim
"
:
"
2000-10
"
},
stats
=
True
)
This diff is collapsed.
Click to expand it.
David Schäfer
@schaefed
mentioned in commit
63b55c6d
·
2 years ago
mentioned in commit
63b55c6d
mentioned in commit 63b55c6d7dadb0e612b23a897f292d5ffc14cb52
Toggle commit list
David Schäfer
@schaefed
mentioned in commit
684dc8a0
·
2 years ago
mentioned in commit
684dc8a0
mentioned in commit 684dc8a0515470d644fc85fee95d07661c8dd572
Toggle commit list
David Schäfer
@schaefed
mentioned in commit
8f7a90e4
·
1 year ago
mentioned in commit
8f7a90e4
mentioned in commit 8f7a90e4aed61c79a9dc8d67541a46beba0907e8
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment