Esempio n. 1
0
def single_point_results_in_single_value_in_cell_with_pressure_with_cube_with_pressure(con, kernel):
    sample_cube = make_square_5x3_2d_cube_with_pressure()
    data_point = make_dummy_ungridded_data_single_point(0.5, 0.5, 1.2, pressure=1.0)
    col = GeneralGriddedCollocator(fill_value=-999.9)
    out_cube = col.collocate(points=sample_cube, data=data_point, constraint=con, kernel=kernel)[0]
    expected_result = numpy.array([[[-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9],
                                    [-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9],
                                    [-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9]],

                                   [[-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9],
                                    [-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9],
                                    [-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9]],

                                   [[-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9],
                                    [-999.9, 1.2, -999.9, -999.9, -999.9, -999.9, -999.9],
                                    [-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9]],

                                   [[-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9],
                                    [-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9],
                                    [-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9]],

                                   [[-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9],
                                    [-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9],
                                    [-999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9]]])
    print(out_cube.data.filled())
    assert_arrays_equal(out_cube.data.filled(), expected_result)
Esempio n. 2
0
def single_masked_point_results_in_single_value_in_cell_using_kernel_and_con(con, kernel):
    sample_cube = make_mock_cube()
    data_point = make_dummy_ungridded_data_single_point(0.5, 0.5, 1.2, mask=True)
    col = GeneralGriddedCollocator(fill_value=-999.9)
    out_cube = col.collocate(points=sample_cube, data=data_point, constraint=con, kernel=kernel)[0]
    expected_result = numpy.array([[-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9]])
    assert_arrays_equal(out_cube.data.filled(), expected_result)
Esempio n. 3
0
def single_point_on_grid_corner_is_counted_once(con, kernel):
    sample_cube = make_mock_cube()
    data_point = make_dummy_ungridded_data_single_point(10, 5, 1.2)
    col = GeneralGriddedCollocator(fill_value=-999.9)
    out_cube = col.collocate(points=sample_cube, data=data_point, constraint=con, kernel=kernel)[0]
    expected_result = numpy.array([[-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, 1.2]])
    assert_arrays_equal(out_cube.data.filled(), expected_result)
Esempio n. 4
0
def single_point_outside_grid_and_one_inside_excludes_outside_using_binned_only(con, kernel):
    sample_cube = make_mock_cube()
    data_point = make_dummy_ungridded_data_single_point([0.5, 99], [0.5, 99], [1.2, 5])
    col = GeneralGriddedCollocator(fill_value=-999.9)
    out_cube = col.collocate(points=sample_cube, data=data_point, constraint=con, kernel=kernel)[0]
    expected_result = numpy.array([[-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9],
                                   [-999.9, 1.2, -999.9],
                                   [-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9]])
    assert_arrays_equal(out_cube.data.filled(), expected_result)
Esempio n. 5
0
def multiple_points_inside_grid_and_outside(con, kernel):
    sample_cube = make_mock_cube()
    data_point = make_dummy_ungridded_data_single_point([0.5, 99, 0.6, 3.0, -9], [0.5, 99, 0.6, 0.5, -3],
                                                        [1.2, 5, 3.4, 5, 8])
    col = GeneralGriddedCollocator(fill_value=-999.9)
    out_cube = col.collocate(points=sample_cube, data=data_point, constraint=con, kernel=kernel)[0]
    expected_result = numpy.array([[8, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9],
                                   [-999.9, 2.3, -999.9],
                                   [-999.9, 5, -999.9],
                                   [-999.9, -999.9, -999.9]])
    assert_arrays_equal(out_cube.data.filled(), expected_result)
Esempio n. 6
0
 def test_longitude_0_360_one_degree(self):
     x = np.arange(0.5, 360.5, 1)
     y = np.array([50.5, 51.5])
     values = np.arange(len(y) * len(x)).reshape((len(y), len(x)))
     latitude = DimCoord(y, standard_name='latitude', units='degrees')
     longitude = DimCoord(x, standard_name='longitude', units='degrees')
     data = make_from_cube(Cube(values, dim_coords_and_dims=[(latitude, 0), (longitude, 1)]))
     out_values, out_x, out_y= Generic2DPlot._cube_manipulation(data, longitude.contiguous_bounds(),
                                                                latitude.contiguous_bounds())
     x_bounds = np.arange(0, 361, 1)
     y_bounds = np.array([50, 51, 52])
     assert_arrays_equal(out_x, x_bounds)
     assert_arrays_equal(out_y, y_bounds)
