Esempio n. 1
0
    def test_ungridded_ungridded_box_moments_no_missing_data_for_missing_sample(
            self):
        data = mock.make_regular_2d_ungridded_data()
        sample = mock.make_dummy_sample_points(
            latitude=[1.0, 3.0, -1.0],
            longitude=[1.0, 3.0, -1.0],
            altitude=[12.0, 7.0, 5.0],
            time=[
                dt.datetime(1984, 8, 29, 8, 34),
                dt.datetime(1984, 8, 29, 8, 34),
                dt.datetime(1984, 8, 29, 8, 34)
            ])

        kernel = moments()

        # Set a missing sample data-value
        sample.data[1] = np.NaN

        output = collocate(sample,
                           data,
                           kernel,
                           h_sep=500,
                           missing_data_for_missing_sample=False)

        expected_result = np.array([28.0 / 3, 10.0, 20.0 / 3])
        expected_stddev = np.array([1.52752523, 1.82574186, 1.52752523])
        expected_n = np.array([3, 4, 3])

        assert isinstance(output, xr.Dataset)
        assert np.allclose(output['var'].data, expected_result)
        assert np.allclose(output['var_std_dev'].data, expected_stddev)
        assert np.allclose(output['var_num_points'].data, expected_n)
Esempio n. 2
0
    def test_already_collocated_in_col_in_2d(self):
        from collocate.kernels import nn_horizontal
        from collocate import collocate

        data = mock.make_regular_2d_ungridded_data()
        # This point already exists on the cube with value 5 - which shouldn't be a problem
        sample_points = mock.make_dummy_sample_points(latitude=[0.0],
                                                      longitude=[0.0])
        new_data = collocate(sample_points, data, nn_horizontal())['var']
        assert_almost_equal(new_data.data[0], 8.0)
Esempio n. 3
0
    def test_basic_col_in_2d(self):
        from collocate.kernels import nn_horizontal
        from collocate import collocate

        data = mock.make_regular_2d_ungridded_data()
        sample_points = mock.make_dummy_sample_points(
            latitude=[1.0, 4.0, -4.0], longitude=[1.0, 4.0, -4.0])
        new_data = collocate(sample_points, data, nn_horizontal())['var']
        assert_almost_equal(new_data.data[0], 8.0)
        assert_almost_equal(new_data.data[1], 12.0)
        assert_almost_equal(new_data.data[2], 4.0)
Esempio n. 4
0
    def test_coordinates_outside_grid_in_col_in_2d(self):
        from collocate.kernels import nn_horizontal
        from collocate import collocate

        data = mock.make_regular_2d_ungridded_data()
        sample_points = mock.make_dummy_sample_points(
            latitude=[5.5, -5.5, 5.5, -5.5], longitude=[5.5, 5.5, -5.5, -5.5])
        new_data = collocate(sample_points, data, nn_horizontal())['var']
        assert_almost_equal(new_data.data[0], 12.0)
        assert_almost_equal(new_data.data[1], 6.0)
        assert_almost_equal(new_data.data[2], 10.0)
        assert_almost_equal(new_data.data[3], 4.0)
Esempio n. 5
0
    def test_list_ungridded_ungridded_box_mean(self):
        ug_data_1 = mock.make_regular_2d_ungridded_data()
        ug_data_2 = mock.make_regular_2d_ungridded_data(data_offset=3)
        ug_data_2.attrs['long_name'] = 'TOTAL SNOWFALL RATE: LS+CONV KG/M2/S'
        ug_data_2.attrs['standard_name'] = 'snowfall_flux'

        data_list = xr.Dataset({'precip': ug_data_1, 'snow': ug_data_2})
        sample_points = mock.make_regular_2d_ungridded_data()
        kernel = moments()
        output = collocate(sample_points, data_list, kernel, h_sep=500)

        expected_result = np.array(list(range(1, 16)))
        expected_n = np.array(15 * [1])
        assert isinstance(output, xr.Dataset)
        assert output['snow'].name == 'snow'
        assert output['snow_std_dev'].name == 'snow_std_dev'
        assert output['snow_num_points'].name == 'snow_num_points'
        assert np.allclose(output['precip'].data, expected_result)
        assert np.isnan(output['precip_std_dev'].data).all()
        assert np.allclose(output['precip_num_points'].data, expected_n)
        assert np.allclose(output['snow'].data, expected_result + 3)
        assert np.isnan(output['snow_std_dev'].data).all()
        assert np.allclose(output['snow_num_points'].data, expected_n)
Esempio n. 6
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_horizontal 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  you would expect the first point to be chosen. This doesn't seem to always be the case but is
                probably down to floating points errors in the haversine calculation as these test points are pretty
                close together. This test is only really for documenting the behaviour for equidistant points.
        """
        from collocate.kernels import nn_horizontal
        from collocate import collocate

        data = mock.make_regular_2d_ungridded_data()
        sample_points = mock.make_dummy_sample_points(
            latitude=[2.5, -2.5, 2.5, -2.5], longitude=[2.5, 2.5, -2.5, -2.5])
        new_data = collocate(sample_points, data, nn_horizontal())['var']
        assert_almost_equal(new_data.data[0], 9.0)
        assert_almost_equal(new_data.data[1], 6.0)
        assert_almost_equal(new_data.data[2], 7.0)
        assert_almost_equal(new_data.data[3], 4.0)