def test_dateline_boundary_cross(self): from pycoast import ContourWriterPIL dl_img = Image.open( os.path.join(os.path.dirname(__file__), 'dateline_boundary_cross.png')) dl_data = np.array(dl_img) img = Image.new('RGB', (640, 480)) proj4_string = \ '+proj=stere +lon_0=140.00 +lat_0=60.00 +lat_ts=50.00 +ellps=WGS84' area_extent = (-3363403.31, -2291879.85, 2630596.69, 2203620.1) area_def = (proj4_string, area_extent) cw = ContourWriterPIL(gshhs_root_dir) cw.add_coastlines(img, area_def, resolution='l', level=4) font = ImageFont.truetype( os.path.join(os.path.dirname(__file__), 'test_data', 'DejaVuSerif.ttf'), 16) cw.add_grid(img, area_def, (10.0, 10.0), (2.0, 2.0), font=font, fill='blue', outline='blue', minor_outline='blue', write_text=False, lon_placement='b', lat_placement='lr') res = np.array(img) self.assertTrue(fft_metric(dl_data, res), 'Writing of dateline boundary crossing data failed')
def test_grid_nh(self): from pycoast import ContourWriterPIL grid_img = Image.open( os.path.join(os.path.dirname(__file__), 'grid_nh.png')) grid_data = np.array(grid_img) img = Image.new('RGB', (425, 425)) 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 = (proj4_string, area_extent) cw = ContourWriterPIL(gshhs_root_dir) cw.add_coastlines(img, area_def, resolution='l', level=4) font = ImageFont.truetype( os.path.join(os.path.dirname(__file__), 'test_data', 'DejaVuSerif.ttf'), 10) cw.add_grid(img, area_def, (10.0, 10.0), (2.0, 2.0), font=font, fill='blue', outline='blue', minor_outline='blue', write_text=False, lon_placement='tblr', lat_placement='') res = np.array(img) self.assertTrue(fft_metric(grid_data, res), 'Writing of nh grid failed')
def test_grid_germ(self): """Check that issue #26 is fixed.""" from pycoast import ContourWriterPIL result_file = os.path.join(os.path.dirname(__file__), 'grid_germ.png') grid_img = Image.open(result_file) grid_data = np.array(grid_img) img = Image.new('RGB', (1024, 1024)) proj4_string = \ '+proj=stere +ellps=bessel +lat_0=90.0 +lon_0=5.0 +lat_ts=50.0 +a=6378144.0 +b=6356759.0' area_extent = [ -155100.436345, -4441495.37946, 868899.563655, -3417495.37946 ] area_def = (proj4_string, area_extent) cw = ContourWriterPIL(gshhs_root_dir) cw.add_coastlines(img, area_def, resolution='l', level=4) font = ImageFont.truetype( os.path.join(os.path.dirname(__file__), 'test_data', 'DejaVuSerif.ttf'), 16) cw.add_grid(img, area_def, (10.0, 10.0), (2.0, 2.0), font=font, fill='yellow', write_text=True, outline='red', minor_outline='white') res = np.array(img) self.assertTrue(fft_metric(grid_data, res), 'Writing of grid to germ failed')
def test_add_shapefile_shapes(self): from pycoast import ContourWriterPIL grid_img = Image.open(os.path.join(os.path.dirname(__file__), 'brazil_shapefiles.png')) grid_data = np.array(grid_img) img = Image.new('RGB', (425, 425)) proj4_string = '+proj=merc +lon_0=-60 +lat_ts=-30.0 +a=6371228.0 +units=m' area_extent = (-2000000.0, -5000000.0, 5000000.0, 2000000.0) area_def = (proj4_string, area_extent) cw = ContourWriterPIL(gshhs_root_dir) cw.add_coastlines(img, area_def, resolution='l', level=4) cw.add_shapefile_shapes(img, area_def, os.path.join( os.path.dirname(__file__), 'test_data/shapes/Metareas.shp'), outline='red') cw.add_shapefile_shape(img, area_def, os.path.join(os.path.dirname(__file__), 'test_data/shapes/divisao_politica/BR_Regioes.shp'), 3, outline='blue') cw.add_shapefile_shape(img, area_def, os.path.join(os.path.dirname(__file__), 'test_data/shapes/divisao_politica/BR_Regioes.shp'), 4, outline='blue', fill='green') res = np.array(img) self.assertTrue( fft_metric(grid_data, res), 'Writing of Brazil shapefiles failed')
def test_add_polygon(self): from pycoast import ContourWriterPIL grid_img = Image.open(os.path.join(os.path.dirname(__file__), 'nh_polygons.png')) grid_data = np.array(grid_img) img = Image.new('RGB', (425, 425)) 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 = (proj4_string, area_extent) cw = ContourWriterPIL(gshhs_root_dir) polygons = { 'REYKJAVIK_ATC_A': ((-20.0, 73.0), (0.0, 73.0), (0.0, 61.0), (-30.0, 61.0), (-39.0, 63.5), (-20, 70)), 'REYKJAVIK_ATC_B': ( (-39, 63.5), (-55 + 4 / 6.0, 63.5), (-57 + 45 / 60.0, 65), (-76, 76), (-75, 78), (-60, 82), (0, 90), (30, 82), (0, 82), (0, 73), (-20, 73), (-20, 70)), 'REYKJAVIK_ATC': ( (0.0, 73.0), (0.0, 61.0), (-30.0, 61.0), (-39, 63.5), (-55 + 4 / 6.0, 63.5), (-57 + 45 / 60.0, 65), (-76, 76), (-75, 78), (-60, 82), (0, 90), (30, 82), (0, 82)), 'ICELAND_BOX': ((-25, 62.5), (-25, 67), (-13, 67), (-13, 62.5)) } cw.add_polygon(img, area_def, polygons['REYKJAVIK_ATC'], outline='red') cw.add_polygon(img, area_def, polygons['ICELAND_BOX'], outline='green', fill='gray') cw.add_coastlines(img, area_def, resolution='l', level=4) res = np.array(img) self.assertTrue(fft_metric(grid_data, res), 'Writing of nh polygons failed')
def test_add_points_pil(self): from pycoast import ContourWriterPIL from pyresample.geometry import AreaDefinition font_file = os.path.join(os.path.dirname(__file__), 'test_data', 'DejaVuSerif.ttf') grid_img = Image.open( os.path.join(os.path.dirname(__file__), 'nh_points_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_coastlines(img, area_def, outline='black', resolution='l', level=4) cw.add_borders(img, area_def, outline='black', level=1, resolution='c') points_list = [((13.4050, 52.5200), 'Berlin')] cw.add_points(img, area_def, points_list=points_list, font_file=font_file, symbol='asterisk', ptsize=6, outline='red', box_outline='black') points_list = [((12.4964, 41.9028), 'Rome')] cw.add_points(img, area_def, points_list=points_list, font_file=font_file, symbol='square', ptsize=6, outline='blue', fill='yellow', box_outline='black') res = np.array(img) self.assertTrue(fft_metric(grid_data, res), 'Writing of nh points failed')
def test_geos(self): from pycoast import ContourWriterPIL geos_img = Image.open( os.path.join(os.path.dirname(__file__), 'contours_geos.png')) geos_data = np.array(geos_img) img = Image.new('RGB', (425, 425)) proj4_string = \ '+proj=geos +lon_0=0.0 +a=6378169.00 +b=6356583.80 +h=35785831.0' area_extent = (-5570248.4773392612, -5567248.074173444, 5567248.074173444, 5570248.4773392612) area_def = (proj4_string, area_extent) cw = ContourWriterPIL(gshhs_root_dir) cw.add_coastlines(img, area_def, resolution='l') res = np.array(img) self.assertTrue(fft_metric(geos_data, res), 'Writing of geos contours failed')
def test_europe(self): from pycoast import ContourWriterPIL euro_img = Image.open( os.path.join(os.path.dirname(__file__), 'contours_europe.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 = (proj4_string, area_extent) cw = ContourWriterPIL(gshhs_root_dir) cw.add_coastlines(img, area_def, resolution='l', level=4) cw.add_rivers(img, area_def, level=5, outline='blue') cw.add_borders(img, area_def, outline=(255, 0, 0)) res = np.array(img) self.assertTrue(fft_metric(euro_data, res), 'Writing of contours failed')