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
b4c6d786
Commit
b4c6d786
authored
5 years ago
by
leufen1
Browse files
Options
Downloads
Patches
Plain Diff
rename stations to station, create helpers module for general functions
parent
24bc55c3
No related branches found
No related tags found
2 merge requests
!6
updated inception model and data prep class
,
!4
data prep class
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+3
-2
3 additions, 2 deletions
.gitignore
src/data_preparation.py
+14
-14
14 additions, 14 deletions
src/data_preparation.py
src/helpers.py
+8
-0
8 additions, 0 deletions
src/helpers.py
with
25 additions
and
16 deletions
.gitignore
+
3
−
2
View file @
b4c6d786
...
...
@@ -40,8 +40,9 @@ Thumbs.db
.idea/
/venv/
# check plot folder #
#####################
# don't check data and plot folder #
####################################
/data/
/plots/
# tmp folder #
...
...
This diff is collapsed.
Click to expand it.
src/data_preparation.py
+
14
−
14
View file @
b4c6d786
...
...
@@ -6,22 +6,23 @@ import xarray as xr
import
pandas
as
pd
import
logging
import
os
from
src
import
join
from
src
import
join
,
helpers
from
typing
import
Union
,
List
class
DataPrep
:
def
__init__
(
self
,
path
:
str
,
network
:
str
,
station
s
,
variables
,
**
kwargs
):
def
__init__
(
self
,
path
:
str
,
network
:
str
,
station
:
Union
[
str
,
List
[
str
]]
,
variables
,
**
kwargs
):
self
.
path
=
path
self
.
network
=
network
self
.
station
s
=
station
s
self
.
station
=
helpers
.
to_list
(
station
)
self
.
variables
=
variables
self
.
statistics_per_var
=
kwargs
.
get
(
"
statistics_per_var
"
,
None
)
if
self
.
statistics_per_var
is
not
None
:
self
.
load_data
()
else
:
raise
NotImplementedError
# self.data, self.meta = Fkf.read_hourly_data_from_csv_to_xarray(self.path, self.network, self.station
s
,
# self.data, self.meta = Fkf.read_hourly_data_from_csv_to_xarray(self.path, self.network, self.station,
# self.variables, **kwargs)
self
.
mean
=
None
self
.
std
=
None
...
...
@@ -33,7 +34,7 @@ class DataPrep:
self
.
meta
=
None
def
load_data
(
self
):
self
.
check_path_and_create
(
self
.
path
)
self
.
check_path_and_create
()
file_name
=
self
.
_set_file_name
()
meta_file
=
self
.
_set_meta_file_name
()
try
:
...
...
@@ -42,8 +43,8 @@ class DataPrep:
except
FileNotFoundError
as
e
:
logging
.
warning
(
e
)
df_all
=
{}
df
,
self
.
meta
=
join
.
download_join
(
station_name
=
self
.
station
s
,
statvar
=
self
.
statistics_per_var
)
df_all
[
self
.
station
s
[
0
]]
=
df
df
,
self
.
meta
=
join
.
download_join
(
station_name
=
self
.
station
,
statvar
=
self
.
statistics_per_var
)
df_all
[
self
.
station
[
0
]]
=
df
# convert df_all to xarray
xarr
=
{
k
:
xr
.
DataArray
(
v
,
dims
=
[
'
datetime
'
,
'
variables
'
])
for
k
,
v
in
df_all
.
items
()}
xarr
=
xr
.
Dataset
(
xarr
).
to_array
(
dim
=
'
Stations
'
)
...
...
@@ -53,20 +54,19 @@ class DataPrep:
self
.
meta
.
to_csv
(
meta_file
)
def
_set_file_name
(
self
):
return
f
"
{
self
.
path
}{
''
.
join
(
self
.
station
s
)
}
_
{
'
_
'
.
join
(
sorted
(
self
.
variables
))
}
.nc
"
return
f
"
{
self
.
path
}{
''
.
join
(
self
.
station
)
}
_
{
'
_
'
.
join
(
sorted
(
self
.
variables
))
}
.nc
"
def
_set_meta_file_name
(
self
):
return
f
"
{
self
.
path
}{
''
.
join
(
self
.
station
s
)
}
_
{
'
_
'
.
join
(
sorted
(
self
.
variables
))
}
_meta.csv
"
return
f
"
{
self
.
path
}{
''
.
join
(
self
.
station
)
}
_
{
'
_
'
.
join
(
sorted
(
self
.
variables
))
}
_meta.csv
"
def
__repr__
(
self
):
return
f
"
Dataprep(path=
'
{
self
.
path
}
'
, network=
'
{
self
.
network
}
'
, station
s
=
{
self
.
station
s
}
,
"
\
return
f
"
Dataprep(path=
'
{
self
.
path
}
'
, network=
'
{
self
.
network
}
'
, station=
{
self
.
station
}
,
"
\
f
"
variables=
{
self
.
variables
}
, **
{
self
.
kwargs
}
"
@staticmethod
def
check_path_and_create
(
path
):
def
check_path_and_create
(
self
):
try
:
os
.
makedirs
(
path
)
logging
.
info
(
"
Created path: {}
"
.
format
(
path
))
os
.
makedirs
(
self
.
path
)
logging
.
info
(
"
Created path: {}
"
.
format
(
self
.
path
))
except
FileExistsError
:
pass
...
...
This diff is collapsed.
Click to expand it.
src/helpers.py
0 → 100644
+
8
−
0
View file @
b4c6d786
__author__
=
'
Lukas Leufen
'
__date__
=
'
2019-10-21
'
def
to_list
(
arg
):
if
not
isinstance
(
arg
,
list
):
arg
=
[
arg
]
return
arg
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