Пример #1
0
    def test_basic_col_gridded_to_ungridded_using_li_in_2d(self):
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li

        cube = gridded_data.make_from_cube(mock.make_square_5x3_2d_cube())
        sample_points = UngriddedData.from_points_array(
            [HyperPoint(1.0, 1.0), HyperPoint(4.0, 4.0), HyperPoint(-4.0, -4.0)])
        col = GeneralUngriddedCollocator()
        new_data = col.collocate(sample_points, cube, None, li())[0]
        assert_almost_equal(new_data.data[0], 8.8)
        assert_almost_equal(new_data.data[1], 11.2)
        assert_almost_equal(new_data.data[2], 4.8)
Пример #2
0
    def test_extrapolation_of_pres_points_on_hybrid_pressure_coordinates(self):
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li
        import datetime as dt

        cube = gridded_data.make_from_cube(mock.make_mock_cube(time_dim_length=3, hybrid_pr_len=10))

        sample_points = UngriddedData.from_points_array(
            # Point interpolated in the horizontal and then extrapolated past the top vertical layer (by one layer)
            [HyperPoint(lat=-4.0, lon=-4.0, pres=68400050.0, t=dt.datetime(1984, 8, 27))])
        col = GeneralUngriddedCollocator()
        new_data = col.collocate(sample_points, cube, None, li(extrapolate=True))[0]
        assert_almost_equal(new_data.data[0], 125.0, decimal=7)
Пример #3
0
    def test_alt_extrapolation(self):
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li
        import datetime as dt

        cube = gridded_data.make_from_cube(mock.make_mock_cube(time_dim_length=3, hybrid_ht_len=10))

        sample_points = UngriddedData.from_points_array(
            [HyperPoint(lat=-4.0, lon=-4.0, alt=6382.8, t=dt.datetime(1984, 8, 27))])

        col = GeneralUngriddedCollocator(fill_value=np.NAN)
        new_data = col.collocate(sample_points, cube, None, li(extrapolate=True))[0]
        assert_almost_equal(new_data.data[0], 126.0, decimal=7)
Пример #4
0
    def test_collocation_of_pres_points_on_hybrid_altitude_coordinates(self):
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li
        import datetime as dt

        cube = gridded_data.make_from_cube(mock.make_mock_cube(time_dim_length=3, hybrid_ht_len=10))

        sample_points = UngriddedData.from_points_array(
            [HyperPoint(lat=-4.0, lon=-4.0, pres=100.0, t=dt.datetime(1984, 8, 27))])

        col = GeneralUngriddedCollocator(fill_value=np.NAN)
        new_data = col.collocate(sample_points, cube, None, li())[0]
        # The kernel can't return a unique point and so should raise a ValueError - leaving the data point blank
        assert_equal(new_data.data[0], np.NAN)
Пример #5
0
    def test_collocation_of_alt_pres_points_on_hybrid_altitude_and_pressure_coordinates(self):
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li, DummyConstraint
        import datetime as dt

        cube = gridded_data.make_from_cube(mock.make_mock_cube(time_dim_length=3, hybrid_pr_len=10))

        sample_points = UngriddedData.from_points_array(
            # Test point with both pressure and altitude should interpolate over the altitude only (since that is also
            #  present in the data cube)
            [HyperPoint(lat=0.0, lon=0.0, alt=234.5, pres=1000, t=dt.datetime(1984, 8, 28, 0, 0, 0))])

        col = GeneralUngriddedCollocator(fill_value=np.NAN)
        new_data = col.collocate(sample_points, cube, None, li())[0]
        assert_almost_equal(new_data.data[0], 225.5, decimal=7)
Пример #6
0
    def test_negative_lon_points_in_2d_dont_matter(self):
        """
            This is exactly the same test as above, except we ommit the point with negative longitude, this makes the
            collocator wrap the longitude coordinate and gives a slightly different interpolation result...
        """
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li

        cube = gridded_data.make_from_cube(mock.make_square_5x3_2d_cube())
        sample_points = UngriddedData.from_points_array(
            [HyperPoint(1.0, 1.0), HyperPoint(4.0, 4.0)])
        col = GeneralUngriddedCollocator()
        new_data = col.collocate(sample_points, cube, None, li())[0]
        assert_almost_equal(new_data.data[0], 8.8)
        assert_almost_equal(new_data.data[1], 11.2)
