Commit 83d54ce4 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[io][utils] Fix save of maps to nexus file

parent 4274e519
......@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "06/02/2020"
__date__ = "03/07/2021"
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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment