Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
AMBS
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
AMBS
Commits
ff258b1d
Commit
ff258b1d
authored
3 years ago
by
Michael Langguth
Browse files
Options
Downloads
Patches
Plain Diff
Add wrapper for datetime-object to ../main_scripts/main_preprocess_data_step2.py.
parent
6452dc72
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
video_prediction_tools/data_preprocess/preprocess_data_step2.py
+22
-2
22 additions, 2 deletions
...prediction_tools/data_preprocess/preprocess_data_step2.py
with
22 additions
and
2 deletions
video_prediction_tools/data_preprocess/preprocess_data_step2.py
+
22
−
2
View file @
ff258b1d
...
...
@@ -116,8 +116,10 @@ class ERA5Pkl2Tfrecords(ERA5Dataset):
"""
sequences
=
np
.
array
(
sequences
)
# sanity checks
print
(
t_start_points
[
0
])
print
(
type
(
t_start_points
[
0
]))
assert
sequences
.
shape
[
0
]
==
len
(
t_start_points
)
assert
type
(
t_start_points
[
0
]
)
==
datetime
.
datetime
assert
type
(
t_start_points
)
==
datetime
.
datetime
,
"
What
'
s that: {0} (type {1})
"
.
format
(
t_start_points
[
0
],
type
(
t_start_points
[
0
]))
with
tf
.
python_io
.
TFRecordWriter
(
output_fname
)
as
writer
:
for
i
in
range
(
len
(
sequences
)):
...
...
@@ -199,7 +201,7 @@ class ERA5Pkl2Tfrecords(ERA5Dataset):
X_end
=
X_start
+
self
.
sequence_length
seq
=
X_train
[
X_start
:
X_end
,
...]
# recording the start point of the timestamps (already datetime-objects)
t_start
=
T_train
[
X_start
]
t_start
=
ERA5Pkl2Tfrecords
.
ensure_datetime
(
T_train
[
X_start
]
[
0
])
print
(
"
t_start,
"
,
t_start
)
print
(
"
type of t_starty
"
,
type
(
t_start
))
seq
=
list
(
np
.
array
(
seq
).
reshape
((
self
.
sequence_length
,
self
.
height
,
self
.
width
,
self
.
nvars
)))
...
...
@@ -244,6 +246,24 @@ class ERA5Pkl2Tfrecords(ERA5Dataset):
with
open
(
os
.
path
.
join
(
self
.
output_dir
,
'
number_sequences.txt
'
),
'
w
'
)
as
seq_file
:
seq_file
.
write
(
"
%d
\n
"
%
self
.
sequences_per_file
)
@staticmethod
def
ensure_datetime
(
date
):
"""
Wrapper to return a datetime-object
"""
fmt
=
"
%Y%m%d %H:%M
"
if
isinstance
(
date
,
datetime
.
datetime
):
date_new
=
date
else
:
try
:
date_new
=
pd
.
to_datetime
(
date
)
date_new
=
datetime
.
datetime
(
date_new
.
strptime
(
fmt
),
fmt
)
except
Exception
as
err
:
print
(
"
%{0}: Could not handle input data {1} which is of type {2}.
"
.
format
(
method
,
date
,
type
(
date
)))
raise
err
return
date_new
# def num_examples_per_epoch(self):
# with open(os.path.join(self.input_dir, 'sequence_lengths.txt'), 'r') as sequence_lengths_file:
# sequence_lengths = sequence_lengths_file.readlines()
...
...
This diff is collapsed.
Click to expand it.
Michael Langguth
@langguth1
mentioned in issue
#124 (closed)
·
3 years ago
mentioned in issue
#124 (closed)
mentioned in issue #124
Toggle commit list
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