Пример #7
0
    def test_nearest_neighbour_vertical_interpolation_on_hybrid_pressure(self):
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li
        import datetime as dt

        cube = gridded_data.make_from_cube(mock.make_mock_cube(time_dim_length=3, hybrid_pr_len=10))

        sample_points = UngriddedData.from_points_array(
            [HyperPoint(lat=0.0, lon=0.0, pres=111100040.5, t=dt.datetime(1984, 8, 28, 0, 0, 0)),
             HyperPoint(lat=5.0, lon=2.5, pres=177125044.5, t=dt.datetime(1984, 8, 28, 0, 0, 0)),
             HyperPoint(lat=-4.0, lon=-4.0, pres=68400050.0, t=dt.datetime(1984, 8, 27))])
        col = GeneralUngriddedCollocator()
        new_data = col.collocate(sample_points, cube, None, li(nn_vertical=True))[0]
        assert_almost_equal(new_data.data[0], 221)
        assert_almost_equal(new_data.data[1], 330)
        assert_almost_equal(new_data.data[2], 124.0)
Пример #8
0
    def test_negative_lon_points_on_hybrid_pressure_coordinates_dont_matter(self):
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li
        import datetime as dt

        cube = gridded_data.make_from_cube(mock.make_mock_cube(time_dim_length=3, hybrid_pr_len=10))

        sample_points = UngriddedData.from_points_array(
            [HyperPoint(lat=0.0, lon=0.0, pres=111100040.5, t=dt.datetime(1984, 8, 28, 0, 0, 0)),
             HyperPoint(lat=5.0, lon=2.5, pres=177125044.5, t=dt.datetime(1984, 8, 28, 0, 0, 0))])
        col = GeneralUngriddedCollocator()
        new_data = col.collocate(sample_points, cube, None, li())[0]
        # Exactly on the lat, lon, time points, interpolated over pressure
        assert_almost_equal(new_data.data[0], 221.5, decimal=5)
        # Exactly on the lat, time points, interpolated over latitude and pressure
        assert_almost_equal(new_data.data[1], 330.5, decimal=7)
Пример #9
0
    def test_nearest_neighbour_vertical_interpolation_on_hybrid_altitude(self):
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li
        import datetime as dt

        cube = gridded_data.make_from_cube(mock.make_mock_cube(time_dim_length=3, hybrid_ht_len=10))

        sample_points = UngriddedData.from_points_array(
            # This is just past the top of the vertical coordinate slice
            [HyperPoint(lat=-4.0, lon=-4.0, alt=6500.0, t=dt.datetime(1984, 8, 27)),
             # This is well past the bottom of the vertical coordinate slice
             HyperPoint(lat=-4.0, lon=-4.0, alt=0.0, t=dt.datetime(1984, 8, 27))])

        col = GeneralUngriddedCollocator(fill_value=np.NAN)
        new_data = col.collocate(sample_points, cube, None, li(nn_vertical=True))[0]
        assert_almost_equal(new_data.data[0], 124.0, decimal=7)
        assert_almost_equal(new_data.data[1], 115.0, decimal=7)
Пример #10
0
    def test_collocation_of_alt_pres_points_on_hybrid_altitude_coordinates(self):
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li
        import datetime as dt

        cube = gridded_data.make_from_cube(mock.make_mock_cube(time_dim_length=3, hybrid_ht_len=10))

        sample_points = UngriddedData.from_points_array(
            [HyperPoint(lat=0.0, lon=0.0, alt=5550.0, pres=10000.0, t=dt.datetime(1984, 8, 28)),
             HyperPoint(lat=4.0, lon=4.0, alt=6000.0, pres=1000.0, t=dt.datetime(1984, 8, 28)),
             HyperPoint(lat=-4.0, lon=-4.0, alt=6500.0, pres=100.0, t=dt.datetime(1984, 8, 27))])

        col = GeneralUngriddedCollocator(fill_value=np.NAN)
        new_data = col.collocate(sample_points, cube, None, li())[0]
        assert_almost_equal(new_data.data[0], 222.4814815, decimal=7)
        assert_almost_equal(new_data.data[1], 321.0467626, decimal=7)
        # Test that points outside the cell are returned as masked, rather than extrapolated by default
        assert_equal(new_data.data[2], np.NAN)
