Skip to content

Commit

Permalink
Fix qcfilter.add_test index (#712)
Browse files Browse the repository at this point in the history
* Fix erroneous flag for scalar qc and boolean index

* Add test for scalar variables

* Add one more check for default index=None
  • Loading branch information
maxwelllevin authored Sep 25, 2023
1 parent 5d5a3de commit 859ef45
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion act/qc/qcfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def set_test(self, var_name, index=None, test_number=None, flag_value=False):
if flag_value:
qc_variable[index] = test_number
else:
if np.size(qc_variable) > 1:
if bool(np.shape(index)):
qc_variable[index] = set_bit(qc_variable[index], test_number)
elif index == 0:
qc_variable = set_bit(qc_variable, test_number)
Expand Down
39 changes: 39 additions & 0 deletions act/tests/test_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,45 @@ def test_qcfilter():
== 0
)

# Test adding QC for length-1 variables
ds['west'] = ('west', ['W'])
ds['avg_wind_speed'] = ('west', [20])

# Should not fail the test
ds.qcfilter.add_test(
'avg_wind_speed',
index=ds.avg_wind_speed.data > 100,
test_meaning='testing bool flag: false',
test_assessment='Suspect',
)
assert ds.qc_avg_wind_speed.data == 0

# Should fail the test
ds.qcfilter.add_test(
'avg_wind_speed',
index=ds.avg_wind_speed.data < 100,
test_meaning='testing bool flag: true',
test_assessment='Suspect',
)
assert ds.qc_avg_wind_speed.data == 2

# Should fail the test
ds.qcfilter.add_test(
'avg_wind_speed',
index=[0],
test_meaning='testing idx flag: true',
test_assessment='Suspect',
)
assert ds.qc_avg_wind_speed.data == 6

# Should not fail the test
ds.qcfilter.add_test(
'avg_wind_speed',
test_meaning='testing idx flag: false',
test_assessment='Suspect',
)
assert ds.qc_avg_wind_speed.data == 6

# Unset a test
ds.qcfilter.unset_test(var_name, index=0, test_number=result['test_number'])
# Remove the test
Expand Down

0 comments on commit 859ef45

Please sign in to comment.