Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pp-mo committed Jun 17, 2022
1 parent 2d9f11c commit d9ef767
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 21 deletions.
13 changes: 5 additions & 8 deletions lib/iris/experimental/ugrid/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
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).
"""
from contextlib import contextmanager
from itertools import groupby
Expand All @@ -19,8 +16,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 +199,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 +236,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 +290,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 +459,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy as np

from iris.fileformats.netcdf import _FillValueMaskCheckAndStoreTarget
from iris.fileformats.netcdf.saver import _FillValueMaskCheckAndStoreTarget


class Test__FillValueMaskCheckAndStoreTarget(tests.IrisTest):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from iris._lazy_data import _optimum_chunksize
import iris.fileformats.cf
from iris.fileformats.netcdf import _get_cf_var_data
from iris.fileformats.netcdf.loader import _get_cf_var_data


class Test__get_cf_var_data(tests.IrisTest):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from iris.coords import DimCoord
from iris.cube import Cube
from iris.fileformats.netcdf import _load_aux_factory
from iris.fileformats.netcdf.loader import _load_aux_factory


class TestAtmosphereHybridSigmaPressureCoordinate(tests.IrisTest):
Expand Down
6 changes: 3 additions & 3 deletions lib/iris/tests/unit/fileformats/netcdf/test__load_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from iris.coords import DimCoord
import iris.fileformats.cf
from iris.fileformats.netcdf import _load_cube
from iris.fileformats.netcdf.loader import _load_cube


class TestCoordAttributes(tests.IrisTest):
Expand All @@ -28,7 +28,7 @@ def _patcher(engine, cf, cf_group):
engine.cube_parts["coordinates"] = coordinates

def setUp(self):
this = "iris.fileformats.netcdf._assert_case_specific_facts"
this = "iris.fileformats.netcdf.loader._assert_case_specific_facts"
patch = mock.patch(this, side_effect=self._patcher)
patch.start()
self.addCleanup(patch.stop)
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_flag_pass_thru_multi(self):

class TestCubeAttributes(tests.IrisTest):
def setUp(self):
this = "iris.fileformats.netcdf._assert_case_specific_facts"
this = "iris.fileformats.netcdf.loader._assert_case_specific_facts"
patch = mock.patch(this)
patch.start()
self.addCleanup(patch.stop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

import iris
from iris.fileformats.cf import CFDataVariable
from iris.fileformats.netcdf import _translate_constraints_to_var_callback
from iris.fileformats.netcdf.loader import (
_translate_constraints_to_var_callback,
)

# import iris tests first so that some things can be initialised before
# importing anything else
Expand Down
10 changes: 5 additions & 5 deletions lib/iris/tests/unit/fileformats/netcdf/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_None(self):
# Test that when no fill_value argument is passed, the fill_value
# argument to Saver.write is None or not present.
cubes = self._make_cubes()
with mock.patch("iris.fileformats.netcdf.Saver") as Saver:
with mock.patch("iris.fileformats.netcdf.saver.Saver") as Saver:
save(cubes, "dummy.nc")

# Get the Saver.write mock
Expand All @@ -161,7 +161,7 @@ def test_single(self):
# that value is passed to each call to Saver.write
cubes = self._make_cubes()
fill_value = 12345.0
with mock.patch("iris.fileformats.netcdf.Saver") as Saver:
with mock.patch("iris.fileformats.netcdf.saver.Saver") as Saver:
save(cubes, "dummy.nc", fill_value=fill_value)

# Get the Saver.write mock
Expand All @@ -178,7 +178,7 @@ def test_multiple(self):
# each element is passed to separate calls to Saver.write
cubes = self._make_cubes()
fill_values = [123.0, 456.0, 789.0]
with mock.patch("iris.fileformats.netcdf.Saver") as Saver:
with mock.patch("iris.fileformats.netcdf.saver.Saver") as Saver:
save(cubes, "dummy.nc", fill_value=fill_values)

# Get the Saver.write mock
Expand All @@ -195,7 +195,7 @@ def test_single_string(self):
# that value is passed to calls to Saver.write
cube = Cube(["abc", "def", "hij"])
fill_value = "xyz"
with mock.patch("iris.fileformats.netcdf.Saver") as Saver:
with mock.patch("iris.fileformats.netcdf.saver.Saver") as Saver:
save(cube, "dummy.nc", fill_value=fill_value)

# Get the Saver.write mock
Expand All @@ -211,7 +211,7 @@ def test_multi_wrong_length(self):
# is passed as the fill_value argument, an error is raised
cubes = self._make_cubes()
fill_values = [1.0, 2.0, 3.0, 4.0]
with mock.patch("iris.fileformats.netcdf.Saver"):
with mock.patch("iris.fileformats.netcdf.saver.Saver"):
with self.assertRaises(ValueError):
save(cubes, "dummy.nc", fill_value=fill_values)

Expand Down

0 comments on commit d9ef767

Please sign in to comment.