Ejemplo n.º 1
0
 def test_lazy_load(self):
     store = InaccessibleVariableDataStore()
     store.set_dimension('dim', 10)
     store.set_variable('dim', XArray(('dim'),
                                       np.arange(10)))
     store.set_variable('var', XArray(('dim'),
                                       np.random.uniform(size=10)))
     ds = Dataset()
     ds = ds.load_store(store, decode_cf=False)
     self.assertRaises(UnexpectedDataAccess, lambda: ds['var'].data)
     ds = ds.load_store(store, decode_cf=True)
     self.assertRaises(UnexpectedDataAccess, lambda: ds['var'].data)
Ejemplo n.º 2
0
 def roundtrip(self, data, decode_cf=True):
     store = CFEncodedInMemoryStore()
     data.dump_to_store(store)
     if decode_cf:
         yield conventions.decode_cf(store)
     else:
         yield Dataset.load_store(store)
Ejemplo n.º 3
0
 def roundtrip(self, data, decode_cf=True):
     store = CFEncodedInMemoryStore()
     data.dump_to_store(store)
     if decode_cf:
         yield conventions.decode_cf(store)
     else:
         yield Dataset.load_store(store)
Ejemplo n.º 4
0
 def test_write_store(self):
     expected = create_test_data()
     with self.create_store() as store:
         expected.dump_to_store(store)
         # the test data contains times.  In case the store
         # cf_encodes them we need to cf_decode them.
         actual = Dataset.load_store(store, cf_decoder)
     self.assertDatasetAllClose(expected, actual)
Ejemplo n.º 5
0
 def test_zero_dimensional_variable(self):
     expected = create_test_data()
     expected['xray_awesomeness'] = ([], np.array(1.e9),
                                     {'units': 'units of awesome'})
     with self.create_store() as store:
         expected.dump_to_store(store)
         actual = Dataset.load_store(store)
     self.assertDatasetAllClose(expected, actual)
Ejemplo n.º 6
0
 def test_cmp_local_file(self):
     url = 'http://test.opendap.org/opendap/hyrax/data/nc/bears.nc'
     actual = Dataset.load_store(backends.PydapDataStore(url))
     with open_example_dataset('bears.nc') as expected:
         # don't check attributes since pydap doesn't serialize them correctly
         # also skip the "bears" variable since the test DAP server incorrectly
         # concatenates it.
         self.assertDatasetEqual(actual.unselect('bears'),
                                 expected.unselect('bears'))
Ejemplo n.º 7
0
 def test_cmp_local_file(self):
     url = 'http://test.opendap.org/opendap/hyrax/data/nc/bears.nc'
     actual = Dataset.load_store(backends.PydapDataStore(url))
     with open_example_dataset('bears.nc') as expected:
         # don't check attributes since pydap doesn't serialize them correctly
         # also skip the "bears" variable since the test DAP server incorrectly
         # concatenates it.
         self.assertDatasetEqual(actual.unselect('bears'),
                                 expected.unselect('bears'))
Ejemplo n.º 8
0
    def test_lazy_load(self):
        store = InaccessibleVariableDataStore()
        create_test_data().dump_to_store(store)

        for decode_cf in [False, True]:
            ds = Dataset.load_store(store, decode_cf=decode_cf)
            with self.assertRaises(UnexpectedDataAccess):
                ds['var1'].values

            # these should not raise UnexpectedDataAccess:
            ds.indexed(time=10)
            ds.indexed(time=slice(10), dim1=[0]).indexed(dim1=0, dim2=-1)
Ejemplo n.º 9
0
    def test_zero_dimensional_variable(self):
        if PY3 and type(self) is ScipyDataTest:
            # see the fix: https://github.com/scipy/scipy/pull/3617
            raise unittest.SkipTest('scipy.io.netcdf is broken on Python 3')

        expected = create_test_data()
        expected['xray_awesomeness'] = ([], np.array(1.e9),
                                        {'units': 'units of awesome'})
        with self.create_store() as store:
            expected.dump_to_store(store)
            actual = Dataset.load_store(store)
        self.assertDatasetAllClose(expected, actual)
Ejemplo n.º 10
0
    def test_zero_dimensional_variable(self):
        if PY3 and type(self) is ScipyDataTest:
            # see the fix: https://github.com/scipy/scipy/pull/3617
            raise unittest.SkipTest('scipy.io.netcdf is broken on Python 3')

        expected = create_test_data()
        expected['xray_awesomeness'] = ([], np.array(1.e9), {
            'units': 'units of awesome'
        })
        with self.create_store() as store:
            expected.dump_to_store(store)
            actual = Dataset.load_store(store)
        self.assertDatasetAllClose(expected, actual)
Ejemplo n.º 11
0
    def test_lazy_load(self):
        store = InaccessibleVariableDataStore()
        create_test_data().dump_to_store(store)

        for decode_cf in [False, True]:
            ds = Dataset.load_store(store, decode_cf=decode_cf)
            with self.assertRaises(UnexpectedDataAccess):
                ds.load_data()
            with self.assertRaises(UnexpectedDataAccess):
                ds['var1'].values

            # these should not raise UnexpectedDataAccess:
            ds.indexed(time=10)
            ds.indexed(time=slice(10), dim1=[0]).indexed(dim1=0, dim2=-1)
Ejemplo n.º 12
0
 def test_write_store(self):
     expected = create_test_data()
     with self.create_store() as store:
         expected.dump_to_store(store)
         actual = Dataset.load_store(store)
     self.assertDatasetAllClose(expected, actual)
Ejemplo n.º 13
0
 def test_cmp_local_file(self):
     url = 'http://test.opendap.org/opendap/hyrax/data/nc/bears.nc'
     actual = Dataset.load_store(backends.PydapDataStore(url))
     expected = open_example_dataset('bears.nc')
     # don't check attributes since pydap doesn't serialize them correctly
     self.assertDatasetEqual(actual, expected)
Ejemplo n.º 14
0
 def roundtrip(self, data, **kwdargs):
     store = CFEncodedInMemoryStore(**kwdargs)
     data.dump_to_store(store)
     store.store_dataset(data)
     yield Dataset.load_store(null_wrap(store))
Ejemplo n.º 15
0
 def test_write_store(self):
     expected = create_test_data()
     with self.create_store() as store:
         expected.dump_to_store(store)
         actual = Dataset.load_store(store)
     self.assertDatasetAllClose(expected, actual)
Ejemplo n.º 16
0
 def test_write_store(self):
     expected = create_test_data()
     store = self.get_store()
     expected.dump_to_store(store)
     actual = Dataset.load_store(store)
     self.assertDatasetEqual(expected, actual)