From 1cfcbc99534acfb3ee41ca5cc8c94506876afe12 Mon Sep 17 00:00:00 2001 From: Patrick Peglar Date: Tue, 23 Jul 2024 12:14:27 +0100 Subject: [PATCH] Remove PARSE_UGRID_ON_LOAD and ParseUGridOnLoad, leave in iris.experimental.ugrid only. --- lib/iris/experimental/ugrid.py | 80 ++++++++++++++++++- .../ugrid}/test_ParseUgridOnLoad.py | 2 +- lib/iris/ugrid/__init__.py | 3 +- lib/iris/ugrid/load.py | 78 ------------------ 4 files changed, 81 insertions(+), 82 deletions(-) rename lib/iris/tests/unit/{ugrid/load => experimental/ugrid}/test_ParseUgridOnLoad.py (90%) diff --git a/lib/iris/experimental/ugrid.py b/lib/iris/experimental/ugrid.py index d8ab9e045bc..f1ad51c2492 100644 --- a/lib/iris/experimental/ugrid.py +++ b/lib/iris/experimental/ugrid.py @@ -26,8 +26,11 @@ """ +from contextlib import contextmanager +import threading + from .._deprecation import warn_deprecated -from ..ugrid.load import PARSE_UGRID_ON_LOAD, load_mesh, load_meshes +from ..ugrid.load import load_mesh, load_meshes from ..ugrid.mesh import Connectivity as _Connectivity from ..ugrid.mesh import Mesh as _Mesh from ..ugrid.mesh import MeshCoord as _MeshCoord @@ -57,6 +60,81 @@ class Connectivity(_Connectivity): pass +class ParseUGridOnLoad(threading.local): + def __init__(self): + """Thead-safe state to enable UGRID-aware NetCDF loading. + + A flag for dictating whether to use the experimental UGRID-aware + version of Iris NetCDF loading. Object is thread-safe. + + Use via the run-time switch + :const:`~iris.ugrid.load.PARSE_UGRID_ON_LOAD`. + Use :meth:`context` to temporarily activate. + + 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. + + """ + + def __bool__(self): + return True + + @contextmanager + def context(self): + """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 + attached to the resultant cube(s) accordingly. + + Use via the run-time switch + :const:`~iris.ugrid.load.PARSE_UGRID_ON_LOAD`. + + For example:: + + with PARSE_UGRID_ON_LOAD.context(): + my_cube_list = iris.load([my_file_path, my_file_path2], + 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) + + """ + 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.ugrid.load.ParseUGridOnLoad`. +PARSE_UGRID_ON_LOAD = ParseUGridOnLoad() + + __all__ = [ "Connectivity", "Mesh", diff --git a/lib/iris/tests/unit/ugrid/load/test_ParseUgridOnLoad.py b/lib/iris/tests/unit/experimental/ugrid/test_ParseUgridOnLoad.py similarity index 90% rename from lib/iris/tests/unit/ugrid/load/test_ParseUgridOnLoad.py rename to lib/iris/tests/unit/experimental/ugrid/test_ParseUgridOnLoad.py index e47dfe8d500..c27cf383d13 100644 --- a/lib/iris/tests/unit/ugrid/load/test_ParseUgridOnLoad.py +++ b/lib/iris/tests/unit/experimental/ugrid/test_ParseUgridOnLoad.py @@ -11,7 +11,7 @@ import pytest from iris._deprecation import IrisDeprecation -from iris.ugrid.load import PARSE_UGRID_ON_LOAD, ParseUGridOnLoad +from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD, ParseUGridOnLoad def test_creation(): diff --git a/lib/iris/ugrid/__init__.py b/lib/iris/ugrid/__init__.py index 1337724a6fc..0e5d053ab71 100644 --- a/lib/iris/ugrid/__init__.py +++ b/lib/iris/ugrid/__init__.py @@ -21,7 +21,7 @@ """ from ..config import get_logger -from .load import PARSE_UGRID_ON_LOAD, load_mesh, load_meshes +from .load import load_mesh, load_meshes from .mesh import Connectivity, MeshCoord, MeshXY from .save import save_mesh from .utils import recombine_submeshes @@ -30,7 +30,6 @@ "Connectivity", "MeshCoord", "MeshXY", - "PARSE_UGRID_ON_LOAD", "load_mesh", "load_meshes", "recombine_submeshes", diff --git a/lib/iris/ugrid/load.py b/lib/iris/ugrid/load.py index a3f278ef239..dba7600ba57 100644 --- a/lib/iris/ugrid/load.py +++ b/lib/iris/ugrid/load.py @@ -17,13 +17,10 @@ """ -from contextlib import contextmanager from itertools import groupby from pathlib import Path -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 @@ -55,81 +52,6 @@ class _WarnComboCfDefaultingIgnoring(_WarnComboCfDefaulting, IrisIgnoringWarning pass -class ParseUGridOnLoad(threading.local): - def __init__(self): - """Thead-safe state to enable UGRID-aware NetCDF loading. - - A flag for dictating whether to use the experimental UGRID-aware - version of Iris NetCDF loading. Object is thread-safe. - - Use via the run-time switch - :const:`~iris.ugrid.load.PARSE_UGRID_ON_LOAD`. - Use :meth:`context` to temporarily activate. - - 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. - - """ - - def __bool__(self): - return True - - @contextmanager - def context(self): - """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 - attached to the resultant cube(s) accordingly. - - Use via the run-time switch - :const:`~iris.ugrid.load.PARSE_UGRID_ON_LOAD`. - - For example:: - - with PARSE_UGRID_ON_LOAD.context(): - my_cube_list = iris.load([my_file_path, my_file_path2], - 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) - - """ - 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.ugrid.load.ParseUGridOnLoad`. -PARSE_UGRID_ON_LOAD = ParseUGridOnLoad() - - def _meshes_from_cf(cf_reader): """Mesh from cf, common behaviour for extracting meshes from a CFReader.