diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 0970718b1a..2d59294cbb 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -50,7 +50,7 @@ jobs: session: "tests" env: - IRIS_TEST_DATA_VERSION: "2.22" + IRIS_TEST_DATA_VERSION: "2.25" ENV_NAME: "ci-tests" steps: diff --git a/lib/iris/experimental/geovista.py b/lib/iris/experimental/geovista.py index 206f2a8c97..3f42f09e03 100644 --- a/lib/iris/experimental/geovista.py +++ b/lib/iris/experimental/geovista.py @@ -59,12 +59,10 @@ def cube_to_polydata(cube, **kwargs): .. testsetup:: from iris import load_cube, sample_data_path - from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD cube = load_cube(sample_data_path("air_temp.pp")) cube_w_time = load_cube(sample_data_path("A1B_north_america.nc")) - with PARSE_UGRID_ON_LOAD.context(): - cube_mesh = load_cube(sample_data_path("mesh_C4_synthetic_float.nc")) + cube_mesh = load_cube(sample_data_path("mesh_C4_synthetic_float.nc")) >>> from iris.experimental.geovista import cube_to_polydata @@ -212,11 +210,9 @@ def extract_unstructured_region(cube, polydata, region, **kwargs): from iris import load_cube, sample_data_path from iris.coords import AuxCoord from iris.cube import CubeList - from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD file_path = sample_data_path("mesh_C4_synthetic_float.nc") - with PARSE_UGRID_ON_LOAD.context(): - cube_w_mesh = load_cube(file_path) + cube_w_mesh = load_cube(file_path) level_cubes = CubeList() for height_level in range(72): diff --git a/lib/iris/experimental/ugrid/__init__.py b/lib/iris/experimental/ugrid/__init__.py index 05f631d1cc..56c1a73411 100644 --- a/lib/iris/experimental/ugrid/__init__.py +++ b/lib/iris/experimental/ugrid/__init__.py @@ -5,6 +5,12 @@ """Infra-structure for unstructured mesh support. +.. deprecated:: 1.10 + + :data:`PARSE_UGRID_ON_LOAD` is due to be removed at next major release. + Please remove all uses of this, which are no longer needed : + UGRID loading is now **always** active for files containing a UGRID mesh. + Based on CF UGRID Conventions (v1.0), https://ugrid-conventions.github.io/ugrid-conventions/. .. note:: diff --git a/lib/iris/experimental/ugrid/load.py b/lib/iris/experimental/ugrid/load.py index d4e6d8afc3..e6b3436185 100644 --- a/lib/iris/experimental/ugrid/load.py +++ b/lib/iris/experimental/ugrid/load.py @@ -10,6 +10,11 @@ Eventual destination: :mod:`iris.fileformats.netcdf`. +.. seealso:: + + The UGRID Conventions, + https://ugrid-conventions.github.io/ugrid-conventions/ + """ from contextlib import contextmanager @@ -18,6 +23,7 @@ import threading import warnings +from ..._deprecation import warn_deprecated from ...config import get_logger from ...coords import AuxCoord from ...fileformats._nc_load_rules.helpers import get_attr_units, get_names @@ -60,20 +66,20 @@ def __init__(self): :const:`~iris.experimental.ugrid.load.PARSE_UGRID_ON_LOAD`. Use :meth:`context` to temporarily activate. - .. seealso:: - - The UGRID Conventions, - https://ugrid-conventions.github.io/ugrid-conventions/ + Notes + ----- + .. deprecated:: 1.10 + Do not use -- due to be removed at next major release : + UGRID loading is now **always** active for files containing a UGRID mesh. """ - self._state = False def __bool__(self): - return self._state + return True @contextmanager def context(self): - """Temporarily activate experimental UGRID-aware NetCDF loading. + """Activate UGRID-aware NetCDF loading. Use the standard Iris loading API while within the context manager. If the loaded file(s) include any UGRID content, this will be parsed and @@ -89,12 +95,35 @@ def context(self): constraint=my_constraint, callback=my_callback) + Notes + ----- + .. deprecated:: 1.10 + Do not use -- due to be removed at next major release : + UGRID loading is now **always** active for files containing a UGRID mesh. + + Examples + -------- + Replace usage, for example: + + .. code-block:: python + + with iris.experimental.ugrid.PARSE_UGRID_ON_LOAD.context(): + mesh_cubes = iris.load(path) + + with: + + .. code-block:: python + + mesh_cubes = iris.load(path) + """ - try: - self._state = True - yield - finally: - self._state = False + wmsg = ( + "iris.experimental.ugrid.load.PARSE_UGRID_ON_LOAD has been deprecated " + "and will be removed. Please remove all uses : these are no longer needed, " + "as UGRID loading is now applied to any file containing a mesh." + ) + warn_deprecated(wmsg) + yield #: Run-time switch for experimental UGRID-aware NetCDF loading. See :class:`~iris.experimental.ugrid.load.ParseUGridOnLoad`. @@ -174,15 +203,6 @@ def load_meshes(uris, var_name=None): from ...fileformats import FORMAT_AGENT - if not PARSE_UGRID_ON_LOAD: - # Explicit behaviour, consistent with netcdf.load_cubes(), rather than - # an invisible assumption. - message = ( - f"PARSE_UGRID_ON_LOAD is {bool(PARSE_UGRID_ON_LOAD)}. Must be " - f"True to enable mesh loading." - ) - raise ValueError(message) - if isinstance(uris, str): uris = [uris] diff --git a/lib/iris/experimental/ugrid/mesh.py b/lib/iris/experimental/ugrid/mesh.py index c90b67e1d6..398c240337 100644 --- a/lib/iris/experimental/ugrid/mesh.py +++ b/lib/iris/experimental/ugrid/mesh.py @@ -786,14 +786,12 @@ def from_coords(cls, *coords): from iris import load_cube, sample_data_path from iris.experimental.ugrid import ( - PARSE_UGRID_ON_LOAD, MeshXY, MeshCoord, ) file_path = sample_data_path("mesh_C4_synthetic_float.nc") - with PARSE_UGRID_ON_LOAD.context(): - cube_w_mesh = load_cube(file_path) + cube_w_mesh = load_cube(file_path) Examples -------- diff --git a/lib/iris/fileformats/netcdf/loader.py b/lib/iris/fileformats/netcdf/loader.py index 9378d7ae1f..5276657195 100644 --- a/lib/iris/fileformats/netcdf/loader.py +++ b/lib/iris/fileformats/netcdf/loader.py @@ -583,7 +583,6 @@ def load_cubes(file_sources, callback=None, constraints=None): # Deferred import to avoid circular imports. from iris.experimental.ugrid.cf import CFUGridReader from iris.experimental.ugrid.load import ( - PARSE_UGRID_ON_LOAD, _build_mesh_coords, _meshes_from_cf, ) @@ -600,15 +599,8 @@ def load_cubes(file_sources, callback=None, constraints=None): for file_source in file_sources: # Ingest the file. At present may be a filepath or an open netCDF4.Dataset. - meshes = {} - if PARSE_UGRID_ON_LOAD: - cf_reader_class = CFUGridReader - else: - cf_reader_class = iris.fileformats.cf.CFReader - - with cf_reader_class(file_source) as cf: - if PARSE_UGRID_ON_LOAD: - meshes = _meshes_from_cf(cf) + with CFUGridReader(file_source) as cf: + meshes = _meshes_from_cf(cf) # Process each CF data variable. data_variables = list(cf.cf_group.data_variables.values()) + list( @@ -626,8 +618,7 @@ def load_cubes(file_sources, callback=None, constraints=None): mesh_name = None mesh = None mesh_coords, mesh_dim = [], None - if PARSE_UGRID_ON_LOAD: - mesh_name = getattr(cf_var, "mesh", None) + mesh_name = getattr(cf_var, "mesh", None) if mesh_name is not None: try: mesh = meshes[mesh_name] diff --git a/lib/iris/tests/integration/experimental/geovista/test_cube_to_poly.py b/lib/iris/tests/integration/experimental/geovista/test_cube_to_poly.py index 582c216a44..26ea8c48ea 100644 --- a/lib/iris/tests/integration/experimental/geovista/test_cube_to_poly.py +++ b/lib/iris/tests/integration/experimental/geovista/test_cube_to_poly.py @@ -8,7 +8,6 @@ from iris import load_cube from iris.experimental.geovista import cube_to_polydata -from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD from iris.tests import get_data_path @@ -57,8 +56,7 @@ def test_integration_mesh(): ] ) - with PARSE_UGRID_ON_LOAD.context(): - cube = load_cube(file_path, "conv_rain") + cube = load_cube(file_path, "conv_rain") polydata = cube_to_polydata(cube[0, :]) # This is a known good output, we have plotted the result and checked it. diff --git a/lib/iris/tests/integration/experimental/geovista/test_extract_unstructured_region.py b/lib/iris/tests/integration/experimental/geovista/test_extract_unstructured_region.py index 47024dc1cd..7343809cdc 100644 --- a/lib/iris/tests/integration/experimental/geovista/test_extract_unstructured_region.py +++ b/lib/iris/tests/integration/experimental/geovista/test_extract_unstructured_region.py @@ -8,7 +8,6 @@ from iris import load_cube from iris.experimental.geovista import cube_to_polydata, extract_unstructured_region -from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD from iris.tests import get_data_path @@ -21,8 +20,7 @@ def test_face_region_extraction(): ] ) - with PARSE_UGRID_ON_LOAD.context(): - global_cube = load_cube(file_path, "conv_rain") + global_cube = load_cube(file_path, "conv_rain") polydata = cube_to_polydata(global_cube[0, :]) region = BBox(lons=[0, 70, 70, 0], lats=[-25, -25, 45, 45]) diff --git a/lib/iris/tests/integration/experimental/test_regrid_ProjectedUnstructured.py b/lib/iris/tests/integration/experimental/test_regrid_ProjectedUnstructured.py index 2a70ac2d32..dd62a7f376 100644 --- a/lib/iris/tests/integration/experimental/test_regrid_ProjectedUnstructured.py +++ b/lib/iris/tests/integration/experimental/test_regrid_ProjectedUnstructured.py @@ -28,7 +28,7 @@ class TestProjectedUnstructured(tests.IrisTest): def setUp(self): path = tests.get_data_path( - ("NetCDF", "unstructured_grid", "theta_nodal_xios.nc") + ("NetCDF", "unstructured_grid", "theta_nodal_not_ugrid.nc") ) self.src = iris.load_cube(path, "Potential Temperature") diff --git a/lib/iris/tests/integration/experimental/test_ugrid_load.py b/lib/iris/tests/integration/experimental/test_ugrid_load.py index 613e5f4e37..4325532fc6 100644 --- a/lib/iris/tests/integration/experimental/test_ugrid_load.py +++ b/lib/iris/tests/integration/experimental/test_ugrid_load.py @@ -18,7 +18,7 @@ import pytest from iris import Constraint, load -from iris.experimental.ugrid.load import PARSE_UGRID_ON_LOAD, load_mesh, load_meshes +from iris.experimental.ugrid.load import load_mesh, load_meshes from iris.experimental.ugrid.mesh import MeshXY from iris.tests.stock.netcdf import ( _file_from_cdl_template as create_file_from_cdl_template, @@ -47,8 +47,7 @@ def ugrid_load(uris, constraints=None, callback=None): constraints = [constraints] constraints.append(filter_orphan_connectivities) - with PARSE_UGRID_ON_LOAD.context(): - return load(uris, constraints, callback) + return load(uris, constraints, callback) @tests.skip_data @@ -110,12 +109,11 @@ def test_3D_veg_pseudo_levels(self): ) def test_no_mesh(self): - with PARSE_UGRID_ON_LOAD.context(): - cube_list = load( - tests.get_data_path( - ["NetCDF", "unstructured_grid", "theta_nodal_not_ugrid.nc"] - ) + cube_list = load( + tests.get_data_path( + ["NetCDF", "unstructured_grid", "theta_nodal_not_ugrid.nc"] ) + ) self.assertTrue(all([cube.mesh is None for cube in cube_list])) @@ -207,10 +205,9 @@ def test_mesh_no_cf_role(self): @tests.skip_data class Test_load_mesh(tests.IrisTest): def common_test(self, file_name, mesh_var_name): - with PARSE_UGRID_ON_LOAD.context(): - mesh = load_mesh( - tests.get_data_path(["NetCDF", "unstructured_grid", file_name]) - ) + mesh = load_mesh( + tests.get_data_path(["NetCDF", "unstructured_grid", file_name]) + ) # NOTE: cannot use CML tests as this isn't supported for non-Cubes. self.assertIsInstance(mesh, MeshXY) self.assertEqual(mesh.var_name, mesh_var_name) @@ -225,12 +222,11 @@ def test_mesh_file(self): self.common_test("mesh_C12.nc", "dynamics") def test_no_mesh(self): - with PARSE_UGRID_ON_LOAD.context(): - meshes = load_meshes( - tests.get_data_path( - ["NetCDF", "unstructured_grid", "theta_nodal_not_ugrid.nc"] - ) + meshes = load_meshes( + tests.get_data_path( + ["NetCDF", "unstructured_grid", "theta_nodal_not_ugrid.nc"] ) + ) self.assertDictEqual({}, meshes) diff --git a/lib/iris/tests/integration/experimental/test_ugrid_save.py b/lib/iris/tests/integration/experimental/test_ugrid_save.py index 85f6024b93..df3c9cc553 100644 --- a/lib/iris/tests/integration/experimental/test_ugrid_save.py +++ b/lib/iris/tests/integration/experimental/test_ugrid_save.py @@ -14,7 +14,6 @@ import tempfile import iris -from iris.experimental.ugrid.load import PARSE_UGRID_ON_LOAD import iris.fileformats.netcdf from iris.tests.stock.netcdf import _add_standard_data, ncgen_from_cdl @@ -48,8 +47,7 @@ def test_example_result_cdls(self): # Fill in blank data-variables. _add_standard_data(target_ncfile_path) # Load as Iris data - with PARSE_UGRID_ON_LOAD.context(): - cubes = iris.load(target_ncfile_path) + cubes = iris.load(target_ncfile_path) # Re-save, to check the save behaviour. resave_ncfile_path = str(self.temp_dir / f"{ex_name}_resaved.nc") iris.save(cubes, resave_ncfile_path) @@ -69,8 +67,7 @@ def test_example_roundtrips(self): # Fill in blank data-variables. _add_standard_data(target_ncfile_path) # Load the original as Iris data - with PARSE_UGRID_ON_LOAD.context(): - orig_cubes = iris.load(target_ncfile_path) + orig_cubes = iris.load(target_ncfile_path) if "ex4" in ex_name: # Discard the extra formula terms component cubes @@ -80,8 +77,7 @@ def test_example_roundtrips(self): # Save-and-load-back to compare the Iris saved result. resave_ncfile_path = str(self.temp_dir / f"{ex_name}_resaved.nc") iris.save(orig_cubes, resave_ncfile_path) - with PARSE_UGRID_ON_LOAD.context(): - savedloaded_cubes = iris.load(resave_ncfile_path) + savedloaded_cubes = iris.load(resave_ncfile_path) # This should match the original exactly # ..EXCEPT for our inability to compare meshes. diff --git a/lib/iris/tests/integration/test_regridding.py b/lib/iris/tests/integration/test_regridding.py index c8197a9d94..7d65577545 100644 --- a/lib/iris/tests/integration/test_regridding.py +++ b/lib/iris/tests/integration/test_regridding.py @@ -98,7 +98,7 @@ def test_nearest(self): class TestUnstructured(tests.IrisTest): def setUp(self): path = tests.get_data_path( - ("NetCDF", "unstructured_grid", "theta_nodal_xios.nc") + ("NetCDF", "unstructured_grid", "theta_nodal_not_ugrid.nc") ) self.src = iris.load_cube(path, "Potential Temperature") self.grid = simple_3d()[0, :, :] diff --git a/lib/iris/tests/unit/experimental/ugrid/load/test_ParseUgridOnLoad.py b/lib/iris/tests/unit/experimental/ugrid/load/test_ParseUgridOnLoad.py index 8f85699037..0c78fa5880 100644 --- a/lib/iris/tests/unit/experimental/ugrid/load/test_ParseUgridOnLoad.py +++ b/lib/iris/tests/unit/experimental/ugrid/load/test_ParseUgridOnLoad.py @@ -4,42 +4,27 @@ # See LICENSE in the root of the repository for full licensing details. """Unit tests for the :class:`iris.experimental.ugrid.load.ParseUgridOnLoad` class. -todo: remove this module when experimental.ugrid is folded into standard behaviour. +TODO: remove this module when ParseUGridOnLoad itself is removed. """ -# Import iris.tests first so that some things can be initialised before -# importing anything else. -import iris.tests as tests # isort:skip +import pytest +from iris._deprecation import IrisDeprecation from iris.experimental.ugrid.load import PARSE_UGRID_ON_LOAD, ParseUGridOnLoad -class TestClass(tests.IrisTest): - @classmethod - def setUpClass(cls): - cls.cls = ParseUGridOnLoad() +def test_creation(): + # I.E. "does not fail". + _ = ParseUGridOnLoad() - def test_default(self): - self.assertFalse(self.cls) - def test_context(self): - self.assertFalse(self.cls) - with self.cls.context(): - self.assertTrue(self.cls) - self.assertFalse(self.cls) +def test_context(): + ugridswitch = ParseUGridOnLoad() + with pytest.warns(IrisDeprecation, match="PARSE_UGRID_ON_LOAD has been deprecated"): + with ugridswitch.context(): + pass -class TestConstant(tests.IrisTest): - @classmethod - def setUpClass(cls): - cls.constant = PARSE_UGRID_ON_LOAD - - def test_default(self): - self.assertFalse(self.constant) - - def test_context(self): - self.assertFalse(self.constant) - with self.constant.context(): - self.assertTrue(self.constant) - self.assertFalse(self.constant) +def test_constant(): + assert isinstance(PARSE_UGRID_ON_LOAD, ParseUGridOnLoad) diff --git a/lib/iris/tests/unit/experimental/ugrid/load/test_load_mesh.py b/lib/iris/tests/unit/experimental/ugrid/load/test_load_mesh.py index 54ca5b8fcf..6d1bbe995c 100644 --- a/lib/iris/tests/unit/experimental/ugrid/load/test_load_mesh.py +++ b/lib/iris/tests/unit/experimental/ugrid/load/test_load_mesh.py @@ -8,7 +8,7 @@ # importing anything else. import iris.tests as tests # isort:skip -from iris.experimental.ugrid.load import PARSE_UGRID_ON_LOAD, load_mesh +from iris.experimental.ugrid.load import load_mesh class Tests(tests.IrisTest): @@ -22,14 +22,12 @@ def setUp(self): def test_calls_load_meshes(self): args = [("file_1", "file_2"), "my_var_name"] - with PARSE_UGRID_ON_LOAD.context(): - _ = load_mesh(args) + _ = load_mesh(args) assert self.load_meshes_mock.call_count == 1 assert self.load_meshes_mock.call_args == ((args, None),) def test_returns_mesh(self): - with PARSE_UGRID_ON_LOAD.context(): - mesh = load_mesh([]) + mesh = load_mesh([]) self.assertEqual(mesh, "mesh") def test_single_mesh(self): @@ -37,8 +35,7 @@ def test_single_mesh(self): def common(ret_val): self.load_meshes_mock.return_value = ret_val with self.assertRaisesRegex(ValueError, "Expecting 1 mesh.*"): - with PARSE_UGRID_ON_LOAD.context(): - _ = load_mesh([]) + _ = load_mesh([]) # Too many. common({"file": ["mesh1", "mesh2"]}) diff --git a/lib/iris/tests/unit/experimental/ugrid/load/test_load_meshes.py b/lib/iris/tests/unit/experimental/ugrid/load/test_load_meshes.py index 0ae09696bb..da7cf9b649 100644 --- a/lib/iris/tests/unit/experimental/ugrid/load/test_load_meshes.py +++ b/lib/iris/tests/unit/experimental/ugrid/load/test_load_meshes.py @@ -13,7 +13,7 @@ import tempfile from uuid import uuid4 -from iris.experimental.ugrid.load import PARSE_UGRID_ON_LOAD, load_meshes, logger +from iris.experimental.ugrid.load import load_meshes, logger from iris.tests.stock.netcdf import ncgen_from_cdl @@ -98,8 +98,7 @@ def add_second_mesh(self): def test_with_data(self): nc_path = cdl_to_nc(self.ref_cdl) - with PARSE_UGRID_ON_LOAD.context(): - meshes = load_meshes(nc_path) + meshes = load_meshes(nc_path) files = list(meshes.keys()) self.assertEqual(1, len(files)) @@ -114,8 +113,7 @@ def test_no_data(self): ref_cdl = "\n".join(cdl_lines) nc_path = cdl_to_nc(ref_cdl) - with PARSE_UGRID_ON_LOAD.context(): - meshes = load_meshes(nc_path) + meshes = load_meshes(nc_path) files = list(meshes.keys()) self.assertEqual(1, len(files)) @@ -135,23 +133,20 @@ def test_no_mesh(self): ref_cdl = "\n".join(cdl_lines) nc_path = cdl_to_nc(ref_cdl) - with PARSE_UGRID_ON_LOAD.context(): - meshes = load_meshes(nc_path) + meshes = load_meshes(nc_path) self.assertDictEqual({}, meshes) def test_multi_files(self): files_count = 3 nc_paths = [cdl_to_nc(self.ref_cdl) for _ in range(files_count)] - with PARSE_UGRID_ON_LOAD.context(): - meshes = load_meshes(nc_paths) + meshes = load_meshes(nc_paths) self.assertEqual(files_count, len(meshes)) def test_multi_meshes(self): ref_cdl, second_name = self.add_second_mesh() nc_path = cdl_to_nc(ref_cdl) - with PARSE_UGRID_ON_LOAD.context(): - meshes = load_meshes(nc_path) + meshes = load_meshes(nc_path) files = list(meshes.keys()) self.assertEqual(1, len(files)) @@ -165,8 +160,7 @@ def test_var_name(self): second_cdl, second_name = self.add_second_mesh() cdls = [self.ref_cdl, second_cdl] nc_paths = [cdl_to_nc(cdl) for cdl in cdls] - with PARSE_UGRID_ON_LOAD.context(): - meshes = load_meshes(nc_paths, second_name) + meshes = load_meshes(nc_paths, second_name) files = list(meshes.keys()) self.assertEqual(1, len(files)) @@ -174,26 +168,15 @@ def test_var_name(self): self.assertEqual(1, len(file_meshes)) self.assertEqual(second_name, file_meshes[0].var_name) - def test_no_parsing(self): - nc_path = cdl_to_nc(self.ref_cdl) - with self.assertRaisesRegex( - ValueError, ".*Must be True to enable mesh loading." - ): - _ = load_meshes(nc_path) - def test_invalid_scheme(self): with self.assertRaisesRegex(ValueError, "Iris cannot handle the URI scheme:.*"): - with PARSE_UGRID_ON_LOAD.context(): - _ = load_meshes("foo://bar") + _ = load_meshes("foo://bar") @tests.skip_data def test_non_nc(self): log_regex = r"Ignoring non-NetCDF file:.*" with self.assertLogs(logger, level="INFO", msg_regex=log_regex): - with PARSE_UGRID_ON_LOAD.context(): - meshes = load_meshes( - tests.get_data_path(["PP", "simple_pp", "global.pp"]) - ) + meshes = load_meshes(tests.get_data_path(["PP", "simple_pp", "global.pp"])) self.assertDictEqual({}, meshes) @@ -205,8 +188,7 @@ def setUp(self): def test_http(self): url = "https://foo" - with PARSE_UGRID_ON_LOAD.context(): - _ = load_meshes(url) + _ = load_meshes(url) self.format_agent_mock.assert_called_with(url, None) def test_mixed_sources(self): @@ -215,8 +197,7 @@ def test_mixed_sources(self): file.touch() glob = f"{TMP_DIR}/*.nc" - with PARSE_UGRID_ON_LOAD.context(): - _ = load_meshes([url, glob]) + _ = load_meshes([url, glob]) file_uris = [call[0][0] for call in self.format_agent_mock.call_args_list] for source in (url, Path(file).name): self.assertIn(source, file_uris) diff --git a/lib/iris/tests/unit/experimental/ugrid/load/test_meshload_checks.py b/lib/iris/tests/unit/experimental/ugrid/load/test_meshload_checks.py index 493ad047a4..ed98c8c3d4 100644 --- a/lib/iris/tests/unit/experimental/ugrid/load/test_meshload_checks.py +++ b/lib/iris/tests/unit/experimental/ugrid/load/test_meshload_checks.py @@ -7,7 +7,6 @@ import pytest import iris -from iris.experimental.ugrid.load import PARSE_UGRID_ON_LOAD from .test_load_meshes import ( _TEST_CDL_HEAD, @@ -55,8 +54,7 @@ def test_extrameshvar__ok(self, tmp_path_factory): # Check that the default cdl construction loads OK self.tmpdir = tmp_path_factory.mktemp("meshload") testnc = self._create_testnc() - with PARSE_UGRID_ON_LOAD.context(): - iris.load(testnc) + iris.load(testnc) def test_extrameshvar__fail(self, failnc): # Check that the expected errors are raised in various cases. @@ -78,6 +76,5 @@ def test_extrameshvar__fail(self, failnc): else: raise ValueError(f"unexpected param: {param}") - with PARSE_UGRID_ON_LOAD.context(): - with pytest.raises(ValueError, match=match_msg): - iris.load(failnc) + with pytest.raises(ValueError, match=match_msg): + iris.load(failnc) diff --git a/lib/iris/tests/unit/fileformats/netcdf/loader/test_load_cubes.py b/lib/iris/tests/unit/fileformats/netcdf/loader/test_load_cubes.py index dfb1379d5a..571a749bf0 100644 --- a/lib/iris/tests/unit/fileformats/netcdf/loader/test_load_cubes.py +++ b/lib/iris/tests/unit/fileformats/netcdf/loader/test_load_cubes.py @@ -21,7 +21,6 @@ import numpy as np from iris.coords import AncillaryVariable, CellMeasure -from iris.experimental.ugrid.load import PARSE_UGRID_ON_LOAD from iris.experimental.ugrid.mesh import MeshCoord from iris.fileformats.netcdf import logger from iris.fileformats.netcdf.loader import load_cubes @@ -262,13 +261,7 @@ def setUpClass(cls): } """ cls.nc_path = cdl_to_nc(cls.ref_cdl) - with PARSE_UGRID_ON_LOAD.context(): - cls.mesh_cubes = list(load_cubes(cls.nc_path)) - - def test_mesh_handled(self): - cubes_no_ugrid = list(load_cubes(self.nc_path)) - self.assertEqual(4, len(cubes_no_ugrid)) - self.assertEqual(2, len(self.mesh_cubes)) + cls.mesh_cubes = list(load_cubes(cls.nc_path)) def test_standard_dims(self): for cube in self.mesh_cubes: @@ -303,7 +296,6 @@ def test_missing_mesh(self): # No error when mesh handling not activated. _ = list(load_cubes(nc_path)) - with PARSE_UGRID_ON_LOAD.context(): - log_regex = r"File does not contain mesh.*" - with self.assertLogs(logger, level="DEBUG", msg_regex=log_regex): - _ = list(load_cubes(nc_path)) + log_regex = r"File does not contain mesh.*" + with self.assertLogs(logger, level="DEBUG", msg_regex=log_regex): + _ = list(load_cubes(nc_path)) diff --git a/lib/iris/tests/unit/fileformats/netcdf/saver/test_save.py b/lib/iris/tests/unit/fileformats/netcdf/saver/test_save.py index ae85dc1aab..860da84e6b 100644 --- a/lib/iris/tests/unit/fileformats/netcdf/saver/test_save.py +++ b/lib/iris/tests/unit/fileformats/netcdf/saver/test_save.py @@ -19,7 +19,6 @@ import iris from iris.coords import AuxCoord, DimCoord from iris.cube import Cube, CubeList -from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD from iris.fileformats.netcdf import CF_CONVENTIONS_VERSION, Saver, _thread_safe_nc, save from iris.tests.stock import lat_lon_cube from iris.tests.stock.mesh import sample_mesh_cube @@ -246,8 +245,7 @@ def _check_save_and_reload(self, cubes): save(cubes, filepath) # Load them back for roundtrip testing. - with PARSE_UGRID_ON_LOAD.context(): - new_cubes = iris.load(str(filepath)) + new_cubes = iris.load(str(filepath)) # There should definitely still be the same number of cubes. self.assertEqual(len(new_cubes), len(cubes)) diff --git a/lib/iris/tests/unit/tests/stock/test_netcdf.py b/lib/iris/tests/unit/tests/stock/test_netcdf.py index e88d3f6abb..c218385425 100644 --- a/lib/iris/tests/unit/tests/stock/test_netcdf.py +++ b/lib/iris/tests/unit/tests/stock/test_netcdf.py @@ -8,7 +8,6 @@ import tempfile from iris import load_cube -from iris.experimental.ugrid.load import PARSE_UGRID_ON_LOAD from iris.experimental.ugrid.mesh import MeshCoord, MeshXY # Import iris.tests first so that some things can be initialised before @@ -38,8 +37,7 @@ def create_synthetic_file(self, **create_kwargs): def create_synthetic_test_cube(self, **create_kwargs): file_path = self.create_synthetic_file(**create_kwargs) - with PARSE_UGRID_ON_LOAD.context(): - cube = load_cube(file_path) + cube = load_cube(file_path) return cube def check_cube(self, cube, shape, location, level):