コード例 #1
0
 def test_specific_subindex_overflow_warning(self):
     dims = self.dimensions
     dims['time'] = [1, 3]
     with nc.loader('unittest0*.nc', dimensions=dims) as t_root:
         t_data = nc.getvar(t_root, 'data')
         data = nc.getvar(t_root.root, 'data')
         self.assertEquals(data.shape, (5, 100, 200))
         self.assertEquals(t_data.shape, (2, 40, 160))
         self.assertEquals(nc.getvar(t_root, 'time').shape, (2, 1))
         # The random values goes from 2.5 to 10 with 0.5 steps.
         with self.assertRaisesRegexp(
                 Exception, 'Overflow: Index outside of the tile '
                 'dimensions.'):
             t_data[1:3, 10, 30] = 1.5
         with self.assertRaisesRegexp(
                 Exception, 'Overflow: Index outside of the tile '
                 'dimensions.'):
             t_data[1:2, -41, 30] = 1.5
         with self.assertRaisesRegexp(
                 Exception, 'Overflow: Index outside of the tile '
                 'dimensions.'):
             t_data[1:2, 10, -161] = 1.5
         with self.assertRaisesRegexp(
                 Exception, 'Overflow: Index outside of the tile '
                 'dimensions.'):
             t_data[-3:-1, -10, -30] = 1.5
         with self.assertRaisesRegexp(
                 Exception, 'Overflow: Index outside of the tile '
                 'dimensions.'):
             t_data[-2:, 41, -30] = 1.5
         with self.assertRaisesRegexp(
                 Exception, 'Overflow: Index outside of the tile '
                 'dimensions.'):
             t_data[-2:, -10, 161] = 1.5
         self.assertTrue((t_data[:] != 1.5).all())
コード例 #2
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_getvar_source_to_single_file(self):
     dims = self.dimensions
     # TODO: It should spread the dimensions limits from the source.
     with nc.loader("unittest_other.nc") as new_root:
         with nc.loader("unittest0*.nc", dimensions=dims) as t_root:
             t_data = nc.getvar(t_root, "data")
             data = nc.getvar(new_root, "new_data", source=t_data)
             self.assertEquals(t_data.shape, (3, 40, 160))
             self.assertEquals(nc.getvar(t_root, "time").shape, (3, 1))
             self.assertTrue((t_data[:] == data[0, :3, 10:50, 20:-20]).all())
             # The random values goes from 2.5 to 10 with 0.5 steps.
             data[0:2, -30:-20, -10:-5] = 1.5
             self.assertTrue((data[:] != 1.5).any())
コード例 #3
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_getvar_source_to_multiple_files(self):
     dims = self.dimensions
     self.mult = [self.create_ref_file("unittest_ot%s.nc" % (str(i).zfill(2))) for i in range(5)]
     # TODO: It should spread the dimensions limits from the source.
     with nc.loader("unittest_ot0*.nc") as new_root:
         with nc.loader("unittest0*.nc", dimensions=dims) as t_root:
             t_data = nc.getvar(t_root, "data")
             data = nc.getvar(new_root, "new_data", source=t_data)
             self.assertEquals(t_data.shape, (3, 40, 160))
             self.assertEquals(nc.getvar(t_root, "time").shape, (3, 1))
             self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
             # The random values goes from 2.5 to 10 with 0.5 steps.
             data[0:2, -30:-20, -10:-5] = 1.5
             self.assertTrue((data[:] != 1.5).any())
