Skip to content

Commit

Permalink
Remove PARSE_UGRID_ON_LOAD and ParseUGridOnLoad, leave in iris.experi…
Browse files Browse the repository at this point in the history
…mental.ugrid only.
  • Loading branch information
pp-mo committed Jul 23, 2024
1 parent 3dd1bc4 commit 1cfcbc9
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 82 deletions.
80 changes: 79 additions & 1 deletion lib/iris/experimental/ugrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 1 addition & 2 deletions lib/iris/ugrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,7 +30,6 @@
"Connectivity",
"MeshCoord",
"MeshXY",
"PARSE_UGRID_ON_LOAD",
"load_mesh",
"load_meshes",
"recombine_submeshes",
Expand Down
78 changes: 0 additions & 78 deletions lib/iris/ugrid/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 1cfcbc9

Please sign in to comment.