From 617cca71a521b710d183d058fa894ea3889d03d0 Mon Sep 17 00:00:00 2001 From: x01da Date: Wed, 27 May 2026 10:06:21 +0200 Subject: [PATCH] fix: nexus structure safe guards. --- .../file_writer/debye_nexus_structure.py | 81 ++++++++++--------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/debye_bec/file_writer/debye_nexus_structure.py b/debye_bec/file_writer/debye_nexus_structure.py index 8364845..b472e94 100644 --- a/debye_bec/file_writer/debye_nexus_structure.py +++ b/debye_bec/file_writer/debye_nexus_structure.py @@ -239,49 +239,52 @@ class DebyeNexusStructure(DefaultFormat): measurement_mode = entry.create_group(name="mode") measurement_mode.attrs["NX_class"] = "NX_CHAR" - if (int(ci_chans_bits) & 0x7F) != 0: - # Create a dataset - rayspec_sdd_active = measurement_mode.create_group( - name="Multi_Element_Partial_Fluorescence_Yield" - ) - me_sdd = rayspec_sdd_active.create_dataset( - name="Detector", data="Rayspec 7 element Silicon Drift Detector" - ) - me_sdd.attrs["NX_class"] = "NX_CHAR" + if ci_chans_bits is not None: + if (int(ci_chans_bits) & 0x7F) != 0: + # Create a dataset + rayspec_sdd_active = measurement_mode.create_group( + name="Multi_Element_Partial_Fluorescence_Yield" + ) + me_sdd = rayspec_sdd_active.create_dataset( + name="Detector", data="Rayspec 7 element Silicon Drift Detector" + ) + me_sdd.attrs["NX_class"] = "NX_CHAR" - if (int(ci_chans_bits) & (1 << 8)) != 0: - # Create a dataset - ketek_sdd_active = measurement_mode.create_group( - name="Single_Element_Partial_Fluorescence_Yield" - ) - se_sdd = ketek_sdd_active.create_dataset( - name="Detector", data="Ketex mini single element Silicon Drift Detector" - ) - se_sdd.attrs["NX_class"] = "NX_CHAR" + if (int(ci_chans_bits) & (1 << 8)) != 0: + # Create a dataset + ketek_sdd_active = measurement_mode.create_group( + name="Single_Element_Partial_Fluorescence_Yield" + ) + se_sdd = ketek_sdd_active.create_dataset( + name="Detector", data="Ketex mini single element Silicon Drift Detector" + ) + se_sdd.attrs["NX_class"] = "NX_CHAR" - if (int(ai_chans_bits) & (1 << 6)) != 0: - # Create a dataset - pips_active = measurement_mode.create_group(name="Total_Flourescence_Yield") - tfy = pips_active.create_dataset( - name="Detector", data="Mirion Technologies Partially Depeleted PIPS Detector" - ) - tfy.attrs["NX_class"] = "NX_CHAR" + if ai_chans_bits is not None: + if (int(ai_chans_bits) & (1 << 6)) != 0: + # Create a dataset + pips_active = measurement_mode.create_group(name="Total_Flourescence_Yield") + tfy = pips_active.create_dataset( + name="Detector", + data="Mirion Technologies Partially Depeleted PIPS Detector", + ) + tfy.attrs["NX_class"] = "NX_CHAR" - if ((int(ai_chans_bits) & (1 << 0)) != 0) & ((int(ai_chans_bits) & (1 << 2)) != 0): - # Create a dataset - ai0ai2_active = measurement_mode.create_group(name="Sample_Transmission") - sam_trans = ai0ai2_active.create_dataset( - name="Detector", data="Ionitec 15 cm gas filled Ionisation Chambers" - ) - sam_trans.attrs["NX_class"] = "NX_CHAR" + if ((int(ai_chans_bits) & (1 << 0)) != 0) & ((int(ai_chans_bits) & (1 << 2)) != 0): + # Create a dataset + ai0ai2_active = measurement_mode.create_group(name="Sample_Transmission") + sam_trans = ai0ai2_active.create_dataset( + name="Detector", data="Ionitec 15 cm gas filled Ionisation Chambers" + ) + sam_trans.attrs["NX_class"] = "NX_CHAR" - if ((int(ai_chans_bits) & (1 << 2)) != 0) & ((int(ai_chans_bits) & (1 << 4)) != 0): - # Create a dataset - ai2ai4_active = measurement_mode.create_group(name="Reference_Transmission") - ref_trans = ai2ai4_active.create_dataset( - name="Detector", data="Ionitec 15 cm gas filled Ionisation Chambers" - ) - ref_trans.attrs["NX_class"] = "NX_CHAR" + if ((int(ai_chans_bits) & (1 << 2)) != 0) & ((int(ai_chans_bits) & (1 << 4)) != 0): + # Create a dataset + ai2ai4_active = measurement_mode.create_group(name="Reference_Transmission") + ref_trans = ai2ai4_active.create_dataset( + name="Detector", data="Ionitec 15 cm gas filled Ionisation Chambers" + ) + ref_trans.attrs["NX_class"] = "NX_CHAR" main_data = entry.create_group(name="data") main_data.attrs["NX_class"] = "NXdata"