# Path: cotede/qctests/qctests.py
# def frozen_profile():
# def grey_list():
# def valid_speed():
# def gross_sensor_drift():
# def platform_identification():


import logging
import numpy as np
    import gsw
from numpy import ma
from .qctests import QCCheck
except ImportError:
    module_logger.debug("Missing package GSW, used to estimate density when needed.")
    GSW_AVAILABLE = False


def densitystep(SA, t, p, auto_rotate=False):
    """Estimates the potential density step of successive mesurements

       Expects the data to be recorded along the time, i.e. first measurement
         was recorded first. This makes difference since the first measurement
         has no reference to define the delta change.
       This is relevant for the type of instrument. For instance: XBTs are
         always measured surface to bottom, CTDs are expected the same, but
         Spray underwater gliders measure bottom to surface.
    """
    assert np.shape(t) == np.shape(p)
    assert np.shape(t) == np.shape(SA)
    assert np.ndim(t) == 1, "Not ready to densitystep an array ndim > 1"

    rho0 = gsw.pot_rho_t_exact(SA, t, p, 0)
    y = np.nan * np.atleast_1d(t)
    y[1:] = np.sign(np.diff(p)) * np.diff(rho0)

    if isinstance(y, ma.MaskedArray):
        y[y.mask] = np.nan
        y = y.data

    return y



# Path: cotede/qctests/qctests.py
# def frozen_profile():
# def grey_list():
# def valid_speed():
# def gross_sensor_drift():
# def platform_identification():


# Path: cotede/qctests/density_inversion.py
import logging
import numpy as np
    import gsw
from numpy import ma
from .qctests import QCCheck

except ImportError:
    module_logger.debug("Missing package GSW, used to estimate density when needed.")
    GSW_AVAILABLE = False


def densitystep(SA, t, p, auto_rotate=False):
    """Estimates the potential density step of successive mesurements

       Expects the data to be recorded along the time, i.e. first measurement
         was recorded first. This makes difference since the first measurement
         has no reference to define the delta change.
       This is relevant for the type of instrument. For instance: XBTs are
         always measured surface to bottom, CTDs are expected the same, but
         Spray underwater gliders measure bottom to surface.
    """
    assert np.shape(t) == np.shape(p)
    assert np.shape(t) == np.shape(SA)
    assert np.ndim(t) == 1, "Not ready to densitystep an array ndim > 1"

    rho0 = gsw.pot_rho_t_exact(SA, t, p, 0)
    y = np.nan * np.atleast_1d(t)
    y[1:] = np.sign(np.diff(p)) * np.diff(rho0)

    if isinstance(y, ma.MaskedArray):
        y[y.mask] = np.nan
        y = y.data

    return y



class DensityInversion(QCCheck):