Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
machine-learning
MLAir
Commits
6c857b76
Commit
6c857b76
authored
4 years ago
by
leufen1
Browse files
Options
Downloads
Patches
Plain Diff
new data handler for separation of scales
parent
5c58d438
No related branches found
No related tags found
3 merge requests
!192
include Develop
,
!191
Resolve "release v1.1.0"
,
!186
Resolve "Separation of Scales"
Pipeline
#51878
passed
4 years ago
Stage: test
Stage: docs
Stage: pages
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mlair/data_handler/data_handler_mixed_sampling.py
+60
-0
60 additions, 0 deletions
mlair/data_handler/data_handler_mixed_sampling.py
with
60 additions
and
0 deletions
mlair/data_handler/data_handler_mixed_sampling.py
+
60
−
0
View file @
6c857b76
...
...
@@ -12,7 +12,9 @@ from mlair.configuration.defaults import DEFAULT_SAMPLING
import
logging
import
os
import
inspect
from
typing
import
Callable
import
numpy
as
np
import
pandas
as
pd
import
xarray
as
xr
...
...
@@ -95,3 +97,61 @@ class DataHandlerMixedSamplingWithFilter(DefaultDataHandler):
data_handler
=
DataHandlerMixedSamplingWithFilterSingleStation
data_handler_transformation
=
DataHandlerMixedSamplingWithFilterSingleStation
_requirements
=
data_handler
.
requirements
()
class
DataHandlerMixedSamplingSeparationOfScalesSingleStation
(
DataHandlerMixedSamplingWithFilterSingleStation
):
_requirements
=
DataHandlerMixedSamplingWithFilterSingleStation
.
requirements
()
def
__init__
(
self
,
*
args
,
time_delta
=
np
.
sqrt
,
**
kwargs
):
assert
isinstance
(
time_delta
,
Callable
)
self
.
time_delta
=
time_delta
super
().
__init__
(
*
args
,
**
kwargs
)
def
make_history_window
(
self
,
dim_name_of_inputs
:
str
,
window
:
int
,
dim_name_of_shift
:
str
)
->
None
:
"""
Create a xr.DataArray containing history data.
Shift the data window+1 times and return a xarray which has a new dimension
'
window
'
containing the shifted
data. This is used to represent history in the data. Results are stored in history attribute.
:param dim_name_of_inputs: Name of dimension which contains the input variables
:param window: number of time steps to look back in history
Note: window will be treated as negative value. This should be in agreement with looking back on
a time line. Nonetheless positive values are allowed but they are converted to its negative
expression
:param dim_name_of_shift: Dimension along shift will be applied
"""
window
=
-
abs
(
window
)
data
=
self
.
input_data
.
data
self
.
history
=
self
.
stride
(
data
,
dim_name_of_shift
,
window
)
def
stride
(
self
,
data
:
xr
.
DataArray
,
dim
:
str
,
window
:
int
)
->
xr
.
DataArray
:
# this is just a code snippet to check the results of the kz filter
# import matplotlib
# matplotlib.use("TkAgg")
# import matplotlib.pyplot as plt
# xr.concat(res, dim="filter").sel({"variables":"temp", "Stations":"DEBW107", "datetime":"2010-01-01T00:00:00"}).plot.line(hue="filter")
time_deltas
=
np
.
round
(
self
.
time_delta
(
self
.
cutoff_period
)).
astype
(
int
)
start
,
end
=
window
,
1
res
=
[]
window_array
=
self
.
create_index_array
(
'
window
'
,
range
(
start
,
end
),
squeeze_dim
=
self
.
target_dim
)
for
delta
,
filter_name
in
zip
(
np
.
append
(
time_deltas
,
1
),
data
.
coords
[
"
filter
"
]):
res_filter
=
[]
data_filter
=
data
.
sel
({
"
filter
"
:
filter_name
})
for
w
in
range
(
start
,
end
):
res_filter
.
append
(
data_filter
.
shift
({
dim
:
-
w
*
delta
}))
res_filter
=
xr
.
concat
(
res_filter
,
dim
=
window_array
)
res
.
append
(
res_filter
)
res
=
xr
.
concat
(
res
,
dim
=
"
filter
"
).
chunk
()
return
res
class
DataHandlerMixedSamplingSeparationOfScales
(
DefaultDataHandler
):
"""
Data handler using mixed sampling for input and target. Inputs are temporal filtered and different time step
sizes are applied in relation to frequencies.
"""
data_handler
=
DataHandlerMixedSamplingWithFilterSingleStation
data_handler_transformation
=
DataHandlerMixedSamplingWithFilterSingleStation
_requirements
=
data_handler
.
requirements
()
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