def test_incomplete_search(self, warning_list=None): """Test a warning is raised when the number of nearest neighbours searched for the minimum dz neighbour does not exhaust the search_radius.""" plugin = NeighbourSelection(search_radius=6) site_altitude = 3. nodes = np.array([[0, 4], [1, 4], [2, 4], [3, 4], [4, 4]]) distance = np.arange(5) indices = np.arange(5) plugin.select_minimum_dz(self.region_orography, site_altitude, nodes, distance, indices) msg = "Limit on number of nearest neighbours" self.assertTrue(any([msg in str(warning) for warning in warning_list])) self.assertTrue( any(item.category == UserWarning for item in warning_list))
def test_all_invalid_points(self): """Test a case where all nodes are beyond the imposed search_radius, so the returned value should be None.""" plugin = NeighbourSelection() site_altitude = 5. nodes = np.array([[0, 4], [1, 4], [2, 4], [3, 4], [4, 4]]) distance = np.full(5, np.inf) indices = np.arange(5) result = plugin.select_minimum_dz(self.region_orography, site_altitude, nodes, distance, indices) self.assertEqual(result, None)
def test_basic(self): """Test a simple case where the first element in the provided lists has the smallest vertical displacement to the site. Expect the coordinates of the first node to be returned.""" plugin = NeighbourSelection() site_altitude = 3. nodes = np.array([[0, 4], [1, 4], [2, 4], [3, 4], [4, 4]]) distance = np.arange(5) indices = np.arange(5) result = plugin.select_minimum_dz(self.region_orography, site_altitude, nodes, distance, indices) self.assertArrayEqual(result, nodes[0])
def test_some_invalid_points(self): """Test a case where some nodes are beyond the imposed search_radius, which means they have a distance of np.inf, ensuring this is handled. Also change the site height so the second node is the expected result.""" plugin = NeighbourSelection() site_altitude = 5. nodes = np.array([[0, 4], [1, 4], [2, 4], [3, 4], [4, 4]]) distance = np.array([0, 1, 2, 3, np.inf]) indices = np.arange(5) result = plugin.select_minimum_dz(self.region_orography, site_altitude, nodes, distance, indices) self.assertArrayEqual(result, nodes[1])