From 2140458375c17e741d44e36be707cc826b754b36 Mon Sep 17 00:00:00 2001 From: Johann Benerradi Date: Fri, 6 Jun 2025 15:21:45 +0100 Subject: [PATCH 1/3] Draft new validation of conflicting measurementList and measurementLists --- snirf/pysnirf2.py | 15 +++++++++------ tests/test.py | 3 +++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/snirf/pysnirf2.py b/snirf/pysnirf2.py index 18023b0..ad6d771 100644 --- a/snirf/pysnirf2.py +++ b/snirf/pysnirf2.py @@ -576,6 +576,9 @@ def _read_float_array(dataset: h5py.Dataset) -> np.ndarray: (27, 1, 'The optional indexed group has no elements'), # OK (Severity 0) 'OK': (28, 0, 'No issues detected'), + 'CONFLICTING_FIELDS_PRESENT': ( + 29, 3, 'Multiple conflicting fields are present in the same file' + ) } @@ -6764,19 +6767,19 @@ def _validate(self, result: ValidationResult): # Override measurementList/measurementLists validation, only one is required ml = self.measurementList is not None mls = self.measurementLists is not None - if (ml and mls): + if (ml or mls): result._add(self.location + '/measurementList', 'OK') result._add(self.location + '/measurementLists', 'OK') - elif (ml or mls): + elif (ml and mls): result._add(self.location + '/measurementList', - ['OPTIONAL_DATASET_MISSING', 'OK'][int(ml)]) + 'CONFLICTING_FIELDS_PRESENT') result._add(self.location + '/measurementLists', - ['OPTIONAL_DATASET_MISSING', 'OK'][int(mls)]) + 'CONFLICTING_FIELDS_PRESENT') else: result._add(self.location + '/measurementList', - ['REQUIRED_DATASET_MISSING', 'OK'][int(ml)]) + 'REQUIRED_DATASET_MISSING') result._add(self.location + '/measurementLists', - ['REQUIRED_DATASET_MISSING', 'OK'][int(mls)]) + 'REQUIRED_DATASET_MISSING') # Check time/dataTimeSeries length agreement if all(attr is not None for attr in [self.time, self.dataTimeSeries]): diff --git a/tests/test.py b/tests/test.py index 7f3c0e8..b509270 100644 --- a/tests/test.py +++ b/tests/test.py @@ -817,6 +817,9 @@ def test_dynamic(self): assert sizes[1] < sizes[0], 'Dynamically-loaded files not smaller in memory' + def test_conflicting_fields(self): + # TODO + pass def setUp(self): if VERBOSE: From 2d5876ad2468ce7af5d01a7ebb8051e7b15a89ae Mon Sep 17 00:00:00 2001 From: sreekanth kura Date: Thu, 3 Jul 2025 14:01:47 -0400 Subject: [PATCH 2/3] Fix issues found during review --- snirf/pysnirf2.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/snirf/pysnirf2.py b/snirf/pysnirf2.py index ad6d771..949b517 100644 --- a/snirf/pysnirf2.py +++ b/snirf/pysnirf2.py @@ -6765,16 +6765,24 @@ def measurementLists_to_measurementList(self): def _validate(self, result: ValidationResult): # Override measurementList/measurementLists validation, only one is required - ml = self.measurementList is not None - mls = self.measurementLists is not None - if (ml or mls): - result._add(self.location + '/measurementList', 'OK') - result._add(self.location + '/measurementLists', 'OK') - elif (ml and mls): + if self.measurementList: + ml = True + else: + ml = False + + if self.measurementLists: + mls = True + else: + mls = False + mls = self.measurementLists.sourceIndex is not None + if (ml and mls): result._add(self.location + '/measurementList', 'CONFLICTING_FIELDS_PRESENT') result._add(self.location + '/measurementLists', 'CONFLICTING_FIELDS_PRESENT') + elif (ml or mls): + result._add(self.location + '/measurementList', 'OK') + result._add(self.location + '/measurementLists', 'OK') else: result._add(self.location + '/measurementList', 'REQUIRED_DATASET_MISSING') From 51a5ce7cb7d72feaee2fa92952fb74341473db48 Mon Sep 17 00:00:00 2001 From: sreekanth kura Date: Fri, 4 Jul 2025 08:26:51 -0400 Subject: [PATCH 3/3] Remove unused if condition --- snirf/pysnirf2.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/snirf/pysnirf2.py b/snirf/pysnirf2.py index 949b517..811a2e0 100644 --- a/snirf/pysnirf2.py +++ b/snirf/pysnirf2.py @@ -6770,10 +6770,6 @@ def _validate(self, result: ValidationResult): else: ml = False - if self.measurementLists: - mls = True - else: - mls = False mls = self.measurementLists.sourceIndex is not None if (ml and mls): result._add(self.location + '/measurementList',