Skip to content

Commit

Permalink
Move ugrid loading support code from iris.mesh to iris.netcdf, and it…
Browse files Browse the repository at this point in the history
…s tests likewise
  • Loading branch information
pp-mo committed Jul 25, 2024
1 parent f0c8a02 commit b9fa42a
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 27 deletions.
3 changes: 2 additions & 1 deletion lib/iris/fileformats/netcdf/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ def load_cubes(file_sources, callback=None, constraints=None):
# Deferred import to avoid circular imports.
from iris.io import run_callback
from iris.mesh.cf import CFUGridReader
from iris.mesh.load import (

from .ugrid_load import (
_build_mesh_coords,
_meshes_from_cf,
)
Expand Down
22 changes: 10 additions & 12 deletions lib/iris/mesh/load.py → lib/iris/fileformats/netcdf/ugrid_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
Extensions to Iris' NetCDF loading to allow the construction of
:class:`~iris.mesh.MeshXY` from UGRID data in the file.
Eventual destination: :mod:`iris.fileformats.netcdf`.
.. seealso::
The UGRID Conventions,
Expand All @@ -21,20 +19,20 @@
from pathlib import Path
import warnings

from ..config import get_logger
from ..coords import AuxCoord
from ..fileformats._nc_load_rules.helpers import get_attr_units, get_names
from ..fileformats.netcdf import loader as nc_loader
from ..io import decode_uri, expand_filespecs
from ..util import guess_coord_axis
from ..warnings import IrisCfWarning, IrisDefaultingWarning, IrisIgnoringWarning
from .cf import (
from iris.config import get_logger
from iris.coords import AuxCoord
from iris.fileformats._nc_load_rules.helpers import get_attr_units, get_names
from iris.fileformats.netcdf import loader as nc_loader
from iris.io import decode_uri, expand_filespecs
from iris.mesh import Connectivity, MeshXY
from iris.mesh.cf import (
CFUGridAuxiliaryCoordinateVariable,
CFUGridConnectivityVariable,
CFUGridMeshVariable,
CFUGridReader,
)
from .components import Connectivity, MeshXY
from iris.util import guess_coord_axis
from iris.warnings import IrisCfWarning, IrisDefaultingWarning, IrisIgnoringWarning

# Configure the logger.
logger = get_logger(__name__, propagate=True, handler=False)
Expand Down Expand Up @@ -124,7 +122,7 @@ def load_meshes(uris, var_name=None):
# No constraints or callbacks supported - these assume they are operating
# on a Cube.

from ..fileformats import FORMAT_AGENT
from iris.fileformats import FORMAT_AGENT

if isinstance(uris, str):
uris = [uris]
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/mesh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"""

from iris.fileformats.netcdf.saver import save_mesh
from iris.fileformats.netcdf.ugrid_load import load_mesh, load_meshes

from ..config import get_logger
from .components import Connectivity, MeshCoord, MeshXY
from .load import load_mesh, load_meshes
from .utils import recombine_submeshes

__all__ = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
#
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""Integration tests for NetCDF-UGRID file loading.
todo: fold these tests into netcdf tests when iris.mesh is folded into
standard behaviour.
TODO: complete iris.mesh replacement
"""
"""Integration tests for NetCDF-UGRID file loading."""

# Import iris.tests first so that some things can be initialised before
# importing anything else.
Expand All @@ -19,8 +13,7 @@
import pytest

from iris import Constraint, load
from iris.mesh import MeshXY
from iris.mesh.load import load_mesh, load_meshes
from iris.mesh import MeshXY, load_mesh, load_meshes
from iris.tests.stock.netcdf import (
_file_from_cdl_template as create_file_from_cdl_template,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""Unit tests for the :mod:`iris.mesh.load` package."""
"""Unit tests for the :mod:`iris.fileformats.netcdf.ugrid_load` package."""
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
# importing anything else.
import iris.tests as tests # isort:skip

from iris.mesh.load import load_mesh
from iris.mesh import load_mesh


class Tests(tests.IrisTest):
# All 'real' tests have been done for load_meshes(). Here we just check
# that load_mesh() works with load_meshes() correctly, using mocking.
def setUp(self):
self.load_meshes_mock = self.patch("iris.mesh.load.load_meshes")
tgt = "iris.fileformats.netcdf.ugrid_load.load_meshes"
self.load_meshes_mock = self.patch(tgt)
# The expected return from load_meshes - a dict of files, each with
# a list of meshes.
self.load_meshes_mock.return_value = {"file": ["mesh"]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import tempfile
from uuid import uuid4

from iris.mesh.load import load_meshes, logger
from iris.fileformats.netcdf.ugrid_load import logger
from iris.mesh import load_meshes
from iris.tests.stock.netcdf import ncgen_from_cdl


Expand Down

0 comments on commit b9fa42a

Please sign in to comment.