Пример #1
0
 def func():
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     for a in self.ncattrs:
         ncf.setncattr(a, self.ncattrs[a])
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     actual = {a: ncfr.getncattr(a) for a in ncfr.ncattrs}
     ncfr.close()
     remove(self.ncfwname)
     return actual
Пример #2
0
 def test_NCFile_setncattr(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     for a in self.ncattrs:
         ncf.setncattr(a, self.ncattrs[a])
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     attrs = {a: ncfr.getncattr(a) for a in ncfr.ncattrs}
     ncfr.close()
     assert attrs == self.ncattrs
Пример #3
0
 def test_NCFile_create_dimension(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     for d in self.ncdims:
         ncf.create_dimension(d, self.ncdims[d])
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     dims = ncfr.dimensions
     ncfr.close()
     assert dims == self.ncdims
Пример #4
0
 def func():
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     for d in self.ncdims:
         ncf.create_dimension(d, self.ncdims[d])
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     actual = ncfr.dimensions
     ncfr.close()
     remove(self.ncfwname)
     return actual
Пример #5
0
 def test_NCFile_create_dimension_unlimited(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     ncf.create_dimension('t')
     ncf.create_dimension('x', 3)
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     assert ncfr.dimensions['t'] == 0
     assert ncfr.unlimited('t') is True
     assert ncfr.dimensions['x'] == 3
     assert ncfr.unlimited('x') is False
     ncfr.close()
Пример #6
0
 def test_cmp_NCVariable_size(self):
     iobackend.set_backend('Nio')
     ncf = iobackend.NCFile(self.ncfrname)
     actual = ncf.variables['v'].size
     ncf.close()
     iobackend.set_backend('netCDF4')
     ncf2 = iobackend.NCFile(self.ncfrname)
     expected = ncf2.variables['v'].size
     ncf2.close()
     print_test_msg('CMP: NCVariable.size',
                    actual=actual,
                    expected=expected)
     self.assertEqual(actual, expected, 'NCVariable size not correct')
Пример #7
0
 def func():
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     ncf.create_dimension('t')
     ncf.create_dimension('x', 3)
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     actual = {
         d: (ncfr.dimensions[d], ncfr.unlimited(d))
         for d in ncfr.dimensions
     }
     ncfr.close()
     remove(self.ncfwname)
     return actual
Пример #8
0
 def test_cmp_NCFile_init_read(self):
     iobackend.set_backend('Nio')
     ncf_nio = iobackend.NCFile(self.ncfrname)
     actual = type(ncf_nio)
     ncf_nio.close()
     iobackend.set_backend('netCDF4')
     ncf_nc4 = iobackend.NCFile(self.ncfrname)
     expected = type(ncf_nc4)
     ncf_nc4.close()
     print_test_msg('CMP: NCFile.__init__()',
                    actual=actual,
                    expected=expected)
     self.assertEqual(actual, expected,
                      'NCFile not created with consisten types')
Пример #9
0
 def test_NCFile_create_variable(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     for d in self.ncdims:
         if d == 't':
             ncf.create_dimension(d)
         else:
             ncf.create_dimension(d, self.ncdims[d])
     for v in self.ncvars:
         ncf.create_variable(v, self.vdtype[v], self.vdims[v])
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     for v in self.ncvars:
         assert isinstance(ncfr.variables[v], iobackend.NCVariable)
     ncfr.close()
Пример #10
0
 def func(variable=''):
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     for d in self.vdims[variable]:
         if d == 't':
             ncf.create_dimension(d)
         else:
             ncf.create_dimension(d, self.ncdims[d])
     ncf.create_variable(variable, self.vdtype[variable],
                         self.vdims[variable])
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     actual = type(ncfr.variables[variable])
     ncfr.close()
     remove(self.ncfwname)
     return actual
Пример #11
0
 def test_NCVariable_fill_value(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfrname)
     for v in self.vfill:
         vfill = ncf.variables[v].fill_value
         assert vfill == self.vfill[v]
     ncf.close()
Пример #12
0
 def test_NCVariable_shape(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfrname)
     for v in self.vshape:
         vshape = ncf.variables[v].shape
         assert vshape == self.vshape[v]
     ncf.close()
Пример #13
0
 def test_NCVariable_dimensions(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfrname)
     for v in self.vdtype:
         vdims = ncf.variables[v].dimensions
         assert vdims == self.vdims[v]
     ncf.close()
Пример #14
0
 def test_NCVariable_setitem_getitem(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     for d in self.ncdims:
         if d == 't':
             ncf.create_dimension(d)
         else:
             ncf.create_dimension(d, self.ncdims[d])
     for v in self.ncvars:
         vobj = ncf.create_variable(v, self.vdtype[v], self.vdims[v])
         vobj[:] = self.ncvars[v]
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     for v in self.ncvars:
         npt.assert_array_equal(ncfr.variables[v][:], self.ncvars[v])
     ncfr.close()
Пример #15
0
 def func(variable=''):
     ncf = iobackend.NCFile(self.ncfrname)
     actual = {
         a: ncf.variables[variable].getncattr(a)
         for a in ncf.variables[variable].ncattrs
     }
     ncf.close()
     return actual
Пример #16
0
 def test_NCVariable_size(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfrname)
     for v in self.vdims:
         vsize1 = ncf.variables[v].size
         vsize2 = reduce(lambda x, y: x * y,
                         (self.ncdims[d] for d in self.vdims[v]), 1)
         assert vsize1 == vsize2
     ncf.close()
Пример #17
0
 def test_nc4_NCFile_init_append(self):
     iobackend.set_backend('netCDF4')
     ncf = iobackend.NCFile(self.ncfaname, mode='a')
     actual = type(ncf)
     ncf.close()
     expected = iobackend.NCFile
     print_test_msg('NCFile.__init__()', actual=actual, expected=expected)
     self.assertEqual(actual, expected,
                      'NCFile not created with correct type')
Пример #18
0
 def test_nio_NCFile_init_write(self):
     iobackend.set_backend('Nio')
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     actual = type(ncf)
     ncf.close()
     expected = iobackend.NCFile
     print_test_msg('NCFile.__init__()', actual=actual, expected=expected)
     self.assertEqual(actual, expected,
                      'NCFile not created with correct type')
Пример #19
0
 def test_NCFile_create_variable_fill(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     for d in self.ncdims:
         if d == 't':
             ncf.create_dimension(d)
         else:
             ncf.create_dimension(d, self.ncdims[d])
     for v in self.ncvars:
         ncf.create_variable(v,
                             self.vdtype[v],
                             self.vdims[v],
                             fill_value=self.vfill[v])
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     for v in self.ncvars:
         vfill = None if v == 's' else self.vfill[v]
         assert ncfr.variables[v].fill_value == vfill
     ncfr.close()
Пример #20
0
 def test_nc4_NCVariable_size(self):
     iobackend.set_backend('netCDF4')
     ncf = iobackend.NCFile(self.ncfrname)
     actual = ncf.variables['v'].size
     expected = self.ncdims['t'] * self.ncdims['x']
     ncf.close()
     print_test_msg('netCDF4: NCVariable.size',
                    actual=actual,
                    expected=expected)
     self.assertEqual(actual, expected, 'NCVariable size not correct')
Пример #21
0
 def test_nc4_NCVariable_datatype(self):
     iobackend.set_backend('netCDF4')
     ncf = iobackend.NCFile(self.ncfrname)
     actual = ncf.variables['v'].datatype
     expected = 'f'
     ncf.close()
     print_test_msg('netCDF4: NCVariable.datatype',
                    actual=actual,
                    expected=expected)
     self.assertEqual(actual, expected, 'NCVariable datatype not correct')
Пример #22
0
 def test_nio_NCVariable_shape(self):
     iobackend.set_backend('Nio')
     ncf = iobackend.NCFile(self.ncfrname)
     actual = ncf.variables['v'].shape
     expected = (self.ncdims['t'], self.ncdims['x'])
     ncf.close()
     print_test_msg('Nio: NCVariable.shape',
                    actual=actual,
                    expected=expected)
     self.assertEqual(actual, expected, 'NCVariable shape not correct')
Пример #23
0
 def test_cmp_NCFile_dimensions(self):
     iobackend.set_backend('Nio')
     ncf = iobackend.NCFile(self.ncfrname)
     actual = ncf.dimensions
     ncf.close()
     iobackend.set_backend('netCDF4')
     ncf2 = iobackend.NCFile(self.ncfrname)
     expected = ncf2.dimensions
     ncf2.close()
     print_test_msg('CMP: NCFile.dimensions',
                    actual=actual,
                    expected=expected)
     self.assertEqual(len(actual), len(expected),
                      'NCFile dimensions not consistent length')
     for dn, dv in expected.iteritems():
         self.assertTrue(dn in actual,
                         'NCFile dimension {0!r} not present'.format(dn))
         self.assertEqual(actual[dn], dv,
                          'NCFile dimension {0!r} not correct'.format(dn))
Пример #24
0
 def test_nc4_NCVariable_dimensions(self):
     iobackend.set_backend('netCDF4')
     ncf = iobackend.NCFile(self.ncfrname)
     actual = ncf.variables['v'].dimensions
     expected = ('t', 'x')
     ncf.close()
     print_test_msg('netCDF4: NCVariable.dimensions',
                    actual=actual,
                    expected=expected)
     self.assertEqual(actual, expected, 'NCVariable dimensions not correct')
Пример #25
0
 def test_NCVariable_ncattrs_getncattr(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfrname)
     for v in self.vattrs:
         vattrs = {
             a: ncf.variables[v].getncattr(a)
             for a in ncf.variables[v].ncattrs
         }
         assert vattrs == self.vattrs[v]
     ncf.close()
Пример #26
0
 def test_NCFile_create_variable_ndim(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfaname, mode='a')
     v2 = ncf.create_variable('v2', np.dtype('f'), ('t', 'x'))
     v2[:] = self.v2
     ncf.close()
     ncfr = netCDF4.Dataset(self.ncfaname)
     actual = ncfr['v2'][:]
     ncfr.close()
     npt.assert_array_equal(actual, self.v2)
Пример #27
0
 def test_NCFile_create_variable_chunksizes(self):
     iobackend.set_backend('netCDF4')
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     for d in self.ncdims:
         if d == 't':
             ncf.create_dimension(d)
         else:
             ncf.create_dimension(d, self.ncdims[d])
     for v in self.ncvars:
         ncf.create_variable(v,
                             self.vdtype[v],
                             self.vdims[v],
                             chunksizes=self.chunks[v])
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     for v in self.ncvars:
         chunksize = self.chunks[v] if self.chunks[v] else 'contiguous'
         assert ncfr.variables[v].chunk_sizes == chunksize
     ncfr.close()
Пример #28
0
 def func(variable=''):
     ncf = iobackend.NCFile(self.ncfwname, mode='w')
     for d in self.vdims[variable]:
         if d == 't':
             ncf.create_dimension(d)
         else:
             ncf.create_dimension(d, self.ncdims[d])
     vobj = ncf.create_variable(variable, self.vdtype[variable],
                                self.vdims[variable])
     for attr in self.vattrs[variable]:
         vobj.setncattr(attr, self.vattrs[variable][attr])
     ncf.close()
     ncfr = iobackend.NCFile(self.ncfwname)
     actual = {
         a: ncfr.variables[variable].getncattr(a)
         for a in ncfr.variables[variable].ncattrs
     }
     ncfr.close()
     remove(self.ncfwname)
     return actual
Пример #29
0
 def test_cmp_NCFile_unlimited(self):
     iobackend.set_backend('Nio')
     ncf = iobackend.NCFile(self.ncfrname)
     t_unlimited_nio = ncf.unlimited('t')
     x_unlimited_nio = ncf.unlimited('x')
     ncf.close()
     iobackend.set_backend('netCDF4')
     ncf2 = iobackend.NCFile(self.ncfrname)
     t_unlimited_nc4 = ncf2.unlimited('t')
     x_unlimited_nc4 = ncf2.unlimited('x')
     ncf2.close()
     print_test_msg('CMP: NCFile.unlimited(t)',
                    actual=t_unlimited_nio,
                    expected=t_unlimited_nc4)
     self.assertEqual(t_unlimited_nio, t_unlimited_nc4,
                      'NCFile dimension t unlimited results inconsistent')
     print_test_msg('CMP: NCFile.unlimited(x)',
                    actual=x_unlimited_nio,
                    expected=x_unlimited_nc4)
     self.assertEqual(x_unlimited_nio, x_unlimited_nc4,
                      'NCFile dimension x unlimited results inconsistent')
Пример #30
0
 def test_NCFile_setncattr(self, backend):
     iobackend.set_backend(backend)
     ncf = iobackend.NCFile(self.ncfaname, mode='a')
     for a, v in self.fattrs2.items():
         ncf.setncattr(a, v)
     ncf.close()
     ncfr = netCDF4.Dataset(self.ncfaname)
     actual = {a: ncfr.getncattr(a) for a in ncfr.ncattrs()}
     ncfr.close()
     expected = self.ncattrs
     expected.update(self.fattrs2)
     assert actual == expected