# Path: cotede/qctests/global_range.py
# class GlobalRange(QCCheckVar):
#     def test(self):
#         self.flags = {}
#         assert ("minval" in self.cfg) and (
#             "maxval" in self.cfg
#         ), "Missing limits: minval & maxval"
# 
#         assert self.cfg["minval"] < self.cfg["maxval"], (
#             "Global Range(%s): "
#             + "minval (%s) must be smaller than maxval(%s)"
#             % (self.varname, self.cfg["minval"], self.cfg["maxval"])
#         )
# 
#         minval = self.cfg["minval"]
#         maxval = self.cfg["maxval"]
# 
#         feature = np.atleast_1d(self.data[self.varname])
#         if isinstance(feature, ma.MaskedArray):
#             feature[feature.mask] = np.nan
#             feature = feature.data
# 
#         flag = np.zeros(np.shape(feature), dtype="i1")
#         flag[feature < minval] = self.flag_bad
#         flag[feature > maxval] = self.flag_bad
#         idx = (feature >= minval) & (feature <= maxval)
#         flag[idx] = self.flag_good
#         flag[~np.isfinite(feature)] = 9
#         self.flags["global_range"] = flag
# 
# Path: tests/data.py
# class DummyData(object):
#     def __init__(self):
#         self.attrs = {
#                 'datetime': datetime(2016,6,4),
#                 'LATITUDE': 15, 'LONGITUDE': -38}
#         self.data = {
#                 'PRES': ma.fix_invalid(
#                     [2, 6, 10, 21, 44, 79, 100, 150,
#                         200, 400, 410, 650, 1000, 2000, 5000]),
#                 'TEMP': ma.fix_invalid(
#                     [25.32, 25.34, 25.34, 25.31, 24.99, 23.46, 21.85, 17.95,
#                         15.39, 11.08, 6.93, 7.93, 5.71, 3.58, np.nan]),
#                 'PSAL': ma.fix_invalid(
#                     [36.49, 36.51, 36.52, 36.53, 36.59, 36.76, 36.81, 36.39,
#                         35.98, 35.30, 35.28, 34.93, 34.86, np.nan, np.nan])}
# 
#     def __getitem__(self, key):
#         return self.data[key]
# 
#     def keys(self):
#         return self.data.keys()
# 
#     @property
#     def attributes(self):
#         print('attributes will be removed. Use attrs instead!')
#         return self.attrs
# 
# Path: tests/qctests/compare.py
# def compare_feature_input_types(feature, *args, **kwargs):
#     compare_feature_tuple(feature, *args, **kwargs)
#     compare_feature_series(feature, *args, **kwargs)
#     compare_feature_dataarray(feature, *args, **kwargs)
# 
# def compare_input_types(Procedure, cfg):
#     compare_tuple(Procedure, cfg)
#     compare_pandas(Procedure, cfg)
#     compare_xarray(Procedure, cfg)


import numpy as np
from numpy import ma
from cotede.qctests import GlobalRange
from ..data import DummyData
from .compare import compare_feature_input_types, compare_input_types
#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" Verify Rate of Change QC test
"""




def test_standard_dataset():
    """Test GlobalRange procedure with a standard dataset
    """
    profile = DummyData()

    flags = {"global_range": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9]}

    cfg = {"threshold": 4, "minval": -2.5, "maxval": 40.0}

    y = GlobalRange(profile, "TEMP", cfg)

    for f in flags:
        assert np.allclose(y.flags[f], flags[f], equal_nan=True)


def test_input_types():
    cfg = {"threshold": 4, "minval": -2.5, "maxval": 40.0}

# Path: cotede/qctests/global_range.py
# class GlobalRange(QCCheckVar):
#     def test(self):
#         self.flags = {}
#         assert ("minval" in self.cfg) and (
#             "maxval" in self.cfg
#         ), "Missing limits: minval & maxval"
# 
#         assert self.cfg["minval"] < self.cfg["maxval"], (
#             "Global Range(%s): "
#             + "minval (%s) must be smaller than maxval(%s)"
#             % (self.varname, self.cfg["minval"], self.cfg["maxval"])
#         )
# 
#         minval = self.cfg["minval"]
#         maxval = self.cfg["maxval"]
# 
#         feature = np.atleast_1d(self.data[self.varname])
#         if isinstance(feature, ma.MaskedArray):
#             feature[feature.mask] = np.nan
#             feature = feature.data
# 
#         flag = np.zeros(np.shape(feature), dtype="i1")
#         flag[feature < minval] = self.flag_bad
#         flag[feature > maxval] = self.flag_bad
#         idx = (feature >= minval) & (feature <= maxval)
#         flag[idx] = self.flag_good
#         flag[~np.isfinite(feature)] = 9
#         self.flags["global_range"] = flag
# 
# Path: tests/data.py
# class DummyData(object):
#     def __init__(self):
#         self.attrs = {
#                 'datetime': datetime(2016,6,4),
#                 'LATITUDE': 15, 'LONGITUDE': -38}
#         self.data = {
#                 'PRES': ma.fix_invalid(
#                     [2, 6, 10, 21, 44, 79, 100, 150,
#                         200, 400, 410, 650, 1000, 2000, 5000]),
#                 'TEMP': ma.fix_invalid(
#                     [25.32, 25.34, 25.34, 25.31, 24.99, 23.46, 21.85, 17.95,
#                         15.39, 11.08, 6.93, 7.93, 5.71, 3.58, np.nan]),
#                 'PSAL': ma.fix_invalid(
#                     [36.49, 36.51, 36.52, 36.53, 36.59, 36.76, 36.81, 36.39,
#                         35.98, 35.30, 35.28, 34.93, 34.86, np.nan, np.nan])}
# 
#     def __getitem__(self, key):
#         return self.data[key]
# 
#     def keys(self):
#         return self.data.keys()
# 
#     @property
#     def attributes(self):
#         print('attributes will be removed. Use attrs instead!')
#         return self.attrs
# 
# Path: tests/qctests/compare.py
# def compare_feature_input_types(feature, *args, **kwargs):
#     compare_feature_tuple(feature, *args, **kwargs)
#     compare_feature_series(feature, *args, **kwargs)
#     compare_feature_dataarray(feature, *args, **kwargs)
# 
# def compare_input_types(Procedure, cfg):
#     compare_tuple(Procedure, cfg)
#     compare_pandas(Procedure, cfg)
#     compare_xarray(Procedure, cfg)


# Path: tests/qctests/test_qc_global_range.py
import numpy as np
from numpy import ma
from cotede.qctests import GlobalRange
from ..data import DummyData
from .compare import compare_feature_input_types, compare_input_types

#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" Verify Rate of Change QC test
"""




def test_standard_dataset():
    """Test GlobalRange procedure with a standard dataset
    """
    profile = DummyData()

    flags = {"global_range": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9]}

    cfg = {"threshold": 4, "minval": -2.5, "maxval": 40.0}

    y = GlobalRange(profile, "TEMP", cfg)

    for f in flags:
        assert np.allclose(y.flags[f], flags[f], equal_nan=True)


def test_input_types():
    cfg = {"threshold": 4, "minval": -2.5, "maxval": 40.0}

    compare_input_types(GlobalRange, cfg)