def test_components_fx_dict(self, tmp_path): """Test compatibility of input fx dictionary.""" sftlf_file = str(tmp_path / 'sftlf_mask.nc') iris.save(self.fx_mask, sftlf_file) new_cube_land = iris.cube.Cube(self.new_cube_data, dim_coords_and_dims=self.coords_spec) result_land = mask_landsea( new_cube_land, { 'sftlf': sftlf_file, 'sftof': [], }, 'land', ) assert isinstance(result_land, iris.cube.Cube) sftgif_file = str(tmp_path / 'sftgif_mask.nc') iris.save(self.fx_mask, sftgif_file) new_cube_ice = iris.cube.Cube(self.new_cube_data, dim_coords_and_dims=self.coords_spec) result_ice = mask_landseaice( new_cube_ice, { 'sftgif': sftgif_file, 'sftof': [], }, 'ice', ) assert isinstance(result_ice, iris.cube.Cube)
def test_mask_landseaice(self, tmp_path): """Test mask_landseaice func.""" self.fx_mask.var_name = 'sftgif' self.fx_mask.standard_name = 'land_ice_area_fraction' sftgif_file = str(tmp_path / 'sftgif_mask.nc') iris.save(self.fx_mask, sftgif_file) fx_vars = { 'sftgif': { 'short_name': 'sftgif', 'project': 'CMIP6', 'dataset': 'EC-Earth3', 'mip': 'fx', 'frequency': 'fx', 'filename': sftgif_file } } new_cube_ice = iris.cube.Cube(self.new_cube_data, dim_coords_and_dims=self.coords_spec) new_cube_ice = add_fx_variables(new_cube_ice, fx_vars, CheckLevels.IGNORE) result_ice = mask_landseaice(new_cube_ice, 'ice') expected = np.ma.empty((3, 3)) expected.data[:] = 200. expected.mask = np.ones((3, 3), bool) expected.mask[1, 2] = False np.ma.set_fill_value(result_ice.data, 1e+20) np.ma.set_fill_value(expected, 1e+20) assert_array_equal(result_ice.data, expected)
def test_mask_landseaice(self): """Test mask_landseaice func.""" iris.save(self.fx_mask, 'sftgif_test.nc') new_cube_ice = iris.cube.Cube( self.new_cube_data, dim_coords_and_dims=self.coords_spec) result_ice = mask_landseaice(new_cube_ice, ['sftgif_test.nc'], 'ice') expected = np.ma.empty((3, 3)) expected.data[:] = 200. expected.mask = np.ones((3, 3), bool) np.ma.set_fill_value(result_ice.data, 1e+20) np.ma.set_fill_value(expected, 1e+20) assert_array_equal(result_ice.data.mask, expected.mask) os.remove('sftgif_test.nc')
def test_components_fx_var(self, tmp_path): """Test compatibility of ancillary variables.""" self.fx_mask.var_name = 'sftlf' self.fx_mask.standard_name = 'land_area_fraction' sftlf_file = str(tmp_path / 'sftlf_mask.nc') iris.save(self.fx_mask, sftlf_file) fx_vars = { 'sftlf': { 'short_name': 'sftlf', 'project': 'CMIP6', 'dataset': 'EC-Earth3', 'mip': 'fx', 'frequency': 'fx', 'filename': sftlf_file } } new_cube_land = iris.cube.Cube(self.new_cube_data, dim_coords_and_dims=self.coords_spec) new_cube_land = add_fx_variables(new_cube_land, fx_vars, CheckLevels.IGNORE) result_land = mask_landsea( new_cube_land, 'land', ) assert isinstance(result_land, iris.cube.Cube) self.fx_mask.var_name = 'sftgif' self.fx_mask.standard_name = 'land_ice_area_fraction' sftgif_file = str(tmp_path / 'sftgif_mask.nc') iris.save(self.fx_mask, sftgif_file) fx_vars = { 'sftgif': { 'short_name': 'sftgif', 'project': 'CMIP6', 'dataset': 'EC-Earth3', 'mip': 'fx', 'frequency': 'fx', 'filename': sftlf_file } } new_cube_ice = iris.cube.Cube(self.new_cube_data, dim_coords_and_dims=self.coords_spec) new_cube_ice = add_fx_variables(new_cube_ice, fx_vars, CheckLevels.IGNORE) result_ice = mask_landseaice( new_cube_ice, 'ice', ) assert isinstance(result_ice, iris.cube.Cube)
def test_mask_landseaice(self, tmp_path): """Test mask_landseaice func.""" sftgif_file = str(tmp_path / 'sftgif_mask.nc') iris.save(self.fx_mask, sftgif_file) new_cube_ice = iris.cube.Cube(self.new_cube_data, dim_coords_and_dims=self.coords_spec) result_ice = mask_landseaice(new_cube_ice, {'sftgif': sftgif_file}, 'ice') expected = np.ma.empty((3, 3)) expected.data[:] = 200. expected.mask = np.ones((3, 3), bool) expected.mask[1, 2] = False np.ma.set_fill_value(result_ice.data, 1e+20) np.ma.set_fill_value(expected, 1e+20) assert_array_equal(result_ice.data, expected)