Beispiel #1
0
    def test_basic_col_with_incompatible_points_throws_a_TypeError(self):
        from collocate.kernels import nn_altitude
        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_altitude())['var']
Beispiel #2
0
    def test_already_collocated_in_col_in_2d(self):
        from collocate.kernels import nn_altitude
        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],
            altitude=[80.0],
            time=[dt.datetime(1984, 9, 4, 15, 54)])
        new_data = collocate(sample_points, data, nn_altitude())['var']
        assert_almost_equal(new_data.data[0], 41.0)
Beispiel #3
0
    def test_basic_col_in_4d(self):
        from collocate.kernels import nn_altitude
        from collocate import collocate
        import datetime as dt

        data = mock.make_regular_4d_ungridded_data()
        sample_points = mock.make_dummy_sample_points(
            latitude=[1.0, 4.0, -4.0],
            longitude=[1.0, 4.0, -4.0],
            altitude=[12.0, 34.0, 89.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_altitude())['var']
        assert_almost_equal(new_data.data[0], 6.0)
        assert_almost_equal(new_data.data[1], 16.0)
        assert_almost_equal(new_data.data[2], 46.0)
Beispiel #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_time 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_altitude
        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],
            altitude=[35.0],
            time=[dt.datetime(1984, 8, 29, 12)])

        new_data = collocate(sample_points, data, nn_altitude())['var']
        assert_almost_equal(new_data.data[0], 16.0)