コード例 #4
0
def cut_positions(filename, blurred, *positions):
	blurred = int(blurred)
	pos = eval("".join(positions))
	root, is_new = nc.open(filename)
	lat = nc.getvar(root, 'lat')
	lon = nc.getvar(root, 'lon')
	data = nc.getvar(root, 'data')
	time = nc.getvar(root, 'time')
	root_cut, is_new = nc.open('cut_positions.' + filename)
	timing_d = nc.getdim(root_cut, 'timing', data.shape[0])
	northing_d = nc.getdim(root_cut, 'northing', len(pos))
	easting_d = nc.getdim(root_cut, 'easting', 2)
	lat_cut = nc.getvar(root_cut, 'lat', 'f4', ('northing','easting',),4)
	lon_cut = nc.getvar(root_cut, 'lon', 'f4', ('northing','easting',),4)
	data_cut = nc.getvar(root_cut, 'data', 'f4', ('timing','northing','easting',),4)
	time_cut = nc.getvar(root_cut, 'time', 'f4', ('timing',),4)
	time_cut[:] = time[:]
	for i in range(len(pos)):
		show("\rCutting data: processing position %d / %d " % (i+1, len(pos)))
		x, y = search_position(pos[i], lat, lon)
		lat_cut[i,0] = lat[x,y]
		lon_cut[i,0] = lon[x,y]
		data_cut[:,i,0] = np.apply_over_axes(np.mean, data[:,x-blurred:x+blurred,y-blurred:y+blurred], axes=[1,2])
		lat_cut[i,1], lon_cut[i,1], data_cut[:,i,1] = lat_cut[i,0], lon_cut[i,0], data_cut[:,i,0]
	nc.close(root)
	nc.close(root_cut)
コード例 #5
0
 def test_getvar_source_to_single_file(self):
     dims = self.dimensions
     # TODO: It should spread the dimensions limits from the source.
     with nc.loader('unittest_other.nc') as new_root:
         with nc.loader('unittest0*.nc', dimensions=dims) as t_root:
             t_data = nc.getvar(t_root, 'data')
             data = nc.getvar(new_root, 'new_data', source=t_data)
             self.assertEquals(t_data.shape, (3, 40, 160))
             self.assertEquals(nc.getvar(t_root, 'time').shape, (3, 1))
             self.assertTrue((t_data[:] == data[0, :3, 10:50,
                                                20:-20]).all())
             # The random values goes from 2.5 to 10 with 0.5 steps.
             data[0:2, -30:-20, -10:-5] = 1.5
             self.assertTrue((data[:] != 1.5).any())
