Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SaQC
Manage
Activity
Members
Labels
Plan
Issues
36
Issue boards
Milestones
Wiki
Code
Merge requests
8
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
677769a7
Commit
677769a7
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
added plot feature
parent
9b89e003
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config.py
+1
-0
1 addition, 0 deletions
config.py
core.py
+85
-0
85 additions, 0 deletions
core.py
with
86 additions
and
0 deletions
config.py
+
1
−
0
View file @
677769a7
...
@@ -18,6 +18,7 @@ class Params:
...
@@ -18,6 +18,7 @@ class Params:
FLAGPERIOD
=
"
flag_period
"
FLAGPERIOD
=
"
flag_period
"
FLAGVALUES
=
"
flag_values
"
FLAGVALUES
=
"
flag_values
"
FLAG
=
"
flag
"
FLAG
=
"
flag
"
PLOT
=
"
plot
"
# FUNCMAP = {
# FUNCMAP = {
...
...
This diff is collapsed.
Click to expand it.
core.py
+
85
−
0
View file @
677769a7
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
numpy
as
np
import
numpy
as
np
import
pandas
as
pd
import
pandas
as
pd
import
matplotlib
as
mpl
from
config
import
Fields
,
Params
from
config
import
Fields
,
Params
from
funcs
import
flagDispatch
from
funcs
import
flagDispatch
...
@@ -117,6 +118,11 @@ def runner(meta, flagger, data, flags=None, nodata=np.nan):
...
@@ -117,6 +118,11 @@ def runner(meta, flagger, data, flags=None, nodata=np.nan):
fchunk
=
fchunk
.
astype
({
fchunk
=
fchunk
.
astype
({
c
:
flagger
.
flags
for
c
in
fchunk
.
columns
if
flagger
.
flag_fields
[
0
]
in
c
})
c
:
flagger
.
flags
for
c
in
fchunk
.
columns
if
flagger
.
flag_fields
[
0
]
in
c
})
if
Params
.
PLOT
in
flag_params
:
new
=
flagger
.
getFlags
(
fchunk
[
varname
])
mask
=
old
!=
new
plot
(
dchunk
,
fchunk
,
mask
,
varname
,
flagger
,
title
=
flag_test
)
data
.
loc
[
start_date
:
end_date
]
=
dchunk
data
.
loc
[
start_date
:
end_date
]
=
dchunk
flags
[
start_date
:
end_date
]
=
fchunk
.
squeeze
()
flags
[
start_date
:
end_date
]
=
fchunk
.
squeeze
()
...
@@ -124,6 +130,85 @@ def runner(meta, flagger, data, flags=None, nodata=np.nan):
...
@@ -124,6 +130,85 @@ def runner(meta, flagger, data, flags=None, nodata=np.nan):
return
data
,
flags
return
data
,
flags
def
plot
(
data
,
flags
,
flagmask
,
varname
,
flagger
,
interactive_backend
=
True
,
title
=
"
Data Plot
"
):
# the flagmask is True for flags to be shown False otherwise
if
not
interactive_backend
:
# Import plot libs without interactivity, if not needed. This ensures that this can
# produce an plot.png even if tkinter is not installed. E.g. if one want to run this
# on machines without X-Server aka. graphic interface.
mpl
.
use
(
'
Agg
'
)
else
:
mpl
.
use
(
'
TkAgg
'
)
from
matplotlib
import
pyplot
as
plt
# needed for datetime conversion
from
pandas.plotting
import
register_matplotlib_converters
register_matplotlib_converters
()
def
plot_vline
(
plt
,
points
,
color
=
'
blue
'
):
# workaround for ax.vlines() as this work unexpected
for
point
in
points
:
plt
.
axvline
(
point
,
color
=
color
,
linestyle
=
'
:
'
)
def
_plot
(
varname
,
ax
):
x
=
data
.
index
y
=
data
[
varname
]
flags_
=
flags
[
varname
]
nrofflags
=
len
(
flagger
.
flags
.
categories
)
ax
.
plot
(
x
,
y
,
'
-
'
,
markersize
=
1
,
color
=
'
silver
'
)
if
nrofflags
==
3
:
colors
=
{
0
:
'
silver
'
,
1
:
'
lime
'
,
2
:
'
red
'
}
if
nrofflags
==
4
:
colors
=
{
0
:
'
silver
'
,
1
:
'
lime
'
,
2
:
'
yellow
'
,
3
:
'
red
'
}
# plot (all) data in silver
ax
.
plot
(
x
,
y
,
'
-
'
,
color
=
'
silver
'
,
label
=
'
data
'
)
# plot (all) missing data in silver
nans
=
y
.
isna
()
ylim
=
plt
.
ylim
()
flagged
=
flagger
.
isFlagged
(
flags_
)
idx
=
y
.
index
[
nans
&
~
flagged
]
# ax.vlines(idx, *ylim, linestyles=':', color='silver', label="missing")
plot_vline
(
ax
,
idx
,
color
=
'
silver
'
)
# plot all flagged data in black
ax
.
plot
(
x
[
flagged
],
y
[
flagged
],
'
.
'
,
color
=
'
black
'
,
label
=
"
flagged by other test
"
)
# plot all flagged missing data (flagged before) in black
idx
=
y
.
index
[
nans
&
flagged
&
~
flagmask
]
# ax.vlines(idx, *ylim, linestyles=':', color='black')
plot_vline
(
ax
,
idx
,
color
=
'
black
'
)
ax
.
set_ylabel
(
varname
)
# plot currently flagged data in color of flag
for
i
,
f
in
enumerate
(
flagger
.
flags
):
if
i
==
0
:
continue
flagged
=
flagger
.
isFlagged
(
flags_
,
flag
=
f
)
&
flagmask
label
=
f
"
flag:
{
f
}
"
if
i
else
'
data
'
ax
.
plot
(
x
[
flagged
],
y
[
flagged
],
'
.
'
,
color
=
colors
[
i
],
label
=
label
)
idx
=
y
.
index
[
nans
&
flagged
]
# ax.vlines(idx, *ylim, linestyles=':', color=colors[i])
plot_vline
(
ax
,
idx
,
color
=
colors
[
i
])
if
not
isinstance
(
varname
,
(
list
,
set
)):
varname
=
set
([
varname
])
plots
=
len
(
varname
)
if
plots
>
1
:
fig
,
axes
=
plt
.
subplots
(
plots
,
1
,
sharex
=
True
)
axes
[
0
].
set_title
(
title
)
for
i
,
v
in
enumerate
(
varname
):
_plot
(
v
,
axes
[
i
])
else
:
fig
,
ax
=
plt
.
subplots
()
plt
.
title
(
title
)
_plot
(
varname
.
pop
(),
ax
)
plt
.
xlabel
(
'
time
'
)
# dummy plot for label `missing` see plot_vline for more info
plt
.
plot
([],
[],
'
:
'
,
color
=
'
silver
'
,
label
=
"
missing data
"
)
plt
.
legend
()
plt
.
show
()
def
prepareMeta
(
meta
,
data
):
def
prepareMeta
(
meta
,
data
):
# NOTE: an option needed to only pass tests within an file and deduce
# NOTE: an option needed to only pass tests within an file and deduce
# everything else from data
# everything else from data
...
...
This diff is collapsed.
Click to expand it.
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