# Path: cotede/qctests/tukey53H.py
# def tukey53H(x, normalize=False):
#     """Spike test Tukey 53H from Goring & Nikora 2002
# 
#     Return
#     ------
#     delta :
#         An array with the same shape of input x of the difference between x
#         and a smoothed x.
#     """
#     if isinstance(x, ma.MaskedArray):
#         x[x.mask] = np.nan
#         x = x.data
# 
#     if not PANDAS_AVAILABLE:
#         return _tukey53H_numpy(x, normalize=normalize)
# 
#     if hasattr(x, "to_series"):
#         x = x.to_series()
#     elif not isinstance(x, pd.Series):
#         x = pd.Series(x)
# 
#     u1 = x.reset_index(drop=True).rolling(5, center=True).median()
#     u2 = u1.rolling(3, center=True).median()
#     u3 = 0.25 * (u2.shift(-1) + 2 * u2 + u2.shift(1))
# 
#     delta = x - u3
# 
#     if not normalize:
#         return np.array(delta)
# 
#     sigma = u1.dropna().std(ddof=1)
#     return np.array(delta / sigma)
# 
# class Tukey53H(QCCheckVar):
#     def set_features(self):
#         self.features = {"tukey53H": tukey53H(self.data[self.varname])}
#         if "l" in self.cfg:
#             self.features["tukey53H_norm"] = tukey53H_norm(self.data[self.varname], l=self.cfg["l"])
# 
# 
#     def test(self):
#         """
# 
#                 I slightly modified the Goring & Nikora 2002. It is
#                   expected that CTD profiles has a typical depth
#                   structure, with a range between surface and bottom.
#         """
#         self.flags = {}
#         try:
#             threshold = self.cfg["threshold"]
#         except KeyError:
#             print("Deprecated cfg format. It should contain a threshold item.")
#             threshold = self.cfg["k"]
# 
#         assert (
#             (np.size(threshold) == 1)
#             and (threshold is not None)
#             and (np.isfinite(threshold))
#         )
# 
#         flag = np.zeros(np.shape(self.data[self.varname]), dtype="i1")
#         feature = np.absolute(self.features["tukey53H"])
#         flag[feature > threshold] = self.flag_bad
#         flag[feature <= threshold] = self.flag_good
#         x = np.atleast_1d(self.data[self.varname])
#         flag[ma.getmaskarray(x) | ~np.isfinite(x)] = 9
#         self.flags["tukey53H"] = 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 cotede.qctests import tukey53H, Tukey53H
from ..data import DummyData
from .compare import compare_feature_input_types, compare_input_types
                -0.045912,
                0.0599597,
                -0.03974471,
                np.nan,
                np.nan,
                np.nan,
                np.nan,
                np.nan,
            ]
        ),
    }
    flags = {
        "tukey53H": np.array(
            [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 9], dtype="i1"
        )
    }

    cfg = {"l": 5, "threshold": 6}

    y = Tukey53H(profile, "TEMP", cfg, autoflag=True)

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


def test_input_types():
    cfg = {"threshold": 1}

# Path: cotede/qctests/tukey53H.py
# def tukey53H(x, normalize=False):
#     """Spike test Tukey 53H from Goring & Nikora 2002
# 
#     Return
#     ------
#     delta :
#         An array with the same shape of input x of the difference between x
#         and a smoothed x.
#     """
#     if isinstance(x, ma.MaskedArray):
#         x[x.mask] = np.nan
#         x = x.data
# 
#     if not PANDAS_AVAILABLE:
#         return _tukey53H_numpy(x, normalize=normalize)
# 
#     if hasattr(x, "to_series"):
#         x = x.to_series()
#     elif not isinstance(x, pd.Series):
#         x = pd.Series(x)
# 
#     u1 = x.reset_index(drop=True).rolling(5, center=True).median()
#     u2 = u1.rolling(3, center=True).median()
#     u3 = 0.25 * (u2.shift(-1) + 2 * u2 + u2.shift(1))
# 
#     delta = x - u3
# 
#     if not normalize:
#         return np.array(delta)
# 
#     sigma = u1.dropna().std(ddof=1)
#     return np.array(delta / sigma)
# 
# class Tukey53H(QCCheckVar):
#     def set_features(self):
#         self.features = {"tukey53H": tukey53H(self.data[self.varname])}
#         if "l" in self.cfg:
#             self.features["tukey53H_norm"] = tukey53H_norm(self.data[self.varname], l=self.cfg["l"])
# 
# 
#     def test(self):
#         """
# 
#                 I slightly modified the Goring & Nikora 2002. It is
#                   expected that CTD profiles has a typical depth
#                   structure, with a range between surface and bottom.
#         """
#         self.flags = {}
#         try:
#             threshold = self.cfg["threshold"]
#         except KeyError:
#             print("Deprecated cfg format. It should contain a threshold item.")
#             threshold = self.cfg["k"]
# 
#         assert (
#             (np.size(threshold) == 1)
#             and (threshold is not None)
#             and (np.isfinite(threshold))
#         )
# 
#         flag = np.zeros(np.shape(self.data[self.varname]), dtype="i1")
#         feature = np.absolute(self.features["tukey53H"])
#         flag[feature > threshold] = self.flag_bad
#         flag[feature <= threshold] = self.flag_good
#         x = np.atleast_1d(self.data[self.varname])
#         flag[ma.getmaskarray(x) | ~np.isfinite(x)] = 9
#         self.flags["tukey53H"] = 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_tukey53H.py
import numpy as np
from cotede.qctests import tukey53H, Tukey53H
from ..data import DummyData
from .compare import compare_feature_input_types, compare_input_types

                -0.045912,
                0.0599597,
                -0.03974471,
                np.nan,
                np.nan,
                np.nan,
                np.nan,
                np.nan,
            ]
        ),
    }
    flags = {
        "tukey53H": np.array(
            [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 9], dtype="i1"
        )
    }

    cfg = {"l": 5, "threshold": 6}

    y = Tukey53H(profile, "TEMP", cfg, autoflag=True)

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


def test_input_types():
    cfg = {"threshold": 1}

    compare_input_types(Tukey53H, cfg)