Example #1
0
    def test_basic_col_with_incompatible_points_throws_an_AttributeError(self):
        from collocate.kernels import nn_pressure
        from collocate import collocate

        data = mock.make_regular_4d_ungridded_data()
        # Make sample points with no time dimension specified
        sample_points = mock.make_dummy_sample_points(
            latitude=[1.0, 4.0, -4.0], longitude=[1.0, 4.0, -4.0])

        with self.assertRaises(AttributeError):
            new_data = collocate(sample_points, data, nn_pressure())['var']
Example #2
0
    def test_already_collocated_in_col_in_2d(self):
        from collocate.kernels import nn_pressure
        from collocate import collocate
        import datetime as dt

        data = mock.make_regular_4d_ungridded_data()
        sample_points = mock.make_dummy_sample_points(
            latitude=[0.0],
            longitude=[0.0],
            air_pressure=[80.0],
            time=[dt.datetime(1984, 9, 4, 15, 54)])

        new_data = collocate(sample_points, data, nn_pressure())['var']
        assert_almost_equal(new_data.data[0], 41.0)
Example #3
0
    def test_coordinates_outside_grid_in_col_in_2d(self):
        from collocate.kernels import nn_pressure
        from collocate import collocate
        import datetime as dt

        data = mock.make_regular_4d_ungridded_data()
        sample_points = mock.make_dummy_sample_points(
            latitude=[0.0, 0.0, 0.0],
            longitude=[0.0, 0.0, 0.0],
            air_pressure=[0.1, 91.0, 890.0],
            time=[
                dt.datetime(1984, 8, 29, 8, 34),
                dt.datetime(1984, 9, 2, 1, 23),
                dt.datetime(1984, 9, 4, 15, 54)
            ])

        new_data = collocate(sample_points, data, nn_pressure())['var']
        assert_almost_equal(new_data.data[0], 1.0)
        assert_almost_equal(new_data.data[1], 46.0)
        assert_almost_equal(new_data.data[2], 46.0)
Example #4
0
    def test_coordinates_exactly_between_points_in_col_in_2d(self):
        """
            This works out the edge case where the points are exactly in the middle or two or more datapoints.
                The nn_pressure algorithm will start with the first point as the nearest and iterates through the
                points finding any points which are closer than the current closest. If two distances were exactly
                the same the first point to be chosen.
        """
        from collocate.kernels import nn_pressure
        from collocate import collocate
        import datetime as dt

        data = mock.make_regular_4d_ungridded_data()
        # Choose a time at midday
        sample_points = mock.make_dummy_sample_points(
            latitude=[0.0],
            longitude=[0.0],
            air_pressure=[8.0],
            time=[dt.datetime(1984, 8, 29, 12)])

        new_data = collocate(sample_points, data, nn_pressure())['var']
        assert_almost_equal(new_data.data[0], 1.0)