Skip to content

Commit

Permalink
ENH: Bug fix for setting tests when it's a scalar (ARM-DOE#681)
Browse files Browse the repository at this point in the history
* ENH: Bug fix for setting tests when it's a scalar

* ENH: Adding tests and fixing one last bug

* ENH: pep8 issue
  • Loading branch information
AdamTheisen authored Jun 8, 2023
1 parent 8ad2c7b commit 9584cb5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions act/qc/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def add_dqr_to_qc(

if 'time' not in ds[var_name].dims:
ind = np.where((ds[var_name].values == ds[var_name].values) | (np.isnan(ds[var_name].values)))
if np.size(ind) == 1:
ind = ind[0]

if dqr_no in dqr_results.keys():
dqr_results[dqr_no]['index'] = np.append(dqr_results[dqr_no]['index'], ind)
Expand Down
5 changes: 4 additions & 1 deletion act/qc/qcfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,10 @@ def set_test(self, var_name, index=None, test_number=None, flag_value=False):
if flag_value:
qc_variable[index] = test_number
else:
qc_variable[index] = set_bit(qc_variable[index], test_number)
if np.size(qc_variable) > 1:
qc_variable[index] = set_bit(qc_variable[index], test_number)
elif index == 0:
qc_variable = set_bit(qc_variable, test_number)

self._ds[qc_var_name].values = qc_variable

Expand Down
1 change: 1 addition & 0 deletions act/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'EXAMPLE_CLOUDPHASE'
'EXAMPLE_ECOR',
'EXAMPLE_SEBS',
'EXAMPLE_ENA_MET',
]
},
)
Binary file added act/tests/data/enametC1.b1.20221109.000000.cdf
Binary file not shown.
1 change: 1 addition & 0 deletions act/tests/sample_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@
EXAMPLE_ECOR = os.path.join(DATA_PATH, 'sgp30ecorE14.b1.20190601.000000.cdf')
EXAMPLE_SEBS = os.path.join(DATA_PATH, 'sgpsebsE14.b1.20190601.000000.cdf')
EXAMPLE_MFAS_SODAR = os.path.join(DATA_PATH, 'sodar.20230404.mnd')
EXAMPLE_ENA_MET = os.path.join(DATA_PATH, 'enametC1.b1.20221109.000000.cdf')
22 changes: 21 additions & 1 deletion act/tests/test_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
EXAMPLE_MFRSR,
EXAMPLE_IRT25m20s,
EXAMPLE_BRS,
EXAMPLE_MET_YAML
EXAMPLE_MET_YAML,
EXAMPLE_ENA_MET
)
from act.qc.bsrn_tests import _calculate_solar_parameters
from act.qc.add_supplemental_qc import read_yaml_supplemental_qc, apply_supplemental_qc
Expand Down Expand Up @@ -1398,3 +1399,22 @@ def test_read_yaml_supplemental_qc():
assert np.sum(ds['qc_temp_mean'].values) == 2840

del ds


def test_scalar_dqr():
# Test DQR Webservice using known DQR
ds = read_netcdf(EXAMPLE_ENA_MET)

# DQR webservice does go down, so ensure it
# properly runs first before testing
try:
ds = add_dqr_to_qc(ds)
ran = True
except ValueError:
ran = False

if ran:
assert 'qc_lat' in ds
assert np.size(ds['qc_lat'].values) == 1
assert np.size(ds['qc_alt'].values) == 1
assert np.size(ds['base_time'].values) == 1

0 comments on commit 9584cb5

Please sign in to comment.