def test_extract_region_irregular(irregular_extract_region_cube, case): """Test `extract_region` with data on an irregular grid.""" start_lon, end_lon, start_lat, end_lat = case['region'] if 'raises' not in case: cube = extract_region( irregular_extract_region_cube, start_longitude=start_lon, end_longitude=end_lon, start_latitude=start_lat, end_latitude=end_lat, ) data = np.arange(9, dtype=np.float32).reshape((3, 3)) np.testing.assert_array_equal(cube.data.mask, case['mask']) np.testing.assert_array_equal(cube.data.data, data) else: with pytest.raises(ValueError) as exc: extract_region( irregular_extract_region_cube, start_longitude=start_lon, end_longitude=end_lon, start_latitude=start_lat, end_latitude=end_lat, ) assert exc.value == case['raises']
def test_extract_region_mean(self): """ Test for extracting a region and performing the area mean of a 2D field. """ cube = guess_bounds(self.grid, ['longitude', 'latitude']) grid_areas = iris.analysis.cartography.area_weights(cube) measure = iris.coords.CellMeasure( grid_areas, standard_name='cell_area', units='m2', measure='area') self.grid.add_cell_measure(measure, range(0, measure.ndim)) region = extract_region(self.grid, 1.5, 2.5, 1.5, 2.5) # expected outcome expected = np.ones((2, 2)) self.assert_array_equal(region.data, expected) result = area_statistics(region, 'mean') expected_mean = np.array([1.]) self.assert_array_equal(result.data, expected_mean)
def test_extract_region_neg_lon(self): """Test for extracting a region with a negative longitude field.""" result = extract_region(self.negative_grid, -0.5, 0.5, -0.5, 0.5) expected = np.ones((2, 2)) self.assert_array_equal(result.data, expected)
def test_extract_region(self): """Test for extracting a region from a 2D field.""" result = extract_region(self.grid, 1.5, 2.5, 1.5, 2.5) # expected outcome expected = np.ones((2, 2)) self.assert_array_equal(result.data, expected)