Skip to content

Commit

Permalink
Adding option to remove QC variable attributes. Updated method to add…
Browse files Browse the repository at this point in the history
… info to history attribute. Removed command that updates orginal Dataset.
  • Loading branch information
kenkehoe committed Aug 9, 2024
1 parent b50fd21 commit 85516b2
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions act/qc/qc_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import datetime
import copy


class QCSummary:
Expand All @@ -23,7 +24,9 @@ def __init__(self, ds):
"""initialize"""
self._ds = ds

def create_qc_summary(self, cleanup_qc=False):
def create_qc_summary(
self, cleanup_qc=False, remove_attrs=['fail_min', 'fail_max', 'fail_delta']
):
"""
Method to convert embedded quality control to summary QC that utilzes
flag values instead of flag masks and summarizes the assessments to only
Expand All @@ -34,6 +37,8 @@ def create_qc_summary(self, cleanup_qc=False):
Call clean.cleanup() method to convert to standardized ancillary quality control
variables. The quality control summary requires the current embedded quality
control variables to use ACT standards.
remove_attrs : None, list
Quality Control variable attributes to remove after creating the summary.
Returns
-------
Expand All @@ -49,17 +54,17 @@ def create_qc_summary(self, cleanup_qc=False):
'Bad',
]
standard_meanings = [
"Data suspect, further analysis recommended",
"Data suspect, further analysis recommended",
"Data incorrect, use not recommended",
"Data incorrect, use not recommended",
"Data suspect further analysis recommended",
"Data suspect further analysis recommended",
"Data incorrect use not recommended",
"Data incorrect use not recommended",
]

if cleanup_qc:
self._ds.clean.cleanup()

return_ds = self._ds.copy()

if cleanup_qc:
return_ds.clean.cleanup()

added = False
for var_name in list(self._ds.data_vars):
qc_var_name = self.check_for_ancillary_qc(var_name, add_if_missing=False, cleanup=False)
Expand Down Expand Up @@ -111,14 +116,23 @@ def create_qc_summary(self, cleanup_qc=False):
flag_value=True,
)

self._ds.update({qc_var_name: return_ds[qc_var_name]})
# Remove fail limit variable attributes
if remove_attrs is not None:
for att_name in copy.copy(list(return_ds[qc_var_name].attrs.keys())):
if att_name in remove_attrs:
del return_ds[qc_var_name].attrs[att_name]

if added:
history = return_ds.attrs['history']
history += (
" ; Quality control summary implemented by ACT at "
f"{datetime.datetime.utcnow().isoformat()} UTC."
from act import __version__ as version

history_value = (
f"Quality control summary implemented by ACT-{version} at "
f"{datetime.datetime.utcnow().replace(microsecond=0)} UTC"
)
return_ds.attrs['history'] = history

if 'history' in list(return_ds.attrs.keys()):
return_ds.attrs['history'] += f" ; {history_value}"
else:
return_ds.attrs['history'] = history_value

return return_ds

0 comments on commit 85516b2

Please sign in to comment.