# 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
    res_1 = np.array([[1, ], ])
    res_2 = np.array([[1, 2, 3, 4, 5, 6], ])
    res_3 = np.array([[1, 2, 3, 4, 5, 6],
                      [2, 3, 4, 5, 6, 7]])
    res_4 = np.array([[1, 2, 3, 4, 5, 6],
                      [7, 8, 9, 10, 11, 12],
                      [13, 14, 15, 16, 17, 18],
                      [19, 20, 21, 22, 23, 24]])
    res_5 = np.array([[1, ],
                      [2, ],
                      [3, ],
                      [4, ]])

    a1 = utilities._align_results_to_spatial_data(res_1, pts_1)
    assert np.all(a1 == res_1)
    a2 = utilities._align_results_to_spatial_data(res_2, pts_2)
    assert np.all(a2 == res_2)
    a3 = utilities._align_results_to_spatial_data(res_3, pts_3)
    assert np.all(a3 == res_3)

    a4 = utilities._align_results_to_spatial_data(res_4, pts_4)
    a5 = utilities._align_results_to_spatial_data(res_5, pts_4)
    assert np.all(a4.T == res_4)
    assert np.all(a5.T == res_5)


def test_regrid_variable_TDStoS(get_s_depth):
    # Time is present
    # Depth is present
    # Grid_S to Grid_S

# 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

    res_1 = np.array([[1, ], ])
    res_2 = np.array([[1, 2, 3, 4, 5, 6], ])
    res_3 = np.array([[1, 2, 3, 4, 5, 6],
                      [2, 3, 4, 5, 6, 7]])
    res_4 = np.array([[1, 2, 3, 4, 5, 6],
                      [7, 8, 9, 10, 11, 12],
                      [13, 14, 15, 16, 17, 18],
                      [19, 20, 21, 22, 23, 24]])
    res_5 = np.array([[1, ],
                      [2, ],
                      [3, ],
                      [4, ]])

    a1 = utilities._align_results_to_spatial_data(res_1, pts_1)
    assert np.all(a1 == res_1)
    a2 = utilities._align_results_to_spatial_data(res_2, pts_2)
    assert np.all(a2 == res_2)
    a3 = utilities._align_results_to_spatial_data(res_3, pts_3)
    assert np.all(a3 == res_3)

    a4 = utilities._align_results_to_spatial_data(res_4, pts_4)
    a5 = utilities._align_results_to_spatial_data(res_5, pts_4)
    assert np.all(a4.T == res_4)
    assert np.all(a5.T == res_5)


def test_regrid_variable_TDStoS(get_s_depth):
    # Time is present
    # Depth is present
    # Grid_S to Grid_S

    sd = get_s_depth