Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tomoscan
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
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
tomotools
tomoscan
Commits
71e79149
Commit
71e79149
authored
1 year ago
by
Pierre Paleo
Committed by
payno
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add h5utils
parent
943832a0
No related branches found
No related tags found
1 merge request
!168
Add fscan
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tomoscan/esrf/scan/h5utils.py
+53
-0
53 additions, 0 deletions
tomoscan/esrf/scan/h5utils.py
with
53 additions
and
0 deletions
tomoscan/esrf/scan/h5utils.py
0 → 100644
+
53
−
0
View file @
71e79149
import
numpy
as
np
from
...io
import
HDF5File
def
get_first_hdf5_entry
(
fname
):
with
HDF5File
(
fname
,
"
r
"
)
as
fid
:
entry
=
list
(
fid
.
keys
())[
0
]
return
entry
def
get_h5_value
(
fname
,
h5_path
,
default_ret
=
None
):
with
HDF5File
(
fname
,
"
r
"
)
as
fid
:
try
:
val_ptr
=
fid
[
h5_path
][()]
except
KeyError
:
val_ptr
=
default_ret
return
val_ptr
def
get_h5obj_value
(
h5_obj
,
name
,
default
=
None
):
if
name
in
h5_obj
:
return
h5_obj
[
name
][()]
return
default
def
_get_3D_subregion
(
sub_region
):
if
sub_region
is
None
:
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
=
None
,
None
,
None
,
None
,
None
,
None
elif
len
(
sub_region
)
==
3
:
first_part
,
second_part
,
third_part
=
sub_region
xmin
,
xmax
=
first_part
ymin
,
ymax
=
second_part
zmin
,
zmax
=
third_part
elif
len
(
sub_region
)
==
6
:
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
=
sub_region
else
:
raise
ValueError
(
"
Expected parameter in the form (xmin, xmax, ymin, ymax, zmin, zmax) or ((xmin, xmax), (ymin, ymax), (zmin, zmax))
"
)
return
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
def
get_hdf5_dataset_shape
(
fname
,
h5_data_path
,
sub_region
=
None
):
zmin
,
zmax
,
ymin
,
ymax
,
xmin
,
xmax
=
_get_3D_subregion
(
sub_region
)
with
HDF5File
(
fname
,
"
r
"
)
as
f
:
d_ptr
=
f
[
h5_data_path
]
shape
=
d_ptr
.
shape
n_z
,
n_y
,
n_x
=
shape
# perhaps there is more elegant
res_shape
=
[]
for
n
,
bounds
in
zip
([
n_z
,
n_y
,
n_x
],
((
zmin
,
zmax
),
(
ymin
,
ymax
),
(
xmin
,
xmax
))):
res_shape
.
append
(
np
.
arange
(
n
)[
bounds
[
0
]
:
bounds
[
1
]].
size
)
return
tuple
(
res_shape
)
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