Пример #1
0
    def test_aggregation_two_dims_using_moments_kernel(self):
        self.kernel = moments()
        data1 = make_regular_2d_ungridded_data_with_missing_values()
        data2 = make_regular_2d_ungridded_data_with_missing_values()
        data2.metadata._name = 'snow'
        data2._data += 10
        data = UngriddedDataList([data1, data2])
        grid = {'y': slice(-12.5, 12.5, 15), 'x': slice(-7.5, 7.5, 10)}

        output = data.aggregate(how=self.kernel, **grid)

        expect_mean = numpy.array([[4.4, 4.5], [35.0 / 3, 13.5]])
        expect_stddev = numpy.array([[numpy.sqrt(9.3), numpy.sqrt(4.5)],
                                     [numpy.sqrt(13.0 / 3), numpy.sqrt(4.5)]])
        expect_count = numpy.array([[5, 2], [3, 2]])

        assert isinstance(output, GriddedDataList)
        assert len(output) == 6
        mean_1, stddev_1, count_1, mean_2, stddev_2, count_2 = output
        assert mean_1.var_name == 'rain'
        assert stddev_1.var_name == 'rain_std_dev'
        assert count_1.var_name == 'rain_num_points'
        assert mean_2.var_name == 'snow'
        assert stddev_2.var_name == 'snow_std_dev'
        assert count_2.var_name == 'snow_num_points'
        assert_arrays_almost_equal(mean_1.data, expect_mean)
        assert_arrays_almost_equal(stddev_1.data, expect_stddev)
        assert_arrays_almost_equal(count_1.data, expect_count)
        assert_arrays_almost_equal(mean_2.data, expect_mean + 10)
        assert_arrays_almost_equal(stddev_2.data, expect_stddev)
        assert_arrays_almost_equal(count_2.data, expect_count)
Пример #2
0
    def test_aggregating_list_of_datasets_over_two_dims_with_diff_masks(self):
        grid = {'x': slice(-7.5, 7.5, 5), 'y': slice(-12.5, 12.5, 5)}

        var_0 = make_regular_2d_ungridded_data_with_missing_values()
        var_1 = make_regular_2d_ungridded_data_with_missing_values()

        var_1.data.mask = 1

        datalist = UngriddedDataList([var_0, var_1])

        cube_out = datalist.aggregate(how=self.kernel, **grid)

        result_0 = numpy.ma.array(
            [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0],
             [10.0, 11.0, 12.0], [13.0, 14.0, 15.0]],
            mask=[[0, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, 0], [1, 0, 0]],
            fill_value=float('nan'))

        result_1 = numpy.ma.array(
            [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0],
             [10.0, 11.0, 12.0], [13.0, 14.0, 15.0]],
            mask=[[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]],
            fill_value=float('nan'))

        print(cube_out[0].data.fill_value)
        assert len(cube_out) == 2
        compare_masked_arrays(cube_out[0].data, result_0)
        compare_masked_arrays(cube_out[1].data, result_1)
Пример #3
0
    def test_aggregation_two_dims_using_moments_kernel(self):
        self.kernel = moments()
        data1 = make_regular_2d_ungridded_data_with_missing_values()
        data2 = make_regular_2d_ungridded_data_with_missing_values()
        data2.metadata._name = 'snow'
        data2._data += 10
        data = UngriddedDataList([data1, data2])
        grid = {'y': slice(-12.5, 12.5, 15), 'x': slice(-7.5, 7.5, 10)}

        output = data.aggregate(how=self.kernel, **grid)

        expect_mean = numpy.array([[4.4, 4.5], [35.0 / 3, 13.5]])
        expect_stddev = numpy.array([[numpy.sqrt(9.3),
                                      numpy.sqrt(4.5)],
                                     [numpy.sqrt(13.0 / 3),
                                      numpy.sqrt(4.5)]])
        expect_count = numpy.array([[5, 2], [3, 2]])

        assert isinstance(output, GriddedDataList)
        assert len(output) == 6
        mean_1, stddev_1, count_1, mean_2, stddev_2, count_2 = output
        assert mean_1.var_name == 'rain'
        assert stddev_1.var_name == 'rain_std_dev'
        assert count_1.var_name == 'rain_num_points'
        assert mean_2.var_name == 'snow'
        assert stddev_2.var_name == 'snow_std_dev'
        assert count_2.var_name == 'snow_num_points'
        assert_arrays_almost_equal(mean_1.data, expect_mean)
        assert_arrays_almost_equal(stddev_1.data, expect_stddev)
        assert_arrays_almost_equal(count_1.data, expect_count)
        assert_arrays_almost_equal(mean_2.data, expect_mean + 10)
        assert_arrays_almost_equal(stddev_2.data, expect_stddev)
        assert_arrays_almost_equal(count_2.data, expect_count)
Пример #4
0
    def test_aggregating_list_of_datasets_over_two_dims(self):
        grid = {'x': slice(-7.5, 7.5, 5), 'y': slice(-12.5, 12.5, 5)}

        datalist = UngriddedDataList([make_regular_2d_ungridded_data_with_missing_values(),
                                      make_regular_2d_ungridded_data_with_missing_values()])

        cube_out = datalist.aggregate(how=self.kernel, **grid)

        result = numpy.ma.array([[1.0, 2.0, 3.0],
                                 [4.0, 5.0, 6.0],
                                 [7.0, 8.0, 9.0],
                                 [10.0, 11.0, 12.0],
                                 [13.0, 14.0, 15.0]],
                                mask=[[0, 0, 0],
                                      [0, 1, 0],
                                      [0, 0, 1],
                                      [0, 0, 0],
                                      [1, 0, 0]], fill_value=float('nan'))

        assert len(cube_out) == 2
        compare_masked_arrays(cube_out[0].data, result)
        compare_masked_arrays(cube_out[1].data, result)