From 0a553dbbe2510ace9dd5b687e78c699fcfa5ada8 Mon Sep 17 00:00:00 2001 From: Tristan Youngs Date: Wed, 20 Sep 2023 20:32:27 +0100 Subject: [PATCH] NeXuS Handling Fix 1 / ??? (#449) * Check for existence of key values before trying to read them. * Format. * More (gee this is fun). * Apply suggestions from code review Co-authored-by: Noella Spitz <101950441+rhinoella@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Noella Spitz <101950441+rhinoella@users.noreply.github.com> * not in. --------- Co-authored-by: Noella Spitz <101950441+rhinoella@users.noreply.github.com> --- .../dialogs/nexus_processing_dialog.py | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/gudpy/gui/widgets/dialogs/nexus_processing_dialog.py b/gudpy/gui/widgets/dialogs/nexus_processing_dialog.py index 5f6df4d4..5e8eb767 100644 --- a/gudpy/gui/widgets/dialogs/nexus_processing_dialog.py +++ b/gudpy/gui/widgets/dialogs/nexus_processing_dialog.py @@ -83,26 +83,35 @@ def initComponents(self): ) ) as fp: - spectra = fp["/raw_data_1/detector_1/spectrum_index"][()][ - : - ].tolist() + if "/raw_data_1/detector_1/spectrum_index" in fp: + spectra = fp["/raw_data_1/detector_1/spectrum_index"][()][ + : + ].tolist() + else: + spectra = [0] self.widget.lowerSpecSpinBox.setRange(min(spectra), max(spectra)) self.widget.upperSpecSpinBox.setRange(min(spectra), max(spectra)) - start = fp["/raw_data_1/start_time"][()][0].decode("utf8") - end = fp["/raw_data_1/end_time"][()][0].decode("utf8") start = ( - datetime.strptime(start, "%Y-%m-%dT%H:%M:%S") + datetime.today() + if "/raw_data_1/start_time" not in fp + else datetime.strptime( + fp["/raw_data_1/start_time"][()][0].decode("utf8"), + "%Y-%m-%dT%H:%M:%S", + ) ) end = ( - datetime.strptime(end, "%Y-%m-%dT%H:%M:%S") + datetime.today() + if "/raw_data_1/end_time" not in fp + else datetime.strptime( + fp["/raw_data_1/end_time"][()][0].decode("utf8"), + "%Y-%m-%dT%H:%M:%S", + ) ) self.start = QDateTime.fromString( start.isoformat(), Qt.ISODateWithMs ) - self.end = QDateTime.fromString( - end.isoformat(), Qt.ISODateWithMs - ) + self.end = QDateTime.fromString(end.isoformat(), Qt.ISODateWithMs) self.widget.lowerSpecSpinBox.setValue(min(spectra)) self.widget.upperSpecSpinBox.setValue(max(spectra))