Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/iris/experimental/ugrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
from ...config import get_logger
from ...coords import AuxCoord, _DimensionalMetadata
from ...exceptions import ConnectivityNotFoundError, CoordinateNotFoundError
from ...fileformats import cf, netcdf
from ...fileformats import cf
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

Expand Down Expand Up @@ -3359,7 +3360,7 @@ def load_meshes(uris, var_name=None):
from iris.fileformats import FORMAT_AGENT

if not PARSE_UGRID_ON_LOAD:
# Explicit behaviour, consistent with netcdf.load_cubes(), rather than
# Explicit behaviour, consistent with netcdf.loader.load_cubes(), rather than
# an invisible assumption.
message = (
f"PARSE_UGRID_ON_LOAD is {bool(PARSE_UGRID_ON_LOAD)}. Must be "
Expand Down Expand Up @@ -3395,7 +3396,7 @@ def load_meshes(uris, var_name=None):
else:
handling_format_spec = FORMAT_AGENT.get_spec(source, None)

if handling_format_spec.handler == netcdf.load_cubes:
if handling_format_spec.handler == nc_loader.load_cubes:
valid_sources.append(source)
else:
message = f"Ignoring non-NetCDF file: {source}"
Expand Down Expand Up @@ -3718,7 +3719,7 @@ class CFUGridReader(cf.CFReader):

############
# Object construction.
# Helper functions, supporting netcdf.load_cubes ONLY, expected to
# Helper functions, supporting netcdf.loader.load_cubes ONLY, expected to
# altered/moved when pyke is removed.


Expand All @@ -3733,7 +3734,7 @@ def _build_aux_coord(coord_var, file_path):
assert isinstance(coord_var, CFUGridAuxiliaryCoordinateVariable)
attributes = {}
attr_units = get_attr_units(coord_var, attributes)
points_data = netcdf._get_cf_var_data(coord_var, file_path)
points_data = nc_loader._get_cf_var_data(coord_var, file_path)

# Bounds will not be loaded:
# Bounds may be present, but the UGRID conventions state this would
Expand Down Expand Up @@ -3785,7 +3786,7 @@ def _build_connectivity(connectivity_var, file_path, location_dims):
assert isinstance(connectivity_var, CFUGridConnectivityVariable)
attributes = {}
attr_units = get_attr_units(connectivity_var, attributes)
indices_data = netcdf._get_cf_var_data(connectivity_var, file_path)
indices_data = nc_loader._get_cf_var_data(connectivity_var, file_path)

cf_role = connectivity_var.cf_role
start_index = connectivity_var.start_index
Expand Down Expand Up @@ -3952,7 +3953,7 @@ def _build_mesh(cf, mesh_var, file_path):
)
mesh_elements = filter(None, mesh_elements)
for iris_object in mesh_elements:
netcdf._add_unused_attributes(
nc_loader._add_unused_attributes(
iris_object, cf.cf_group[iris_object.var_name]
)

Expand Down
12 changes: 8 additions & 4 deletions lib/iris/fileformats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ def _load_grib(*args, **kwargs):
#
FORMAT_AGENT.add_spec(
FormatSpecification(
"NetCDF", MagicNumber(4), 0x43444601, netcdf.load_cubes, priority=5
"NetCDF",
MagicNumber(4),
0x43444601,
netcdf.loader.load_cubes,
priority=5,
)
)

Expand All @@ -100,7 +104,7 @@ def _load_grib(*args, **kwargs):
"NetCDF 64 bit offset format",
MagicNumber(4),
0x43444602,
netcdf.load_cubes,
netcdf.loader.load_cubes,
priority=5,
)
)
Expand All @@ -112,7 +116,7 @@ def _load_grib(*args, **kwargs):
"NetCDF_v4",
MagicNumber(8),
0x894844460D0A1A0A,
netcdf.load_cubes,
netcdf.loader.load_cubes,
priority=5,
)
)
Expand All @@ -122,7 +126,7 @@ def _load_grib(*args, **kwargs):
"NetCDF OPeNDAP",
UriProtocol(),
lambda protocol: protocol in ["http", "https"],
netcdf.load_cubes,
netcdf.loader.load_cubes,
priority=6,
)
FORMAT_AGENT.add_spec(_nc_dap)
Expand Down
12 changes: 6 additions & 6 deletions lib/iris/fileformats/_nc_load_rules/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# licensing details.
"""
A simple mimic of the Pyke 'knowledge_engine', for interfacing to the routines
in 'iris.fileformats.netcdf' with minimal changes to that code.
in 'iris.fileformats.netcdf.loader' with minimal changes to that code.

This allows us to replace the Pyke rules operation with the simpler pure-Python
translation operations in :mod:`iris.fileformats._nc_load_rules.actions`.
Expand All @@ -15,7 +15,7 @@

engine.get_kb() also returns a FactEntity object, which mimics *just enough*
API of a Pyke.knowlege_base, so that we can list its case-specific facts, as
used in :meth:`iris.fileformats.netcdf._actions_activation_stats`.
used in :meth:`iris.fileformats.netcdf.loader._actions_activation_stats`.

"""
from .actions import run_actions
Expand Down Expand Up @@ -66,7 +66,7 @@ class Engine:
A minimal mimic of a Pyke.engine.

Provides just enough API so that the existing code in
:mod:`iris.fileformats.netcdf` can interface with our new rules functions.
:mod:`iris.fileformats.netcdf.loader` can interface with our new rules functions.

A list of possible fact-arglists is stored, for each of a set of fact-names
(which are strings).
Expand All @@ -91,7 +91,7 @@ def activate(self):
set by engine.cf_var (a CFDataVariable).

The rules operation itself is coded elsewhere,
in :mod:`iris.fileformats.netcdf._nc_load_rules.actions`.
in :mod:`iris.fileformats.netcdf.loader._nc_load_rules.actions`.

"""
run_actions(self)
Expand All @@ -101,7 +101,7 @@ def get_kb(self):
Get a FactEntity, which mimic (bits of) a knowledge-base.

Just allowing
:meth:`iris.fileformats.netcdf._action_activation_stats` to list the
:meth:`iris.fileformats.netcdf.loader._action_activation_stats` to list the
facts.

"""
Expand All @@ -110,7 +110,7 @@ def get_kb(self):
def print_stats(self):
"""
No-op, called by
:meth:`iris.fileformats.netcdf._action_activation_stats`.
:meth:`iris.fileformats.netcdf.loader._action_activation_stats`.

"""
pass
Expand Down
3 changes: 1 addition & 2 deletions lib/iris/fileformats/_nc_load_rules/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
import iris.coords
import iris.exceptions
import iris.fileformats.cf as cf
import iris.fileformats.netcdf
from iris.fileformats.netcdf import (
from iris.fileformats.netcdf.loader import (
UnknownCellMethodWarning,
_get_cf_var_data,
parse_cell_methods,
Expand Down
28 changes: 28 additions & 0 deletions lib/iris/fileformats/netcdf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright Iris contributors
#
# This file is part of Iris and is released under the LGPL license.
# See COPYING and COPYING.LESSER in the root of the repository for full
# licensing details.
"""
A package for loading and saving cubes to and from netcdf files.

"""
from .loader import (
NetCDFDataProxy,
OrderedAddableList,
UnknownCellMethodWarning,
load_cubes,
parse_cell_methods,
)
from .saver import CFNameCoordMap, Saver, save

__all__ = [
"CFNameCoordMap",
"NetCDFDataProxy",
"OrderedAddableList",
"Saver",
"UnknownCellMethodWarning",
"load_cubes",
"parse_cell_methods",
"save",
]
Loading