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
ba364dd9
Commit
ba364dd9
authored
Nov 22, 2016
by
Damien Naudet
Browse files
WIP
parent
9cdb6d2b
Changes
3
Hide whitespace changes
Inline
Side-by-side
kmap/io/XsocsH5.py
View file @
ba364dd9
...
...
@@ -30,7 +30,7 @@ __license__ = "MIT"
__date__
=
"15/09/2016"
import
weakref
from
collections
import
OrderedDict
from
collections
import
OrderedDict
,
namedtuple
from
contextlib
import
contextmanager
import
h5py
as
_h5py
...
...
@@ -43,6 +43,10 @@ class InvalidEntryError(Exception):
pass
ScanPositions
=
namedtuple
(
'ScanPositions'
,
[
'motor_0'
,
'pos_0'
,
'motor_1'
,
'pos_1'
,
'shape'
])
class
XsocsH5
(
XsocsH5Base
):
TOP_ENTRY
=
'global'
...
...
@@ -163,10 +167,16 @@ class XsocsH5(XsocsH5Base):
params
=
self
.
scan_params
(
entry
)
m0
=
'/adc{0}'
.
format
(
params
[
'motor_0'
][
-
1
].
upper
())
m1
=
'/adc{0}'
.
format
(
params
[
'motor_1'
][
-
1
].
upper
())
n_0
=
params
[
'motor_0_steps'
]
n_1
=
params
[
'motor_1_steps'
]
x_pos
=
self
.
_get_array_data
(
path
+
m0
)
y_pos
=
self
.
_get_array_data
(
path
+
m1
)
return
(
x_pos
,
y_pos
)
return
ScanPositions
(
motor_0
=
params
[
'motor_0'
],
pos_0
=
x_pos
,
motor_1
=
params
[
'motor_1'
],
pos_1
=
y_pos
,
shape
=
(
n_0
,
n_1
))
def
acquisition_params
(
self
,
entry
):
beam_energy
=
self
.
beam_energy
(
entry
)
...
...
@@ -197,8 +207,6 @@ class XsocsH5(XsocsH5Base):
_np
.
array
(
None
))[
()])
for
param
in
param_names
])
return
{
param_names
:
h5_file
.
get
(
path
.
format
(
param_names
),
_np
.
array
(
None
))[()]}
def
positioner
(
self
,
entry
,
positioner
):
path
=
self
.
positioners_tpl
.
format
(
entry
)
+
'/'
+
positioner
...
...
@@ -244,12 +252,6 @@ class XsocsH5Writer(XsocsH5):
for
param_name
,
param_value
in
params
.
items
():
self
.
_set_scalar_data
(
path
.
format
(
param_name
),
param_value
)
# def __set_measurement_params(self, entry, params):
# with self._get_file() as h5_file:
# path = self.scan_params_tpl.format(entry) + '/{0}'
# for param_name, param_value in params.items():
# self._set_scalar_data(path.format(param_name), param_value)
def
set_beam_energy
(
self
,
beam_energy
,
entry
):
return
self
.
__set_detector_params
(
entry
,
{
'beam_energy'
:
beam_energy
})
...
...
kmap/io/XsocsH5Base.py
View file @
ba364dd9
...
...
@@ -59,6 +59,18 @@ class XsocsH5Base(object):
filename
=
property
(
lambda
self
:
self
.
__h5_f
)
def
_path_exists
(
self
,
path
):
with
self
.
_get_file
()
as
h5f
:
return
path
in
h5f
def
set_attribute
(
self
,
path
,
name
,
value
):
with
self
.
_get_file
()
as
h5f
:
h5f
[
path
].
attrs
[
name
]
=
value
def
attribute
(
self
,
path
,
name
):
with
self
.
_get_file
()
as
h5f
:
return
h5f
[
path
].
attrs
.
get
(
name
)
@
contextmanager
def
_get_file
(
self
,
mode
=
None
):
"""
...
...
@@ -148,6 +160,10 @@ class XsocsH5Base(object):
with
self
.
_get_file
()
as
h5_file
:
h5_file
[
in_path
]
=
_h5py
.
ExternalLink
(
file_name
,
ext_path
)
def
add_soft_link
(
self
,
from_path
,
target_path
):
with
self
.
_get_file
()
as
h5_file
:
h5_file
[
from_path
]
=
_h5py
.
SoftLink
(
target_path
)
@
contextmanager
def
item_context
(
self
,
item_path
,
**
kwargs
):
"""
...
...
@@ -193,3 +209,9 @@ class XsocsH5Base(object):
src_grp
=
src_grp
,
dest_grp
=
dest_grp
))
def
object_filename
(
self
,
path
):
with
self
.
_get_file
()
as
h5f
:
obj
=
h5f
.
get
(
path
)
if
obj
is
None
:
return
None
return
obj
.
file
.
filename
kmap/util/id01_spec.py
View file @
ba364dd9
...
...
@@ -1073,10 +1073,12 @@ class _MergeThread(Thread):
progress
=
np
.
frombuffer
(
self
.
__shared_progress
,
dtype
=
'int32'
)
proc_indices
=
self
.
__proc_indices
if
proc_indices
:
merge_progress
=
{
scan_id
:
progress
[
proc_idx
]
for
scan_id
,
proc_idx
in
proc_indices
.
items
()}
merge_progress
=
dict
([(
scan_id
,
progress
[
proc_idx
])
for
scan_id
,
proc_idx
in
proc_indices
.
items
()])
else
:
merge_progress
=
{
scan_id
:
0
for
scan_id
in
self
.
__scans
.
keys
()}
merge_progress
=
dict
([(
scan_id
,
0
)
for
scan_id
in
self
.
__scans
.
keys
()])
return
merge_progress
def
results
(
self
,
wait
=
True
):
...
...
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