Esempio n. 7
0
 def test_longitude_0_360_one_degree(self):
     x = np.arange(0.5, 360.5, 1)
     y = np.array([50.5, 51.5])
     values = np.arange(len(y) * len(x)).reshape((len(y), len(x)))
     latitude = DimCoord(y, standard_name='latitude', units='degrees')
     longitude = DimCoord(x, standard_name='longitude', units='degrees')
     data = make_from_cube(
         Cube(values, dim_coords_and_dims=[(latitude, 0), (longitude, 1)]))
     out_values, out_x, out_y = Generic2DPlot._cube_manipulation(
         data, longitude.contiguous_bounds(), latitude.contiguous_bounds())
     x_bounds = np.arange(0, 361, 1)
     y_bounds = np.array([50, 51, 52])
     assert_arrays_equal(out_x, x_bounds)
     assert_arrays_equal(out_y, y_bounds)
Esempio n. 8
0
def can_collocate_list_of_data(constraint, kernel):
    col = GeneralGriddedCollocator()
    sample = make_square_5x3_2d_cube()
    data1 = make_regular_2d_ungridded_data(10, -10, 10, 6, -5, 5, 0)
    data2 = make_regular_2d_ungridded_data(10, -10, 10, 6, -5, 5, 10)
    output = col.collocate(sample, UngriddedDataList([data1, data2]), constraint, kernel)
    assert len(output) == 2
    expected_data2 = numpy.array([[14.5, 16.5, 18.5],
                                  [26.5, 28.5, 30.5],
                                  [38.5, 40.5, 42.5],
                                  [50.5, 52.5, 54.5],
                                  [62.5, 64.5, 66.5]])
    expected_data1 = expected_data2 - 10
    assert_arrays_equal(output[0].data, expected_data1)
    assert_arrays_equal(output[1].data, expected_data2)
Esempio n. 9
0
def single_point_results_in_single_value_in_masked_cell_using_kernel_and_con_missing_for_masked_false(con, kernel):
    mask = [[False, False, False],
            [False, False, False],
            [False, True, False],
            [False, False, False],
            [False, False, False]]
    sample_cube = make_mock_cube(mask=mask)
    data_point = make_dummy_ungridded_data_single_point(0.5, 0.5, 1.2)
    col = GeneralGriddedCollocator(fill_value=-999.9, missing_data_for_missing_sample=False)
    out_cube = col.collocate(points=sample_cube, data=data_point, constraint=con, kernel=kernel)[0]
    expected_result = numpy.array([[-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9],
                                   [-999.9, 1.2, -999.9],
                                   [-999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9]])
    assert_arrays_equal(out_cube.data.filled(), expected_result)
Esempio n. 10
0
    def test_longitude_0_360(self):
        x = np.arange(10, 370, 20)
        y = np.array([50.5, 51.5])
        values = np.arange(len(y) * len(x)).reshape((len(y), len(x)))
        latitude = DimCoord(y, standard_name='latitude', units='degrees')
        longitude = DimCoord(x, standard_name='longitude', units='degrees')
        data = make_from_cube(Cube(values, dim_coords_and_dims=[(latitude, 0), (longitude, 1)]))
        out_x, out_y, out_values = make_color_mesh_cells(data, self.plot_args)
        x_bounds = np.arange(0, 380, 20)
        y_bounds = np.array([50, 51, 52])
        expected_x, expected_y = np.meshgrid(x_bounds, y_bounds)
        assert_arrays_equal(out_x, expected_x)
        assert_arrays_equal(out_y, expected_y)

        # Test that a plot doesn't fail.
        map = Heatmap([data], self.plot_args)
        map.plot()
