From ae97d7c8b05c05e556ac6d657f3174ba57f149e1 Mon Sep 17 00:00:00 2001 From: Rubel Date: Fri, 20 Dec 2024 13:28:39 +0100 Subject: [PATCH] Ruff --- src/nomad_measurements/utils.py | 9 ++++---- src/nomad_measurements/xrd/nx.py | 33 ++++++++++++++++++++-------- src/nomad_measurements/xrd/schema.py | 22 +++++++++++-------- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/nomad_measurements/utils.py b/src/nomad_measurements/utils.py index c4518ab..d2f8651 100644 --- a/src/nomad_measurements/utils.py +++ b/src/nomad_measurements/utils.py @@ -351,8 +351,9 @@ def write_file(self): nexus file. Creating h5 file instead.""" ) if self.archive.m_context.raw_path_exists(self.data_file): - os.remove(os.path.join(self.archive.m_context.raw_path(), - self.data_file)) + os.remove( + os.path.join(self.archive.m_context.raw_path(), self.data_file) + ) self._write_hdf5_file() else: self._write_hdf5_file() @@ -519,9 +520,7 @@ def walk_through_object(parent_obj, attr_chain): return child_obj - def populate_nx_dataset_and_attribute( - self, attr_dict: dict, dataset_dict: dict - ): + def populate_nx_dataset_and_attribute(self, attr_dict: dict, dataset_dict: dict): """Construct datasets and attributes for nexus and populate.""" for nx_path, arch_path in CONCEPT_MAP.items(): diff --git a/src/nomad_measurements/xrd/nx.py b/src/nomad_measurements/xrd/nx.py index 201f423..21474ae 100644 --- a/src/nomad_measurements/xrd/nx.py +++ b/src/nomad_measurements/xrd/nx.py @@ -45,13 +45,28 @@ '/ENTRY[entry]/method': 'archive.data.method', '/ENTRY[entry]/measurement_type': 'archive.data.diffraction_method_name', '/ENTRY[entry]/experiment_result/@signal': 'intensity', - '/ENTRY[entry]/INSTRUMENT[instrument]/DETECTOR[detector]/scan_axis': 'archive.data.results[0].scan_axis', - '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/xray_tube_material': 'archive.data.xrd_settings.source.xray_tube_material', - '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/xray_tube_current': 'archive.data.xrd_settings.source.xray_tube_current', - '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/xray_tube_voltage': 'archive.data.xrd_settings.source.xray_tube_voltage', - '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/k_alpha_one': 'archive.data.xrd_settings.source.kalpha_one', - '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/k_alpha_two': 'archive.data.xrd_settings.source.kalpha_two', - '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/ratio_k_alphatwo_k_alphaone': 'archive.data.xrd_settings.source.ratio_kalphatwo_kalphaone', - '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/kbeta': 'archive.data.xrd_settings.source.kbeta', + '/ENTRY[entry]/INSTRUMENT[instrument]/DETECTOR[detector]/scan_axis': ( + 'archive.data.results[0].scan_axis' + ), + '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/xray_tube_material': ( + 'archive.data.xrd_settings.source.xray_tube_material' + ), + '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/xray_tube_current': ( + 'archive.data.xrd_settings.source.xray_tube_current' + ), + '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/xray_tube_voltage': ( + 'archive.data.xrd_settings.source.xray_tube_voltage' + ), + '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/k_alpha_one': ( + 'archive.data.xrd_settings.source.kalpha_one' + ), + '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/k_alpha_two': ( + 'archive.data.xrd_settings.source.kalpha_two' + ), + '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/ratio_k_alphatwo_k_alphaone': ( + 'archive.data.xrd_settings.source.ratio_kalphatwo_kalphaone' + ), + '/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/kbeta': ( + 'archive.data.xrd_settings.source.kbeta' + ), } - diff --git a/src/nomad_measurements/xrd/schema.py b/src/nomad_measurements/xrd/schema.py index 870832c..0a161f7 100644 --- a/src/nomad_measurements/xrd/schema.py +++ b/src/nomad_measurements/xrd/schema.py @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + from typing import ( TYPE_CHECKING, Any, @@ -73,9 +74,9 @@ from nomad_measurements.utils import ( HDF5Handler, get_bounding_range_2d, - merge_sections, get_entry_id_from_file_name, - get_reference + get_reference, + merge_sections, ) from nomad_measurements.xrd.nx import NEXUS_DATASET_PATHS @@ -1142,7 +1143,7 @@ class ELNXRayDiffraction(XRayDiffraction, EntryData): nexus_results = Quantity( type=ArchiveSection, description='Reference to the NeXus entry.', - a_eln = ELNAnnotation(component=ELNComponentEnum.ReferenceEditQuantity) + a_eln=ELNAnnotation(component=ELNComponentEnum.ReferenceEditQuantity), ) def get_read_write_functions(self) -> tuple[Callable, Callable]: @@ -1308,12 +1309,15 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger'): if self.hdf5_handler.data_file != self.auxiliary_file: self.auxiliary_file = self.hdf5_handler.data_file - if (archive.m_context.raw_path_exists(self.auxiliary_file) and - self.auxiliary_file.endswith('.nxs')): - nx_entry_id = get_entry_id_from_file_name(archive=archive, - file_name=self.auxiliary_file) - ref_to_nx_entry_data = get_reference(archive.metadata.upload_id, - nx_entry_id) + if archive.m_context.raw_path_exists( + self.auxiliary_file + ) and self.auxiliary_file.endswith('.nxs'): + nx_entry_id = get_entry_id_from_file_name( + archive=archive, file_name=self.auxiliary_file + ) + ref_to_nx_entry_data = get_reference( + archive.metadata.upload_id, nx_entry_id + ) self.nexus_results = f'{ref_to_nx_entry_data}' super().normalize(archive, logger)