Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netcdf separate loadsave #4803

Merged
merged 9 commits into from
Sep 28, 2022
Merged
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
4 changes: 4 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ This document explains the changes made to Iris for this release
bin in the system PATH.
(:pull:`4794`)

#. `@pp-mo`_ split the module :mod:`iris.fileformats.netcdf` into separate
:mod:`~iris.fileformats.netcdf.loader` and :mod:`~iris.fileformats.netcdf.saver`
submodules, just to make the code easier to handle.


.. comment
Whatsnew author names (@github name) in alphabetical order. Note that,
Expand Down
13 changes: 6 additions & 7 deletions lib/iris/experimental/ugrid/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
Extensions to Iris' NetCDF loading to allow the construction of
:class:`~iris.experimental.ugrid.mesh.Mesh`\\ es from UGRID data in the file.

Eventual destination: :mod:`iris.fileformats.netcdf` (plan to split that module
into ``load`` and ``save`` in future).
trexfeathers marked this conversation as resolved.
Show resolved Hide resolved
Eventual destination: :mod:`iris.fileformats.netcdf`.

"""
from contextlib import contextmanager
Expand All @@ -19,8 +18,8 @@

from ...config import get_logger
from ...coords import AuxCoord
from ...fileformats import netcdf
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 .cf import (
Expand Down Expand Up @@ -202,7 +201,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 @@ -239,7 +238,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 @@ -293,7 +292,7 @@ def _build_connectivity(connectivity_var, file_path, element_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 @@ -462,7 +461,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
3 changes: 1 addition & 2 deletions lib/iris/experimental/ugrid/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
Extensions to Iris' NetCDF saving to allow
:class:`~iris.experimental.ugrid.mesh.Mesh` saving in UGRID format.

Eventual destination: :mod:`iris.fileformats.netcdf` (plan to split that module
into ``load`` and ``save`` in future).
Eventual destination: :mod:`iris.fileformats.netcdf`.

"""
from collections.abc import Iterable
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/fileformats/_nc_load_rules/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import iris.fileformats.netcdf
from iris.fileformats.netcdf import (
UnknownCellMethodWarning,
_get_cf_var_data,
parse_cell_methods,
)
from iris.fileformats.netcdf.loader import _get_cf_var_data
import iris.std_names
import iris.util

Expand Down
49 changes: 49 additions & 0 deletions lib/iris/fileformats/netcdf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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.
"""
Module to support the loading and saving of NetCDF files, also using the CF conventions
for metadata interpretation.

See : `NetCDF User's Guide <https://docs.unidata.ucar.edu/nug/current/>`_
and `netCDF4 python module <https://github.com/Unidata/netcdf4-python>`_.

Also : `CF Conventions <https://cfconventions.org/>`_.

"""
import iris.config

# Note: *must* be done before importing from submodules, as they also use this !
logger = iris.config.get_logger(__name__)

from .loader import DEBUG, NetCDFDataProxy, load_cubes
from .saver import (
CF_CONVENTIONS_VERSION,
MESH_ELEMENTS,
SPATIO_TEMPORAL_AXES,
CFNameCoordMap,
Saver,
UnknownCellMethodWarning,
parse_cell_methods,
save,
)

# Export all public elements from the loader and saver submodules.
# NOTE: the separation is purely for neatness and developer convenience; from
# the user point of view, it is still all one module.
__all__ = (
"CFNameCoordMap",
"CF_CONVENTIONS_VERSION",
"DEBUG",
"MESH_ELEMENTS",
"NetCDFDataProxy",
"SPATIO_TEMPORAL_AXES",
"Saver",
"UnknownCellMethodWarning",
"load_cubes",
"logger",
"parse_cell_methods",
"save",
)
Loading