Пример #11
0
    def test_negative_lon_points_on_hybrid_altitude_coordinates_dont_matter(self):
        """
            This is exactly the same test as above, except we ommit the point with negative longitude, this makes the
            collocator wrap the longitude coordinate and gives a slightly different interpolation result...
        """
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li
        import datetime as dt

        cube = gridded_data.make_from_cube(mock.make_mock_cube(time_dim_length=3, hybrid_ht_len=10))

        sample_points = UngriddedData.from_points_array(
            [HyperPoint(lat=4.0, lon=4.0, alt=6000.0, t=dt.datetime(1984, 8, 28)),
             HyperPoint(lat=0.0, lon=0.0, alt=5550.0, t=dt.datetime(1984, 8, 28))])

        col = GeneralUngriddedCollocator(fill_value=np.NAN)
        new_data = col.collocate(sample_points, cube, None, li())[0]
        assert_almost_equal(new_data.data[0], 321.0467626, decimal=7)
        assert_almost_equal(new_data.data[1], 222.4814815, decimal=7)
    def test_gridded_ungridded_lin(self):
        data = make_from_cube(mock.make_mock_cube())
        data.name = lambda: 'Name'
        data.var_name = 'var_name'
        data._standard_name = 'y_wind'
        sample = UngriddedData.from_points_array(
            [HyperPoint(lat=1.0, lon=1.0, alt=12.0, t=dt.datetime(1984, 8, 29, 8, 34)),
             HyperPoint(lat=3.0, lon=3.0, alt=7.0, t=dt.datetime(1984, 8, 29, 8, 34)),
             HyperPoint(lat=-1.0, lon=-1.0, alt=5.0, t=dt.datetime(1984, 8, 29, 8, 34))])
        constraint = None
        kernel = li()

        col = GeneralUngriddedCollocator()
        output = col.collocate(sample, data, constraint, kernel)

        expected_result = np.array([8.8, 10.4, 7.2])
        assert len(output) == 1
        assert isinstance(output, UngriddedDataList)
        assert np.allclose(output[0].data, expected_result)
Пример #13
0
    def test_collocation_of_pres_points_on_hybrid_pressure_coordinates(self):
        from cis.collocation.col_implementations import GeneralUngriddedCollocator, li
        import datetime as dt

        cube = gridded_data.make_from_cube(mock.make_mock_cube(time_dim_length=3, hybrid_pr_len=10))

        sample_points = UngriddedData.from_points_array(
            [HyperPoint(lat=0.0, lon=0.0, pres=111100040.5, t=dt.datetime(1984, 8, 28, 0, 0, 0)),
             HyperPoint(lat=0.0, lon=0.0, pres=113625040.5, t=dt.datetime(1984, 8, 28, 12, 0, 0)),
             HyperPoint(lat=5.0, lon=2.5, pres=177125044.5, t=dt.datetime(1984, 8, 28, 0, 0, 0)),
             HyperPoint(lat=-4.0, lon=-4.0, pres=166600039.0, t=dt.datetime(1984, 8, 27))])
        col = GeneralUngriddedCollocator()
        new_data = col.collocate(sample_points, cube, None, li())[0]
        # Exactly on the lat, lon, time points, interpolated over pressure
        assert_almost_equal(new_data.data[0], 221.5, decimal=5)
        # Exactly on the lat, lon, points, interpolated over time and pressure
        assert_almost_equal(new_data.data[1], 226.5, decimal=7)
        # Exactly on the lat, time points, interpolated over longitude and pressure
        assert_almost_equal(new_data.data[2], 330.5, decimal=7)
        # Outside of the pressure bounds - extrapolation off
        assert_equal(new_data.data[3], np.inf)