コード例 #6
0
 def test_specific_subindex_support(self):
     dims = self.dimensions
     with nc.loader('unittest0*.nc', dimensions=dims) as t_root:
         t_data = nc.getvar(t_root, 'data')
         data = nc.getvar(t_root.root, 'data')
         self.assertEquals(data.shape, (5, 100, 200))
         self.assertEquals(t_data.shape, (3, 40, 160))
         self.assertEquals(nc.getvar(t_root, 'time').shape, (3, 1))
         # The random values goes from 2.5 to 10 with 0.5 steps.
         t_data[0:2, 10, 3] = 1.5
         self.assertTrue((t_data[0:2, 10, 3] == 1.5).all())
         self.assertTrue((data[0:2, 20, 23] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
     with nc.loader('unittest0*.nc') as root:
         data = nc.getvar(root, 'data')
         self.assertTrue((data[0, 20, 23] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
コード例 #7
0
 def test_getvar_source_to_multiple_files(self):
     dims = self.dimensions
     self.mult = [
         self.create_ref_file('unittest_ot%s.nc' % (str(i).zfill(2)))
         for i in range(5)
     ]
     # TODO: It should spread the dimensions limits from the source.
     with nc.loader('unittest_ot0*.nc') as new_root:
         with nc.loader('unittest0*.nc', dimensions=dims) as t_root:
             t_data = nc.getvar(t_root, 'data')
             data = nc.getvar(new_root, 'new_data', source=t_data)
             self.assertEquals(t_data.shape, (3, 40, 160))
             self.assertEquals(nc.getvar(t_root, 'time').shape, (3, 1))
             self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
             # The random values goes from 2.5 to 10 with 0.5 steps.
             data[0:2, -30:-20, -10:-5] = 1.5
             self.assertTrue((data[:] != 1.5).any())
コード例 #8
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_specific_subindex_support(self):
     dims = self.dimensions
     with nc.loader("unittest0*.nc", dimensions=dims) as t_root:
         t_data = nc.getvar(t_root, "data")
         data = nc.getvar(t_root.root, "data")
         self.assertEquals(data.shape, (5, 100, 200))
         self.assertEquals(t_data.shape, (3, 40, 160))
         self.assertEquals(nc.getvar(t_root, "time").shape, (3, 1))
         # The random values goes from 2.5 to 10 with 0.5 steps.
         t_data[0:2, 10, 3] = 1.5
         self.assertTrue((t_data[0:2, 10, 3] == 1.5).all())
         self.assertTrue((data[0:2, 20, 23] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
     with nc.loader("unittest0*.nc") as root:
         data = nc.getvar(root, "data")
         self.assertTrue((data[0, 20, 23] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
コード例 #9
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_compact_multiple_files(self):
     t_root = nc.tailor("unittest0*.nc", dimensions=self.dimensions)
     t_data = nc.getvar(t_root, "data")
     data = nc.getvar(t_root.root, "data")
     self.assertEquals(data.shape, (5, 100, 200))
     self.assertEquals(t_data.shape, (3, 40, 160))
     self.assertEquals(nc.getvar(t_root, "time").shape, (3, 1))
     self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
     # The random values goes from 2.5 to 10 with 0.5 steps.
     t_data[:] = 1.5
     self.assertTrue((t_data[:] == 1.5).all())
     self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
     self.assertTrue((data[:] != 1.5).any())
     nc.close(t_root)
     with nc.loader("unittest0*.nc") as root:
         data = nc.getvar(root, "data")
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
コード例 #10
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_using_with_and_readonly_restriction(self):
     # check the files are NOT read only.
     filenames = map(lambda i: "unittest0%i.nc" % i, range(5))
     can_write = map(lambda f: os.access(f, os.W_OK), filenames)
     self.assertTrue(all(can_write))
     # use the with to open the files with readonly access.
     dims = self.dimensions
     with nc.loader("unittest0*.nc", dimensions=dims, read_only=True) as t_root:
         self.assertTrue(t_root.read_only)
         t_data = nc.getvar(t_root, "data")
         data = nc.getvar(t_root.root, "data")
         self.assertEquals(data.shape, (5, 100, 200))
         self.assertEquals(t_data.shape, (3, 40, 160))
         self.assertEquals(nc.getvar(t_root, "time").shape, (3, 1))
         self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
         with self.assertRaisesRegexp(Exception, u"NetCDF: Write to read only"):
             var = nc.getvar(t_root, "data")
             var[:] = 0
コード例 #11
0
 def test_compact_multiple_files(self):
     t_root = nc.tailor('unittest0*.nc', dimensions=self.dimensions)
     t_data = nc.getvar(t_root, 'data')
     data = nc.getvar(t_root.root, 'data')
     self.assertEquals(data.shape, (5, 100, 200))
     self.assertEquals(t_data.shape, (3, 40, 160))
     self.assertEquals(nc.getvar(t_root, 'time').shape, (3, 1))
     self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
     # The random values goes from 2.5 to 10 with 0.5 steps.
     t_data[:] = 1.5
     self.assertTrue((t_data[:] == 1.5).all())
     self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
     self.assertTrue((data[:] != 1.5).any())
     nc.close(t_root)
     with nc.loader('unittest0*.nc') as root:
         data = nc.getvar(root, 'data')
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
コード例 #12
0
 def test_getvar_source(self):
     dims = self.dimensions
     with nc.loader('unittest0*.nc', dimensions=dims) as t_root:
         ref_data = nc.getvar(t_root.root, 'data')
         t_data = nc.getvar(t_root, 'new_data', source=ref_data)
         data = nc.getvar(t_root.root, 'new_data')
         self.assertEquals(data.shape, (5, 100, 200))
         self.assertEquals(t_data.shape, (3, 40, 160))
         self.assertEquals(nc.getvar(t_root, 'time').shape, (3, 1))
         self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
         # The random values goes from 2.5 to 10 with 0.5 steps.
         t_data[:] = 1.5
         self.assertTrue((t_data[:] == 1.5).all())
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
     with nc.loader('unittest0*.nc') as root:
         data = nc.getvar(root, 'new_data')
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
コード例 #13
0
 def test_using_with(self):
     # use the with to open the files.
     dims = self.dimensions
     with nc.loader('unittest0*.nc', dimensions=dims) as t_root:
         t_data = nc.getvar(t_root, 'data')
         data = nc.getvar(t_root.root, 'data')
         self.assertEquals(data.shape, (5, 100, 200))
         self.assertEquals(t_data.shape, (3, 40, 160))
         self.assertEquals(nc.getvar(t_root, 'time').shape, (3, 1))
         self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
         # The random values goes from 2.5 to 10 with 0.5 steps.
         t_data[:] = 1.5
         self.assertTrue((t_data[:] == 1.5).all())
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
     with nc.loader('unittest0*.nc') as root:
         data = nc.getvar(root, 'data')
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
コード例 #14
0
 def test_simple_file(self):
     root = nc.open('unittest00.nc')[0]
     t_root = nc.tailor(root, dimensions=self.dimensions)
     t_data = nc.getvar(t_root, 'data')
     data = nc.getvar(root, 'data')
     self.assertEquals(data.shape, (1, 100, 200))
     self.assertEquals(t_data.shape, (1, 40, 160))
     self.assertEquals(nc.getvar(t_root, 'time').shape, (1, ))
     self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
     # The random values goes from 2.5 to 10 with 0.5 steps.
     t_data[:] = 1.5
     nc.sync(t_root)
     self.assertTrue((t_data[:] == 1.5).all())
     self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
     # self.assertTrue((data[:] != 1.5).any())
     nc.close(t_root)
     with nc.loader('unittest00.nc') as root:
         data = nc.getvar(root, 'data')
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
コード例 #15
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_using_with(self):
     # use the with to open the files.
     dims = self.dimensions
     with nc.loader("unittest0*.nc", dimensions=dims) as t_root:
         t_data = nc.getvar(t_root, "data")
         data = nc.getvar(t_root.root, "data")
         self.assertEquals(data.shape, (5, 100, 200))
         self.assertEquals(t_data.shape, (3, 40, 160))
         self.assertEquals(nc.getvar(t_root, "time").shape, (3, 1))
         self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
         # The random values goes from 2.5 to 10 with 0.5 steps.
         t_data[:] = 1.5
         self.assertTrue((t_data[:] == 1.5).all())
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
     with nc.loader("unittest0*.nc") as root:
         data = nc.getvar(root, "data")
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
コード例 #16
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_getvar_source(self):
     dims = self.dimensions
     with nc.loader("unittest0*.nc", dimensions=dims) as t_root:
         ref_data = nc.getvar(t_root.root, "data")
         t_data = nc.getvar(t_root, "new_data", source=ref_data)
         data = nc.getvar(t_root.root, "new_data")
         self.assertEquals(data.shape, (5, 100, 200))
         self.assertEquals(t_data.shape, (3, 40, 160))
         self.assertEquals(nc.getvar(t_root, "time").shape, (3, 1))
         self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
         # The random values goes from 2.5 to 10 with 0.5 steps.
         t_data[:] = 1.5
         self.assertTrue((t_data[:] == 1.5).all())
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
     with nc.loader("unittest0*.nc") as root:
         data = nc.getvar(root, "new_data")
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
コード例 #17
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_simple_file(self):
     root = nc.open("unittest00.nc")[0]
     t_root = nc.tailor(root, dimensions=self.dimensions)
     t_data = nc.getvar(t_root, "data")
     data = nc.getvar(root, "data")
     self.assertEquals(data.shape, (1, 100, 200))
     self.assertEquals(t_data.shape, (1, 40, 160))
     self.assertEquals(nc.getvar(t_root, "time").shape, (1,))
     self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
     # The random values goes from 2.5 to 10 with 0.5 steps.
     t_data[:] = 1.5
     nc.sync(t_root)
     self.assertTrue((t_data[:] == 1.5).all())
     self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
     # self.assertTrue((data[:] != 1.5).any())
     nc.close(t_root)
     with nc.loader("unittest00.nc") as root:
         data = nc.getvar(root, "data")
         self.assertTrue((data[:3, 10:50, 20:-20] == 1.5).all())
コード例 #18
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_getdim(self):
     dims = self.dimensions
     with nc.loader("unittest_dims.nc", dimensions=dims) as t_root:
         t_dim_x = nc.getdim(t_root, "xc_k", 1)
         t_dim_y = nc.getdim(t_root, "yc_k", 1)
         t_dim_time = nc.getdim(t_root, "time", 1)
         self.assertEquals(len(t_dim_x[0]), 1)
         self.assertEquals(len(t_dim_y[0]), 1)
         self.assertEquals(len(t_dim_time[0]), 1)
         t_data = nc.getvar(t_root, "only_one_pixel", "f4", ("time", "yc_k", "xc_k"))
         self.assertEquals(t_data.shape, (1, 1, 1))
コード例 #19
0
 def test_using_with_and_readonly_restriction(self):
     # check the files are NOT read only.
     filenames = map(lambda i: 'unittest0%i.nc' % i, range(5))
     can_write = map(lambda f: os.access(f, os.W_OK), filenames)
     self.assertTrue(all(can_write))
     # use the with to open the files with readonly access.
     dims = self.dimensions
     with nc.loader('unittest0*.nc', dimensions=dims,
                    read_only=True) as t_root:
         self.assertTrue(t_root.read_only)
         t_data = nc.getvar(t_root, 'data')
         data = nc.getvar(t_root.root, 'data')
         self.assertEquals(data.shape, (5, 100, 200))
         self.assertEquals(t_data.shape, (3, 40, 160))
         self.assertEquals(nc.getvar(t_root, 'time').shape, (3, 1))
         self.assertTrue((t_data[:] == data[:3, 10:50, 20:-20]).all())
         with self.assertRaisesRegexp(Exception,
                                      u'NetCDF: Write to read only'):
             var = nc.getvar(t_root, 'data')
             var[:] = 0
コード例 #20
0
 def test_getdim(self):
     dims = self.dimensions
     with nc.loader('unittest_dims.nc', dimensions=dims) as t_root:
         t_dim_x = nc.getdim(t_root, 'xc_k', 1)
         t_dim_y = nc.getdim(t_root, 'yc_k', 1)
         t_dim_time = nc.getdim(t_root, 'time', 1)
         self.assertEquals(len(t_dim_x[0]), 1)
         self.assertEquals(len(t_dim_y[0]), 1)
         self.assertEquals(len(t_dim_time[0]), 1)
         t_data = nc.getvar(t_root, 'only_one_pixel', 'f4',
                            ('time', 'yc_k', 'xc_k'))
         self.assertEquals(t_data.shape, (1, 1, 1))
コード例 #21
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_getvar_with_incomplete_limited_dimensions(self):
     self.dimensions.pop("time", None)
     root = nc.open("unittest0*.nc")[0]
     t_root = nc.tailor(root, dimensions=self.dimensions)
     t_data = nc.getvar(t_root, "data")
     data = nc.getvar(root, "data")
     nc.sync(root)
     self.assertEquals(data.shape, (5, 100, 200))
     self.assertEquals(t_data.shape, (5, 40, 160))
     self.assertEquals(nc.getvar(t_root, "time").shape, (5, 1))
     self.assertTrue((t_data[:] == data[:, 10:50, 20:-20]).all())
     # The random values goes from 2.5 to 10 with 0.5 steps.
     t_data[:] = 1.5
     self.assertTrue((t_data[:] == 1.5).all())
     self.assertTrue((data[:, 10:50, 20:-20] == 1.5).all())
     self.assertTrue((data[:] != 1.5).any())
     nc.close(t_root)
     with nc.loader("unittest0*.nc") as root:
         data = nc.getvar(root, "data")
         self.assertTrue((data[:, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
コード例 #22
0
 def test_getvar_with_incomplete_limited_dimensions(self):
     self.dimensions.pop('time', None)
     root = nc.open('unittest0*.nc')[0]
     t_root = nc.tailor(root, dimensions=self.dimensions)
     t_data = nc.getvar(t_root, 'data')
     data = nc.getvar(root, 'data')
     nc.sync(root)
     self.assertEquals(data.shape, (5, 100, 200))
     self.assertEquals(t_data.shape, (5, 40, 160))
     self.assertEquals(nc.getvar(t_root, 'time').shape, (5, 1))
     self.assertTrue((t_data[:] == data[:, 10:50, 20:-20]).all())
     # The random values goes from 2.5 to 10 with 0.5 steps.
     t_data[:] = 1.5
     self.assertTrue((t_data[:] == 1.5).all())
     self.assertTrue((data[:, 10:50, 20:-20] == 1.5).all())
     self.assertTrue((data[:] != 1.5).any())
     nc.close(t_root)
     with nc.loader('unittest0*.nc') as root:
         data = nc.getvar(root, 'data')
         self.assertTrue((data[:, 10:50, 20:-20] == 1.5).all())
         self.assertTrue((data[:] != 1.5).any())
コード例 #23
0
def cut_positions(filename, blurred, *positions):
	blurred = int(blurred)
	pos = eval("".join(positions))
	root = nc.open(filename)[0]
	lat = nc.getvar(root, 'lat')
	lon = nc.getvar(root, 'lon')
	data = nc.getvar(root, 'data')
	root_cut = nc.clonefile(root, 'cut_positions.' + filename, ['lat', 'lon', 'data'])[0]
	nc.getdim(root_cut, 'northing_cut', len(pos))
	nc.getdim(root_cut, 'easting_cut', 2)
	lat_cut = nc.getvar(root_cut, 'lat', 'f4', ('northing_cut','easting_cut',),4)
	lon_cut = nc.getvar(root_cut, 'lon', 'f4', ('northing_cut','easting_cut',),4)
	data_cut = nc.getvar(root_cut, 'data', 'f4', ('timing','northing_cut','easting_cut',),4)
	ix = 0
	for i in range(len(pos)):
		show("\rCutting data: processing position %d / %d " % (i+1, len(pos)))
		x, y = statistical_search_position(pos[i], lat, lon)
		if x and y:
			lat_cut[ix,0] = lat[x,y]
			lon_cut[ix,0] = lon[x,y]
			data_cut[:,ix,0] = np.apply_over_axes(np.mean, data[:,x-blurred:x+blurred,y-blurred:y+blurred], axes=[1,2]) if blurred > 0 else data[:,x,y]
			lat_cut[ix,1], lon_cut[ix,1], data_cut[:,ix,1] = lat_cut[ix,0], lon_cut[ix,0], data_cut[:,ix,0]
			ix += 1
	nc.close(root)
	nc.close(root_cut)
コード例 #24
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_specific_subindex_overflow_warning(self):
     dims = self.dimensions
     dims["time"] = [1, 3]
     with nc.loader("unittest0*.nc", dimensions=dims) as t_root:
         t_data = nc.getvar(t_root, "data")
         data = nc.getvar(t_root.root, "data")
         self.assertEquals(data.shape, (5, 100, 200))
         self.assertEquals(t_data.shape, (2, 40, 160))
         self.assertEquals(nc.getvar(t_root, "time").shape, (2, 1))
         # The random values goes from 2.5 to 10 with 0.5 steps.
         with self.assertRaisesRegexp(Exception, "Overflow: Index outside of the tile " "dimensions."):
             t_data[1:3, 10, 30] = 1.5
         with self.assertRaisesRegexp(Exception, "Overflow: Index outside of the tile " "dimensions."):
             t_data[1:2, -41, 30] = 1.5
         with self.assertRaisesRegexp(Exception, "Overflow: Index outside of the tile " "dimensions."):
             t_data[1:2, 10, -161] = 1.5
         with self.assertRaisesRegexp(Exception, "Overflow: Index outside of the tile " "dimensions."):
             t_data[-3:-1, -10, -30] = 1.5
         with self.assertRaisesRegexp(Exception, "Overflow: Index outside of the tile " "dimensions."):
             t_data[-2:, 41, -30] = 1.5
         with self.assertRaisesRegexp(Exception, "Overflow: Index outside of the tile " "dimensions."):
             t_data[-2:, -10, 161] = 1.5
         self.assertTrue((t_data[:] != 1.5).all())
コード例 #25
0
def cut_projected_linke(filename):
	root, is_new = nc.open(filename)
	lat = nc.getvar(root, 'lat')
	lon = nc.getvar(root, 'lon')
	data = nc.getvar(root, 'data')
	time = nc.getvar(root, 'time')
	root_cut, is_new = nc.open('wlinke.' + filename)
	timing_d = nc.getdim(root_cut, 'timing', data.shape[0])
	northing_d = nc.getdim(root_cut, 'northing', data.shape[1])
	easting_d = nc.getdim(root_cut, 'easting', data.shape[2])
	lat_cut = nc.getvar(root_cut, 'lat', 'f4', ('northing','easting',),4)
	lon_cut = nc.getvar(root_cut, 'lon', 'f4', ('northing','easting',),4)
	data_cut = nc.getvar(root_cut, 'data', 'f4', ('timing','northing','easting',),4)
	time_cut = nc.getvar(root_cut, 'time', 'f4', ('timing',),4)
	lat_cut[:] = lat[:]
	lon_cut[:] = lon[:]
	data_cut[:] = data[:]
	time_cut[:] = time[:]
	linke.cut_projected(root_cut)
	nc.close(root)
	nc.close(root_cut)
コード例 #26
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_multiple_files_with_readonly_restriction(self):
     # check the files are NOT read only.
     filenames = map(lambda i: "unittest0%i.nc" % i, range(5))
     can_write = map(lambda f: os.access(f, os.W_OK), filenames)
     self.assertTrue(all(can_write))
     # check if open the pattern selection using using a package instance.
     root = nc.tailor("unittest0*.nc", dimensions=self.dimensions, read_only=True)
     self.assertEquals(root.files, ["unittest0%i.nc" % i for i in range(5)])
     self.assertEquals(root.pattern, "unittest0*.nc")
     self.assertEquals(len(root.roots), 5)
     self.assertFalse(root.is_new)
     self.assertTrue(root.read_only)
     with self.assertRaisesRegexp(Exception, u"NetCDF: Write to read only"):
         var = nc.getvar(root, "data")
         var[:] = 0
     # check if close the package with all the files.
     nc.close(root)
     with self.assertRaisesRegexp(RuntimeError, u"NetCDF: Not a valid ID"):
         nc.close(root)
コード例 #27
0
ファイル: tailored_test.py プロジェクト: li12242/netcdf
 def test_file_with_readonly_restriction(self):
     # check the file is NOT read only.
     filename = "unittest00.nc"
     can_write = os.access(filename, os.W_OK)
     self.assertTrue(can_write)
     # check if open an existent file.
     root = nc.tailor("unittest00.nc", dimensions=self.dimensions, read_only=True)
     self.assertEquals(root.files, ["unittest00.nc"])
     self.assertEquals(root.pattern, "unittest00.nc")
     self.assertEquals(len(root.roots), 1)
     self.assertFalse(root.is_new)
     self.assertTrue(root.read_only)
     with self.assertRaisesRegexp(Exception, u"NetCDF: Write to read only"):
         var = nc.getvar(root, "data")
         var[:] = 0
     # check if close an existent file.
     nc.close(root)
     with self.assertRaisesRegexp(RuntimeError, u"NetCDF: Not a valid ID"):
         nc.close(root)
コード例 #28
0
def cut_projected_terrain(filename):
	from libs.dem import dem
	root = nc.open(filename)[0]
	lat = nc.getvar(root, 'lat')
	lon = nc.getvar(root, 'lon')
	data = nc.getvar(root, 'data')
	time = nc.getvar(root, 'data_time')
	root_cut = nc.open('wterrain.' + filename)[0]
	nc.getdim(root_cut, 'timing', data.shape[0])
	nc.getdim(root_cut, 'northing', data.shape[1])
	nc.getdim(root_cut, 'easting', data.shape[2])
	lat_cut = nc.getvar(root_cut, 'lat', 'f4', ('northing','easting',),4)
	lon_cut = nc.getvar(root_cut, 'lon', 'f4', ('northing','easting',),4)
	data_cut = nc.getvar(root_cut, 'data', 'f4', ('timing','northing','easting',),4)
	time_cut = nc.getvar(root_cut, 'data_time', 'f4', ('timing',),4)
	lat_cut[:] = lat[:]
	lon_cut[:] = lon[:]
	data_cut[:] = data[:]
	time_cut[:] = time[:]
	dem.cut_projected(root_cut)
	nc.close(root)
	nc.close(root_cut)
コード例 #29
0
 def test_file_with_readonly_restriction(self):
     # check the file is NOT read only.
     filename = 'unittest00.nc'
     can_write = os.access(filename, os.W_OK)
     self.assertTrue(can_write)
     # check if open an existent file.
     root = nc.tailor('unittest00.nc',
                      dimensions=self.dimensions,
                      read_only=True)
     self.assertEquals(root.files, ['unittest00.nc'])
     self.assertEquals(root.pattern, 'unittest00.nc')
     self.assertEquals(len(root.roots), 1)
     self.assertFalse(root.is_new)
     self.assertTrue(root.read_only)
     with self.assertRaisesRegexp(Exception, u'NetCDF: Write to read only'):
         var = nc.getvar(root, 'data')
         var[:] = 0
     # check if close an existent file.
     nc.close(root)
     with self.assertRaisesRegexp(RuntimeError, u'NetCDF: Not a valid ID'):
         nc.close(root)
コード例 #30
0
 def test_multiple_files_with_readonly_restriction(self):
     # check the files are NOT read only.
     filenames = map(lambda i: 'unittest0%i.nc' % i, range(5))
     can_write = map(lambda f: os.access(f, os.W_OK), filenames)
     self.assertTrue(all(can_write))
     # check if open the pattern selection using using a package instance.
     root = nc.tailor('unittest0*.nc',
                      dimensions=self.dimensions,
                      read_only=True)
     self.assertEquals(root.files, ['unittest0%i.nc' % i for i in range(5)])
     self.assertEquals(root.pattern, 'unittest0*.nc')
     self.assertEquals(len(root.roots), 5)
     self.assertFalse(root.is_new)
     self.assertTrue(root.read_only)
     with self.assertRaisesRegexp(Exception, u'NetCDF: Write to read only'):
         var = nc.getvar(root, 'data')
         var[:] = 0
     # check if close the package with all the files.
     nc.close(root)
     with self.assertRaisesRegexp(RuntimeError, u'NetCDF: Not a valid ID'):
         nc.close(root)
コード例 #31
0
def cut(filename, i_from, i_to):
	img_from = int(i_from)
	img_to = int(i_to)
	img_range = img_to - img_from
	root = nc.open(filename)[0]
	lat = nc.getvar(root, 'lat')
	lon = nc.getvar(root, 'lon')
	data = nc.getvar(root, 'data')
	time = nc.getvar(root, 'data_time')
	root_cut = nc.open('cut.' + filename)[0]
	nc.getdim(root_cut, 'timing', img_range)
	nc.getdim(root_cut, 'northing', data.shape[1])
	nc.getdim(root_cut, 'easting', data.shape[2])
	lat_cut = nc.getvar(root_cut, 'lat', 'f4', ('northing','easting',),4)
	lon_cut = nc.getvar(root_cut, 'lon', 'f4', ('northing','easting',),4)
	lat_cut[:] = lat[:]
	lon_cut[:] = lon[:]
	data_cut = nc.getvar(root_cut, 'data', 'f4', ('timing','northing','easting',),4)
	time_cut = nc.getvar(root_cut, 'data_time', 'f4', ('timing',),4)
	for i in range(img_range):
		data_cut[i] = data[img_from + i]
		time_cut[i] = time[img_from + i]
	nc.close(root)
	nc.close(root_cut)