Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MLAir
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
76
Issues
76
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
toar
MLAir
Commits
6c857b76
Commit
6c857b76
authored
Nov 12, 2020
by
lukas leufen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new data handler for separation of scales
parent
5c58d438
Pipeline
#51878
passed with stages
in 8 minutes and 18 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
mlair/data_handler/data_handler_mixed_sampling.py
mlair/data_handler/data_handler_mixed_sampling.py
+60
-0
No files found.
mlair/data_handler/data_handler_mixed_sampling.py
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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment