def test_return_type(self): data = numpy.ones((3712, 3712)).astype('int') msg_con = image.ImageContainerQuick(data, self.msg_area, segments=1) area_con = msg_con.resample(self.area_def) res = area_con.image_data self.assertTrue( data.dtype is res.dtype, msg='Failed to maintain input data type')
def project_pyresample(self): """ Reproject the satellite image on an equirectangular map using the pyresample library """ from pyresample import image, geometry from .satellites import pc self.load_image() x_size = self.data.shape[1] y_size = self.data.shape[0] proj_dict = {'a': '6378137.0', 'b': '6356752.3', 'lon_0': self.longitude, 'h': '35785831.0', 'proj': 'geos'} self.extent = 5568742.4 * 0.964 area_extent = (-self.extent, -self.extent, self.extent, self.extent) area = geometry.AreaDefinition('geo', 'geostat', 'geo', proj_dict, x_size, y_size, area_extent) dataIC = image.ImageContainerQuick(self.data, area) dataResampled = dataIC.resample(pc(self.outwidth, self.outheight)) dataResampledImage = self.rescale(dataResampled.image_data) dataResampledImage = self.polar_clouds(dataResampledImage) weight = self.get_weight() if self.debug: print("image max:", np.max(dataResampledImage)) result = np.array([dataResampledImage, weight]) return result
def test_image_segments(self): data = numpy.fromfunction(lambda y, x: y * x * 10**-6, (3712, 3712)) msg_con = image.ImageContainerQuick(data, self.msg_area, segments=8) area_con = msg_con.resample(self.area_def) res = area_con.image_data cross_sum = res.sum() expected = 399936.39392500359 self.assertAlmostEqual(cross_sum, expected)
def resample(field, nrows, ncols, src_area, dest_area): field2d = field.reshape((nrows, ncols)) src_container = image.ImageContainerQuick(field2d, src_area) dest_container = src_container.resample(dest_area) resampled = dest_container.image_data return resampled.flatten()
def project_pyresample(self): """ Reproject the satellite image on an equirectangular map using the pyresample library """ from pyresample import image, geometry from .satellites import pc from PIL import ImageFilter img = Image.open(self.filename).convert("L") img = self.cut_borders(img) # round away grid im2 = img.filter(ImageFilter.MedianFilter(3)) # create mask for borders mask = img.point(lambda x: 0 if x < 250 else 255).filter( ImageFilter.FIND_EDGES).filter(ImageFilter.MaxFilter(3)) # create replacement picture with borders smoothed way # picture_count += 1 im3 = im2.filter(ImageFilter.MinFilter(7)) im4 = Image.composite(im3, im2, mask) self.data = np.array(im4) self.x_size = self.data.shape[1] self.y_size = self.data.shape[0] proj_dict = { 'lon_0': self.longitude, 'lat_0': self.latitude, 'proj': 'stere', 'ellps': 'WGS84', 'units': 'm' } area = geometry.AreaDefinition('stere', 'stere', 'stere', proj_dict, self.x_size, self.y_size, self.extent) dataIC = image.ImageContainerQuick(self.data, area) dataResampled = dataIC.resample(pc(self.outwidth, self.outheight)) dataResampledImage = self.rescale(dataResampled.image_data) # dataResampledImage = np.ones(shape=dataResampledImage.shape) * 1e-7 weightResampledImage = self.get_weight() # weightIC = image.ImageContainerQuick(weight, area) # weightResampled = weightIC.resample(pc(self.outwidth, # self.outheight)) # weightResampledImage = weightResampled.image_data # dataResampledImage = self.polar_clouds(dataResampledImage) self.logger.info("image max: %r" % np.max(dataResampledImage)) result = np.array([dataResampledImage, weightResampledImage]) return result
def test_masked_image(self): data = numpy.zeros((3712, 3712)) mask = numpy.zeros((3712, 3712)) mask[:, 1865:] = 1 data_masked = numpy.ma.array(data, mask=mask) msg_con = image.ImageContainerQuick( data_masked, self.msg_area, segments=1) area_con = msg_con.resample(self.area_def) res = area_con.image_data resampled_mask = res.mask.astype('int') expected = numpy.fromfile(os.path.join(os.path.dirname(__file__), 'test_files', 'mask_grid.dat'), sep=' ').reshape((800, 800)) self.assertTrue(numpy.array_equal( resampled_mask, expected), msg='Failed to resample masked array')
def project_pyresample(self): """ Reproject the satellite image on an equirectangular map using the pyresample library """ from pyresample import image, geometry from .satellites import pc img = Image.open(self.filename).convert("L") self.logger.debug("image size uncut: %s" % (np.array(img).shape, )) self.data = self.cut_borders(np.array(img)) self.logger.debug("image size cut: %s" % (self.data.shape, )) x_size = self.data.shape[1] y_size = self.data.shape[0] proj_dict = { 'a': '6378137.0', 'b': '6356752.3', 'lon_0': self.longitude, 'h': '35785831.0', 'proj': 'geos' } self.extent = 5568742.4 * 0.964 area_extent = (-self.extent, -self.extent, self.extent, self.extent) area = geometry.AreaDefinition('geo', 'geostat', 'geo', proj_dict, x_size, y_size, area_extent) dataIC = image.ImageContainerQuick(self.data, area) dataResampled = dataIC.resample(pc(self.outwidth, self.outheight)) dataResampledImage = self.rescale(dataResampled.image_data) dataResampledImage = self.polar_clouds(dataResampledImage) weight = self.get_weight() self.logger.debug("image max: %d" % np.max(dataResampledImage)) result = np.array([dataResampledImage, weight]) return result
def main(): lons1 = list(range(10)) lats1 = list(range(10)) lons2 = list(range(0, 10, 2)) lats2 = list(range(0, 10, 2)) lats1, lons1 = np.meshgrid(lats1, lons1) lats2, lons2 = np.meshgrid(lats2, lons2) gd1 = geometry.SwathDefinition(lons=lons1, lats=lats1) gd2 = geometry.SwathDefinition(lons=lons2, lats=lats2) data = np.ones(lons1.shape) img1 = image.ImageContainerQuick(data, gd1, nprocs=5, fill_value=None) img2 = img1.resample(gd2) plot.show_quicklook(gd2, img2.image_data, label="test") #TODO: implement pass
#Dy SIGN REVERSED IN VERSION 1.3!!!! #calculate drift from second file u_coarse2 = dx * 1000 / (2 * 24 * 60 * 60) #sea ice velocity in m/s v_coarse2 = -dy * 1000 / (2 * 24 * 60 * 60) #make average over the two files u_coarse = (u_coarse1 + u_coarse2) / 2 v_coarse = (v_coarse1 + v_coarse2) / 2 #take values just form the first file u_coarse = u_coarse2 v_coarse = v_coarse2 ##reproject the sea ice drift to the ice concentration grid (62.5 > 10km) ##tmp = image.ImageContainerNearest(u_coarse, area_def_coarse, radius_of_influence=70000) tmp = image.ImageContainerQuick(u_coarse, area_def_coarse) u = tmp.resample(area_def).image_data ##tmp = image.ImageContainerNearest(v_coarse, area_def_coarse, radius_of_influence=70000) tmp = image.ImageContainerQuick(v_coarse, area_def_coarse) v = tmp.resample(area_def).image_data #interpolate missing drift values #u = kd_tree.resample_nearest(area_def_coarse, u_coarse ,area_def, radius_of_influence=100000) #v = kd_tree.resample_nearest(area_def_coarse, u_coarse ,area_def, radius_of_influence=100000) #mask all the data #ic_gates = np.ma.array(icecon,mask=~gates) u_n = np.ma.array(u, mask=~mask1) u_s = np.ma.array(u, mask=~mask2) v_e = np.ma.array(v, mask=~mask3) v_w = np.ma.array(v, mask=~mask4)
inputs = np.dsplit(testdata, 13) ir108 = inputs[0] ir039 = inputs[1] vis008 = inputs[2] nir016 = inputs[3] vis006 = inputs[4] ir087 = inputs[5] ir120 = inputs[6] elev = inputs[7] cot = inputs[8] reff = inputs[9] cwp = inputs[10] lat = inputs[11] lon = inputs[12] msg_con_quick = image.ImageContainerQuick(ir108.squeeze(), area_def) area_con_quick = msg_con_quick.resample(euro_areadef) result_data_quick = area_con_quick.image_data # Create satpy scene testscene = Scene(platform_name="msg", sensor="seviri", start_time=datetime(2013, 11, 12, 8, 30), end_time=datetime(2013, 11, 12, 8, 45), area=area_def) array_kwargs = {'area': area_def} testscene['ir108'] = Dataset(ir108.squeeze(), **array_kwargs) print(testscene['ir108']) testscene.show( 'ir108',
def resample_data(lats, lons, data): #Grid definition information of existing data grid_def = geometry.GridDefinition(lons=lons, lats=lats) #Wanted projection area_id = 'laps_scan' description = 'LAPS Scandinavian domain' proj_id = 'stere' proj = 'epsg:3995' lon_0 = 20.0 lat_0 = 90.0 #x_size = 1000 #y_size = 1000 #Corner points to be converted to wanted projection lon1 = -2.448425 lat1 = 68.79139 lon2 = 29.38635 lat2 = 54.67893 #Calculate coordinate points in projection p = Proj(init=proj) x1, y1 = p(lon1, lat1) x2, y2 = p(lon2, lat2) print x1, y1, x2, y2 print abs(x1 - x2) / abs(y1 - y2) print abs(y1 - y2) / abs(x1 - x2) x_size = 1000 y_size = abs(x1 - x2) / abs(y1 - y2) * 1000 area_extent = (x1, y1, x2, y2) proj_dict = { 'a': '6371228.0', 'units': 'm', 'lon_0': lon_0, 'proj': proj_id, 'lat_0': lat_0 } area_def = geometry.AreaDefinition(area_id, description, proj_id, proj_dict, x_size, y_size, area_extent) print area_def #Finland domain #lon1=16.52893 #lat1=70.34990 #lon2=31.85138 #lat2=58.76623 #Resampling data laps_con_quick = image.ImageContainerQuick(data, grid_def) area_con_quick = laps_con_quick.resample(area_def) result_data_quick = area_con_quick.image_data laps_con_nn = image.ImageContainerNearest(data, grid_def, radius_of_influence=50000) area_con_nn = laps_con_nn.resample(area_def) result_data_nn = area_con_nn.image_data print result_data_nn
x_ur, y_ur = prj(19, 55) ger_extent = (x_ll, y_ll, x_ur, y_ur) germ_areadef = utils.load_area( os.path.join(os.getenv("PPP_CONFIG_DIR"), "areas.yaml"), 'germ') germ_extent = germ_areadef.area_extent_ll x_ll, y_ll = prj(*germ_extent[0:2]) x_ur, y_ur = prj(*germ_extent[2:]) ger_extent = (x_ll, y_ll, x_ur, y_ur) # Import geoftiff with DEM information tiff = "/media/nas/satablage/Thomas/Grassdata/srtm_germany_dsm.tif" params, dem = gtiff.read_geotiff(tiff) tiffarea = gtiff.tiff2areadef(params['projection'], params['geotransform'], dem.shape) elevation = image.ImageContainerQuick(dem, tiffarea) # Directory for cloud physical properties cpp_dir = '/media/nas/satablage/Thomas/Nebel/CMSAF_microphysics' # Define time series for analysis #start = "201408270700" #end = "201408270715" start = "201311120830" end = "201311120845" #start = "201407110800" #end = "201407110815" step = [15] time_period = get_time_period(start, end, step)
'lat_ts': '50.00', 'lon_0': '8.00', 'proj': 'stere' }, 5924, 7930, [-1370912.72, -909968.64, 1029087.28, 1490031.36]) msg_area = geometry.AreaDefinition( 'msg_full', 'Full globe MSG image 0 degrees', 'msg_full', { 'a': '6378169.0', 'b': '6356584.0', 'h': '35785831.0', 'lon_0': '0', 'proj': 'geos' }, 5924, 7930, [-5568742.4, -5568742.4, 5568742.4, 5568742.4]) data = S_VV_ABS msg_con_quick = image.ImageContainerQuick(data, msg_area) area_con_quick = msg_con_quick.resample(area_def) result_data_quick = area_con_quick.image_data msg_con_nn = image.ImageContainerNearest(data, msg_area, radius_of_influence=50000) area_con_nn = msg_con_nn.resample(area_def) result_data_nn = area_con_nn.image_data result = pr.kd_tree.resample_nearest(msg_area, data.ravel(), \ area_def, radius_of_influence=50000, epsilon=100, nprocs=4)