def extract_nearest_neighbour(cube, sample_points): msg = (_INTERPOLATE_DEPRECATION_WARNING + '\n' + 'Please replace usage of ' 'iris.analysis.interpolate.extract_nearest_neighbour() with ' 'iris.cube.Cube.interpolate(..., scheme=iris.analysis.Nearest()).') _warn_deprecated(msg) return oldinterp.extract_nearest_neighbour(cube, sample_points)
def test_nearest_neighbour_bounded_simple(self): point_spec = [('latitude', 37), ('longitude', 38)] coord = self.cube.coord('latitude') coord.guess_bounds(0.5) b = iintrp.extract_nearest_neighbour(self.cube, point_spec) self.assertCML(b, ('analysis', 'interpolation', 'nearest_neighbour_extract_bounded.cml'))
def test_nearest_neighbour_bounded_requested_midpoint(self): # This test checks the "point inside cell" logic point_spec = [('latitude', 38), ('longitude', 38)] coord = self.cube.coord('latitude') coord.guess_bounds(0.5) b = iintrp.extract_nearest_neighbour(self.cube, point_spec) self.assertCML(b, ('analysis', 'interpolation', 'nearest_neighbour_extract_bounded_mid_point.cml'))
def test_nearest_neighbour_slice(self): point_spec = [('latitude', 40)] indices = iintrp.nearest_neighbour_indices(self.cube, point_spec) self.assertEqual(indices, (20, slice(None, None))) b = iintrp.extract_nearest_neighbour(self.cube, point_spec) self.assertCML(b, ('analysis', 'interpolation', 'nearest_neighbour_extract_latitude.cml')) # cannot get a specific point from these point specifications self.assertRaises(ValueError, iintrp.nearest_neighbour_data_value, self.cube, point_spec)
def test_nearest_neighbour_over_specification_which_is_consistent(self): # latitude 40 is the 20th point point_spec = [('latitude', 40), ('i', 20), ('longitude', 38)] indices = iintrp.nearest_neighbour_indices(self.cube, point_spec) self.assertEqual(indices, (20, 10)) b = iintrp.extract_nearest_neighbour(self.cube, point_spec) self.assertCML(b, ('analysis', 'interpolation', 'nearest_neighbour_extract_latitude_longitude.cml')) value = iintrp.nearest_neighbour_data_value(self.cube, point_spec) # Check that the value back is that which was returned by the extract method self.assertEqual(value, b.data)
def test_nearest_neighbour(self): point_spec = [('latitude', 40), ('longitude', 39)] indices = iintrp.nearest_neighbour_indices(self.cube, point_spec) self.assertEqual(indices, (20, 10)) b = iintrp.extract_nearest_neighbour(self.cube, point_spec) # Check that the data has not been loaded on either the original cube, # nor the interpolated one. self.assertTrue(b.has_lazy_data()) self.assertTrue(self.cube.has_lazy_data()) self.assertCML(b, ('analysis', 'interpolation', 'nearest_neighbour_extract_latitude_longitude.cml')) value = iintrp.nearest_neighbour_data_value(self.cube, point_spec) self.assertEqual(value, np.array(285.98785, dtype=np.float32)) # Check that the value back is that which was returned by the extract method self.assertEqual(value, b.data)
def test_nearest_neighbour_locator_style_coord(self): point_spec = [('latitude', 39)] b = iintrp.extract_nearest_neighbour(self.cube, point_spec) self.assertCML(b, ('analysis', 'interpolation', 'nearest_neighbour_extract_latitude.cml'))