def test_get_corner(self): """Test finding the closest corners.""" import dask.array as da from pyresample.bilinear import _get_corner, _get_input_xy from pyresample import CHUNK_SIZE from pyresample._spatial_mp import Proj proj = Proj(self.target_def.proj_str) in_x, in_y = _get_input_xy(self.source_def, proj, self._valid_input_index, self._index_array) out_x, out_y = self.target_def.get_proj_coords(chunks=CHUNK_SIZE) out_x = da.ravel(out_x) out_y = da.ravel(out_y) # Some copy&paste from the code to get the input out_x_tile = np.reshape(np.tile(out_x, self._neighbours), (self._neighbours, out_x.size)).T out_y_tile = np.reshape(np.tile(out_y, self._neighbours), (self._neighbours, out_y.size)).T x_diff = out_x_tile - in_x y_diff = out_y_tile - in_y stride = np.arange(x_diff.shape[0]) # Use lower left source pixels for testing valid = (x_diff > 0) & (y_diff > 0) x_3, y_3, idx_3 = _get_corner(stride, valid, in_x, in_y, self._index_array) self.assertTrue( x_3.shape == y_3.shape == idx_3.shape == (self.target_def.size, )) # Four locations have no data to the lower left of them (the # bottom row of the area self.assertEqual(np.sum(np.isnan(x_3.compute())), 4)
def test_get_four_closest_corners(self): """Test finding surrounding bounding corners.""" import dask.array as da from pyresample.bilinear.xarr import _get_input_xy from pyresample.bilinear import _get_four_closest_corners from pyresample._spatial_mp import Proj from pyresample import CHUNK_SIZE proj = Proj(self.target_def.proj_str) out_x, out_y = self.target_def.get_proj_coords(chunks=CHUNK_SIZE) out_x = da.ravel(out_x) out_y = da.ravel(out_y) in_x, in_y = _get_input_xy(self.source_def, proj, self._valid_input_index, self._index_array) (pt_1, pt_2, pt_3, pt_4), ia_ = _get_four_closest_corners(in_x, in_y, out_x, out_y, self._neighbours, self._index_array) self.assertTrue(pt_1.shape == pt_2.shape == pt_3.shape == pt_4.shape == (self.target_def.size, 2)) self.assertTrue(ia_.shape == (self.target_def.size, 4)) # Check which of the locations has four valid X/Y pairs by # finding where there are non-NaN values res = da.sum(pt_1 + pt_2 + pt_3 + pt_4, axis=1).compute() self.assertEqual(np.sum(~np.isnan(res)), 10)
def test_get_input_xy(self): """Test calculation of input xy-coordinates.""" from pyresample.bilinear import _get_input_xy from pyresample._spatial_mp import Proj proj = Proj(self.target_def.proj_str) in_x, in_y = _get_input_xy(self.swath_def, proj, self.input_idxs, self.idx_ref) self.assertTrue(in_x.all()) self.assertTrue(in_y.all())
def test_get_bounding_corners(self): proj = Proj(self.target_def.proj4_string) out_x, out_y = bil._get_output_xy(self.target_def, proj) in_x, in_y = bil._get_input_xy(self.swath_def, proj, self.input_idxs, self.idx_ref) res = bil._get_bounding_corners(in_x, in_y, out_x, out_y, self.neighbours, self.idx_ref) for i in range(len(res) - 1): pt_ = res[i] for j in range(2): # Only the sixth output location has four valid corners self.assertTrue(np.isfinite(pt_[5, j]))
def test_get_bounding_corners(self): proj = Proj(self.target_def.proj_str) out_x, out_y = bil._get_output_xy(self.target_def, proj) in_x, in_y = bil._get_input_xy(self.swath_def, proj, self.input_idxs, self.idx_ref) res = bil._get_bounding_corners(in_x, in_y, out_x, out_y, self.neighbours, self.idx_ref) for i in range(len(res) - 1): pt_ = res[i] for j in range(2): # Only the sixth output location has four valid corners self.assertTrue(np.isfinite(pt_[5, j]))
def test_get_input_xy(self): """Test computation of input X and Y coordinates in target proj.""" from pyresample.bilinear.xarr import _get_input_xy from pyresample._spatial_mp import Proj proj = Proj(self.target_def.proj_str) in_x, in_y = _get_input_xy(self.source_def, proj, self._valid_input_index, self._index_array) self.assertTrue(in_x.shape, (self.target_def.size, 32)) self.assertTrue(in_y.shape, (self.target_def.size, 32)) self.assertTrue(in_x.all()) self.assertTrue(in_y.all())
def test_get_bounding_corners(self): """Test calculation of bounding corners.""" from pyresample.bilinear import (_get_output_xy, _get_input_xy, _get_bounding_corners) from pyresample._spatial_mp import Proj proj = Proj(self.target_def.proj_str) out_x, out_y = _get_output_xy(self.target_def, proj) in_x, in_y = _get_input_xy(self.swath_def, proj, self.input_idxs, self.idx_ref) res = _get_bounding_corners(in_x, in_y, out_x, out_y, self.neighbours, self.idx_ref) for i in range(len(res) - 1): pt_ = res[i] for j in range(2): # Only the sixth output location has four valid corners self.assertTrue(np.isfinite(pt_[5, j]))
def test_get_four_closest_corners(self): """Test calculation of bounding corners.""" from pyresample.bilinear import (_get_output_xy, _get_input_xy, _get_four_closest_corners) from pyresample._spatial_mp import Proj proj = Proj(self.target_def.proj_str) out_x, out_y = _get_output_xy(self.target_def) in_x, in_y = _get_input_xy(self.source_def, proj, self.input_idxs, self.idx_ref) (pt_1, pt_2, pt_3, pt_4), ia_ = _get_four_closest_corners(in_x, in_y, out_x, out_y, self._neighbours, self.idx_ref) self.assertTrue(pt_1.shape == pt_2.shape == pt_3.shape == pt_4.shape == (self.target_def.size, 2)) self.assertTrue(ia_.shape == (self.target_def.size, 4)) # Check which of the locations has four valid X/Y pairs by # finding where there are non-NaN values res = np.sum(pt_1 + pt_2 + pt_3 + pt_4, axis=1) self.assertEqual(np.sum(~np.isnan(res)), 10)