Skip to content

Commit

Permalink
add qc_filter function (#57)
Browse files Browse the repository at this point in the history
>
> the self.qc attribute is still not available in the class. this will be added later on.
> see #56 for a detailed explanation.
  • Loading branch information
Geet-George committed Nov 15, 2023
1 parent 63e069e commit d9306f1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/halodrops/sonde.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,39 @@ def apply_qc_checks(self, qc_checks):
object.__setattr__(self, f"{check}", func())
else:
raise ValueError(f"The QC function '{check}' does not exist.")

def qc_filter(self, filter_flags):
"""
Filters the sonde based on a list of QC flags. If any of the flags are False, the sonde will be filtered out from creating L2.
If the sonde passes all the QC checks, the attributes listed in filter_flags will be removed from the sonde object.
Parameters
----------
filter_flags : list
List of QC-related attribute names to be checked.
Returns
-------
self : object
The sonde object itself, with the attributes listed in filter_flags removed if it passes all the QC checks.
Raises
------
ValueError
If a flag in filter_flags does not exist as an attribute of the sonde object.
"""
for flag in filter_flags:
if not hasattr(self.qc, flag):
raise ValueError(
f"The attribute {flag} does not exist. Please check your skipped QC functions or your provided list of filter flags."
)
if not bool(getattr(self.qc, flag)):
return print(
f"{flag} returned False. Therefore, filtering this sonde ({self.serial_id}) out from L2"
)

# If the sonde passes all the QC checks, remove all attributes listed in filter_flags
for flag in filter_flags:
delattr(self, flag)

return self

0 comments on commit d9306f1

Please sign in to comment.