# Path: data_cube_utilities/dc_utilities.py
# def create_default_clean_mask(dataset_in):
#     """
#     Creates a data mask that masks nothing.
#     
#     Parameters
#     ----------
#     dataset_in: xarray.Dataset
#         dataset retrieved from the Data Cube.
#     
#     Raises
#     ------
#     ValueError
#         if dataset_in is an empty xarray.Dataset.
#     """
#     data = None
#     if isinstance(dataset_in, xr.Dataset):
#         data_vars = list(dataset_in.data_vars)
#         if len(data_vars) != 0:
#             data = dataset_in[data_vars[0]].data
#     elif isinstance(dataset_in, xr.DataArray):
#         data = dataset_in.data
#     clean_mask = None
#     if isinstance(data, dask.array.core.Array):
#         clean_mask = dask.array.ones_like(data, dtype='uint8')
#     else:
#         if data is None:
#             clean_mask = np.ones(dataset_in.shape, dtype=np.bool)
#         else:
#             clean_mask = np.ones_like(data, dtype=np.bool)
#     return clean_mask.astype(np.bool)


import gc
import numpy as np
import xarray as xr
import warnings
    import scipy.ndimage.filters as conv
from xarray.ufuncs import sign as xr_sign
from . import dc_utilities as utilities
from .dc_utilities import create_default_clean_mask
from datetime import datetime


def _tsmi(dataset):
    out = (dataset.red + dataset.green) * 0.0001 / 2
    return out.where(out>0, 0)

def tsm(dataset_in, clean_mask=None, no_data=0):
    """
    Calculate Total Suspended Matter (TSM) for water.

    Parameters
    ----------
    dataset_in: xarray.Dataset
        Dataset retrieved from the Data Cube.
        Must have 'red' and 'green' data variables.
    clean_mask: np.ndarray 
        A NumPy array with dtype boolean
        True for values considered clean;
        if no clean mask is supplied, all values will be considered clean
    no_data: numeric
        no data pixel value; default: -9999
    
    Raises
    ------
    ValueError
        if dataset_in is an empty xarray.Dataset.
    """
    assert 'red' in dataset_in and 'green' in dataset_in, "Red and Green bands are required for the TSM analysis."
    # Default to masking nothing.
    if clean_mask is None:

# Path: data_cube_utilities/dc_utilities.py
# def create_default_clean_mask(dataset_in):
#     """
#     Creates a data mask that masks nothing.
#     
#     Parameters
#     ----------
#     dataset_in: xarray.Dataset
#         dataset retrieved from the Data Cube.
#     
#     Raises
#     ------
#     ValueError
#         if dataset_in is an empty xarray.Dataset.
#     """
#     data = None
#     if isinstance(dataset_in, xr.Dataset):
#         data_vars = list(dataset_in.data_vars)
#         if len(data_vars) != 0:
#             data = dataset_in[data_vars[0]].data
#     elif isinstance(dataset_in, xr.DataArray):
#         data = dataset_in.data
#     clean_mask = None
#     if isinstance(data, dask.array.core.Array):
#         clean_mask = dask.array.ones_like(data, dtype='uint8')
#     else:
#         if data is None:
#             clean_mask = np.ones(dataset_in.shape, dtype=np.bool)
#         else:
#             clean_mask = np.ones_like(data, dtype=np.bool)
#     return clean_mask.astype(np.bool)


# Path: data_cube_utilities/dc_water_quality.py
import gc
import numpy as np
import xarray as xr
import warnings
    import scipy.ndimage.filters as conv
from xarray.ufuncs import sign as xr_sign
from . import dc_utilities as utilities
from .dc_utilities import create_default_clean_mask
from datetime import datetime



def _tsmi(dataset):
    out = (dataset.red + dataset.green) * 0.0001 / 2
    return out.where(out>0, 0)

def tsm(dataset_in, clean_mask=None, no_data=0):
    """
    Calculate Total Suspended Matter (TSM) for water.

    Parameters
    ----------
    dataset_in: xarray.Dataset
        Dataset retrieved from the Data Cube.
        Must have 'red' and 'green' data variables.
    clean_mask: np.ndarray 
        A NumPy array with dtype boolean
        True for values considered clean;
        if no clean mask is supplied, all values will be considered clean
    no_data: numeric
        no data pixel value; default: -9999
    
    Raises
    ------
    ValueError
        if dataset_in is an empty xarray.Dataset.
    """
    assert 'red' in dataset_in and 'green' in dataset_in, "Red and Green bands are required for the TSM analysis."
    # Default to masking nothing.
    if clean_mask is None:

        clean_mask = create_default_clean_mask(dataset_in)