Skip to content
GitLab
Menu
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
e9995eed
Commit
e9995eed
authored
Mar 09, 2020
by
payno
Browse files
Merge branch 'add_hdf5' of gitlab.esrf.fr:tomotools/tomoscan into add_hdf5
parents
2e08f186
10b46184
Changes
1
Hide whitespace changes
Inline
Side-by-side
tomoscan/esrf/hdf5scan.py
View file @
e9995eed
...
...
@@ -46,8 +46,9 @@ _logger = logging.getLogger(__name__)
class
ImageKey
(
_Enum
):
PROJECTION
=
0
,
FLAT_FIELD
=
1
,
ALIGNMENT
=
-
1
PROJECTION
=
0
FLAT_FIELD
=
1
DARK_FIELD
=
2
INVALID
=
3
...
...
@@ -303,7 +304,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_control
is
False
,
self
.
frames
))
proj_frames
=
tuple
(
filter
(
lambda
x
:
x
.
image_key
==
ImageKey
.
PROJECTION
and
x
.
is_control
==
False
,
self
.
frames
))
self
.
_projections
=
{}
for
proj_frame
in
proj_frames
:
self
.
_projections
[
proj_frame
.
index
]
=
proj_frame
.
url
...
...
@@ -318,7 +319,7 @@ class HDF5TomoScan(TomoScanBase):
def
darks
(
self
)
->
typing
.
Union
[
dict
,
None
]:
if
self
.
_darks
is
None
:
if
self
.
frames
:
dark_frames
=
tuple
(
filter
(
lambda
x
:
x
.
image_key
is
ImageKey
.
DARK_FIELD
,
self
.
frames
))
dark_frames
=
tuple
(
filter
(
lambda
x
:
x
.
image_key
==
ImageKey
.
DARK_FIELD
,
self
.
frames
))
self
.
_darks
=
{}
for
dark_frame
in
dark_frames
:
self
.
_darks
[
dark_frame
.
index
]
=
dark_frame
.
url
...
...
@@ -329,7 +330,7 @@ class HDF5TomoScan(TomoScanBase):
def
flats
(
self
)
->
typing
.
Union
[
dict
,
None
]:
if
self
.
_flats
is
None
:
if
self
.
frames
:
flat_frames
=
tuple
(
filter
(
lambda
x
:
x
.
image_key
is
ImageKey
.
FLAT_FIELD
,
self
.
frames
))
flat_frames
=
tuple
(
filter
(
lambda
x
:
x
.
image_key
==
ImageKey
.
FLAT_FIELD
,
self
.
frames
))
self
.
_flats
=
{}
for
flat_frame
in
flat_frames
:
self
.
_flats
[
flat_frame
.
index
]
=
flat_frame
.
url
...
...
@@ -379,7 +380,7 @@ class HDF5TomoScan(TomoScanBase):
""""""
frames
=
self
.
frames
if
frames
:
return_frames
=
list
(
filter
(
lambda
x
:
x
.
is_control
is
True
,
frames
))
return_frames
=
list
(
filter
(
lambda
x
:
x
.
is_control
==
True
,
frames
))
return
return_frames
else
:
return
None
...
...
@@ -453,18 +454,14 @@ class HDF5TomoScan(TomoScanBase):
@
property
def
dim_1
(
self
)
->
typing
.
Union
[
None
,
int
]:
if
self
.
_dim_1
is
None
and
self
.
master_file
and
os
.
path
.
exists
(
self
.
master_file
):
if
self
.
projections
is
not
None
:
if
len
(
self
.
projections
)
>
0
:
self
.
_dim_1
,
self
.
_dim_2
=
get_data
(
list
(
self
.
projections
.
values
())[
0
]).
shape
if
self
.
_dim_1
is
None
:
self
.
_get_dim1_dim2
()
return
self
.
_dim_1
@
property
def
dim_2
(
self
)
->
typing
.
Union
[
None
,
int
]:
if
self
.
_dim_2
is
None
and
self
.
master_file
and
os
.
path
.
exists
(
self
.
master_file
):
if
self
.
projections
is
not
None
:
if
len
(
self
.
projections
)
>
0
:
self
.
_dim_1
,
self
.
_dim_2
=
get_data
(
list
(
self
.
projections
.
values
())[
0
]).
shape
if
self
.
_dim_2
is
None
:
self
.
_get_dim1_dim2
()
return
self
.
_dim_2
@
property
...
...
@@ -483,11 +480,17 @@ class HDF5TomoScan(TomoScanBase):
"""read x and y pixel values"""
with
h5py
.
File
(
self
.
master_file
,
'r'
)
as
h5_file
:
x_pixel_dataset
=
h5_file
[
self
.
_entry
][
self
.
_X_PIXEL_SIZE_PATH
]
_x_pixel_size
=
self
.
_get_value
(
x_pixel_dataset
,
default_unit
=
'm
m
'
)
_x_pixel_size
=
self
.
_get_value
(
x_pixel_dataset
,
default_unit
=
'm
icrometer
'
)
y_pixel_dataset
=
h5_file
[
self
.
_entry
][
self
.
_Y_PIXEL_SIZE_PATH
]
_y_pixel_size
=
self
.
_get_value
(
y_pixel_dataset
,
default_unit
=
'm
m
'
)
_y_pixel_size
=
self
.
_get_value
(
y_pixel_dataset
,
default_unit
=
'm
icrometer
'
)
return
_x_pixel_size
,
_y_pixel_size
def
_get_dim1_dim2
(
self
):
if
self
.
master_file
and
os
.
path
.
exists
(
self
.
master_file
):
if
self
.
projections
is
not
None
:
if
len
(
self
.
projections
)
>
0
:
self
.
_dim_2
,
self
.
_dim_1
=
get_data
(
list
(
self
.
projections
.
values
())[
0
]).
shape
@
property
def
y_pixel_size
(
self
)
->
typing
.
Union
[
None
,
float
]:
if
(
self
.
_y_pixel_size
is
None
and
self
.
master_file
and
...
...
@@ -553,14 +556,14 @@ class HDF5TomoScan(TomoScanBase):
frame
=
Frame
(
index
=
i_frame
,
url
=
url
,
image_key
=
img_key
,
rotation_angle
=
rot_a
)
if
self
.
image_key_control
is
not
None
:
is_control_frame
=
self
.
image_key_control
[
frame
.
index
]
is_control_frame
=
(
self
.
image_key_control
[
frame
.
index
]
==
ImageKey
.
ALIGNMENT
.
value
)
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
frame
.
_
is_control_frame
=
is_control_frame
self
.
_frames
.
append
(
frame
)
last_proj_frame
=
frame
self
.
_frames
=
tuple
(
self
.
_frames
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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