# Path: gridded/utilities.py
# def gen_celltree_mask_from_center_mask(center_mask, sl):
# def regrid_variable(grid, o_var, location='node'):
# def _regrid_s_depth(grid, o_depth):
# def _reorganize_spatial_data(points):
# def _align_results_to_spatial_data(result, points):
# def isarraylike(obj):
# def asarraylike(obj):
# def isstring(obj):
# def get_dataset(ncfile, dataset=None):
# def get_writable_dataset(ncfile, format="netcdf4"):
# def get_dataset_attrs(ds):
# 
# Path: gridded/tests/test_depth.py
# @pytest.fixture(scope="module")
# def get_s_depth():
#     """
#     This is setup for a ROMS S-level Depth that is on a square grid with a center
#     mound. Control vars: sz=xy size, center_el=height of the mound in meters,
#     d0=general depth in meters, sig=steepness of mound, nz=number of z levels.
#     """
#     sz = 40
#     center_el = 10
#     d0 = 20
#     sig = 0.75
#     nz = 11
#     node_lat, node_lon = np.mgrid[0:sz, 0:sz]
#     b_data = np.empty((sz, sz))
#     for x in range(0, sz):
#         for y in range(0, sz):
#             b_data[x, y] = d0 - center_el * np.exp(
#                 -0.1
#                 * (
#                     (x - (sz / 2)) ** 2 / 2.0 * ((sig) ** 2)
#                     + (y - (sz / 2)) ** 2
#                     / 2.0
#                     * ((sig) ** 2)
#                 )
#             )
#     z_data = np.empty((3, sz, sz))
#     for t in range(0, 3):
#         for x in range(0, sz):
#             for y in range(0, sz):
#                 z_data[t, x, y] = (t - 1.0) / 2.0
#     g = Grid_S(node_lon=node_lon, node_lat=node_lat)
#     bathy = Variable(name="bathy", grid=g, data=b_data)
#     t_data = np.array(
#         [
#             Time.constant_time().data[0]
#             + datetime.timedelta(minutes=10 * d)
#             for d in range(0, 3)
#         ]
#     )
#     zeta = Variable(
#         name="zeta",
#         time=Time(data=t_data),
#         grid=g,
#         data=z_data,
#     )
# 
#     s_w = np.linspace(-1, 0, nz)
#     s_rho = (s_w[0:-1] + s_w[1:]) / 2
#     # equidistant layers, no stretching
#     Cs_w = np.linspace(-1, 0, nz)
#     Cs_w = 1 - 1 / np.exp(2 * Cs_w)
#     Cs_w /= -Cs_w[0]
#     Cs_r = (Cs_w[0:-1] + Cs_w[1:]) / 2
#     hc = np.array([0])
# 
#     sd = S_Depth(
#         time=zeta.time,
#         grid=zeta.grid,
#         bathymetry=bathy,
#         zeta=zeta,
#         terms={
#             "s_w": s_w,
#             "s_rho": s_rho,
#             "Cs_w": Cs_w,
#             "Cs_r": Cs_r,
#             "hc": hc,
#         },
#     )
#     return sd


import os
import numpy as np
import netCDF4 as nc
from gridded import utilities
from gridded.tests.test_depth import get_s_depth
    from gridded.variable import Variable
    from gridded.time import Time
    from gridded.grids import Grid_S
    from gridded.variable import Variable
    from gridded.time import Time
    from gridded.grids import Grid_S
#!/usr/bin/env python

# py2/3 compatibility
from __future__ import absolute_import, division, print_function, unicode_literals





data_dir = os.path.join(os.path.split(__file__)[0], 'test_data')


def test_gen_celltree_mask_from_center_mask():
    center_mask = np.array(([True, True, True, True, True],
                     [True, False, True, True, True],
                     [True, False, False, False, True],
                     [True, True, True, True, True]))
    center_sl = np.s_[1:-1,1:-1] #'both' padding


