예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
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())
예제 #7
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())
예제 #8
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())
예제 #9
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())