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
XRD
darfix
Commits
c4650078
Commit
c4650078
authored
Feb 12, 2020
by
Julia Garriga Ferrer
Browse files
[io][utils] Add overwrite option to write_process function
parent
7969fad8
Changes
1
Hide whitespace changes
Inline
Side-by-side
darfix/io/utils.py
View file @
c4650078
...
...
@@ -117,7 +117,7 @@ def write_process(h5_file, entry, dimensions, W, data, processing_order,
return
'image'
return
None
def
save_key
(
path_name
,
key_path
,
value
):
def
save_key
(
path_name
,
key_path
,
value
,
overwrite
=
True
):
"""Save the given value to the associated path. Manage numpy arrays
and dictionaries"""
key_path
=
key_path
.
replace
(
'.'
,
'/'
)
...
...
@@ -129,6 +129,8 @@ def write_process(h5_file, entry, dimensions, W, data, processing_order,
else
:
with
h5py
.
File
(
h5_file
,
'a'
)
as
h5f
:
nx
=
h5f
.
require_group
(
path_name
)
if
overwrite
and
key_path
in
nx
:
del
nx
[
key_path
]
try
:
nx
[
key_path
]
=
value
except
TypeError
as
e
:
...
...
@@ -147,8 +149,7 @@ def write_process(h5_file, entry, dimensions, W, data, processing_order,
nx_process
=
nx_entry
.
require_group
(
process_name
)
nx_process
.
attrs
[
'NX_class'
]
=
"NXprocess"
if
overwrite
:
for
key
in
(
'program'
,
'version'
,
'date'
,
'processing_order'
,
'class_instance'
,
'ft'
):
for
key
in
(
'program'
,
'version'
,
'date'
,
'processing_order'
):
if
key
in
nx_process
:
del
nx_process
[
key
]
nx_process
[
'program'
]
=
'darfix'
...
...
@@ -158,19 +159,18 @@ def write_process(h5_file, entry, dimensions, W, data, processing_order,
nx_parameters
=
nx_process
.
require_group
(
"inputs"
)
nx_parameters
.
attrs
[
'NX_class'
]
=
"NXparameters"
nx_parameters_path
=
nx_parameters
.
name
for
key
,
value
in
dimensions
.
items
():
save_key
(
nx_parameters
.
name
,
key_path
=
key
,
value
=
value
)
results
=
nx_process
.
require_group
(
"results"
)
results
.
attrs
[
"NX_class"
]
=
"NXcollection"
results_path
=
results
.
name
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"
results
.
attrs
[
"target"
]
=
"components"
save_key
(
results_path
,
"W"
,
W
)
save_key
(
results_path
,
"components"
,
data
)
nx_data
[
"components"
]
=
h5f
[
source_addr
]
for
key
,
value
in
dimensions
.
items
():
save_key
(
nx_parameters_path
,
key_path
=
key
,
value
=
value
)
save_key
(
results
.
name
,
"W"
,
W
)
save_key
(
results
.
name
,
"components"
,
data
)
save_key
(
nx_data
.
name
,
"components"
,
h5f
[
source_addr
])
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