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
af1ecb8a
Commit
af1ecb8a
authored
5 years ago
by
lukas leufen
Browse files
Options
Downloads
Patches
Plain Diff
minor modifications, add docs
parent
a6dccb6d
No related branches found
No related tags found
2 merge requests
!37
include new development
,
!33
Lukas issue036 feat local temp data storage
Pipeline
#29078
passed
5 years ago
Stage: test
Stage: pages
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/data_handling/data_generator.py
+19
-6
19 additions, 6 deletions
src/data_handling/data_generator.py
src/run_modules/pre_processing.py
+1
-1
1 addition, 1 deletion
src/run_modules/pre_processing.py
with
20 additions
and
7 deletions
src/data_handling/data_generator.py
+
19
−
6
View file @
af1ecb8a
...
...
@@ -5,7 +5,7 @@ import keras
from
src
import
helpers
from
src.data_handling.data_preparation
import
DataPrep
import
os
from
typing
import
Union
,
List
,
Tuple
from
typing
import
Union
,
List
,
Tuple
,
Any
import
xarray
as
xr
import
pickle
import
logging
...
...
@@ -93,16 +93,18 @@ class DataGenerator(keras.utils.Sequence):
return
data
.
history
.
transpose
(
"
datetime
"
,
"
window
"
,
"
Stations
"
,
"
variables
"
),
\
data
.
label
.
squeeze
(
"
Stations
"
).
transpose
(
"
datetime
"
,
"
window
"
)
def
get_data_generator
(
self
,
key
:
Union
[
str
,
int
]
=
None
,
lo
ad
_tmp
:
bool
=
True
)
->
DataPrep
:
def
get_data_generator
(
self
,
key
:
Union
[
str
,
int
]
=
None
,
lo
cal
_tmp
_storage
:
bool
=
True
)
->
DataPrep
:
"""
Select data for given key, create a DataPrep object and interpolate, transform, make history and labels and
remove nans.
:param key: station key to choose the data generator.
:param local_tmp_storage: say if data should be processed from scratch or loaded as already processed data from
tmp pickle file to save computational time (but of course more disk space required).
:return: preprocessed data as a DataPrep instance
"""
station
=
self
.
get_station_key
(
key
)
try
:
if
not
lo
ad
_tmp
:
if
not
lo
cal
_tmp
_storage
:
raise
FileNotFoundError
data
=
self
.
_load_pickle_data
(
station
,
self
.
variables
)
except
FileNotFoundError
:
...
...
@@ -117,15 +119,26 @@ class DataGenerator(keras.utils.Sequence):
self
.
_save_pickle_data
(
data
)
return
data
def
_save_pickle_data
(
self
,
data
):
def
_save_pickle_data
(
self
,
data
:
Any
):
"""
Save given data locally as .pickle in self.data_path_tmp with name
'
<station>_<var1>_<var2>_..._<varX>.pickle
'
:param data: any data, that should be saved
"""
file
=
os
.
path
.
join
(
self
.
data_path_tmp
,
f
"
{
''
.
join
(
data
.
station
)
}
_
{
'
_
'
.
join
(
sorted
(
data
.
variables
))
}
.pickle
"
)
with
open
(
file
,
"
wb
"
)
as
f
:
pickle
.
dump
(
data
,
f
)
logging
.
debug
(
f
"
save pickle data to
{
file
}
"
)
def
_load_pickle_data
(
self
,
station
,
variables
):
def
_load_pickle_data
(
self
,
station
:
Union
[
str
,
List
[
str
]],
variables
:
List
[
str
])
->
Any
:
"""
Load locally saved data from self.data_path_tmp and name
'
<station>_<var1>_<var2>_..._<varX>.pickle
'
.
:param station: station to load
:param variables: list of variables to load
:return: loaded data
"""
file
=
os
.
path
.
join
(
self
.
data_path_tmp
,
f
"
{
''
.
join
(
station
)
}
_
{
'
_
'
.
join
(
sorted
(
variables
))
}
.pickle
"
)
data
=
pickle
.
load
(
open
(
file
,
"
rb
"
))
with
open
(
file
,
"
rb
"
)
as
f
:
data
=
pickle
.
load
(
f
)
logging
.
debug
(
f
"
load pickle data from
{
file
}
"
)
return
data
...
...
This diff is collapsed.
Click to expand it.
src/run_modules/pre_processing.py
+
1
−
1
View file @
af1ecb8a
...
...
@@ -119,7 +119,7 @@ class PreProcessing(RunEnvironment):
t_inner
.
run
()
try
:
# (history, label) = data_gen[station]
data
=
data_gen
.
get_data_generator
(
key
=
station
,
lo
ad
_tmp
=
load_tmp
)
data
=
data_gen
.
get_data_generator
(
key
=
station
,
lo
cal
_tmp
_storage
=
load_tmp
)
valid_stations
.
append
(
station
)
logging
.
debug
(
f
'
{
station
}
: history_shape =
{
data
.
history
.
transpose
(
"
datetime
"
,
"
window
"
,
"
Stations
"
,
"
variables
"
).
shape
}
'
)
logging
.
debug
(
f
"
{
station
}
: loading time =
{
t_inner
}
"
)
...
...
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