Esempio n. 11
0
def single_moments(constraint, kernel):
    col = GeneralGriddedCollocator()
    sample = make_square_5x3_2d_cube()
    data = make_regular_2d_ungridded_data(10, -9.9, 9.9, 6, -4.9, 4.9, 10)
    output = col.collocate(sample, data, constraint, kernel)
    expected_data = numpy.array([[14.5, 16.5, 18.5],
                                 [26.5, 28.5, 30.5],
                                 [38.5, 40.5, 42.5],
                                 [50.5, 52.5, 54.5],
                                 [62.5, 64.5, 66.5]])
    expected_stddev = numpy.ones((5, 3)) * 3.5118845842842465
    expected_num = numpy.ones((5, 3)) * 4
    assert len(output) == 3
    assert isinstance(output, GriddedDataList)
    assert output[0].var_name == 'rain'
    assert output[1].var_name == 'rain_std_dev'
    assert output[2].var_name == 'rain_num_points'
    assert_arrays_equal(output[0].data, expected_data)
    assert numpy.allclose(output[1].data, expected_stddev)
    assert numpy.array_equal(output[2].data, expected_num)
Esempio n. 12
0
 def test_lat_lon_decreasing_no_bounds(self):
     x = np.array([0.5, -0.5])
     y = np.array([51.5, 50.5])
     values = np.array([[1, 2], [3, 4]])
     latitude = DimCoord(y, standard_name='latitude', units='degrees')
     longitude = DimCoord(x, standard_name='longitude', units='degrees')
     data = make_from_cube(Cube(values, dim_coords_and_dims=[(latitude, 0), (longitude, 1)]))
     out_values, out_x, out_y= Generic2DPlot._cube_manipulation(data, longitude.contiguous_bounds(),
                                                                latitude.contiguous_bounds())
     expected_x = np.array([1, 0, -1])
     expected_y = np.array([52, 51, 50])
     expected_v = np.array([[1, 2],
                            [3, 4]])
     assert_arrays_equal(out_x, expected_x)
     assert_arrays_equal(out_y, expected_y)
     assert_arrays_equal(out_values, expected_v)
Esempio n. 13
0
 def test_lat_lon_increasing_no_bounds(self):
     x = np.array([0.5, 1.5])
     y = np.array([50.5, 51.5])
     values = np.array([[1, 2], [3, 4]])
     latitude = DimCoord(y, standard_name='latitude', units='degrees')
     longitude = DimCoord(x, standard_name='longitude', units='degrees')
     data = make_from_cube(
         Cube(values, dim_coords_and_dims=[(latitude, 0), (longitude, 1)]))
     out_values, out_x, out_y = Generic2DPlot._cube_manipulation(
         data, longitude.contiguous_bounds(), latitude.contiguous_bounds())
     expected_x = np.array([0, 1, 2])
     expected_y = np.array([50, 51, 52])
     expected_v = np.array([[1, 2], [3, 4]])
     assert_arrays_equal(out_x, expected_x)
     assert_arrays_equal(out_y, expected_y)
     assert_arrays_equal(out_values, expected_v)
Esempio n. 14
0
    def test_lat_lon_decreasing_no_bounds(self):
        x = np.array([0.5, -0.5])
        y = np.array([51.5, 50.5])
        values = np.array([[1, 2], [3, 4]])
        latitude = DimCoord(y, standard_name='latitude', units='degrees')
        longitude = DimCoord(x, standard_name='longitude', units='degrees')
        data = make_from_cube(Cube(values, dim_coords_and_dims=[(latitude, 0), (longitude, 1)]))
        out_x, out_y, out_values = make_color_mesh_cells(data, self.plot_args)
        expected_x = np.array([[1, 0, -1],
                               [1, 0, -1],
                               [1, 0, -1]])
        expected_y = np.array([[52, 52, 52],
                               [51, 51, 51],
                               [50, 50, 50]])
        expected_v = np.array([[1, 2],
                               [3, 4]])
        assert_arrays_equal(out_x, expected_x)
        assert_arrays_equal(out_y, expected_y)
        assert_arrays_equal(out_values, expected_v)

        # Test that a plot doesn't fail.
        map = Heatmap([data], self.plot_args)
        map.plot()