def test_config_file_points_and_borders_pil(self): from pycoast import ContourWriterPIL from pyresample.geometry import AreaDefinition config_file = os.path.join(os.path.dirname(__file__), 'nh_points_pil.ini') grid_img = Image.open( os.path.join(os.path.dirname(__file__), 'nh_points_cfg_pil.png')) grid_data = np.array(grid_img) img = Image.new('RGB', (1024, 1024), (255, 255, 255)) proj4_string = '+proj=laea +lat_0=90 +lon_0=0 +a=6371228.0 +units=m' area_extent = (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625) area_def = AreaDefinition('nh', 'nh', 'nh', proj4_string, 1024, 1024, area_extent) cw = ContourWriterPIL(gshhs_root_dir) cw.add_overlay_from_config(config_file, area_def, img) res = np.array(img) self.assertTrue(fft_metric(grid_data, res), 'Writing of nh points failed')
def test_config_file_coasts_and_grid(self): from pycoast import ContourWriterPIL from pyresample.geometry import AreaDefinition overlay_config = os.path.join(os.path.dirname(__file__), "coasts_and_grid.ini") grid_img = Image.open( os.path.join(os.path.dirname(__file__), 'grid_nh.png')) grid_data = np.array(grid_img) proj_dict = { 'proj': 'laea', 'lat_0': 90.0, 'lon_0': 0.0, 'a': 6371228.0, 'units': 'm' } area_extent = (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625) area_def = AreaDefinition('nh', 'nh', 'nh', proj_dict, 425, 425, area_extent) cw = ContourWriterPIL(gshhs_root_dir) overlay = cw.add_overlay_from_config(overlay_config, area_def) img = Image.new('RGB', (425, 425)) img.paste(overlay, mask=overlay) res = np.array(img) self.assertTrue(fft_metric(grid_data, res), 'Writing of nh grid failed')
def test_foreground(self): """Test generating a transparent foreground.""" from pycoast import ContourWriterPIL euro_img = Image.open(os.path.join(os.path.dirname(__file__), 'contours_europe_alpha.png')) euro_data = np.array(euro_img) # img = Image.new('RGB', (640, 480)) proj4_string = \ '+proj=stere +lon_0=8.00 +lat_0=50.00 +lat_ts=50.00 +ellps=WGS84' area_extent = (-3363403.31, -2291879.85, 2630596.69, 2203620.1) area_def = FakeAreaDef(proj4_string, area_extent, 640, 480) cw = ContourWriterPIL(gshhs_root_dir) config_file = os.path.join(os.path.dirname(__file__), 'test_data', 'test_config.ini') img = cw.add_overlay_from_config(config_file, area_def) res = np.array(img) self.assertTrue(fft_metric(euro_data, res), 'Writing of contours failed') overlays = {'coasts': {'level': [1, 2, 3, 4], 'resolution': 'l'}, 'borders': {'outline': (255, 0, 0), 'resolution': 'c'}, 'rivers': {'outline': 'blue', 'resolution': 'c', 'level': 5}} img = cw.add_overlay_from_dict(overlays, area_def) res = np.array(img) self.assertTrue(fft_metric(euro_data, res), 'Writing of contours failed')