Skip to content

Commit

Permalink
ENH: Fix to resolve #750 for older ARM qc convention in files (#755)
Browse files Browse the repository at this point in the history
* ENH: Fix to resolve #750 for older ARM qc convention in files

* ENH: Adding in tesets

* ENH: Streamlining code
  • Loading branch information
AdamTheisen authored Nov 17, 2023
1 parent 787314e commit 402389d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
31 changes: 30 additions & 1 deletion act/qc/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,36 @@ def get_attr_info(self, variable=None, flag=False):
# If nothing to return set to None
return_dict = None

# If no QC is found but there's a Mentor_QC_Field_Information global attribute,
# hard code the information. This is for older ARM files that had QC information
# in this global attribute. For these cases, this should hold 100%
if return_dict is None and 'Mentor_QC_Field_Information' in self._ds.attrs:
qc_att = self._ds.attrs['Mentor_QC_Field_Information']
if 'Basic mentor QC checks' in qc_att:
if len(qc_att) == 920 or len(qc_att) == 1562:
return_dict = dict()
return_dict['flag_meanings'] = [
'Value is equal to missing_value.',
'Value is less than the valid_min.',
'Value is greater than the valid_max.',
'Difference between current and previous values exceeds valid_delta.'
]
return_dict['flag_tests'] = [1, 2, 3, 4]
return_dict['flag_masks'] = [1, 2, 4, 8]
return_dict['flag_assessments'] = ['Bad', 'Bad', 'Bad', 'Indeterminate']
return_dict['flag_values'] = []
return_dict['flag_comments'] = []
return_dict['arm_attributes'] = [
'bit_1_description',
'bit_1_assessment',
'bit_2_description',
'bit_2_assessment',
'bit_3_description',
'bit_3_assessment',
'bit_4_description',
'bit_4_assessment'
]

return return_dict

def clean_arm_state_variables(
Expand Down Expand Up @@ -643,7 +673,6 @@ def clean_arm_qc(
'flag_values',
'flag_comments',
]:

if qc_attributes is not None and len(qc_attributes[attr]) > 0:
# Only add if attribute does not exists
if attr in self._ds[qc_var].attrs.keys() is False:
Expand Down
1 change: 1 addition & 0 deletions act/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
'EXAMPLE_SEBS',
'EXAMPLE_ENA_MET',
'EXAMPLE_CCN',
'EXAMPLE_OLD_QC',
]
},
)
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 @@ -70,3 +70,4 @@
EXAMPLE_MFAS_SODAR = os.path.join(DATA_PATH, 'sodar.20230404.mnd')
EXAMPLE_ENA_MET = os.path.join(DATA_PATH, 'enametC1.b1.20221109.000000.cdf')
EXAMPLE_CCN = os.path.join(DATA_PATH, 'sgpaosccn2colaE13.b1.20170903.000000.nc')
EXAMPLE_OLD_QC = os.path.join(DATA_PATH, 'sgp30ecorE6.b1.20040705.000000.cdf')
11 changes: 10 additions & 1 deletion act/tests/test_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
EXAMPLE_IRT25m20s,
EXAMPLE_BRS,
EXAMPLE_MET_YAML,
EXAMPLE_ENA_MET
EXAMPLE_ENA_MET,
EXAMPLE_OLD_QC
)
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 @@ -1474,3 +1475,11 @@ def test_scalar_dqr():
assert np.size(ds['qc_lat'].values) == 1
assert np.size(ds['qc_alt'].values) == 1
assert np.size(ds['base_time'].values) == 1


def test_get_attr_info():
ds = read_netcdf(EXAMPLE_OLD_QC, cleanup_qc=True)
assert 'flag_assessments' in ds['qc_lv'].attrs
assert 'fail_min' in ds['qc_lv'].attrs
assert ds['qc_lv'].attrs['flag_assessments'][0] == 'Bad'
assert ds['qc_lv'].attrs['flag_masks'][-1] == 4

0 comments on commit 402389d

Please sign in to comment.