# Path: cotede/qctests/profile_envelop.py
# class ProfileEnvelop(QCCheckVar):
#     def test(self):
#         self.flags = {}
# 
#         x = self.data[self.varname]
#         if isinstance(x, ma.MaskedArray):
#             x[x.mask] = np.nan
#             x = x.data
#         x = np.atleast_1d(x)
# 
#         z = self.data["PRES"]
#         if isinstance(z, ma.MaskedArray):
#             if z.mask.any():
#                 mask = np.ones_like(z, dtype="float32")
#                 mask[z.mask] = np.nan
#                 z = z * mask
#             z = z.data
#         z = np.atleast_1d(z)
# 
#         assert np.shape(z) == np.shape(x)
# 
#         assert "layers" in self.cfg, "Profile envelop cfg requires layers"
# 
#         flag = np.zeros(np.shape(x), dtype="i1")
#         for layer in self.cfg["layers"]:
#             ind = np.nonzero(eval("(z %s) & (z %s)" % (layer[0], layer[1])))[0]
#             f = eval("(x[ind] > %s) & (x[ind] < %s)" % (layer[2], layer[3]))
# 
#             flag[ind[f == True]] = self.flag_good
#             flag[ind[f == False]] = self.flag_bad
# 
#         flag[ma.getmaskarray(x) | ~np.isfinite(x)] = 9
#         self.flags["profile_envelop"] = 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_input_types(Procedure, cfg):
#     compare_tuple(Procedure, cfg)
#     compare_pandas(Procedure, cfg)
#     compare_xarray(Procedure, cfg)


import numpy as np
from cotede.qctests.profile_envelop import ProfileEnvelop
from ..data import DummyData
from .compare import compare_input_types
# -*- coding: utf-8 -*-
# Licensed under a 3-clause BSD style license - see LICENSE.rst

"""
"""





def notest_profile_envelop():
    profile = DummyData()

    cfg = {"layers": [["> 0", "<= 25", -2, 37], ["> 25", "<= 50", -2, 36]]}

    flags = profile_envelop(profile, cfg, "TEMP")

    # Check for BUG #9.
    assert 9 in flags


def test_standard_dataset():
    """Test ProfileEnvelop QC procedure with standard dataset

    Also tets a case with depths not included in the layers definition, thus
    it should return flag 0, i.e. not evaluated on those depths.
    """

# Path: cotede/qctests/profile_envelop.py
# class ProfileEnvelop(QCCheckVar):
#     def test(self):
#         self.flags = {}
# 
#         x = self.data[self.varname]
#         if isinstance(x, ma.MaskedArray):
#             x[x.mask] = np.nan
#             x = x.data
#         x = np.atleast_1d(x)
# 
#         z = self.data["PRES"]
#         if isinstance(z, ma.MaskedArray):
#             if z.mask.any():
#                 mask = np.ones_like(z, dtype="float32")
#                 mask[z.mask] = np.nan
#                 z = z * mask
#             z = z.data
#         z = np.atleast_1d(z)
# 
#         assert np.shape(z) == np.shape(x)
# 
#         assert "layers" in self.cfg, "Profile envelop cfg requires layers"
# 
#         flag = np.zeros(np.shape(x), dtype="i1")
#         for layer in self.cfg["layers"]:
#             ind = np.nonzero(eval("(z %s) & (z %s)" % (layer[0], layer[1])))[0]
#             f = eval("(x[ind] > %s) & (x[ind] < %s)" % (layer[2], layer[3]))
# 
#             flag[ind[f == True]] = self.flag_good
#             flag[ind[f == False]] = self.flag_bad
# 
#         flag[ma.getmaskarray(x) | ~np.isfinite(x)] = 9
#         self.flags["profile_envelop"] = 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_input_types(Procedure, cfg):
#     compare_tuple(Procedure, cfg)
#     compare_pandas(Procedure, cfg)
#     compare_xarray(Procedure, cfg)


# Path: tests/qctests/test_qc_profile_envelop.py
import numpy as np
from cotede.qctests.profile_envelop import ProfileEnvelop
from ..data import DummyData
from .compare import compare_input_types

# -*- coding: utf-8 -*-
# Licensed under a 3-clause BSD style license - see LICENSE.rst

"""
"""





def notest_profile_envelop():
    profile = DummyData()

    cfg = {"layers": [["> 0", "<= 25", -2, 37], ["> 25", "<= 50", -2, 36]]}

    flags = profile_envelop(profile, cfg, "TEMP")

    # Check for BUG #9.
    assert 9 in flags


def test_standard_dataset():
    """Test ProfileEnvelop QC procedure with standard dataset

    Also tets a case with depths not included in the layers definition, thus
    it should return flag 0, i.e. not evaluated on those depths.
    """

    profile = DummyData()