Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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))
Ejemplo n.º 4
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))
Ejemplo n.º 5
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)
Ejemplo n.º 6
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, 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.' + filename)
	timing_d = nc.getdim(root_cut, 'timing', img_range)
	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)
	lat_cut[:] = lat[:]
	lon_cut[:] = lon[:]
	data_cut = nc.getvar(root_cut, 'data', 'f4', ('timing','northing','easting',),4)
	time_cut = nc.getvar(root_cut, '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)
Ejemplo n.º 7
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)