示例#1
0
 def test_setting_new_hyperpoint_coord_can_raise_exception(self):
     gd = gridded_data.make_from_cube(mock.make_5x3_lon_lat_2d_cube_with_missing_data())
     hpv = gd.get_non_masked_points()
     hpv._verify_no_coord_change_on_setting = True
     p = hpv[6]
     p_new = p.modified(lon=123, val=99)
     hpv[6] = p_new
示例#2
0
 def test_can_access_point_in_gridded_hyper_point_view_(self):
     gd = gridded_data.make_from_cube(mock.make_5x3_lon_lat_2d_cube_with_missing_data())
     hpv = gd.get_all_points()
     p = hpv[3, 1]
     assert(p.val[0] == 11.0)
     assert(p.longitude == 5.0)
     assert(p.latitude == 0.0)
示例#3
0
 def test_can_iterate_over_non_masked_points(self):
     gd = gridded_data.make_from_cube(mock.make_5x3_lon_lat_2d_cube_with_missing_data())
     hpv = gd.get_non_masked_points()
     count = 0
     vals = []
     for p in hpv:
         count += 1
         vals.append(p.val[0])
     assert(count == 12)
     assert(vals == [1, 2, 3, 4, 6, 7, 8, 10, 11, 12, 14, 15])
示例#4
0
 def test_can_modify_a_hyperpoint_value_via_flat_index(self):
     gd = gridded_data.make_from_cube(mock.make_5x3_lon_lat_2d_cube_with_missing_data())
     hpv = gd.get_non_masked_points()
     hpv[6] = 99
     p = hpv[6]
     assert(p.latitude == -5)
     assert(p.longitude == 0)
     assert(p.val[0] == 99)
     # Check an unmodified point.
     p = hpv[5]
     assert(p.latitude == 5)
     assert(p.longitude == -5)
     assert(p.val[0] == 6)
示例#5
0
 def test_can_enumerate_non_masked_points(self):
     gd = gridded_data.make_from_cube(mock.make_5x3_lon_lat_2d_cube_with_missing_data())
     hpv = gd.get_non_masked_points()
     count = 0
     indices = []
     vals = []
     for i, p in hpv.enumerate_non_masked_points():
         count += 1
         indices.append(i)
         vals.append(p.val[0])
     assert(count == 12)
     assert(indices == [0, 1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14])
     assert(vals == [1, 2, 3, 4, 6, 7, 8, 10, 11, 12, 14, 15])
示例#6
0
 def test_can_set_a_hyperpoint(self):
     gd = gridded_data.make_from_cube(mock.make_5x3_lon_lat_2d_cube_with_missing_data())
     hpv = gd.get_non_masked_points()
     p = hpv[2, 0]
     p_new = p.modified(lon=123, val=99)
     hpv[6] = p_new
     p = hpv[2, 0]
     assert(p.latitude == -5)
     # Note: the coordinates cannot be changed for GriddedHyperPointView.
     assert(p.longitude == 0)
     assert(p.val[0] == 99)
     # Check an unmodified point.
     p = hpv[1, 2]
     assert(p.latitude == 5)
     assert(p.longitude == -5)
     assert(p.val[0] == 6)
示例#7
0
def test_can_add_history():
    gd = gridded_data.make_from_cube(mock.make_5x3_lon_lat_2d_cube_with_missing_data())
    new_history = 'This is a new history entry.'
    gd.add_history(new_history)
    assert (gd.attributes['history'].find(new_history) >= 0)
示例#8
0
def test_get_coordinates_points_returns_points():
    gd = gridded_data.make_from_cube(mock.make_5x3_lon_lat_2d_cube_with_missing_data())
    points = gd.get_coordinates_points()
    num_points = len([p for p in points])
    assert (num_points == 15)
示例#9
0
def test_can_create_gridded_data():
    gd = gridded_data.make_from_cube(mock.make_5x3_lon_lat_2d_cube_with_missing_data())
    assert (gd.coord(standard_name='latitude') is not None)
    assert (gd.coord(standard_name='longitude') is not None)
    assert (gd.data.size == 15)
    assert (isinstance(gd, gridded_data.GriddedData))
示例#10
0
 def test_GIVEN_missing_data_WHEN_count_THEN_calculation_correct(self):
     cube = mock.make_5x3_lon_lat_2d_cube_with_missing_data()
     kernel = CountKernel()
     data = kernel.count_kernel_func(cube.data, 0)
     assert_that(numpy.array_equal(data, numpy.array([4, 4, 4])))
示例#11
0
 def test_accessing_with_invalid_flat_index_raises_error(self):
     gd = gridded_data.make_from_cube(mock.make_5x3_lon_lat_2d_cube_with_missing_data())
     hpv = gd.get_all_points()
     p = hpv[16]
示例#12
0
 def test_can_create_gridded_hyper_point_view(self):
     gd = gridded_data.make_from_cube(mock.make_5x3_lon_lat_2d_cube_with_missing_data())
     all_coords = [((c[0].points, c[1]) if c is not None else None) for c in gd.find_standard_coords()]
     hpv = GriddedHyperPointView(all_coords, gd.data)
     assert(len(hpv) == 15)
 def test_GIVEN_missing_data_WHEN_count_THEN_calculation_correct(self):
     cube = mock.make_5x3_lon_lat_2d_cube_with_missing_data()
     kernel = CountKernel()
     data = kernel.count_kernel_func(cube.data, 0)
     assert_that(numpy.array_equal(data, numpy.array([4, 4, 4])))