Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
KI-WaVo
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Landesamt für Umwelt
KI-WaVo
Commits
16095bc3
Commit
16095bc3
authored
7 months ago
by
Michel Spils
Browse files
Options
Downloads
Patches
Plain Diff
Use fallback values for bsh forecast
parent
e08cf546
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/scripts/bsh_extractor_v2.py
+12
-5
12 additions, 5 deletions
src/scripts/bsh_extractor_v2.py
with
12 additions
and
5 deletions
src/scripts/bsh_extractor_v2.py
+
12
−
5
View file @
16095bc3
...
@@ -3,7 +3,7 @@ from io import TextIOWrapper
...
@@ -3,7 +3,7 @@ from io import TextIOWrapper
from
pathlib
import
Path
from
pathlib
import
Path
from
typing
import
Tuple
from
typing
import
Tuple
from
zipfile
import
ZipFile
from
zipfile
import
ZipFile
import
numpy
as
np
import
pandas
as
pd
import
pandas
as
pd
...
@@ -88,11 +88,18 @@ def read_dat_file(zip_file:Path,dat_file:str,tsVorh:str) -> pd.DataFrame:
...
@@ -88,11 +88,18 @@ def read_dat_file(zip_file:Path,dat_file:str,tsVorh:str) -> pd.DataFrame:
with
my_zip
.
open
(
dat_file
)
as
csv_file
:
with
my_zip
.
open
(
dat_file
)
as
csv_file
:
csv_file_str
=
TextIOWrapper
(
csv_file
)
csv_file_str
=
TextIOWrapper
(
csv_file
)
df
=
pd
.
read_fwf
(
filepath_or_buffer
=
csv_file_str
,
colspecs
=
[(
7
,
19
),(
23
,
26
),(
26
,
28
),(
40
,
43
),(
45
,
48
)],
header
=
None
,
skiprows
=
1
,
parse_dates
=
[
0
],
date_format
=
"
%Y%m%d%H%M
"
)
df
=
pd
.
read_fwf
(
filepath_or_buffer
=
csv_file_str
,
df
.
columns
=
[
"
timestamp
"
,
"
stunden
"
,
"
minuten
"
,
"
gztmn
"
,
"
stau
"
]
colspecs
=
[(
7
,
19
),(
23
,
26
),(
26
,
28
),(
40
,
43
),(
43
,
48
),(
48
,
53
),(
53
,
58
),(
58
,
63
),(
63
,
68
),(
68
,
73
)],
header
=
None
,
skiprows
=
1
,
parse_dates
=
[
0
],
date_format
=
"
%Y%m%d%H%M
"
)
df
.
columns
=
[
"
timestamp
"
,
"
Vorhersagezeitpunkt
"
,
"
Differenzzeit
"
,
"
gztmn
"
,
"
stau
"
,
"
r1
"
,
"
r2
"
,
"
r3
"
,
"
r4
"
,
"
r5
"
]
df
[
"
member
"
]
=
0
df
[
"
member
"
]
=
0
df
[
"
pegel
"
]
=
df
[
"
gztmn
"
]
+
df
[
"
stau
"
]
stau_cols
=
[
"
stau
"
,
"
r1
"
,
"
r2
"
,
"
r3
"
,
"
r4
"
,
"
r5
"
]
df
[
"
forecast
"
]
=
df
[
"
timestamp
"
]
+
pd
.
to_timedelta
(
df
[
"
stunden
"
],
unit
=
"
h
"
)
+
pd
.
to_timedelta
(
df
[
"
minuten
"
],
unit
=
"
m
"
)
+
pd
.
to_timedelta
(
1
,
unit
=
"
h
"
)
#Take the first valid fallback value or np.nan if all are invalid
df
[
'
pegel
'
]
=
df
[
'
gztmn
'
]
+
df
[
stau_cols
].
apply
(
lambda
row
:
next
((
x
for
x
in
row
if
x
>=
-
9900
),
np
.
nan
),
axis
=
1
)
#for col in stau_cols:
# df.loc[df[col] < -9900, col] = np.nan
#df['pegel'] = df['gztmn'] + df[stau_cols].apply(lambda row: next((x for x in row if pd.notna(x)), 0), axis=1)
df
[
"
forecast
"
]
=
df
[
"
timestamp
"
]
+
pd
.
to_timedelta
(
df
[
"
Vorhersagezeitpunkt
"
],
unit
=
"
h
"
)
+
pd
.
to_timedelta
(
df
[
"
Differenzzeit
"
],
unit
=
"
m
"
)
+
pd
.
to_timedelta
(
1
,
unit
=
"
h
"
)
df
[
"
timestamp
"
]
=
tsVorh
#TODO @Ralf diese Zeile finde ich etwas fragwürdig. Ich vermute dass diese Zeit falsch und die IN der datei richtig ist.
df
[
"
timestamp
"
]
=
tsVorh
#TODO @Ralf diese Zeile finde ich etwas fragwürdig. Ich vermute dass diese Zeit falsch und die IN der datei richtig ist.
...
...
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