Skip to content

Commit

Permalink
remove apply_qc_checks and other fns with qc_check_ prefix (#57)
Browse files Browse the repository at this point in the history
with the new filter_qc function and the self.qc attrs (upcoming, see #56),
these unused functions are removed. #56 also explains how the whole procedure provides
more flexibility for the user in terms of QC selection of checks and filtering flags.
  • Loading branch information
Geet-George committed Nov 15, 2023
1 parent d9306f1 commit 855d0b2
Showing 1 changed file with 0 additions and 92 deletions.
92 changes: 0 additions & 92 deletions src/halodrops/sonde.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,40 +240,6 @@ def weighted_fullness(
)
return self

def qc_check_profile_fullness(self, qc_threshold=0.8):
"""Return True if profile coverage is above threshold
The function checks if the attributes set by the `weighted_fullness` method are above the threshold.
If the attributes are not set, the function will raise an error.
If the attributes are set, the function will check if all of them are above the threshold and if not, it will return False.
Parameters
----------
qc_threshold : float, optional
Threshold for profile fullness, by default 0.8
Returns
-------
bool
True if profile coverage is above threshold, else False
Raises
------
ValueError
If no attributes starting with `profile_coverage_` exist.
"""
attr_prefix = "profile_fullness_"
attributes = [attr for attr in dir(self) if attr.startswith(attr_prefix)]
if len(attributes) > 0:
for attribute in attributes:
if getattr(self, attribute) < qc_threshold:
return False
return True
else:
raise ValueError(
"No attributes starting with f`{attr_prefix}` does not exist. Please run `weighted_fullness` method first."
)

def near_surface_coverage(
self,
variables=["u_wind", "v_wind", "rh", "tdry", "pres"],
Expand Down Expand Up @@ -320,64 +286,6 @@ def near_surface_coverage(
)
return self

def qc_check_near_surface_coverage(self, samples_threshold=10):
"""Return True if near surface coverage is above threshold
Parameters
----------
samples_threshold : int, optional
Threshold for number of samples near surface, by default 10
Returns
-------
bool
True if near surface coverage is above threshold, else False
"""
attr_prefix = "near_surface_coverage_"
attributes = [attr for attr in dir(self) if attr.startswith(attr_prefix)]

if len(attributes) > 0:
for attribute in attributes:
if getattr(self, attribute) < samples_threshold:
return False
return True
else:
raise ValueError(
"No attributes starting with f`{attr_prefix}` does not exist. Please run `near_surface_coverage` method first."
)

def apply_qc_checks(self, qc_checks):
"""Apply QC checks to the sonde
Parameters
----------
qc_checks : list
List of QC checks to be applied; names must remove the `qc_check_` prefix of the method names
Raises
------
ValueError
If the QC check does not exist.
Attributes Set
--------------
profile_fullness : bool
Return value of qc_check for profile coverage (qc_check_profile_fullness)
near_surface_coverage : bool
Return value of qc_check for near surface coverage (qc_check_near_surface_coverage)
"""
qc_functions = {
"profile_fullness": self.qc_check_profile_fullness,
"near_surface_coverage": self.qc_check_near_surface_coverage,
}

for check in qc_checks:
func = qc_functions.get(check)
if func is not None:
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.
Expand Down

0 comments on commit 855d0b2

Please sign in to comment.