def test_nearest_neighbor_grid_grid(self): from pyresample import utils, geometry lon_arr = create_test_longitude(-95.0, -85.0, (40, 50), dtype=np.float64) lat_arr = create_test_latitude(25.0, 35.0, (40, 50), dtype=np.float64) grid_dst = geometry.GridDefinition(lons=lon_arr, lats=lat_arr) lon_arr = create_test_longitude(-100.0, -80.0, (400, 500), dtype=np.float64) lat_arr = create_test_latitude(20.0, 40.0, (400, 500), dtype=np.float64) grid = geometry.GridDefinition(lons=lon_arr, lats=lat_arr) rows, cols = utils.generate_nearest_neighbour_linesample_arrays(grid, grid_dst, 12000.)
def test_basic1(self): from pyresample.ewa import ll2cr from pyresample.geometry import SwathDefinition, AreaDefinition from pyresample.utils import proj4_str_to_dict lon_arr = create_test_longitude(-95.0, -75.0, (50, 100), dtype=np.float64) lat_arr = create_test_latitude(18.0, 40.0, (50, 100), dtype=np.float64) swath_def = SwathDefinition(lon_arr, lat_arr) grid_info = static_lcc.copy() cw = grid_info["cell_width"] ch = grid_info["cell_height"] ox = grid_info["origin_x"] oy = grid_info["origin_y"] w = grid_info["width"] h = grid_info["height"] half_w = abs(cw / 2.) half_h = abs(ch / 2.) extents = [ ox - half_w, oy - h * abs(ch) - half_h, ox + w * abs(cw) + half_w, oy + half_h ] area = AreaDefinition('test_area', 'test_area', 'test_area', proj4_str_to_dict(grid_info['proj4_definition']), w, h, extents) points_in_grid, lon_res, lat_res, = ll2cr(swath_def, area, fill=np.nan, copy=False) self.assertEqual(points_in_grid, lon_arr.size, "all points should be contained in a dynamic grid") self.assertIs(lon_arr, lon_res) self.assertIs(lat_arr, lat_res) self.assertEqual(points_in_grid, lon_arr.size, "all these test points should fall in this grid")
def test_latlong_basic1(self): from pyresample.ewa import _ll2cr lon_arr = create_test_longitude(-95.0, -75.0, (50, 100), dtype=np.float64) lat_arr = create_test_latitude(15.0, 30.0, (50, 100), dtype=np.float64) grid_info = dynamic_wgs84.copy() fill_in = np.nan proj_str = grid_info["proj4_definition"] cw = grid_info["cell_width"] ch = grid_info["cell_height"] ox = grid_info["origin_x"] oy = grid_info["origin_y"] w = grid_info["width"] h = grid_info["height"] points_in_grid, lon_res, lat_res, ox, oy, w, h = _ll2cr.ll2cr_dynamic( lon_arr, lat_arr, fill_in, proj_str, cw, ch, w, h, ox, oy) self.assertEqual(points_in_grid, lon_arr.size, "all points should be contained in a dynamic grid") self.assertIs(lon_arr, lon_res) self.assertIs(lat_arr, lat_res) self.assertEqual( lon_arr[0, 0], 0, "ll2cr returned the wrong result for a dynamic latlong grid") self.assertEqual( lat_arr[-1, 0], 0, "ll2cr returned the wrong result for a dynamic latlong grid")
def test_latlong_dateline1(self): from pyresample.ewa import _ll2cr lon_arr = create_test_longitude(165.0, -165.0, (50, 100), twist_factor=0.6, dtype=np.float64) lat_arr = create_test_latitude(15.0, 30.0, (50, 100), twist_factor=-0.1, dtype=np.float64) grid_info = dynamic_wgs84.copy() fill_in = np.nan proj_str = grid_info["proj4_definition"] cw = grid_info["cell_width"] ch = grid_info["cell_height"] ox = grid_info["origin_x"] oy = grid_info["origin_y"] w = grid_info["width"] h = grid_info["height"] points_in_grid, lon_res, lat_res, ox, oy, w, h = _ll2cr.ll2cr_dynamic( lon_arr, lat_arr, fill_in, proj_str, cw, ch, w, h, ox, oy) self.assertEqual(points_in_grid, lon_arr.size, "all points should be contained in a dynamic grid") self.assertIs(lon_arr, lon_res) self.assertIs(lat_arr, lat_res) self.assertEqual( lon_arr[0, 0], 0, "ll2cr returned the wrong result for a dynamic latlong grid") self.assertEqual( lat_arr[-1, 0], 0, "ll2cr returned the wrong result for a dynamic latlong grid") self.assertTrue( np.all(np.diff(lon_arr[0]) >= 0), "ll2cr didn't return monotonic columns over the dateline")
def test_nearest_neighbor_grid_area(self): from pyresample import utils, geometry proj_str = "+proj=lcc +datum=WGS84 +ellps=WGS84 +lat_0=25 +lat_1=25 +lon_0=-95 +units=m +no_defs" proj_dict = utils._proj4.proj4_str_to_dict(proj_str) extents = [0, 0, 1000. * 2500., 1000. * 2000.] area_def = geometry.AreaDefinition('CONUS', 'CONUS', 'CONUS', proj_dict, 40, 50, extents) lon_arr = create_test_longitude(-100.0, -60.0, (550, 500), dtype=np.float64) lat_arr = create_test_latitude(20.0, 45.0, (550, 500), dtype=np.float64) grid = geometry.GridDefinition(lons=lon_arr, lats=lat_arr) rows, cols = utils.generate_nearest_neighbour_linesample_arrays(grid, area_def, 12000.)
def test_nearest_neighbor_grid_area(self): from pyresample import utils, geometry proj_str = "+proj=lcc +datum=WGS84 +ellps=WGS84 +lat_0=25 +lat_1=25 +lon_0=-95 +units=m +no_defs" proj_dict = pyresample.utils._proj4.proj4_str_to_dict(proj_str) extents = [0, 0, 1000. * 2500., 1000. * 2000.] area_def = geometry.AreaDefinition('CONUS', 'CONUS', 'CONUS', proj_dict, 40, 50, extents) lon_arr = create_test_longitude(-100.0, -60.0, (550, 500), dtype=np.float64) lat_arr = create_test_latitude(20.0, 45.0, (550, 500), dtype=np.float64) grid = geometry.GridDefinition(lons=lon_arr, lats=lat_arr) rows, cols = utils.generate_nearest_neighbour_linesample_arrays(grid, area_def, 12000.)
def test_nearest_neighbor_area_grid(self): from pyresample import utils, geometry lon_arr = create_test_longitude(-94.9, -90.0, (50, 100), dtype=np.float64) lat_arr = create_test_latitude(25.1, 30.0, (50, 100), dtype=np.float64) grid = geometry.GridDefinition(lons=lon_arr, lats=lat_arr) proj_str = "+proj=lcc +datum=WGS84 +ellps=WGS84 +lat_0=25 +lat_1=25 +lon_0=-95 +units=m +no_defs" proj_dict = utils.proj4.proj4_str_to_dict(proj_str) extents = [0, 0, 1000. * 5000, 1000. * 5000] area_def = geometry.AreaDefinition('CONUS', 'CONUS', 'CONUS', proj_dict, 400, 500, extents) rows, cols = utils.generate_nearest_neighbour_linesample_arrays(area_def, grid, 12000.)
def _get_test_swath_def(input_shape, chunk_size, geo_dims): from pyresample.geometry import SwathDefinition from pyresample.test.utils import create_test_longitude, create_test_latitude lon_arr = create_test_longitude(-95.0, -75.0, input_shape, dtype=np.float64) lat_arr = create_test_latitude(15.0, 30.0, input_shape, dtype=np.float64) lons = da.from_array(lon_arr, chunks=chunk_size) lats = da.from_array(lat_arr, chunks=chunk_size) swath_def = SwathDefinition(xr.DataArray(lons, dims=geo_dims), xr.DataArray(lats, dims=geo_dims)) return swath_def
def test_lcc_fail1(self): from pyresample.ewa import _ll2cr lon_arr = create_test_longitude(-15.0, 15.0, (50, 100), dtype=np.float64) lat_arr = create_test_latitude(18.0, 40.0, (50, 100), dtype=np.float64) grid_info = static_lcc.copy() fill_in = np.nan proj_str = grid_info["proj4_definition"] cw = grid_info["cell_width"] ch = grid_info["cell_height"] ox = grid_info["origin_x"] oy = grid_info["origin_y"] w = grid_info["width"] h = grid_info["height"] points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, proj_str, cw, ch, w, h, ox, oy) self.assertEqual(points_in_grid, 0, "none of these test points should fall in this grid")
def test_lcc_basic1(self): from pyresample.ewa import _ll2cr lon_arr = create_test_longitude(-95.0, -75.0, (50, 100), dtype=np.float64) lat_arr = create_test_latitude(18.0, 40.0, (50, 100), dtype=np.float64) grid_info = static_lcc.copy() fill_in = np.nan proj_str = grid_info["proj4_definition"] cw = grid_info["cell_width"] ch = grid_info["cell_height"] ox = grid_info["origin_x"] oy = grid_info["origin_y"] w = grid_info["width"] h = grid_info["height"] points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, proj_str, cw, ch, w, h, ox, oy) self.assertEqual(points_in_grid, lon_arr.size, "all these test points should fall in this grid")
def test_latlong_basic1(self): from pyresample.ewa import _ll2cr lon_arr = create_test_longitude(-95.0, -75.0, (50, 100), dtype=np.float64) lat_arr = create_test_latitude(15.0, 30.0, (50, 100), dtype=np.float64) grid_info = dynamic_wgs84.copy() fill_in = np.nan proj_str = grid_info["proj4_definition"] cw = grid_info["cell_width"] ch = grid_info["cell_height"] ox = grid_info["origin_x"] oy = grid_info["origin_y"] w = grid_info["width"] h = grid_info["height"] points_in_grid, lon_res, lat_res, ox, oy, w, h = _ll2cr.ll2cr_dynamic(lon_arr, lat_arr, fill_in, proj_str, cw, ch, w, h, ox, oy) self.assertEqual(points_in_grid, lon_arr.size, "all points should be contained in a dynamic grid") self.assertIs(lon_arr, lon_res) self.assertIs(lat_arr, lat_res) self.assertEqual(lon_arr[0, 0], 0, "ll2cr returned the wrong result for a dynamic latlong grid") self.assertEqual(lat_arr[-1, 0], 0, "ll2cr returned the wrong result for a dynamic latlong grid")
def test_latlong_dateline1(self): from pyresample.ewa import _ll2cr lon_arr = create_test_longitude(165.0, -165.0, (50, 100), twist_factor=0.6, dtype=np.float64) lat_arr = create_test_latitude(15.0, 30.0, (50, 100), twist_factor=-0.1, dtype=np.float64) grid_info = dynamic_wgs84.copy() fill_in = np.nan proj_str = grid_info["proj4_definition"] cw = grid_info["cell_width"] ch = grid_info["cell_height"] ox = grid_info["origin_x"] oy = grid_info["origin_y"] w = grid_info["width"] h = grid_info["height"] points_in_grid, lon_res, lat_res, ox, oy, w, h = _ll2cr.ll2cr_dynamic(lon_arr, lat_arr, fill_in, proj_str, cw, ch, w, h, ox, oy) self.assertEqual(points_in_grid, lon_arr.size, "all points should be contained in a dynamic grid") self.assertIs(lon_arr, lon_res) self.assertIs(lat_arr, lat_res) self.assertEqual(lon_arr[0, 0], 0, "ll2cr returned the wrong result for a dynamic latlong grid") self.assertEqual(lat_arr[-1, 0], 0, "ll2cr returned the wrong result for a dynamic latlong grid") self.assertTrue(np.all(np.diff(lon_arr[0]) >= 0), "ll2cr didn't return monotonic columns over the dateline")
def test_geo_antimeridian(self): """Ensure output for anti-meridian crossing input includes all points.""" from pyresample.ewa import _ll2cr lon_arr = create_test_longitude(160.0, 200.0, (50, 100), dtype=np.float64) lat_arr = create_test_latitude(40.0, 60.0, (50, 100), dtype=np.float64) # wrap values in lon_arr so -180 ≤ longitude (degrees east) ≤ 180 lon_arr[lon_arr > 180] -= 360.0 grid_info = static_geo_whole_earth.copy() fill_in = np.nan proj_str = grid_info['proj4_definition'] cw = grid_info['cell_width'] ch = grid_info['cell_height'] ox = grid_info['origin_x'] oy = grid_info['origin_y'] w = grid_info['width'] h = grid_info['height'] points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, proj_str, cw, ch, w, h, ox, oy) self.assertEqual(points_in_grid, lon_arr.size, 'all these test points should fall in this grid')
def _antimeridian_lonlats(): lons = create_test_longitude(172.0, 190.0, SRC_SWATH_2D_SHAPE) lons[lons > 180.0] = lons - 360.0 lats = create_test_latitude(25.0, 33.0, SRC_SWATH_2D_SHAPE) return lons, lats
def _euro_lonlats(): lons = create_test_longitude(3.0, 12.0, SRC_SWATH_2D_SHAPE) lats = create_test_latitude(75.0, 26.0, SRC_SWATH_2D_SHAPE) return lons, lats