Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
webgeodyn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Geodynamo
webgeodyn
Commits
88dd645a
Commit
88dd645a
authored
3 years ago
by
EXT Istas
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
https://gricad-gitlab.univ-grenoble-alpes.fr/Geodynamo/webgeodyn
parents
cffb3270
646fcb34
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
webgeodyn/inout/pygeodyn_hdf5.py
+65
-66
65 additions, 66 deletions
webgeodyn/inout/pygeodyn_hdf5.py
with
65 additions
and
66 deletions
webgeodyn/inout/pygeodyn_hdf5.py
+
65
−
66
View file @
88dd645a
#-*- coding: utf-8 -*-
#-*- coding: utf-8 -*-
import
glob
import
glob
import
h5py
import
h5py
import
os
import
os
import
numpy
as
np
import
numpy
as
np
from
.default
import
giveMeasureTypeUnits
from
.default
import
giveMeasureTypeUnits
def
load
(
dataDirectory
,
dataModel
,
keepRealisations
,
state_type
=
'
analysed
'
):
def
load
(
dataDirectory
,
dataModel
,
keepRealisations
,
state_type
=
'
analysed
'
):
"""
Loading function for pygeodyn files of hdf5 format. Also adds the data to the dataModel.
"""
Loading function for pygeodyn files of hdf5 format. Also adds the data to the dataModel.
:param dataDirectory: Location of the pygeodyn files
:param dataDirectory: Location of the pygeodyn files
:type dataDirectory: os.path
:type dataDirectory: os.path
:param dataModel: Model in which to add the loaded measures
:param dataModel: Model in which to add the loaded measures
:type dataModel: Model
:type dataModel: Model
:param keepRealisations: If True, all realisations are kept in the data. Else, the data is averaged over the realisations
:param keepRealisations: If True, all realisations are kept in the data. Else, the data is averaged over the realisations
:type keepRealisations: bool
:type keepRealisations: bool
:return: 0 if everything went well, -1 otherwise
:return: 0 if everything went well, -1 otherwise
:rtype: int
:rtype: int
:param state_type: Either forecast, computed or analysed depending on the type of states needed
:param state_type: Either forecast, computed or analysed depending on the type of states needed
"""
"""
firstpoint
=
3
firstpoint
=
3
assert
state_type
in
(
'
computed
'
,
'
analysed
'
,
'
forecast
'
)
assert
state_type
in
(
'
computed
'
,
'
analysed
'
,
'
analysis
'
,
'
forecast
'
)
measures_to_load
=
[
'
MF
'
,
'
SV
'
,
'
ER
'
,
'
U
'
]
measures_to_load
=
[
'
MF
'
,
'
SV
'
,
'
ER
'
,
'
U
'
]
hdf5_files
=
glob
.
glob
(
os
.
path
.
join
(
dataDirectory
,
'
*.hdf5
'
))
hdf5_files
=
glob
.
glob
(
os
.
path
.
join
(
dataDirectory
,
'
*.hdf5
'
))
if
len
(
hdf5_files
)
==
0
:
if
len
(
hdf5_files
)
==
0
:
raise
IOError
(
'
No hdf5 file was found in {} !
'
.
format
(
dataDirectory
))
raise
IOError
(
'
No hdf5 file was found in {} !
'
.
format
(
dataDirectory
))
# Assuming that the file to read is the first one
# Assuming that the file to read is the first one
hdf_filename
=
hdf5_files
[
0
]
hdf_filename
=
hdf5_files
[
0
]
print
(
'
Reading:
'
,
hdf_filename
,
'
state_type:
'
,
state_type
)
print
(
'
Reading:
'
,
hdf_filename
,
'
state_type:
'
,
state_type
)
with
h5py
.
File
(
hdf_filename
)
as
hdf_file
:
with
h5py
.
File
(
hdf_filename
)
as
hdf_file
:
computed_data
=
hdf_file
[
state_type
]
computed_data
=
hdf_file
[
state_type
]
times
=
np
.
array
(
computed_data
[
'
times
'
])[
firstpoint
:]
times
=
np
.
array
(
computed_data
[
'
times
'
])[
firstpoint
:]
for
measureName
,
measureData
in
computed_data
.
items
():
for
measureName
,
measureData
in
computed_data
.
items
():
if
measureName
not
in
measures_to_load
:
if
measureName
not
in
measures_to_load
:
continue
continue
else
:
else
:
measureType
,
units
=
giveMeasureTypeUnits
(
measureName
)
measureType
,
units
=
giveMeasureTypeUnits
(
measureName
)
# Move realisation axis to last place to have data of form [ntimes, ncoef, nreal] (originally [nreal, ntimes, ncoef])
# Move realisation axis to last place to have data of form [ntimes, ncoef, nreal] (originally [nreal, ntimes, ncoef])
# Remove firstpoints
# Remove firstpoints
formattedData
=
np
.
moveaxis
(
measureData
,
0
,
-
1
)[
firstpoint
:]
formattedData
=
np
.
moveaxis
(
measureData
,
0
,
-
1
)[
firstpoint
:]
if
measureName
==
'
MF
'
:
if
measureName
==
'
MF
'
:
lmax
=
hdf_file
.
attrs
[
'
Lb
'
]
lmax
=
hdf_file
.
attrs
[
'
Lb
'
]
elif
measureName
==
'
U
'
:
elif
measureName
==
'
U
'
:
lmax
=
hdf_file
.
attrs
[
'
Lu
'
]
lmax
=
hdf_file
.
attrs
[
'
Lu
'
]
else
:
else
:
lmax
=
hdf_file
.
attrs
[
'
Lsv
'
]
lmax
=
hdf_file
.
attrs
[
'
Lsv
'
]
if
keepRealisations
:
if
keepRealisations
:
dataModel
.
addMeasure
(
measureName
,
measureType
,
lmax
,
units
,
dataModel
.
addMeasure
(
measureName
,
measureType
,
lmax
,
units
,
formattedData
,
times
=
times
)
formattedData
,
times
=
times
)
else
:
else
:
meanData
=
formattedData
.
mean
(
axis
=
2
)
meanData
=
formattedData
.
mean
(
axis
=
2
)
rmsData
=
formattedData
.
std
(
axis
=
2
)
rmsData
=
formattedData
.
std
(
axis
=
2
)
dataModel
.
addMeasure
(
measureName
,
measureType
,
lmax
,
units
,
dataModel
.
addMeasure
(
measureName
,
measureType
,
lmax
,
units
,
meanData
,
rmsData
,
times
)
meanData
,
rmsData
,
times
)
# Returns 0 if everything went well
# Returns 0 if everything went well
return
0
return
0
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