From 62c8297d4ff94afae61daac1fee5a20303053501 Mon Sep 17 00:00:00 2001 From: Ken Kehoe Date: Wed, 17 Jul 2024 14:03:59 +0000 Subject: [PATCH] Checking for scalar variables before indexing. Resizing the QC data variable when it only has a time dimension but data has time/height --- act/qc/qcfilter.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/act/qc/qcfilter.py b/act/qc/qcfilter.py index 27b352fdf2..289da14136 100644 --- a/act/qc/qcfilter.py +++ b/act/qc/qcfilter.py @@ -13,8 +13,7 @@ @xr.register_dataset_accessor('qcfilter') -class QCFilter(qctests.QCTests, comparison_tests.QCTests, - bsrn_tests.QCTests, qc_summary.QCSummary): +class QCFilter(qctests.QCTests, comparison_tests.QCTests, bsrn_tests.QCTests, qc_summary.QCSummary): """ A class for building quality control variables containing arrays for filtering data based on a set of test condition typically based on the @@ -540,7 +539,10 @@ def set_test(self, var_name, index=None, test_number=None, flag_value=False): if index is not None: if flag_value: - qc_variable[index] = test_number + if len(qc_variable.shape) == 0: + qc_variable = test_number + else: + qc_variable[index] = test_number else: if bool(np.shape(index)): qc_variable[index] = set_bit(qc_variable[index], test_number) @@ -905,7 +907,14 @@ def get_masked_data( mask = np.zeros(variable.shape, dtype=bool) for test in test_numbers: - mask = mask | self._ds.qcfilter.get_qc_test_mask(var_name, test, flag_value=flag_value) + qc_test_mask = self._ds.qcfilter.get_qc_test_mask(var_name, test, flag_value=flag_value) + # There are some variables that incorrectly have only a time dimension for QC + # variable which corresponds to a time-height data variable. If that is the case + # streach the QC Mask along the height dimension to match for broadcasting. + if variable.shape != qc_test_mask.shape: + qc_test_mask = np.resize(qc_test_mask, variable.shape) + + mask = mask | qc_test_mask # Convert data numpy array into masked array try: