def setUp(self): p = np.arange(1, 1001, 2) temp = 10. * np.exp(-.008*p) - 15. * np.exp(-0.005*(p+100)) + 2. sal = -14. * np.exp(-.01*p) + 34. self.p = p self.temp = temp self.sal = sal dt = datetime.datetime(1993, 8, 18, 14, 42, 36) self.cast = Cast(pres=self.p, temp=self.temp, sal=self.sal, date=dt) self.ctd = CTDCast(self.p, self.sal, self.temp, date=dt) self.collection = CastCollection(self.ctd, self.ctd) return
def setUp(self): p = np.linspace(1, 999, 500) casts = [] for i in range(10): cast = Cast(pres=p, temp=2 * np.ones_like(p), sal=30 * np.ones_like(p), station=i, val=abs(i - 5), uniq_val=-i**2) casts.append(cast) self.cc = CastCollection(casts) return
def test_defray(self): lengths = np.arange(50, 71) casts = [] for n in lengths: p = np.r_[np.arange(0, 250, 5), np.arange(250, 250 + 5 * (n - 50), 5)] t = np.ones(n) * 10.0 s = np.ones(n) * 34.0 cast = Cast(pres=p, temp=t, sal=s) casts.append(cast) defrayed_casts = CastCollection(casts).defray() for cast in defrayed_casts: self.assertEqual(len(cast), 70) return
def test_nearest_to(self): casts = [] for i in range(10): casts.append( Cast(pressure=[1, 2, 3], temperature=[5, 6, 7], coordinates=(-30.0 + i, 10.0 - 2 * i))) cc = CastCollection(casts) pt = Point((-26.2, 2.1), crs=LonLatWGS84) nearest, dist = cc.nearest_to_point(pt) self.assertEqual(nearest.coordinates.vertex, (-26.0, 2.0)) self.assertAlmostEqual(dist, 24845.9422, places=4) return
def test_eofs(self): pres = np.arange(1, 300) casts = [ Cast(depth=np.arange(1, 300), theta=np.sin(pres * i * np.pi / 300)) for i in range(3) ] cc = CastCollection(casts) structures, lamb, eofs = narwhal.analysis.eofs(cc, key="theta") self.assertAlmostEqual(np.mean(np.abs(structures["theta_eof1"])), 0.634719360307) self.assertAlmostEqual(np.mean(np.abs(structures["theta_eof2"])), 0.363733575635) self.assertAlmostEqual(np.mean(np.abs(structures["theta_eof3"])), 0.350665870142) self.assertTrue( np.allclose(lamb, [87.27018523, 40.37800904, 2.02016724])) return
def test_castswhere_onearg(self): cc = self.cc self.assertEqual(cc.castswhere("station", 5), CastCollection(cc[5])) return