# Path: gridded/utilities.py
# def gen_celltree_mask_from_center_mask(center_mask, sl):
# def regrid_variable(grid, o_var, location='node'):
# def _regrid_s_depth(grid, o_depth):
# def _reorganize_spatial_data(points):
# def _align_results_to_spatial_data(result, points):
# def isarraylike(obj):
# def asarraylike(obj):
# def isstring(obj):
# def get_dataset(ncfile, dataset=None):
# def get_writable_dataset(ncfile, format="netcdf4"):
# def get_dataset_attrs(ds):
# 
# Path: gridded/tests/test_depth.py
# @pytest.fixture(scope="module")
# def get_s_depth():
#     """
#     This is setup for a ROMS S-level Depth that is on a square grid with a center
#     mound. Control vars: sz=xy size, center_el=height of the mound in meters,
#     d0=general depth in meters, sig=steepness of mound, nz=number of z levels.
#     """
#     sz = 40
#     center_el = 10
#     d0 = 20
#     sig = 0.75
#     nz = 11
#     node_lat, node_lon = np.mgrid[0:sz, 0:sz]
#     b_data = np.empty((sz, sz))
#     for x in range(0, sz):
#         for y in range(0, sz):
#             b_data[x, y] = d0 - center_el * np.exp(
#                 -0.1
#                 * (
#                     (x - (sz / 2)) ** 2 / 2.0 * ((sig) ** 2)
#                     + (y - (sz / 2)) ** 2
#                     / 2.0
#                     * ((sig) ** 2)
#                 )
#             )
#     z_data = np.empty((3, sz, sz))
#     for t in range(0, 3):
#         for x in range(0, sz):
#             for y in range(0, sz):
#                 z_data[t, x, y] = (t - 1.0) / 2.0
#     g = Grid_S(node_lon=node_lon, node_lat=node_lat)
#     bathy = Variable(name="bathy", grid=g, data=b_data)
#     t_data = np.array(
#         [
#             Time.constant_time().data[0]
#             + datetime.timedelta(minutes=10 * d)
#             for d in range(0, 3)
#         ]
#     )
#     zeta = Variable(
#         name="zeta",
#         time=Time(data=t_data),
#         grid=g,
#         data=z_data,
#     )
# 
#     s_w = np.linspace(-1, 0, nz)
#     s_rho = (s_w[0:-1] + s_w[1:]) / 2
#     # equidistant layers, no stretching
#     Cs_w = np.linspace(-1, 0, nz)
#     Cs_w = 1 - 1 / np.exp(2 * Cs_w)
#     Cs_w /= -Cs_w[0]
#     Cs_r = (Cs_w[0:-1] + Cs_w[1:]) / 2
#     hc = np.array([0])
# 
#     sd = S_Depth(
#         time=zeta.time,
#         grid=zeta.grid,
#         bathymetry=bathy,
#         zeta=zeta,
#         terms={
#             "s_w": s_w,
#             "s_rho": s_rho,
#             "Cs_w": Cs_w,
#             "Cs_r": Cs_r,
#             "hc": hc,
#         },
#     )
#     return sd


# Path: gridded/tests/test_utilities.py
import os
import numpy as np
import netCDF4 as nc
from gridded import utilities
from gridded.tests.test_depth import get_s_depth
    from gridded.variable import Variable
    from gridded.time import Time
    from gridded.grids import Grid_S
    from gridded.variable import Variable
    from gridded.time import Time
    from gridded.grids import Grid_S

#!/usr/bin/env python

# py2/3 compatibility
from __future__ import absolute_import, division, print_function, unicode_literals





data_dir = os.path.join(os.path.split(__file__)[0], 'test_data')


def test_gen_celltree_mask_from_center_mask():
    center_mask = np.array(([True, True, True, True, True],
                     [True, False, True, True, True],
                     [True, False, False, False, True],
                     [True, True, True, True, True]))
    center_sl = np.s_[1:-1,1:-1] #'both' padding


    m = utilities.gen_celltree_mask_from_center_mask(center_mask, center_sl)