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
d339e348
Commit
d339e348
authored
1 year ago
by
David Schäfer
Browse files
Options
Downloads
Patches
Plain Diff
first draft - squeeze not working
parent
3f2320b0
No related branches found
No related tags found
1 merge request
!801
Make transferFlags a multivariate function
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
saqc/funcs/flagtools.py
+34
-31
34 additions, 31 deletions
saqc/funcs/flagtools.py
saqc/lib/tools.py
+14
-0
14 additions, 0 deletions
saqc/lib/tools.py
with
48 additions
and
31 deletions
saqc/funcs/flagtools.py
+
34
−
31
View file @
d339e348
...
@@ -19,7 +19,7 @@ from saqc import BAD, FILTER_ALL, UNFLAGGED
...
@@ -19,7 +19,7 @@ from saqc import BAD, FILTER_ALL, UNFLAGGED
from
saqc.core
import
DictOfSeries
,
flagging
,
register
from
saqc.core
import
DictOfSeries
,
flagging
,
register
from
saqc.core.history
import
History
from
saqc.core.history
import
History
from
saqc.lib.checking
import
validateChoice
,
validateWindow
from
saqc.lib.checking
import
validateChoice
,
validateWindow
from
saqc.lib.tools
import
initializeTargets
,
isflagged
,
isunflagged
,
toSequence
from
saqc.lib.tools
import
initializeTargets
,
isflagged
,
isunflagged
,
multivariateParameters
,
toSequence
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
saqc
import
SaQC
from
saqc
import
SaQC
...
@@ -290,6 +290,7 @@ class FlagtoolsMixin:
...
@@ -290,6 +290,7 @@ class FlagtoolsMixin:
demask
=
[],
demask
=
[],
squeeze
=
[],
squeeze
=
[],
handles_target
=
True
,
# function defines a target parameter, so it needs to handle it
handles_target
=
True
,
# function defines a target parameter, so it needs to handle it
multivariate
=
True
,
)
)
def
transferFlags
(
def
transferFlags
(
self
:
"
SaQC
"
,
self
:
"
SaQC
"
,
...
@@ -349,37 +350,39 @@ class FlagtoolsMixin:
...
@@ -349,37 +350,39 @@ class FlagtoolsMixin:
0
-
inf
-
inf
-
inf
0
-
inf
-
inf
-
inf
1
255.0
255.0
255.0
1
255.0
255.0
255.0
"""
"""
history
=
self
.
_flags
.
history
[
field
]
if
target
is
None
:
target
=
field
if
overwrite
is
False
:
mask
=
isflagged
(
self
.
_flags
[
target
],
thresh
=
kwargs
[
"
dfilter
"
])
history
.
_hist
[
mask
]
=
np
.
nan
# append a dummy column
meta
=
{
"
func
"
:
f
"
transferFlags
"
,
"
args
"
:
(),
"
kwargs
"
:
{
"
field
"
:
field
,
"
target
"
:
target
,
"
squeeze
"
:
squeeze
,
"
overwrite
"
:
overwrite
,
**
kwargs
,
},
}
if
squeeze
:
flags
=
history
.
squeeze
(
raw
=
True
)
# init an empty history to which we later append the squeezed flags
history
=
History
(
index
=
history
.
index
)
else
:
flags
=
pd
.
Series
(
np
.
nan
,
index
=
history
.
index
,
dtype
=
float
)
history
.
append
(
flags
,
meta
)
fields
,
targets
=
multivariateParameters
(
field
,
target
)
self
.
_flags
.
history
[
target
].
append
(
history
)
for
field
,
target
in
zip
(
fields
,
targets
):
history
=
self
.
_flags
.
history
[
field
]
# append a dummy column
meta
=
{
"
func
"
:
f
"
transferFlags
"
,
"
args
"
:
(),
"
kwargs
"
:
{
"
field
"
:
field
,
"
target
"
:
target
,
"
squeeze
"
:
squeeze
,
"
overwrite
"
:
overwrite
,
**
kwargs
,
},
}
if
overwrite
is
False
:
mask
=
isflagged
(
self
.
_flags
[
target
],
thresh
=
kwargs
[
"
dfilter
"
])
history
.
_hist
[
mask
]
=
np
.
nan
if
squeeze
:
flags
=
history
.
squeeze
(
raw
=
True
)
# init an empty history to which we later append the squeezed flags
history
=
History
(
index
=
history
.
index
)
else
:
flags
=
pd
.
Series
(
np
.
nan
,
index
=
history
.
index
,
dtype
=
float
)
history
.
append
(
flags
,
meta
)
self
.
_flags
.
history
[
target
].
append
(
history
)
return
self
return
self
...
...
This diff is collapsed.
Click to expand it.
saqc/lib/tools.py
+
14
−
0
View file @
d339e348
...
@@ -652,3 +652,17 @@ def joinExt(sep: str, iterable: Iterable[str], last_sep: str | None = None) -> s
...
@@ -652,3 +652,17 @@ def joinExt(sep: str, iterable: Iterable[str], last_sep: str | None = None) -> s
if
len
(
iterable
)
<
2
:
if
len
(
iterable
)
<
2
:
return
sep
.
join
(
iterable
)
return
sep
.
join
(
iterable
)
return
f
"
{
sep
.
join
(
iterable
[
:
-
1
])
}{
last_sep
}{
iterable
[
-
1
]
}
"
return
f
"
{
sep
.
join
(
iterable
[
:
-
1
])
}{
last_sep
}{
iterable
[
-
1
]
}
"
def
multivariateParameters
(
field
:
str
|
list
[
str
],
target
:
str
|
list
[
str
]
|
None
=
None
)
->
tuple
[
list
[
str
],
list
[
str
]]:
fields
=
toSequence
(
field
)
targets
=
fields
if
target
is
None
else
toSequence
(
target
)
if
len
(
targets
)
==
1
:
targets
=
targets
*
len
(
fields
)
if
len
(
targets
)
!=
len
(
fields
):
raise
ValueError
(
"
expected a single
'
target
'
or the same number of
'
field
'
and
'
target
'
values
"
)
return
fields
,
targets
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