Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tomotools
tomoscan
Commits
675c0d30
Commit
675c0d30
authored
Feb 27, 2020
by
payno
Browse files
[hdf5scan] add management of image_key_control
parent
c5f1b243
Pipeline
#22065
failed with stages
in 1 minute and 26 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tomoscan/esrf/hdf5scan.py
View file @
675c0d30
...
...
@@ -84,6 +84,8 @@ class HDF5TomoScan(TomoScanBase):
_IMG_KEY_PATH
=
'instrument/detector/image_key'
_IMG_KEY_CONTROL_PATH
=
'instrument/detector/image_key_control'
_X_PIXEL_SIZE_PATH
=
'instrument/detector/x_pixel_size'
_Y_PIXEL_SIZE_PATH
=
'instrument/detector/y_pixel_size'
...
...
@@ -150,6 +152,7 @@ class HDF5TomoScan(TomoScanBase):
# pixel dimensions (tuple)
self
.
_frames
=
None
self
.
_image_keys
=
None
self
.
_image_keys_control
=
None
self
.
_rotation_angles
=
None
self
.
_distance
=
None
self
.
_energy
=
None
...
...
@@ -184,6 +187,7 @@ class HDF5TomoScan(TomoScanBase):
self
.
_y_pixel_size
=
None
self
.
_rotation_angles
=
None
self
.
_distance
=
None
self
.
_image_keys_control
=
None
@
staticmethod
def
_get_entry_at
(
index
:
int
,
file_path
:
str
)
->
str
:
...
...
@@ -299,7 +303,7 @@ class HDF5TomoScan(TomoScanBase):
"""projections / radio, does not include the return projections"""
if
self
.
_projections
is
None
:
if
self
.
frames
:
proj_frames
=
tuple
(
filter
(
lambda
x
:
x
.
image_key
is
ImageKey
.
PROJECTION
and
x
.
is_
return
is
False
,
self
.
frames
))
proj_frames
=
tuple
(
filter
(
lambda
x
:
x
.
image_key
is
ImageKey
.
PROJECTION
and
x
.
is_
control
is
False
,
self
.
frames
))
self
.
_projections
=
{}
for
proj_frame
in
proj_frames
:
self
.
_projections
[
proj_frame
.
index
]
=
proj_frame
.
url
...
...
@@ -375,7 +379,7 @@ class HDF5TomoScan(TomoScanBase):
""""""
frames
=
self
.
frames
if
frames
:
return_frames
=
list
(
filter
(
lambda
x
:
x
.
is_
return
is
True
,
frames
))
return_frames
=
list
(
filter
(
lambda
x
:
x
.
is_
control
is
True
,
frames
))
return
return_frames
else
:
return
None
...
...
@@ -398,6 +402,17 @@ class HDF5TomoScan(TomoScanBase):
self
.
_image_keys
=
h5_file
[
self
.
_entry
][
self
.
_IMG_KEY_PATH
][()]
return
self
.
_image_keys
@
property
def
image_key_control
(
self
)
->
typing
.
Union
[
list
,
None
]:
if
self
.
_entry
and
self
.
_image_keys_control
is
None
:
self
.
_check_hdf5scan_validity
()
with
h5py
.
File
(
self
.
master_file
,
'r'
)
as
h5_file
:
if
self
.
_IMG_KEY_CONTROL_PATH
in
h5_file
[
self
.
_entry
]:
self
.
_image_keys_control
=
h5_file
[
self
.
_entry
][
self
.
_IMG_KEY_CONTROL_PATH
][()]
else
:
self
.
_image_keys_control
=
None
return
self
.
_image_keys_control
@
docstring
(
TomoScanBase
.
dark_n
)
@
property
def
dark_n
(
self
)
->
typing
.
Union
[
None
,
int
]:
...
...
@@ -537,11 +552,15 @@ class HDF5TomoScan(TomoScanBase):
frame
=
Frame
(
index
=
i_frame
,
url
=
url
,
image_key
=
img_key
,
rotation_angle
=
rot_a
)
return_already_reach
,
delta_angle
=
is_return
(
lframe
=
frame
,
llast_proj_frame
=
last_proj_frame
,
ldelta_angle
=
delta_angle
,
return_already_reach
=
return_already_reach
)
frame
.
is_return
=
return_already_reach
if
self
.
image_key_control
is
not
None
:
is_control_frame
=
self
.
image_key_control
[
frame
.
index
]
else
:
return_already_reach
,
delta_angle
=
is_return
(
lframe
=
frame
,
llast_proj_frame
=
last_proj_frame
,
ldelta_angle
=
delta_angle
,
return_already_reach
=
return_already_reach
)
is_control_frame
=
return_already_reach
frame
.
is_control_frame
=
is_control_frame
self
.
_frames
.
append
(
frame
)
last_proj_frame
=
frame
self
.
_frames
=
tuple
(
self
.
_frames
)
...
...
@@ -553,7 +572,7 @@ class HDF5TomoScan(TomoScanBase):
res
=
{}
for
frame
in
self
.
frames
:
if
frame
.
image_key
is
ImageKey
.
PROJECTION
:
if
frame
.
is_
return
is
False
:
if
frame
.
is_
control
is
False
:
res
[
frame
.
rotation_angle
]
=
frame
.
url
else
:
res
[
str
(
frame
.
rotation_angle
)
+
'(1)'
]
=
frame
.
url
...
...
@@ -597,13 +616,13 @@ class Frame:
def
__init__
(
self
,
index
:
int
,
url
:
typing
.
Union
[
None
,
DataUrl
]
=
None
,
image_key
:
typing
.
Union
[
None
,
ImageKey
,
int
]
=
None
,
rotation_angle
:
typing
.
Union
[
None
,
float
]
=
None
,
is_
return
_proj
:
bool
=
False
):
is_
control
_proj
:
bool
=
False
):
assert
type
(
index
)
is
int
self
.
_index
=
index
self
.
_image_key
=
ImageKey
.
from_value
(
image_key
)
self
.
_rotation_angle
=
rotation_angle
self
.
_url
=
url
self
.
_is_
return
_frame
=
is_
return
_proj
self
.
_is_
control
_frame
=
is_
control
_proj
self
.
_data
=
None
@
property
...
...
@@ -631,9 +650,9 @@ class Frame:
return
self
.
_url
@
property
def
is_
return
(
self
)
->
bool
:
return
self
.
_is_
return
_frame
def
is_
control
(
self
)
->
bool
:
return
self
.
_is_
control
_frame
@
is_
return
.
setter
def
is_
return
(
self
,
is_return
:
bool
):
self
.
_is_
return
_frame
=
is_return
@
is_
control
.
setter
def
is_
control
(
self
,
is_return
:
bool
):
self
.
_is_
control
_frame
=
is_return
tomoscan/esrf/test/test_hdf5scan.py
View file @
675c0d30
...
...
@@ -97,7 +97,7 @@ class TestHDF5Scan(HDF5TestBaseClass):
self
.
assertTrue
(
isinstance
(
proj_2
,
Frame
))
self
.
assertEqual
(
proj_2
.
index
,
24
)
numpy
.
isclose
(
proj_2
.
rotation_angle
,
0.24
)
self
.
assertFalse
(
proj_2
.
is_
return
)
self
.
assertFalse
(
proj_2
.
is_
control
)
self
.
assertEqual
(
proj_2
.
url
.
file_path
(),
self
.
scan
.
master_file
)
self
.
assertEqual
(
proj_2
.
url
.
data_path
(),
'/entry0000/instrument/detector/data'
)
self
.
assertEqual
(
proj_2
.
url
.
data_slice
(),
24
)
...
...
@@ -108,13 +108,13 @@ class TestHDF5Scan(HDF5TestBaseClass):
with
self
.
subTest
(
frame_index
=
frame_index
):
frame
=
frames
[
frame_index
]
self
.
assertTrue
(
frame
.
image_key
,
ImageKey
.
PROJECTION
)
self
.
assertFalse
(
frame
.
is_
return
)
self
.
assertFalse
(
frame
.
is_
control
)
# check some darks
dark_0
=
frames
[
0
]
self
.
assertEqual
(
dark_0
.
index
,
0
)
numpy
.
isclose
(
dark_0
.
rotation_angle
,
0.0
)
self
.
assertFalse
(
dark_0
.
is_
return
)
self
.
assertFalse
(
dark_0
.
is_
control
)
self
.
assertEqual
(
dark_0
.
url
.
file_path
(),
self
.
scan
.
master_file
)
self
.
assertEqual
(
dark_0
.
url
.
data_path
(),
'/entry0000/instrument/detector/data'
)
self
.
assertEqual
(
dark_0
.
url
.
data_slice
(),
0
)
...
...
@@ -125,7 +125,7 @@ class TestHDF5Scan(HDF5TestBaseClass):
ref_1
=
frames
[
2
]
self
.
assertEqual
(
ref_1
.
index
,
2
)
numpy
.
isclose
(
ref_1
.
rotation_angle
,
0.0
)
self
.
assertFalse
(
ref_1
.
is_
return
)
self
.
assertFalse
(
ref_1
.
is_
control
)
self
.
assertEqual
(
ref_1
.
url
.
file_path
(),
self
.
scan
.
master_file
)
self
.
assertEqual
(
ref_1
.
url
.
data_path
(),
'/entry0000/instrument/detector/data'
)
...
...
@@ -138,7 +138,7 @@ class TestHDF5Scan(HDF5TestBaseClass):
self
.
assertTrue
(
isinstance
(
r_proj_0
,
Frame
))
self
.
assertEqual
(
r_proj_0
.
index
,
1543
)
numpy
.
isclose
(
r_proj_0
.
rotation_angle
,
180
)
self
.
assertTrue
(
r_proj_0
.
is_
return
)
self
.
assertTrue
(
r_proj_0
.
is_
control
)
self
.
assertEqual
(
r_proj_0
.
url
.
file_path
(),
self
.
scan
.
master_file
)
self
.
assertEqual
(
r_proj_0
.
url
.
data_path
(),
'/entry0000/instrument/detector/data'
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment