Skip to content

Commit

Permalink
Checking for scalar variables before indexing. Resizing the QC data v…
Browse files Browse the repository at this point in the history
…ariable when it only has a time dimension but data has time/height
  • Loading branch information
kenkehoe committed Jul 17, 2024
1 parent 31dafc5 commit 62c8297
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions act/qc/qcfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 62c8297

Please sign in to comment.