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
5576f0c9
Commit
5576f0c9
authored
4 years ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Patches
Plain Diff
linear correction implemented
parent
5c109650
No related branches found
No related tags found
2 merge requests
!193
Release 1.4
,
!188
Release 1.4
Pipeline
#5260
passed with stage
in 6 minutes and 35 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
saqc/funcs/proc_functions.py
+33
-21
33 additions, 21 deletions
saqc/funcs/proc_functions.py
with
33 additions
and
21 deletions
saqc/funcs/proc_functions.py
+
33
−
21
View file @
5576f0c9
...
...
@@ -10,7 +10,8 @@ import dios
import
functools
import
matplotlib.pyplot
as
plt
from
scipy.optimize
import
curve_fit
import
pickle
from
sklearn.linear_model
import
LinearRegression
ORIGINAL_SUFFIX
=
'
_original
'
METHOD2ARGS
=
{
'
inverse_fshift
'
:
(
'
backward
'
,
pd
.
Timedelta
),
...
...
@@ -158,8 +159,8 @@ def proc_interpolateGrid(data, field, flagger, freq, method, inter_order=2, drop
Note, it is possible to interpolate unregular
"
grids
"
(with no frequencies). In fact, any date index
can be target of the interpolation. Just pass the field name of the variable, holding the index
you want to interpolate, to
"
grid_field
"
.
The feature is currently regarded experimental. Interpolation
range can not be controll
ed.
you want to interpolate, to
"
grid_field
"
.
'
freq
'
is then use to determine the maximum gap size for
a grid point to be interpolat
ed.
Parameters
---------.copy()
...
...
@@ -742,13 +743,6 @@ def proc_seefoExpDriftCorrecture(data, field, flagger, maint_data_field, cal_mea
# define target values for correction
shift_targets
=
drift_grouper
.
aggregate
(
lambda
x
:
x
[:
cal_mean
].
mean
()).
shift
(
-
1
)
########################### plotting stuff for testing phase #############################################
fig
,
axes
=
plt
.
subplots
(
nrows
=
2
,
ncols
=
1
,
sharex
=
True
)
axes
[
0
].
plot
(
to_correct
[
drift_frame
.
index
[
0
]:
drift_frame
.
index
[
-
1
]])
axes
[
0
].
set
(
ylabel
=
'
sak
'
)
axes
[
1
].
set
(
ylabel
=
'
shifted - sak
'
)
##########################################################################################################
for
k
,
group
in
drift_grouper
:
dataSeries
=
group
[
to_correct
.
name
]
dataFit
,
dataShiftTarget
=
_drift_fit
(
dataSeries
,
shift_targets
.
loc
[
k
,
:][
0
],
cal_mean
)
...
...
@@ -757,21 +751,39 @@ def proc_seefoExpDriftCorrecture(data, field, flagger, maint_data_field, cal_mea
dataShiftVektor
=
dataShiftTarget
-
dataFit
shiftedData
=
dataSeries
+
dataShiftVektor
to_correct
[
shiftedData
.
index
]
=
shiftedData
########################### plotting stuff for testing phase ##################################################
axes
[
0
].
plot
(
dataFit
,
color
=
'
red
'
)
axes
[
0
].
plot
(
dataShiftTarget
,
color
=
'
yellow
'
)
axes
[
1
].
plot
(
shiftedData
,
color
=
'
green
'
)
axes
[
0
].
vlines
(
maint_data
[
drift_frame
.
index
[
0
]:
drift_frame
.
index
[
-
1
]].
index
,
to_correct
.
min
(),
to_correct
.
max
(),
color
=
'
black
'
)
axes
[
0
].
vlines
(
maint_data
[
drift_frame
.
index
[
0
]:
drift_frame
.
index
[
-
1
]].
values
,
to_correct
.
min
(),
to_correct
.
max
(),
color
=
'
black
'
)
fig
.
autofmt_xdate
()
with
open
(
'
/home/luenensc/PyPojects/testSpace/SEEFOPics/DriftCorrecture2.pkl
'
,
'
wb
'
)
as
file
:
pickle
.
dump
(
fig
,
file
)
################################################################################################################
if
flag_maint_period
:
to_flag
=
drift_frame
[
'
drift_group
'
]
to_flag
=
to_flag
.
drop
(
to_flag
[:
maint_data
.
index
[
0
]].
index
)
to_flag
=
to_flag
[
to_flag
.
isna
()]
flagger
=
flagger
.
setFlags
(
field
,
loc
=
to_flag
,
**
kwargs
)
return
data
,
flagger
@register
def
proc_seefoLinearDriftCorrecture
(
data
,
field
,
flagger
,
x_field
,
y_field
,
**
kwargs
):
"""
Train a linear model that predicts data[y_field] by x_1*(data[x_field]) + x_0. (Least squares fit)
Then correct the data[field] via:
data[field] = data[field]*x_1 + x_0
Note, that data[x_field] and data[y_field] must be of equal length.
(Also, you might want them to be sampled at same timestamps.)
Parameters
----------
x_field : String
Field name of x - data.
y_field : String
Field name of y - data.
"""
data
=
data
.
copy
()
datcol
=
data
[
field
]
reg
=
LinearRegression
()
reg
.
fit
(
data
[
x_field
].
values
.
reshape
(
-
1
,
1
),
data
[
y_field
].
values
)
datcol
=
(
datcol
*
reg
.
coef_
[
0
])
+
reg
.
intercept_
data
[
field
]
=
datcol
return
data
,
flagger
\ No newline at end of file
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