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
XRD
darfix
Commits
83d54ce4
Commit
83d54ce4
authored
Aug 03, 2021
by
Julia Garriga Ferrer
Browse files
[io][utils] Fix save of maps to nexus file
parent
4274e519
Changes
1
Hide whitespace changes
Inline
Side-by-side
darfix/io/utils.py
View file @
83d54ce4
...
...
@@ -26,7 +26,7 @@
__authors__
=
[
"J. Garriga"
]
__license__
=
"MIT"
__date__
=
"0
6
/0
2
/202
0
"
__date__
=
"0
3
/0
7
/202
1
"
import
logging
import
h5py
...
...
@@ -71,7 +71,9 @@ def advancement_display(iteration, total, prefix='', suffix='', decimals=1, leng
if
iteration
==
total
:
print
()
def
write_maps
(
h5_file
,
list_of_maps
,
data_path
=
'/'
,
overwrite
=
True
):
def
write_maps
(
h5_file
,
list_of_maps
,
default_map
,
entry
,
processing_order
,
data_path
=
'/'
,
overwrite
=
True
):
"""
Write a stack of components and its parameters into .h5
...
...
@@ -118,7 +120,7 @@ def write_maps(h5_file, list_of_maps, data_path='/', overwrite=True):
nx
[
key_path
].
attrs
[
'interpretation'
]
=
interpretation
with
h5py
.
File
(
h5_file
,
'a'
)
as
h5f
:
h5f
.
attrs
[
"default"
]
=
"
entry
"
h5f
.
attrs
[
"default"
]
=
entry
nx_entry
=
h5f
.
require_group
(
'/'
.
join
((
data_path
,
entry
)))
nx_entry
.
attrs
[
"NX_class"
]
=
"NXentry"
nx_entry
.
attrs
[
"default"
]
=
"data"
...
...
@@ -136,15 +138,24 @@ def write_maps(h5_file, list_of_maps, data_path='/', overwrite=True):
results
=
nx_process
.
require_group
(
"results"
)
results
.
attrs
[
"NX_class"
]
=
"NXcollection"
nx_data
=
nx_entry
.
require_group
(
"data"
)
nx_data
.
attrs
[
"NX_class"
]
=
"NXdata"
default
=
list_of_maps
[
default_map
]
source_addr
=
entry
+
"/"
+
process_name
+
"/results/"
+
default_map
results
.
attrs
[
"target"
]
=
default_map
save_key
(
results
.
name
,
default_map
,
default
)
save_key
(
nx_data
.
name
,
default_map
,
h5f
[
source_addr
])
for
_map
in
list_of_maps
:
nx_data
=
nx_entry
.
require_group
(
_map
)
nx_data
.
attrs
[
"NX_class"
]
=
"NXdata"
nx_data
.
attrs
[
"signal"
]
=
_map
source_addr
=
"entry/"
+
process_name
+
"/results/"
+
_map
results
.
attrs
[
"target"
]
=
write_maps
save_key
(
results
.
name
,
_map
,
W
)
save_key
(
nx_data
.
name
,
_map
,
h5f
[
source_addr
])
if
_map
==
default_map
:
continue
if
isinstance
(
list_of_maps
[
_map
],
dict
):
maps
=
results
.
require_group
(
_map
)
maps
.
attrs
[
"NX_class"
]
=
"NXcollection"
for
method
in
list_of_maps
[
_map
]:
save_key
(
maps
.
name
,
method
,
list_of_maps
[
_map
][
method
])
else
:
save_key
(
results
.
name
,
_map
,
list_of_maps
[
_map
])
def
read_components
(
h5_file
):
...
...
@@ -217,7 +228,7 @@ def write_components(h5_file, entry, dimensions, W, data, processing_order,
nx
[
key_path
].
attrs
[
'interpretation'
]
=
interpretation
with
h5py
.
File
(
h5_file
,
'a'
)
as
h5f
:
h5f
.
attrs
[
"default"
]
=
"
entry
"
h5f
.
attrs
[
"default"
]
=
entry
nx_entry
=
h5f
.
require_group
(
'/'
.
join
((
data_path
,
entry
)))
nx_entry
.
attrs
[
"NX_class"
]
=
"NXentry"
nx_entry
.
attrs
[
"default"
]
=
"data"
...
...
@@ -244,7 +255,7 @@ def write_components(h5_file, entry, dimensions, W, data, processing_order,
nx_data
=
nx_entry
.
require_group
(
"data"
)
nx_data
.
attrs
[
"NX_class"
]
=
"NXdata"
nx_data
.
attrs
[
"signal"
]
=
"components"
source_addr
=
"
entry/"
+
process_name
+
"/results/components"
source_addr
=
entry
+
"
/"
+
process_name
+
"/results/components"
results
.
attrs
[
"target"
]
=
"components"
save_key
(
results
.
name
,
"W"
,
W
)
...
...
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