예제 #1
0
    def test_variables(self):
        with mercator.Mercator('data/testdata/mercator_test.nc') as n:
            variables = n.variables

            self.assertEqual(len(variables), 6)
            self.assertTrue('votemper' in variables)
            self.assertEqual(variables['votemper'].name,
                             'Sea water potential temperature')
            self.assertEqual(variables['votemper'].unit, 'Kelvin')
예제 #2
0
    def test_get_raw_point(self):
        with mercator.Mercator('data/testdata/mercator_test.nc') as n:
            lat, lon, data = n.get_raw_point(
                13.0, -149.0, 0, 0, 'votemper'
            )

        self.assertEqual(len(lat.ravel()), 100)
        self.assertEqual(len(lon.ravel()), 100)
        self.assertEqual(len(data.ravel()), 100)
        self.assertAlmostEqual(data[4, 4], 298.6, places=1)
예제 #3
0
    def test_timestamps(self):
        with mercator.Mercator('data/testdata/mercator_test.nc') as n:
            self.assertEqual(len(n.timestamps), 1)
            self.assertEqual(n.timestamps[0],
                             datetime.datetime(2017, 3, 3, 0, 0, 0, 0,
                                               pytz.UTC))

            # Property is read-only
            with self.assertRaises(AttributeError):
                n.timestamps = []

            # List is immutable
            with self.assertRaises(ValueError):
                n.timestamps[0] = 0
예제 #4
0
    def test_get_point(self):
        with mercator.Mercator('data/testdata/mercator_test.nc') as n:
            self.assertAlmostEqual(
                n.get_point(13.0, -149.0, 0, 0, 'votemper'),
                298.42, places=2
            )
            self.assertAlmostEqual(
                n.get_point(47.0, -47.0, 0, 0, 'votemper'),
                273.66, places=2
            )

            p = n.get_point([13.0, 47.0], [-149.0, -47.0], 0, 0, 'votemper')
            self.assertAlmostEqual(p[0], 298.42, places=2)
            self.assertAlmostEqual(p[1], 273.66, places=2)
예제 #5
0
def open_dataset(url):
    if url is not None:
        if __dataset_cache.get(url) is None:
            if url.startswith("http") or url.endswith(".nc"):
                with Dataset(url, 'r') as ds:
                    if 'latitude_longitude' in ds.variables or \
                            'LatLon_Projection' in ds.variables:
                        __dataset_cache[url] = mercator.Mercator(url)
                    elif 'siglay' in ds.variables:
                        __dataset_cache[url] = fvcom.Fvcom(url)
                    elif 'polar_stereographic' in ds.variables:
                        __dataset_cache[url] = nemo.Nemo(url)
                    else:
                        __dataset_cache[url] = nemo.Nemo(url)

    return __dataset_cache.get(url)
예제 #6
0
 def test_init(self):
     mercator.Mercator(None)
예제 #7
0
 def test_bottom_point(self):
     with mercator.Mercator('data/testdata/mercator_test.nc') as n:
         self.assertAlmostEqual(
             n.get_point(13.01, -149.0, 'bottom', 0, 'votemper'),
             273.95, places=2
         )
예제 #8
0
 def test_get_profile(self):
     with mercator.Mercator('data/testdata/mercator_test.nc') as n:
         p, d = n.get_profile(13.0, -149.0, 0, 'votemper')
         self.assertAlmostEqual(p[0], 298.42, places=2)
         self.assertAlmostEqual(p[10], 298.42, places=2)
         self.assertTrue(np.ma.is_masked(p[49]))
예제 #9
0
 def test_open(self):
     with mercator.Mercator('data/testdata/mercator_test.nc'):
         pass