예제 #1
0
def test_M2():
    z_rho_xi1 = np.array([-97.50211538, -50.04230769, -2.5825])
    rho_xi0 = xroms.density(temp, salt, z_rho)
    rho_xi1 = xroms.density(temp, salt, z_rho_xi1)
    drhodxi = (rho_xi1[1] - rho_xi0[1]) / (2 * dx)
    drhodeta = 0
    var = np.sqrt(drhodxi**2 + drhodeta**2) * g / rho0
예제 #2
0
def test_N2():
    rho = xroms.density(temp, salt, z_rho)
    drhodz = (rho[2] - rho[0]) / (z_rho[2] - z_rho[0])
    var = -g * drhodz / rho0
    xrho = xroms.density(ds.temp, ds.salt, ds.z_rho)
    # compare above estimate with two averaged since
    # there is a grid change
    assert np.allclose(xroms.N2(xrho, grid)[0, 1:3, 0, 0].mean(), var)
예제 #3
0
def test_KE():
    rho = xroms.density(temp, salt, z_rho)[:, np.newaxis, np.newaxis]
    s2 = (u**2 + v**2)[np.newaxis, :, :]
    KE = 0.5 * rho * s2
    assert np.allclose(ds.xroms.KE.xroms.to_grid(hcoord="psi").mean(),
                       KE.mean(),
                       rtol=1e-2)
예제 #4
0
def test_rho():
    acc = ds.xroms.rho
    assert np.allclose(acc, xroms.density(ds.temp, ds.salt, ds.z_rho))
    acc.name == acc.attrs["name"]
    acc.attrs["grid"] == ds.xroms.grid
    items = ["T", "X", "Y", "Z", "longitude", "latitude", "vertical", "time"]
    assert set(items).issubset(acc.cf.get_valid_keys())
예제 #5
0
def test_KE():
    rho = xroms.density(temp, salt, z_rho)[:, np.newaxis, np.newaxis]
    s2 = (u ** 2 + v ** 2)[np.newaxis, :, :]
    KE = 0.5 * rho * s2

    # xroms
    s = xroms.speed(ds.u, ds.v, grid)
    assert np.allclose(
        xroms.to_grid(xroms.KE(ds.rho0, s), grid, hcoord="psi").mean(),
        KE.mean(),
        rtol=1e-2,
    )
예제 #6
0
def test_ertel():
    v_z = 0
    u_z = 0
    # test one corner of domain
    f = ds.f[0, 0].values
    vort = 0
    sig0 = xroms.density(temp, salt, 0)
    buoy = -g * sig0 / rho0
    phi_z = (buoy[2] - buoy[0]) / (z_rho[2] - z_rho[0])
    ertel = -v_z + u_z + (f + vort) * phi_z

    xsig0 = xroms.potential_density(ds.temp, ds.salt)
    xbuoy = xroms.buoyancy(xsig0)

    assert np.allclose(xroms.ertel(xbuoy, ds.u, ds.v, ds.f, grid)[0, 1, 0, 0], ertel)
예제 #7
0
    def rho(self):
        """Return existing rho or calculate, on rho/rho grids.

        Notes
        -----
        See `xroms.density` for full docstring.

        Example usage
        -------------
        >>> ds.xroms.rho
        """

        if "rho" not in self.ds:
            var = xroms.density(self.ds.temp, self.ds.salt, self.ds.z_rho)
            self.ds["rho"] = var

        return self.ds.rho
예제 #8
0
y = 2010
path = '/d1/shared/TXLA_ROMS/output_20yr_obc/%i/ocean_his_00*.nc' % y
ds = xroms.open_roms_netcdf_dataset(path).sel(ocean_time='%i-08' % y)
ds, grid = xroms.roms_dataset(ds, Vtransform=None)

msk = (ds.lon_rho > -94.5) * (ds.lon_rho < -89.5) * (ds.h >= 10.) * (ds.h <=
                                                                     50.)
msk = msk.load()
msk[165:-1, 440:460] = False
msk[130:160, 300:350] = True
msk[76:83, 490:520] = True

h = ds.h.where(msk, drop=True)
# rho_depths = ds.z_rho.where(msk, drop=True)
# do = ds.dye_01.where(msk, drop=True)
# print("vars for ldo", flush=True)
# ldo_thk = (h + rho_depths.where(do<=60).max('s_rho')).squeeze()
# print("saving ldo", flush=True)
# ldo_thk.to_netcdf('files/ldo_2010_08.nc')
# print("ldo done", flush=True)

rho = xroms.density(ds.temp, ds.salt, ds.z_rho)
drhodz = grid.derivative(rho, 'Z', boundary='extend').where(msk, drop=True)
w_depths = ds.z_w.where(msk, drop=True)
vcrit = .1
depth_grad = w_depths.where(abs(drhodz) >= vcrit).isel(s_w=slice(1, -1))
print("vars for bbl", flush=True)
bbl = (h + depth_grad.min('s_w')).squeeze()
print("ready", flush=True)
bbl = bbl.to_netcdf('files/bbl_2010_08_v2.nc')
print("done", flush=True)
예제 #9
0
def test_mld():
    # choose threshold so that z_rho[-2] is the mld
    sig0 = xroms.density(temp, salt, 0)
    thresh = sig0[-2] - sig0[-1]
    assert np.allclose(ds.xroms.mld(thresh=thresh)[0, 0, 0], z_rho[-2])
예제 #10
0
def test_sig0():
    assert np.allclose(ds.xroms.sig0[0, :, 0, 0], xroms.density(temp, salt, 0))
예제 #11
0
def test_rho():
    assert np.allclose(ds.xroms.rho[0, :, 0, 0],
                       xroms.density(temp, salt, z_rho))
예제 #12
0
def test_mld():
    # choose threshold so that z_rho[-2] is the mld
    xsig0 = xroms.density(ds.temp, ds.salt, 0)
    thresh = xsig0[0, -2, 0, 0] - xsig0[0, -1, 0, 0]
    assert np.allclose(
        xroms.mld(xsig0, ds.h, ds.mask_rho, thresh=thresh)[0, 0, 0], z_rho[-2])
예제 #13
0
def test_buoyancy():
    xsig0 = xroms.potential_density(ds.temp, ds.salt)
    xbuoy = xroms.buoyancy(xsig0)
    sig0 = xroms.density(temp, salt, 0)
    buoy = -g * sig0 / rho0
    assert np.allclose(xbuoy[0, :, 0, 0], buoy)
예제 #14
0
def test_potential_density():
    sig0 = xroms.density(temp, salt, 0)
    xsig0 = xroms.potential_density(ds.temp, ds.salt)
    assert np.allclose(xsig0[0, :, 0, 0], sig0)
예제 #15
0
def test_rho():
    rho = xroms.density(temp, salt, z_rho)
    xrho = xroms.density(ds.temp, ds.salt, ds.z_rho)
    assert np.allclose(xrho[0, :, 0, 0], rho)