Skip to content
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
8 changes: 4 additions & 4 deletions lib/iris/experimental/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ def _regrid_indices(cells, depth, points):
return cube


class CurvilinearRegridder(object):
class _CurvilinearRegridder(object):
"""
This class provides support for performing point-in-cell regridding
between a curvilinear source grid and a rectilinear target grid.
Expand Down Expand Up @@ -1074,10 +1074,10 @@ def _get_horizontal_coord(cube, axis):
def __call__(self, src):
"""
Regrid the supplied :class:`~iris.cube.Cube` on to the target grid of
this :class:`CurvilinearRegridder`.
this :class:`_CurvilinearRegridder`.

The given cube must be defined with the same grid as the source
grid used to create this :class:`CurvilinearRegridder`.
grid used to create this :class:`_CurvilinearRegridder`.

Args:

Expand Down Expand Up @@ -1158,4 +1158,4 @@ def regridder(self, src_grid, target_grid):
that is to be regridded to the `target_grid`.

"""
return CurvilinearRegridder(src_grid, target_grid, self.weights)
return _CurvilinearRegridder(src_grid, target_grid, self.weights)
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Test_regridder(tests.IrisTest):
def test(self):
point_in_cell = PointInCell(mock.sentinel.weights)

with mock.patch('iris.experimental.regrid.CurvilinearRegridder',
with mock.patch('iris.experimental.regrid._CurvilinearRegridder',
return_value=mock.sentinel.regridder) as ecr:
regridder = point_in_cell.regridder(mock.sentinel.src,
mock.sentinel.target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with Iris. If not, see <http://www.gnu.org/licenses/>.
"""Unit tests for :class:`iris.experimental.regrid.CurvilinearRegridder`."""
"""Unit tests for :class:`iris.experimental.regrid._CurvilinearRegridder`."""

from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip) # noqa
Expand All @@ -26,14 +26,14 @@
import mock
import numpy as np

from iris.experimental.regrid import CurvilinearRegridder as Regridder
from iris.experimental.regrid import _CurvilinearRegridder as Regridder
from iris.tests.stock import global_pp, lat_lon_cube


RESULT_DIR = ('analysis', 'regrid')


class Test__initialisation(tests.IrisTest):
class Test___init__(tests.IrisTest):
def setUp(self):
self.ok = lat_lon_cube()
self.bad = np.ones((3, 4))
Expand All @@ -48,7 +48,7 @@ def test_bad_grid_type(self):
Regridder(self.ok, self.bad, self.weights)


class Test__operation(tests.IrisTest):
class Test___call__(tests.IrisTest):
def setUp(self):
self.func = ('iris.experimental.regrid.'
'regrid_weighted_curvilinear_to_rectilinear')
Expand All @@ -61,23 +61,35 @@ def setUp(self):
self.ok.add_aux_coord(x, 1)
self.weights = np.ones(self.ok.shape, self.ok.dtype)

def test__use_once(self):
def test_same_src_as_init(self):
# Modify the names so we can tell them apart.
src_grid = self.ok.copy()
src_grid.rename('src_grid')
target_grid = self.ok.copy()
target_grid.rename('TARGET_GRID')
regridder = Regridder(src_grid, target_grid, self.weights)
with mock.patch(self.func,
return_value=mock.sentinel.regridded) as clr:
Regridder(self.ok, self.ok, self.weights)

clr.assertCalledOnceWith(self.ok, self.weights, self.ok)

def test__cache_regridder(self):
regridder = Regridder(self.ok, self.ok, self.weights)
src = self.ok
src.data = np.ones(src.shape, src.dtype)
result = regridder(src_grid)

clr.assert_called_once_with(src_grid, self.weights, target_grid)
self.assertIs(result, mock.sentinel.regridded)

def test_diff_src_from_init(self):
# Modify the names so we can tell them apart.
src_grid = self.ok.copy()
src_grid.rename('SRC_GRID')
target_grid = self.ok.copy()
target_grid.rename('TARGET_GRID')
regridder = Regridder(src_grid, target_grid, self.weights)
src = self.ok.copy()
src.rename('SRC')
with mock.patch(self.func,
return_value=mock.sentinel.regridded) as clr:
res = regridder(src)
result = regridder(src)

clr.assertCalledOnceWith(src, self.weights, self.ok)
self.assertIs(res, mock.sentinel.regridded)
clr.assert_called_once_with(src, self.weights, target_grid)
self.assertIs(result, mock.sentinel.regridded)


class Test___call____bad_src(tests.IrisTest):
Expand All @@ -100,3 +112,7 @@ def test_bad_src_shape(self):
with self.assertRaisesRegexp(ValueError,
'not defined on the same source grid'):
self.regridder(self.ok[::2, ::2])


if __name__ == '__main__':
tests.main()
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,35 @@

import mock

import iris.coords

from iris.fileformats.name_loaders import _build_cell_methods


class Tests(tests.IrisTest):
def setUp(self):
patch = mock.patch('iris.coords.CellMethod')
self.mock_CellMethod = patch.start()
self.addCleanup(patch.stop)

def test_nameII_average(self):
av_or_int = ['something average ob bla'] * 3
av_or_int = ['something average ob bla']
coord_name = 'foo'
res = _build_cell_methods(av_or_int, coord_name)
self.mock_CellMethod.assert_called('average', coord_name)
self.assertEqual(res, [iris.coords.CellMethod('mean', 'foo')])

def test_nameIII_averaged(self):
av_or_int = ['something averaged ob bla'] * 3
av_or_int = ['something averaged ob bla']
coord_name = 'bar'
res = _build_cell_methods(av_or_int, coord_name)
self.mock_CellMethod.assert_called('average', coord_name)
self.assertEqual(res, [iris.coords.CellMethod('mean', 'bar')])

def test_nameII_integral(self):
av_or_int = ['something integral ob bla'] * 3
av_or_int = ['something integral ob bla']
coord_name = 'ensemble'
res = _build_cell_methods(av_or_int, coord_name)
self.mock_CellMethod.assert_called('sum', coord_name)
self.assertEqual(res, [iris.coords.CellMethod('sum', 'ensemble')])

def test_nameIII_integrated(self):
av_or_int = ['something integrated ob bla'] * 3
av_or_int = ['something integrated ob bla']
coord_name = 'time'
res = _build_cell_methods(av_or_int, coord_name)
self.mock_CellMethod.assert_called('sum', coord_name)
self.assertEqual(res, [iris.coords.CellMethod('sum', 'time')])

def test_no_averaging(self):
av_or_int = ['No foo averaging',
Expand All @@ -72,6 +69,26 @@ def test_no_averaging(self):
res = _build_cell_methods(av_or_int, coord_name)
self.assertEqual(res, [None] * len(av_or_int))

def test_nameII_mixed(self):
av_or_int = ['something integral ob bla',
'no averaging',
'other average']
coord_name = 'ensemble'
res = _build_cell_methods(av_or_int, coord_name)
self.assertEqual(res, [iris.coords.CellMethod('sum', 'ensemble'),
None,
iris.coords.CellMethod('mean', 'ensemble')])

def test_nameIII_mixed(self):
av_or_int = ['something integrated ob bla',
'no averaging',
'other averaged']
coord_name = 'ensemble'
res = _build_cell_methods(av_or_int, coord_name)
self.assertEqual(res, [iris.coords.CellMethod('sum', 'ensemble'),
None,
iris.coords.CellMethod('mean', 'ensemble')])

def test_unrecognised(self):
unrecognised_heading = 'bla else'
av_or_int = ['something average',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def test_cell_methods(self):
cubes = list(_generate_cubes(header, column_headings, coords,
data_arrays, cell_methods))

cubes[0].assert_has_call(mock.call.add_cell_method('cell_method_1'))
cubes[1].assert_has_call(mock.call.add_cell_method('cell_method_2'))
cubes[0].assert_has_calls([mock.call.add_cell_method('cell_method_1')])
cubes[1].assert_has_calls([mock.call.add_cell_method('cell_method_2')])


class TestCircularLongitudes(tests.IrisTest):
Expand Down
5 changes: 4 additions & 1 deletion lib/iris/tests/unit/fileformats/pp/test_PPField.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def field_checksum(data):
checksum_64 = field_checksum(data_64.astype('>f8'))

self.assertEqual(checksum_32, checksum_64)
warn.assert_called()
warn.assert_called_once_with(
'Downcasting array precision from float64 to float32 for save.'
'If float64 precision is required then please save in a '
'different format')


class Test_calendar(tests.IrisTest):
Expand Down