def check_call(self, mdtol=None): # Check that `iris.analysis.AreaWeighted` correctly calls an # `iris.analysis._area_weighted.AreaWeightedRegridder` object. if mdtol is None: area_weighted = AreaWeighted() mdtol = 1 else: area_weighted = AreaWeighted(mdtol=mdtol) self.assertEqual(area_weighted.mdtol, mdtol) with mock.patch("iris.analysis.AreaWeightedRegridder", return_value=mock.sentinel.regridder) as awr: regridder = area_weighted.regridder(mock.sentinel.src, mock.sentinel.target) awr.assert_called_once_with(mock.sentinel.src, mock.sentinel.target, mdtol=mdtol) self.assertIs(regridder, mock.sentinel.regridder)
def test_regrid_area_w_real_start(self): real_cube = self.cube.copy() real_cube.data # Regrid the cube onto the template. out = real_cube.regrid(self.template_cube, AreaWeighted()) # Save the data with self.temp_filename(suffix=".nc") as fname: iris.save(out, fname)
def test_regrid_area_w_lazy(self): # Regrid the cube onto the template. out = self.cube.regrid(self.template_cube, AreaWeighted()) # Check data is still lazy self.assertTrue(self.cube.has_lazy_data()) self.assertTrue(out.has_lazy_data()) # Save the data with self.temp_filename(suffix=".nc") as fname: iris.save(out, fname)
def check_call(self, mdtol=None): # Check that `iris.analysis.AreaWeighted` correctly calls an # `iris.analysis._area_weighted.AreaWeightedRegridder` object. if mdtol is None: area_weighted = AreaWeighted() mdtol = 1 else: area_weighted = AreaWeighted(mdtol=mdtol) self.assertEqual(area_weighted.mdtol, mdtol) with mock.patch('iris.analysis.AreaWeightedRegridder', return_value=mock.sentinel.regridder) as awr: regridder = area_weighted.regridder(mock.sentinel.src, mock.sentinel.target) awr.assert_called_once_with(mock.sentinel.src, mock.sentinel.target, mdtol=mdtol) self.assertIs(regridder, mock.sentinel.regridder)
def test_regrid_area_w_lazy_chunked(self): # Chunked data makes the regridder run repeatedly self.cube.data = self.cube.lazy_data().rechunk((1, -1, -1)) # Regrid the cube onto the template. out = self.cube.regrid(self.template_cube, AreaWeighted()) # Check data is still lazy self.assertTrue(self.cube.has_lazy_data()) self.assertTrue(out.has_lazy_data()) # Save the data with self.temp_filename(suffix=".nc") as fname: iris.save(out, fname)
def setup(self) -> None: # Prepare a cube and a template cube_file_path = tests.get_data_path( ["NetCDF", "regrid", "regrid_xyt.nc"]) self.cube = iris.load_cube(cube_file_path) # Prepare a tougher cube and chunk it chunked_cube_file_path = tests.get_data_path( ["NetCDF", "regrid", "regrid_xyt.nc"]) self.chunked_cube = iris.load_cube(chunked_cube_file_path) # Chunked data makes the regridder run repeatedly self.cube.data = self.cube.lazy_data().rechunk((1, -1, -1)) template_file_path = tests.get_data_path( ["NetCDF", "regrid", "regrid_template_global_latlon.nc"]) self.template_cube = iris.load_cube(template_file_path) # Prepare a regridding scheme self.scheme_area_w = AreaWeighted()
# A cached stock of standard horizontal target grids. _CACHE = dict() # Supported point interpolation schemes. POINT_INTERPOLATION_SCHEMES = { 'linear': Linear(extrapolation_mode='mask'), 'nearest': Nearest(extrapolation_mode='mask'), } # Supported horizontal regridding schemes. HORIZONTAL_SCHEMES = { 'linear': Linear(extrapolation_mode='mask'), 'linear_extrapolate': Linear(extrapolation_mode='extrapolate'), 'nearest': Nearest(extrapolation_mode='mask'), 'area_weighted': AreaWeighted(), 'unstructured_nearest': UnstructuredNearest(), } # Supported vertical interpolation schemes. VERTICAL_SCHEMES = ('linear', 'nearest', 'linear_horizontal_extrapolate_vertical', 'nearest_horizontal_extrapolate_vertical') def parse_cell_spec(spec): """ Parse an MxN cell specification string. Parameters ----------
def test_invalid_low_mdtol(self): msg = "mdtol must be in range 0 - 1" with self.assertRaisesRegex(ValueError, msg): AreaWeighted(mdtol=-0.2)
def test_invalid_high_mdtol(self): msg = 'mdtol must be in range 0 - 1' with self.assertRaisesRegexp(ValueError, msg): AreaWeighted(mdtol=1.2)
def setup(self): # Prepare a cube and a regridding scheme. file_path = tests.get_data_path( ["NetCDF", "global", "xyt", "SMALL_hires_wind_u_for_ipcc4.nc"]) self.cube = iris.load_cube(file_path) self.scheme_area_w = AreaWeighted()
def time_regrid_area_w(self) -> None: # Regrid the cube onto the template. out = self.cube.regrid(self.template_cube, AreaWeighted()) # Realise the data out.data