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
11 changes: 0 additions & 11 deletions lib/iris/analysis/_interpolate_backdoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ def _warn_deprecated(msg=None):
iris_warn_deprecated(msg)


def nearest_neighbour_indices(cube, sample_points):
msg = (_INTERPOLATE_DEPRECATION_WARNING + '\n' +
'Please replace usage of '
'iris.analysis.interpolate.nearest_neighbour_indices() '
'with iris.coords.Coord.nearest_neighbour_index()).')
_warn_deprecated(msg)
return _interp.nearest_neighbour_indices(cube, sample_points)

nearest_neighbour_indices.__doc__ = _interp.nearest_neighbour_indices.__doc__


def extract_nearest_neighbour(cube, sample_points):
msg = (_INTERPOLATE_DEPRECATION_WARNING + '\n' +
'Please replace usage of '
Expand Down
99 changes: 0 additions & 99 deletions lib/iris/analysis/_interpolate_private.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,105 +94,6 @@ def _cartesian_sample_points(sample_points, sample_point_coord_names):
return cartesian_points


def nearest_neighbour_indices(cube, sample_points):
"""
Returns the indices to select the data value(s) closest to the given coordinate point values.

The sample_points mapping does not have to include coordinate values corresponding to all data
dimensions. Any dimensions unspecified will default to a full slice.

For example:

>>> cube = iris.load_cube(iris.sample_data_path('ostia_monthly.nc'))
>>> iris.analysis.interpolate.nearest_neighbour_indices(cube, [('latitude', 0), ('longitude', 10)])
(slice(None, None, None), 9, 12)
>>> iris.analysis.interpolate.nearest_neighbour_indices(cube, [('latitude', 0)])
(slice(None, None, None), 9, slice(None, None, None))

Args:

* cube:
An :class:`iris.cube.Cube`.
* sample_points
A list of tuple pairs mapping coordinate instances or unique coordinate names in the cube to point values.

Returns:
The tuple of indices which will select the point in the cube closest to the supplied coordinate values.

.. note::

Nearest neighbour interpolation of multidimensional coordinates is not
yet supported.

.. deprecated:: 1.10

The module :mod:`iris.analysis.interpolate` is deprecated.
Please replace usage of
:func:`iris.analysis.interpolate.nearest_neighbour_indices`
with :meth:`iris.coords.Coord.nearest_neighbour_index`.

"""
if isinstance(sample_points, dict):
msg = ('Providing a dictionary to specify points is deprecated. '
'Please provide a list of (coordinate, values) pairs.')
warn_deprecated(msg)
sample_points = list(sample_points.items())

if sample_points:
try:
coord, values = sample_points[0]
except ValueError:
raise ValueError('Sample points must be a list of (coordinate, value) pairs. Got %r.' % sample_points)

points = []
for coord, values in sample_points:
if isinstance(coord, six.string_types):
coord = cube.coord(coord)
else:
coord = cube.coord(coord)
points.append((coord, values))
sample_points = points

# Build up a list of indices to span the cube.
indices = [slice(None, None)] * cube.ndim

# Build up a dictionary which maps the cube's data dimensions to a list (which will later
# be populated by coordinates in the sample points list)
dim_to_coord_map = {}
for i in range(cube.ndim):
dim_to_coord_map[i] = []

# Iterate over all of the specifications provided by sample_points
for coord, point in sample_points:
data_dim = cube.coord_dims(coord)

# If no data dimension then we don't need to make any modifications to indices.
if not data_dim:
continue
elif len(data_dim) > 1:
raise iris.exceptions.CoordinateMultiDimError("Nearest neighbour interpolation of multidimensional "
"coordinates is not supported.")
data_dim = data_dim[0]

dim_to_coord_map[data_dim].append(coord)

#calculate the nearest neighbour
min_index = coord.nearest_neighbour_index(point)

if getattr(coord, 'circular', False):
warnings.warn("Nearest neighbour on a circular coordinate may not be picking the nearest point.", DeprecationWarning)

# If the dimension has already been interpolated then assert that the index from this coordinate
# agrees with the index already calculated, otherwise we have a contradicting specification
if indices[data_dim] != slice(None, None) and min_index != indices[data_dim]:
raise ValueError('The coordinates provided (%s) over specify dimension %s.' %
(', '.join([coord.name() for coord in dim_to_coord_map[data_dim]]), data_dim))

indices[data_dim] = min_index

return tuple(indices)


def _nearest_neighbour_indices_ndcoords(cube, sample_points, cache=None):
"""
See documentation for :func:`iris.analysis.interpolate.nearest_neighbour_indices`.
Expand Down