def test_add_buoyancy_freq_squared(self): # This is a fairly lousy test, merely ensuring that an N^2 field was # calculated, and that it's not wildly different than the direct # calculation. p = np.arange(10) t = 20.0 * 0.2 * p s = 30.0 * 0.25 * p x = [-20.0 for _ in p] y = [50.0 for _ in p] sa = gsw.sa_from_sp(s, p, x, y) ct = gsw.ct_from_t(sa, t, p) rho = np.asarray(gsw.rho(sa, ct, p)) cast = CTDCast(p, s, t, coordinates=(-20, 50), density=rho) cast.add_depth() cast.add_Nsquared(depthkey="depth") # Calculate the buoyancy frequency directly z = cast["depth"].values drhodz = -np.r_[rho[1]-rho[0], rho[2:]-rho[:-2], rho[-1]-rho[-2]] / \ np.r_[z[1]-z[0], z[2:]-z[:-2], z[-1]-z[-2]] N2_direct = -9.81 / rho * drhodz self.assertTrue( np.mean(np.abs(cast["N2"][1:] - N2_direct[1:])) < 0.0004) return
def test_add_density(self): p = np.arange(10) t = 20.0 * 0.2 * p s = 30.0 * 0.25 * p x = [-20.0 for _ in p] y = [50.0 for _ in p] sa = gsw.sa_from_sp(s, p, x, y) ct = gsw.ct_from_t(sa, t, p) rho = gsw.rho(sa, ct, p) cast = CTDCast(p, s, t, coordinates=(-20, 50)) cast.add_density() self.assertTrue(np.allclose(rho, cast["density"])) return
def test_add_buoyancy_freq_squared(self): # This is a fairly lousy test, merely ensuring that an N^2 field was # calculated, and that it's not wildly different than the direct # calculation. p = np.arange(10) t = 20.0 * 0.2 * p s = 30.0 * 0.25 * p x = [-20.0 for _ in p] y = [50.0 for _ in p] sa = gsw.sa_from_sp(s, p, x, y) ct = gsw.ct_from_t(sa, t, p) rho = np.asarray(gsw.rho(sa, ct, p)) cast = CTDCast(p, s, t, coordinates=(-20, 50), density=rho) cast.add_depth() cast.add_Nsquared(depthkey="depth") # Calculate the buoyancy frequency directly z = cast["depth"].values drhodz = -np.r_[rho[1]-rho[0], rho[2:]-rho[:-2], rho[-1]-rho[-2]] / \ np.r_[z[1]-z[0], z[2:]-z[:-2], z[-1]-z[-2]] N2_direct = -9.81 / rho * drhodz self.assertTrue(np.mean(np.abs(cast["N2"][1:] - N2_direct[1:])) < 0.0004) return