コード例 #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)
コード例 #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)
コード例 #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)
コード例 #4
0
def point_on_a_lat_lon_boundary_appears_in_highest_cell(con, kernel):
    sample_cube = make_mock_cube()
    data_point = make_dummy_ungridded_data_single_point(2.5, 2.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, 1.2],
                                   [-999.9, -999.9, -999.9]])
    assert_arrays_almost_equal(out_cube.data.filled(), expected_result)
コード例 #5
0
def point_on_180_is_included_in_lower_bound(con, kernel):
    sample_cube = make_square_NxM_2d_cube_with_time(start_lon=-135, end_lon=135, lon_point_count=4)
    data_point = make_dummy_ungridded_data_single_point(0, 180.0, 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],
                                   [1.2, -999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9, -999.9],
                                   [-999.9, -999.9, -999.9, -999.9]])
    assert_arrays_almost_equal(out_cube.data.filled(), expected_result)
コード例 #6
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)
コード例 #7
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)
コード例 #8
0
    def test_fill_value_for_cube_cell_constraint_default_fill_value(self):
        sample_cube = make_mock_cube()
        data_point = make_dummy_ungridded_data_single_point(99, 99, 0.0)

        col = GeneralGriddedCollocator()
        con = CubeCellConstraint()

        out_cube = col.collocate(points=sample_cube, data=data_point, constraint=con, kernel=SlowMean())[0]

        expected_result = numpy.array([[float('nan'), float('nan'), float('nan')],
                                       [float('nan'), float('nan'), float('nan')],
                                       [float('nan'), float('nan'), float('nan')],
                                       [float('nan'), float('nan'), float('nan')],
                                       [float('nan'), float('nan'), float('nan')]])

        numpy.testing.assert_array_equal(out_cube.data.filled(), expected_result)
コード例 #9
0
    def test_fill_value_for_cube_cell_constraint(self):
        sample_cube = make_mock_cube()
        data_point = make_dummy_ungridded_data_single_point(99, 99, 0.0)

        col = GeneralGriddedCollocator(fill_value=-999.9)
        con = CubeCellConstraint()

        out_cube = col.collocate(points=sample_cube, data=data_point, constraint=con, kernel=SlowMean())[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 numpy.array_equal(out_cube.data.filled(), expected_result)
コード例 #10
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)
コード例 #11
0
def single_point_gives_single_val_in_cell_w_no_time_with_cube_w_time_and_missing_samples_THEN_error(con, kernel):
    sample_cube = make_square_5x3_2d_cube_with_time()
    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=True)
    assert_that(calling(col.collocate).with_args(points=sample_cube, data=data_point, constraint=con, kernel=kernel),
                raises(UserPrintableException, pattern=".*sample variable.*"))