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
kmap
xsocs
Commits
800c8de3
Commit
800c8de3
authored
Jul 10, 2017
by
Carsten Richter
Browse files
Allow default entry and entry index as XsocsH5 method arguments
parent
303929b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
xsocs/io/XsocsH5.py
View file @
800c8de3
...
...
@@ -47,6 +47,18 @@ ScanPositions = namedtuple('ScanPositions',
[
'motor_0'
,
'pos_0'
,
'motor_1'
,
'pos_1'
,
'shape'
])
def
_process_entry
(
method
):
def
_method
(
inst
,
entry
=
None
,
*
args
,
**
kwargs
):
if
entry
is
None
:
entry
=
inst
.
get_entry_name
()
elif
isinstance
(
entry
,
int
):
entry
=
inst
.
get_entry_name
(
entry
)
return
method
(
inst
,
entry
,
*
args
,
**
kwargs
)
return
_method
class
XsocsH5
(
XsocsH5Base
):
TOP_ENTRY
=
'global'
...
...
@@ -61,11 +73,13 @@ class XsocsH5(XsocsH5Base):
self
.
__entries
=
None
@
_process_entry
def
title
(
self
,
entry
):
with
self
.
_get_file
()
as
h5_file
:
path
=
entry
+
'/title'
return
h5_file
[
path
][()]
@
_process_entry
def
entry_filename
(
self
,
entry
):
with
self
.
_get_file
()
as
h5_file
:
return
h5_file
[
entry
].
file
.
filename
...
...
@@ -85,11 +99,12 @@ class XsocsH5(XsocsH5Base):
self
.
_update_entries
()
return
self
.
__entries
[:]
@
_process_entry
def
scan_angle
(
self
,
entry
):
# TODO : get the correct angle name
return
self
.
positioner
(
entry
,
'eta'
)
def
get_entry_name
(
self
,
entry_idx
):
def
get_entry_name
(
self
,
entry_idx
=
0
):
"""
Get the entry found at position *entry_idx* (entries names sorted
alphabeticaly).
...
...
@@ -101,6 +116,7 @@ class XsocsH5(XsocsH5Base):
raise
InvalidEntryError
(
'Entry not found (entry_idx={0}).'
''
.
format
(
entry_idx
))
@
_process_entry
def
__detector_params
(
self
,
entry
,
param_names
):
with
self
.
_get_file
()
as
h5_file
:
path
=
self
.
detector_tpl
.
format
(
entry
)
+
'/{0}'
...
...
@@ -109,34 +125,42 @@ class XsocsH5(XsocsH5Base):
for
param
in
param_names
]
return
h5_file
.
get
(
path
.
format
(
param_names
),
_np
.
array
(
None
))[()]
@
_process_entry
def
beam_energy
(
self
,
entry
):
return
self
.
__detector_params
(
entry
,
'beam_energy'
)
@
_process_entry
def
direct_beam
(
self
,
entry
):
return
self
.
__detector_params
(
entry
,
[
'center_chan_dim0'
,
'center_chan_dim1'
])
@
_process_entry
def
chan_per_deg
(
self
,
entry
):
return
self
.
__detector_params
(
entry
,
[
'chan_per_deg_dim0'
,
'chan_per_deg_dim1'
])
@
_process_entry
def
n_images
(
self
,
entry
):
# TODO : make sure that data.ndims = 3
path
=
self
.
img_data_tpl
.
format
(
entry
)
return
self
.
_get_array_data
(
path
,
shape
=
True
)[
0
]
@
_process_entry
def
image_size
(
self
,
entry
):
# TODO : make sure that data.ndims = 3
path
=
self
.
img_data_tpl
.
format
(
entry
)
return
self
.
_get_array_data
(
path
,
shape
=
True
)[
1
:
3
]
@
_process_entry
def
image_dtype
(
self
,
entry
):
path
=
self
.
img_data_tpl
.
format
(
entry
)
return
self
.
_get_array_data
(
path
,
dtype
=
True
)
@
_process_entry
def
dset_shape
(
self
,
path
):
return
self
.
_get_array_data
(
path
,
shape
=
True
)
@
_process_entry
def
image_cumul
(
self
,
entry
,
dtype
=
None
):
"""
Returns the summed intensity for each image.
...
...
@@ -156,6 +180,7 @@ class XsocsH5(XsocsH5Base):
intensity
[
idx
]
=
_np
.
sum
(
img_buffer
)
return
intensity
@
_process_entry
def
scan_positions
(
self
,
entry
):
path
=
self
.
measurement_tpl
.
format
(
entry
)
params
=
self
.
scan_params
(
entry
)
...
...
@@ -172,6 +197,7 @@ class XsocsH5(XsocsH5Base):
pos_1
=
y_pos
,
shape
=
(
n_0
,
n_1
))
@
_process_entry
def
acquisition_params
(
self
,
entry
):
beam_energy
=
self
.
beam_energy
(
entry
)
direct_beam
=
self
.
direct_beam
(
entry
)
...
...
@@ -184,6 +210,7 @@ class XsocsH5(XsocsH5Base):
return
result
@
_process_entry
def
is_regular_grid
(
self
,
entry
):
# TODO
"""
...
...
@@ -193,6 +220,7 @@ class XsocsH5(XsocsH5Base):
"""
return
True
@
_process_entry
def
scan_params
(
self
,
entry
):
# TODO : make this more generic to make it compatible
# with irregular grids
...
...
@@ -207,15 +235,18 @@ class XsocsH5(XsocsH5Base):
_np
.
array
(
None
))[()])
for
param
in
param_names
])
@
_process_entry
def
positioner
(
self
,
entry
,
positioner
):
path
=
self
.
positioners_tpl
.
format
(
entry
)
+
'/'
+
positioner
return
self
.
_get_scalar_data
(
path
)
@
_process_entry
def
measurement
(
self
,
entry
,
measurement
):
path
=
self
.
measurement_tpl
.
format
(
entry
)
+
'/'
+
measurement
return
self
.
_get_array_data
(
path
)
@
contextmanager
@
_process_entry
def
image_dset_ctx
(
self
,
entry
,
create
=
False
,
...
...
@@ -300,7 +331,7 @@ class XsocsH5Writer(XsocsH5):
grp
.
attrs
[
'interpretation'
]
=
_np
.
string_
(
'image'
)
# setting the nexus classes
entry_grp
.
attrs
[
'NX_class'
]
=
_np
.
string_
(
'NXentry'
)
#
entry_grp.attrs['NX_class'] = _np.string_('NXentry')
grp
=
entry_grp
.
require_group
(
'instrument'
)
grp
.
attrs
[
'NX_class'
]
=
_np
.
string_
(
'NXinstrument'
)
...
...
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