示例#1
0
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)
示例#2
0
 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'))
示例#3
0
 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'))
示例#4
0
 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'))
示例#5
0
 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'))
示例#6
0
    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)
示例#7
0
    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)
示例#8
0
 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)
示例#9
0
 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)
示例#10
0
    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)
示例#11
0
    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)
示例#12
0
 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'))
示例#13
0
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)
示例#14
0
 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'))