Skip to content

Commit

Permalink
Ellips reader attribute issues (#115)
Browse files Browse the repository at this point in the history
* Update writer.py

trying to fix issues with writing attributes

* testing writing attributes to plot(NXdata)

* fix for adding units to existing elements

* Updated reader to be consisent with NXellipsometry

* fixing pycodestyle errors in reader

* fixing pycodestyle errors in reader

* fixing pycodestyle errors in reader

* fixing pylint errors

* removed redundant backslash

---------

Co-authored-by: Sandor Brockhauser <sandor.brockhauser@xfel.eu>
  • Loading branch information
cmmngr and sanbrock committed May 25, 2023
1 parent 7a9a464 commit 628f293
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
26 changes: 17 additions & 9 deletions pynxtools/dataconverter/readers/ellips/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,29 @@ def read(self,
template["/ENTRY[entry]/plot/wavelength"] = {"link":
"/entry/instrument/spectrometer/wavelength"
}
template["/ENTRY[entry]/plot/wavelength/@units"] = header["wavelength_unit"]
for data_indx in range(0, len(labels.keys())):
for index, key in enumerate(data_list[data_indx]):
template[f"/ENTRY[entry]/plot/{key}"] = {"link":
"/entry/sample/measured_data",
"shape":
np.index_exp[0, 0, index, data_indx, :]
}
template[f"/ENTRY[entry]/plot/{key}/@units"] = "degrees"
template["/ENTRY[entry]/INSTRUMENT[instrument]/spectrometer/wavelength/@units"] = \
"Angstroms"
template["/ENTRY[entry]/INSTRUMENT[instrument]/spectrometer/wavelength/@long_name"] = \
"wavelength (Angstroms)"

for dindx in range(0, len(labels.keys())):
for index, key in enumerate(data_list[dindx]):
template[f"/ENTRY[entry]/plot/DATA[{key}]"] = {"link":
"/entry/sample/measured_data",
"shape":
np.index_exp[0, 0, index, dindx, :]
}
template[f"/ENTRY[entry]/plot/DATA[{key}]/@units"] = "degrees"
if dindx == 0 and index == 0:
template[f"/ENTRY[entry]/plot/DATA[{key}]/@long_name"] = \
"Psi and Delta (degrees)"

# Define default plot showing psi and delta at all angles:
template["/@default"] = "entry"
template["/ENTRY[entry]/@default"] = "plot"
template["/ENTRY[entry]/plot/@signal"] = f"{data_list[0][0]}"
template["/ENTRY[entry]/plot/@axes"] = "wavelength"
template["/ENTRY[entry]/plot/title"] = "Psi and Delta"

# if len(data_list[0]) > 1:
template["/ENTRY[entry]/plot/@auxiliary_signals"] = data_list[0][1:]
Expand Down
33 changes: 26 additions & 7 deletions pynxtools/dataconverter/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def handle_shape_entries(data, file, path):
return layout


def handle_dicts_entries(data, grp, entry_name, output_path):
def handle_dicts_entries(data, grp, entry_name, output_path, path):
"""Handle function for dictionaries found as value of the nexus file.
Several cases can be encoutered:
Expand Down Expand Up @@ -253,12 +253,34 @@ def add_units_key(dataset, path):
grp = self.ensure_and_get_parent_node(path, self.data.undocumented.keys())
if isinstance(data, dict):
if "compress" in data.keys():
dataset = handle_dicts_entries(data, grp, entry_name, self.output_path)
dataset = handle_dicts_entries(data, grp, entry_name,
self.output_path, path)
else:
hdf5_links_for_later.append([data, grp, entry_name, self.output_path])
hdf5_links_for_later.append([data, grp, entry_name,
self.output_path, path])
else:
dataset = grp.create_dataset(entry_name, data=data)
add_units_key(dataset, path)
except Exception as exc:
raise IOError(f"Unknown error occured writing the path: {path} "
f"with the following message: {str(exc)}") from exc

for links in hdf5_links_for_later:
dataset = handle_dicts_entries(*links)

for path, value in self.data.items():
try:
if path[path.rindex('/') + 1:] == '@units':
continue

entry_name = helpers.get_name_from_data_dict_entry(path[path.rindex('/') + 1:])
if is_not_data_empty(value):
data = value
else:
continue

if entry_name[0] != "@":
path_hdf5 = helpers.convert_data_dict_path_to_hdf5_path(path)
add_units_key(self.output_nexus[path_hdf5], path)
else:
# consider changing the name here the lvalue can also be group!
dataset = self.ensure_and_get_parent_node(path, self.data.undocumented.keys())
Expand All @@ -267,7 +289,4 @@ def add_units_key(dataset, path):
raise IOError(f"Unknown error occured writing the path: {path} "
f"with the following message: {str(exc)}") from exc

for links in hdf5_links_for_later:
dataset = handle_dicts_entries(*links)

self.output_nexus.close()

0 comments on commit 628f293

Please sign in to comment.