def test_area_parser_legacy(self): """Test legacy area parser.""" from pyresample import parse_area_file ease_nh, ease_sh = parse_area_file(os.path.join(os.path.dirname(__file__), 'test_files', 'areas.cfg'), 'ease_nh', 'ease_sh') nh_str = """Area ID: ease_nh Description: Arctic EASE grid Projection ID: ease_nh Projection: {'a': '6371228.0', 'lat_0': '90.0', 'lon_0': '0.0', 'proj': 'laea', 'units': 'm'} Number of columns: 425 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""" self.assertEqual(ease_nh.__str__(), nh_str) self.assertIsInstance(ease_nh.proj_dict['lat_0'], float) sh_str = """Area ID: ease_sh Description: Antarctic EASE grid Projection ID: ease_sh Projection: {'a': '6371228.0', 'lat_0': '-90.0', 'lon_0': '0.0', 'proj': 'laea', 'units': 'm'} Number of columns: 425 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""" self.assertEqual(ease_sh.__str__(), sh_str) self.assertIsInstance(ease_sh.proj_dict['lat_0'], float)
def test_def2yaml_converter(self): from pyresample import parse_area_file, convert_def_to_yaml import tempfile def_file = os.path.join(os.path.dirname(__file__), 'test_files', 'areas.cfg') filehandle, yaml_file = tempfile.mkstemp() os.close(filehandle) try: convert_def_to_yaml(def_file, yaml_file) areas_new = set(parse_area_file(yaml_file)) areas = parse_area_file(def_file) for area in areas: area.proj_dict.pop('units', None) areas_old = set(areas) self.assertEqual(areas_new, areas_old) finally: os.remove(yaml_file)
def test_area_def2basemap(self): from pyresample import plot from pyresample import parse_area_file area_def = parse_area_file(os.path.join(os.path.dirname(__file__), 'test_files', 'areas.cfg'), 'ease_sh')[0] bmap = plot.area_def2basemap(area_def) self.assertTrue(bmap.rmajor == bmap.rminor and bmap.rmajor == 6371228.0, 'Failed to create Basemap object')
def test_orthoplot(self): from pyresample import plot, kd_tree, geometry from pyresample import parse_area_file area_def = parse_area_file(os.path.join(os.path.dirname(__file__), 'test_files', 'areas.cfg'), 'ortho')[0] swath_def = geometry.SwathDefinition(self.lons, self.lats) result = kd_tree.resample_nearest(swath_def, self.tb37v, area_def, radius_of_influence=20000, fill_value=None) plot._get_quicklook(area_def, result)
def test_area_parser_yaml(self): """Test YAML area parser.""" from pyresample import parse_area_file test_area_file = os.path.join(os.path.dirname(__file__), 'test_files', 'areas.yaml') test_areas = parse_area_file(test_area_file, 'ease_nh', 'ease_sh', 'test_meters', 'test_degrees', 'test_latlong') ease_nh, ease_sh, test_m, test_deg, test_latlong = test_areas nh_str = """Area ID: ease_nh Description: Arctic EASE grid Projection: {'a': '6371228.0', 'lat_0': '-90.0', 'lon_0': '0.0', 'proj': 'laea', 'units': 'm'} Number of columns: 425 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""" self.assertEqual(ease_nh.__str__(), nh_str) sh_str = """Area ID: ease_sh Description: Antarctic EASE grid Projection: {'a': '6371228.0', 'lat_0': '-90.0', 'lon_0': '0.0', 'proj': 'laea', 'units': 'm'} Number of columns: 425 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""" self.assertEqual(ease_sh.__str__(), sh_str) m_str = """Area ID: test_meters Description: test_meters Projection: {'a': '6371228.0', 'lat_0': '-90.0', 'lon_0': '0.0', 'proj': 'laea', 'units': 'm'} Number of columns: 850 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""" self.assertEqual(test_m.__str__(), m_str) deg_str = """Area ID: test_degrees Description: test_degrees Projection: {'a': '6371228.0', 'lat_0': '-90.0', 'lon_0': '0.0', 'proj': 'laea', 'units': 'm'} Number of columns: 850 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""" self.assertEqual(test_deg.__str__(), deg_str) latlong_str = """Area ID: test_latlong Description: Basic latlong grid Projection: {'ellps': 'WGS84', 'lat_0': '27.12', 'lon_0': '-81.36', 'proj': 'longlat'} Number of columns: 3473 Number of rows: 4058 Area extent: (-0.0812, 0.4039, 0.0812, 0.5428)""" self.assertEqual(test_latlong.__str__(), latlong_str)
def test_multiple_file_content(self): from pyresample import parse_area_file area_list = ["""ease_sh: description: Antarctic EASE grid projection: a: 6371228.0 units: m lon_0: 0 proj: laea lat_0: -90 shape: height: 425 width: 425 area_extent: lower_left_xy: [-5326849.0625, -5326849.0625] upper_right_xy: [5326849.0625, 5326849.0625] units: m """, """ease_sh2: description: Antarctic EASE grid projection: a: 6371228.0 units: m lon_0: 0 proj: laea lat_0: -90 shape: height: 425 width: 425 area_extent: lower_left_xy: [-5326849.0625, -5326849.0625] upper_right_xy: [5326849.0625, 5326849.0625] units: m """] results = parse_area_file(area_list) self.assertEqual(len(results), 2) self.assertIn(results[0].area_id, ('ease_sh', 'ease_sh2')) self.assertIn(results[1].area_id, ('ease_sh', 'ease_sh2'))
def test_commented(self): from pyresample import parse_area_file areas = parse_area_file( os.path.join(os.path.dirname(__file__), 'test_files', 'areas.cfg')) self.assertNotIn('commented', [area.name for area in areas])
def test_area_parser_yaml(self): """Test YAML area parser.""" from pyresample import parse_area_file test_area_file = os.path.join(os.path.dirname(__file__), 'test_files', 'areas.yaml') test_areas = parse_area_file(test_area_file, 'ease_nh', 'ease_sh', 'test_meters', 'test_degrees', 'test_latlong') ease_nh, ease_sh, test_m, test_deg, test_latlong = test_areas from pyresample.utils import is_pyproj2 if is_pyproj2(): # pyproj 2.0+ adds some extra parameters projection = ("{'R': '6371228', 'lat_0': '-90', 'lon_0': '0', " "'no_defs': 'None', 'proj': 'laea', 'type': 'crs', " "'units': 'm', 'x_0': '0', 'y_0': '0'}") else: projection = ("{'a': '6371228.0', 'lat_0': '-90.0', " "'lon_0': '0.0', 'proj': 'laea', 'units': 'm'}") nh_str = """Area ID: ease_nh Description: Arctic EASE grid Projection: {} Number of columns: 425 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""".format( projection) self.assertEqual(ease_nh.__str__(), nh_str) sh_str = """Area ID: ease_sh Description: Antarctic EASE grid Projection: {} Number of columns: 425 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""".format( projection) self.assertEqual(ease_sh.__str__(), sh_str) m_str = """Area ID: test_meters Description: test_meters Projection: {} Number of columns: 850 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""".format( projection) self.assertEqual(test_m.__str__(), m_str) deg_str = """Area ID: test_degrees Description: test_degrees Projection: {} Number of columns: 850 Number of rows: 425 Area extent: (-5326849.0625, -5326849.0625, 5326849.0625, 5326849.0625)""".format( projection) self.assertEqual(test_deg.__str__(), deg_str) if is_pyproj2(): # pyproj 2.0+ adds some extra parameters projection = ("{'ellps': 'WGS84', 'lat_0': '27.12', " "'lon_0': '-81.36', 'proj': 'longlat', " "'type': 'crs'}") else: projection = ("{'ellps': 'WGS84', 'lat_0': '27.12', " "'lon_0': '-81.36', 'proj': 'longlat'}") latlong_str = """Area ID: test_latlong Description: Basic latlong grid Projection: {} Number of columns: 3473 Number of rows: 4058 Area extent: (-0.0812, 0.4039, 0.0812, 0.5428)""".format(projection) self.assertEqual(test_latlong.__str__(), latlong_str)
def test_commented(self): from pyresample import parse_area_file areas = parse_area_file(os.path.join(os.path.dirname(__file__), 'test_files', 'areas.cfg')) self.assertNotIn('commented', [area.name for area in areas])