diff --git a/cotede/qctests/constant_cluster_size.py b/cotede/qctests/constant_cluster_size.py index db8b62e..9abcc27 100644 --- a/cotede/qctests/constant_cluster_size.py +++ b/cotede/qctests/constant_cluster_size.py @@ -4,7 +4,7 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar def constant_cluster_size(x, tol=0): @@ -36,7 +36,7 @@ def constant_cluster_size(x, tol=0): return cluster_size -class ConstantClusterSize(QCCheck): +class ConstantClusterSize(QCCheckVar): def set_features(self): cluster_size = constant_cluster_size(self.data[self.varname]) N = ma.compressed(self.data[self.varname]).size diff --git a/cotede/qctests/cum_rate_of_change.py b/cotede/qctests/cum_rate_of_change.py index df4544e..0eb368e 100644 --- a/cotede/qctests/cum_rate_of_change.py +++ b/cotede/qctests/cum_rate_of_change.py @@ -24,7 +24,7 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar def cum_rate_of_change(x, memory): @@ -39,7 +39,7 @@ def cum_rate_of_change(x, memory): return y -class CumRateOfChange(QCCheck): +class CumRateOfChange(QCCheckVar): def set_features(self): self.features = { 'cum_rate_of_change': cum_rate_of_change( diff --git a/cotede/qctests/digit_roll_over.py b/cotede/qctests/digit_roll_over.py index 60f72c4..c0eb285 100644 --- a/cotede/qctests/digit_roll_over.py +++ b/cotede/qctests/digit_roll_over.py @@ -13,13 +13,13 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar from .rate_of_change import rate_of_change module_logger = logging.getLogger(__name__) -class DigitRollOver(QCCheck): +class DigitRollOver(QCCheckVar): def set_features(self): self.features = { 'rate_of_change': rate_of_change(self.data[self.varname])} diff --git a/cotede/qctests/global_range.py b/cotede/qctests/global_range.py index 7c2ec82..cb4ed79 100644 --- a/cotede/qctests/global_range.py +++ b/cotede/qctests/global_range.py @@ -15,12 +15,12 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar module_logger = logging.getLogger(__name__) -class GlobalRange(QCCheck): +class GlobalRange(QCCheckVar): def test(self): self.flags = {} assert ('minval' in self.cfg) and ('maxval' in self.cfg), \ diff --git a/cotede/qctests/gradient.py b/cotede/qctests/gradient.py index 8585bb9..b8744b9 100644 --- a/cotede/qctests/gradient.py +++ b/cotede/qctests/gradient.py @@ -11,7 +11,7 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar module_logger = logging.getLogger(__name__) @@ -28,7 +28,7 @@ def gradient(x): return y -class Gradient(QCCheck): +class Gradient(QCCheckVar): def set_features(self): self.features = {'gradient': gradient(self.data[self.varname])} diff --git a/cotede/qctests/gradient_depthconditional.py b/cotede/qctests/gradient_depthconditional.py index fd194d4..a07dfef 100644 --- a/cotede/qctests/gradient_depthconditional.py +++ b/cotede/qctests/gradient_depthconditional.py @@ -11,13 +11,13 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar from .gradient import gradient module_logger = logging.getLogger(__name__) -class GradientDepthConditional(QCCheck): +class GradientDepthConditional(QCCheckVar): def set_features(self): self.features = {"gradient": gradient(self.data[self.varname])} diff --git a/cotede/qctests/profile_envelop.py b/cotede/qctests/profile_envelop.py index 0e18ce1..313e5d6 100644 --- a/cotede/qctests/profile_envelop.py +++ b/cotede/qctests/profile_envelop.py @@ -9,7 +9,7 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar module_logger = logging.getLogger(__name__) @@ -40,7 +40,7 @@ def profile_envelop(data, cfg, varname): return flag -class ProfileEnvelop(QCCheck): +class ProfileEnvelop(QCCheckVar): def test(self): self.flags = {} diff --git a/cotede/qctests/qctests.py b/cotede/qctests/qctests.py index 719cce3..2fd6b57 100644 --- a/cotede/qctests/qctests.py +++ b/cotede/qctests/qctests.py @@ -73,9 +73,8 @@ def constant_value(): class QCCheck(object): """Basic template for a QC check """ - def __init__(self, data, varname, cfg, autoflag=True): + def __init__(self, data, cfg=None, autoflag=True): self.data = data - self.varname = varname self.cfg = cfg self.set_flags() @@ -83,6 +82,16 @@ def __init__(self, data, varname, cfg, autoflag=True): if autoflag: self.test() + def __getitem__(self, key): + return self.data[key] + + @property + def attrs(self): + return self.data.attrs + + def set_features(self): + self.features = {} + def set_flags(self): try: self.flag_good = self.cfg['flag_good'] @@ -99,3 +108,11 @@ def set_flags(self): def keys(self): return self.features.keys() + \ ["flag_%s" % f for f in self.flags.keys()] + + +class QCCheckVar(QCCheck): + """Template for a QC check of a specific variable + """ + def __init__(self, data, varname, cfg=None, autoflag=True): + self.varname = varname + super().__init__(data, cfg, autoflag) diff --git a/cotede/qctests/rate_of_change.py b/cotede/qctests/rate_of_change.py index 290b1ce..a0e9ed9 100644 --- a/cotede/qctests/rate_of_change.py +++ b/cotede/qctests/rate_of_change.py @@ -15,7 +15,7 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar module_logger = logging.getLogger(__name__) @@ -27,7 +27,7 @@ def rate_of_change(x): return y -class RateOfChange(QCCheck): +class RateOfChange(QCCheckVar): def set_features(self): self.features = { 'rate_of_change': rate_of_change(self.data[self.varname])} diff --git a/cotede/qctests/spike.py b/cotede/qctests/spike.py index f7ddb77..0a0d232 100644 --- a/cotede/qctests/spike.py +++ b/cotede/qctests/spike.py @@ -11,7 +11,7 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar module_logger = logging.getLogger(__name__) @@ -25,7 +25,7 @@ def spike(x): return y -class Spike(QCCheck): +class Spike(QCCheckVar): def set_features(self): self.features = {'spike': spike(self.data[self.varname])} diff --git a/cotede/qctests/spike_depthconditional.py b/cotede/qctests/spike_depthconditional.py index c779ee9..6bff665 100644 --- a/cotede/qctests/spike_depthconditional.py +++ b/cotede/qctests/spike_depthconditional.py @@ -11,14 +11,14 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar from .spike import spike module_logger = logging.getLogger(__name__) -class SpikeDepthConditional(QCCheck): +class SpikeDepthConditional(QCCheckVar): def set_features(self): self.features = {"spike": spike(self.data[self.varname])} diff --git a/cotede/qctests/stuck_value.py b/cotede/qctests/stuck_value.py index d4b08e6..89a4d9c 100644 --- a/cotede/qctests/stuck_value.py +++ b/cotede/qctests/stuck_value.py @@ -7,15 +7,12 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar module_logger = logging.getLogger(__name__) -class StuckValue(QCCheck): - def set_features(self): - self.features = {} - +class StuckValue(QCCheckVar): def test(self): self.flags = {} diff --git a/cotede/qctests/tukey53H.py b/cotede/qctests/tukey53H.py index 88e0550..bd5a8cf 100644 --- a/cotede/qctests/tukey53H.py +++ b/cotede/qctests/tukey53H.py @@ -8,7 +8,7 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar module_logger = logging.getLogger(__name__) @@ -53,7 +53,7 @@ def tukey53H_norm(x, l=12): return Delta/sigma -class Tukey53H(QCCheck): +class Tukey53H(QCCheckVar): def set_features(self): self.features = { 'tukey53H': tukey53H(self.data[self.varname]), diff --git a/cotede/qctests/valid_geolocation.py b/cotede/qctests/valid_geolocation.py index 3f75a3b..6f704a7 100644 --- a/cotede/qctests/valid_geolocation.py +++ b/cotede/qctests/valid_geolocation.py @@ -11,7 +11,7 @@ import numpy as np from numpy import ma -from .qctests import QCCheck +from .qctests import QCCheckVar module_logger = logging.getLogger(__name__) @@ -29,7 +29,7 @@ def valid_geolocation(lat, lon): return idx -class ValidGeolocation(QCCheck): +class ValidGeolocation(QCCheckVar): def test(self): self.flags = {}