Skip to content

Commit

Permalink
Generic classes for tests
Browse files Browse the repository at this point in the history
QCCheckVar is a variation of QCCheck that requires a varname. For
instance, a gradient check is for a specific variable like temperature.
  • Loading branch information
castelao committed Jan 14, 2020
1 parent 01bca37 commit 1f6e8b6
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 31 deletions.
4 changes: 2 additions & 2 deletions cotede/qctests/constant_cluster_size.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cotede/qctests/cum_rate_of_change.py
Expand Up @@ -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):
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions cotede/qctests/digit_roll_over.py
Expand Up @@ -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])}
Expand Down
4 changes: 2 additions & 2 deletions cotede/qctests/global_range.py
Expand Up @@ -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), \
Expand Down
4 changes: 2 additions & 2 deletions cotede/qctests/gradient.py
Expand Up @@ -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__)
Expand All @@ -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])}

Expand Down
4 changes: 2 additions & 2 deletions cotede/qctests/gradient_depthconditional.py
Expand Up @@ -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])}

Expand Down
4 changes: 2 additions & 2 deletions cotede/qctests/profile_envelop.py
Expand Up @@ -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__)

Expand Down Expand Up @@ -40,7 +40,7 @@ def profile_envelop(data, cfg, varname):
return flag


class ProfileEnvelop(QCCheck):
class ProfileEnvelop(QCCheckVar):
def test(self):
self.flags = {}

Expand Down
21 changes: 19 additions & 2 deletions cotede/qctests/qctests.py
Expand Up @@ -73,16 +73,25 @@ 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()
self.set_features()
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']
Expand All @@ -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)
4 changes: 2 additions & 2 deletions cotede/qctests/rate_of_change.py
Expand Up @@ -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__)
Expand All @@ -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])}
Expand Down
4 changes: 2 additions & 2 deletions cotede/qctests/spike.py
Expand Up @@ -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__)
Expand All @@ -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])}

Expand Down
4 changes: 2 additions & 2 deletions cotede/qctests/spike_depthconditional.py
Expand Up @@ -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])}

Expand Down
7 changes: 2 additions & 5 deletions cotede/qctests/stuck_value.py
Expand Up @@ -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 = {}

Expand Down
4 changes: 2 additions & 2 deletions cotede/qctests/tukey53H.py
Expand Up @@ -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__)
Expand Down Expand Up @@ -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]),
Expand Down
4 changes: 2 additions & 2 deletions cotede/qctests/valid_geolocation.py
Expand Up @@ -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__)

Expand All @@ -29,7 +29,7 @@ def valid_geolocation(lat, lon):
return idx


class ValidGeolocation(QCCheck):
class ValidGeolocation(QCCheckVar):
def test(self):
self.flags = {}

Expand Down

0 comments on commit 1f6e8b6

Please sign in to comment.