def test_negative_lon_points_dont_matter_with_0_360_grid_in_2d(self):
        # This cube is defined over a 0-360 longitude grid
        cube = make_from_cube(mock.make_dummy_2d_cube())

        sample_points = UngriddedData.from_points_array(
            [HyperPoint(lat=1.0, lon=1.0),
             HyperPoint(lat=19.0, lon=44.0),
             HyperPoint(lat=-4.0, lon=-14.0),
             HyperPoint(lat=-4.0, lon=-44.0)])
        col = GriddedUngriddedCollocator()
        new_data = col.collocate(sample_points, cube, None, 'nn')[0]
        eq_(new_data.data[0], 325.0)  # float(cube[9,0].data)
        eq_(new_data.data[1], 365.0)  # float(cube[10,4].data))
        eq_(new_data.data[2], 324.0)  # float(cube[8,35].data))
        eq_(new_data.data[3], 321.0)  # float(cube[8,32].data))
    def test_lon_points_over_360_dont_matter_with_0_360_grid_in_2d(self):
        # This cube is defined over a 0-360 longitude grid
        cube = make_from_cube(mock.make_dummy_2d_cube())

        sample_points = UngriddedData.from_points_array(
            [HyperPoint(lat=1.0, lon=0.0),
             HyperPoint(lat=1.0, lon=20.0),
             HyperPoint(lat=1.0, lon=361.0),
             HyperPoint(lat=1.0, lon=381.0)])
        col = GriddedUngriddedCollocator(extrapolate=True)
        new_data = col.collocate(sample_points, cube, None, 'nn')[0]
        eq_(new_data.data[0], 325.0)  # float(cube[9,0].data))
        eq_(new_data.data[1], 327.0)  # float(cube[9,0].data))
        eq_(new_data.data[2], 325.0)  # float(cube[9,0].data))
        eq_(new_data.data[3], 327.0)  # float(cube[9,2].data))
Example #3
0
    def test_lon_points_over_360_dont_matter_with_0_360_grid_in_2d(self):
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, nn_gridded
        # This cube is defined over a 0-360 longitude grid
        cube = gridded_data.make_from_cube(mock.make_dummy_2d_cube())

        sample_points = UngriddedData.from_points_array(
            [HyperPoint(lat=1.0, lon=0.0),
             HyperPoint(lat=1.0, lon=20.0),
             HyperPoint(lat=1.0, lon=361.0),
             HyperPoint(lat=1.0, lon=381.0)])
        col = GeneralUngriddedCollocator()
        new_data = col.collocate(sample_points, cube, None, nn_gridded())[0]
        eq_(new_data.data[0], 325.0)  # float(cube[9,0].data))
        eq_(new_data.data[1], 327.0)  # float(cube[9,0].data))
        eq_(new_data.data[2], 325.0)  # float(cube[9,0].data))
        eq_(new_data.data[3], 327.0)  # float(cube[9,2].data))
    def test_lon_points_over_360_dont_matter_with_0_360_grid_in_2d(self):
        # This cube is defined over a 0-360 longitude grid
        cube = make_from_cube(mock.make_dummy_2d_cube())

        sample_points = UngriddedData.from_points_array([
            HyperPoint(lat=1.0, lon=0.0),
            HyperPoint(lat=1.0, lon=20.0),
            HyperPoint(lat=1.0, lon=361.0),
            HyperPoint(lat=1.0, lon=381.0)
        ])
        col = GriddedUngriddedCollocator(extrapolate=True)
        new_data = col.collocate(sample_points, cube, None, 'nn')[0]
        eq_(new_data.data[0], 325.0)  # float(cube[9,0].data))
        eq_(new_data.data[1], 327.0)  # float(cube[9,0].data))
        eq_(new_data.data[2], 325.0)  # float(cube[9,0].data))
        eq_(new_data.data[3], 327.0)  # float(cube[9,2].data))
    def test_negative_lon_points_dont_matter_with_0_360_grid_in_2d(self):
        # This cube is defined over a 0-360 longitude grid
        cube = make_from_cube(mock.make_dummy_2d_cube())

        sample_points = UngriddedData.from_points_array([
            HyperPoint(lat=1.0, lon=1.0),
            HyperPoint(lat=19.0, lon=44.0),
            HyperPoint(lat=-4.0, lon=-14.0),
            HyperPoint(lat=-4.0, lon=-44.0)
        ])
        col = GriddedUngriddedCollocator()
        new_data = col.collocate(sample_points, cube, None, 'nn')[0]
        eq_(new_data.data[0], 325.0)  # float(cube[9,0].data)
        eq_(new_data.data[1], 365.0)  # float(cube[10,4].data))
        eq_(new_data.data[2], 324.0)  # float(cube[8,35].data))
        eq_(new_data.data[3], 321.0)  # float(cube[8,32].data))
    def test_guessing_the_bounds_on_a_cube_doesnt_matter_for_negative_lon_points_on_a_0_360_grid_in_2d(self):
        """This should be identical to above but there was an issue in iris where this caused a problem"""

        # This cube is defined over a 0-360 longitude grid
        cube = make_from_cube(mock.make_dummy_2d_cube())
        cube.coord(standard_name='longitude').guess_bounds()

        sample_points = UngriddedData.from_points_array(
            [HyperPoint(lat=1.0, lon=1.0),
             HyperPoint(lat=19.0, lon=44.0),
             HyperPoint(lat=-4.0, lon=-14.0),
             HyperPoint(lat=-4.0, lon=-44.0)])
        col = GriddedUngriddedCollocator()
        new_data = col.collocate(sample_points, cube, None, 'nn')[0]
        eq_(new_data.data[0], 325.0)  # float(cube[9,0].data)
        eq_(new_data.data[1], 365.0)  # float(cube[10,4].data))
        eq_(new_data.data[2], 324.0)  # float(cube[8,35].data))
        eq_(new_data.data[3], 321.0)  # float(cube[8,32].data))
    def test_guessing_the_bounds_on_a_cube_doesnt_matter_for_negative_lon_points_on_a_0_360_grid_in_2d(
            self):
        """This should be identical to above but there was an issue in iris where this caused a problem"""

        # This cube is defined over a 0-360 longitude grid
        cube = make_from_cube(mock.make_dummy_2d_cube())
        cube.coord(standard_name='longitude').guess_bounds()

        sample_points = UngriddedData.from_points_array([
            HyperPoint(lat=1.0, lon=1.0),
            HyperPoint(lat=19.0, lon=44.0),
            HyperPoint(lat=-4.0, lon=-14.0),
            HyperPoint(lat=-4.0, lon=-44.0)
        ])
        col = GriddedUngriddedCollocator()
        new_data = col.collocate(sample_points, cube, None, 'nn')[0]
        eq_(new_data.data[0], 325.0)  # float(cube[9,0].data)
        eq_(new_data.data[1], 365.0)  # float(cube[10,4].data))
        eq_(new_data.data[2], 324.0)  # float(cube[8,35].data))
        eq_(new_data.data[3], 321.0)  # float(cube[8,32].data))