Skip to content

Commit

Permalink
Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder committed Dec 20, 2024
1 parent 17fdf24 commit ae97d7c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
9 changes: 4 additions & 5 deletions src/nomad_measurements/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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():
Expand Down
33 changes: 24 additions & 9 deletions src/nomad_measurements/xrd/nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
),
}

22 changes: 13 additions & 9 deletions src/nomad_measurements/xrd/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ae97d7c

Please sign in to comment.