class Test__locate_source_points(IrisTest): """Test the _locate_source_points method""" def setUp(self): """Define input matrices and plugin""" self.wind_speed = np.ones((3, 4), dtype=np.float32) self.sin_wind_dir = np.full((3, 4), 0.4, dtype=np.float32) self.cos_wind_dir = np.full((3, 4), np.sqrt(0.84), dtype=np.float32) self.plugin = OrographicEnhancement() self.plugin.grid_spacing_km = 3.0 def test_basic(self): """Test location of source points""" distance = self.plugin._get_point_distances(self.wind_speed, self.cos_wind_dir) xsrc, ysrc = self.plugin._locate_source_points(self.wind_speed, distance, self.sin_wind_dir, self.cos_wind_dir) expected_xsrc = np.array([ [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]], [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]], [[0, 0, 1, 2], [0, 0, 1, 2], [0, 0, 1, 2]], [[0, 0, 1, 2], [0, 0, 1, 2], [0, 0, 1, 2]], ]) expected_ysrc = np.array([ [[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2]], [[0, 0, 0, 0], [0, 0, 0, 0], [1, 1, 1, 1]], [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], ]) self.assertArrayEqual(xsrc, expected_xsrc) self.assertArrayEqual(ysrc, expected_ysrc)
class Test__compute_weighted_values(IrisTest): """Test the _compute_weighted_values method""" def setUp(self): """Set up plugin and some inputs""" self.plugin = OrographicEnhancement() self.plugin.grid_spacing_km = 3.0 self.point_orogenh = np.array([ [4.1, 4.6, 5.6, 6.8, 5.5], [4.4, 4.6, 5.8, 6.2, 5.5], [5.2, 3.0, 3.4, 5.1, 3.3], [0.6, 2.0, 1.8, 4.2, 2.5], [0.0, 0.0, 0.2, 3.2, 1.8], ]) self.wind_speed = np.full((5, 5), 25.0, dtype=np.float32) sin_wind_dir = np.full((5, 5), 0.4, dtype=np.float32) cos_wind_dir = np.full((5, 5), np.sqrt(0.84), dtype=np.float32) self.distance = self.plugin._get_point_distances( self.wind_speed, cos_wind_dir) self.xsrc, self.ysrc = self.plugin._locate_source_points( self.wind_speed, self.distance, sin_wind_dir, cos_wind_dir) def test_basic(self): """Test output is two arrays""" orogenh, weights = self.plugin._compute_weighted_values( self.point_orogenh, self.xsrc, self.ysrc, self.distance, self.wind_speed) self.assertIsInstance(orogenh, np.ndarray) self.assertIsInstance(weights, np.ndarray) def test_values(self): """Test values are as expected""" expected_orogenh = np.array([ [6.0531969, 6.7725644, 8.2301264, 9.9942646, 8.1690931], [6.3531971, 6.7725644, 8.4301271, 9.3942642, 8.1690931], [7.2848172, 5.1725645, 6.1178742, 8.0310230, 5.9690924], [3.0469213, 3.4817038, 3.4649093, 6.6558237, 4.1816435], [0.4585612, 1.0727906, 1.1036499, 5.1721582, 3.0895371], ]) expected_weights = np.full((5, 5), 1.4763895, dtype=np.float32) orogenh, weights = self.plugin._compute_weighted_values( self.point_orogenh, self.xsrc, self.ysrc, self.distance, self.wind_speed) self.assertArrayAlmostEqual(orogenh, expected_orogenh) self.assertArrayAlmostEqual(weights, expected_weights)