Skip to content

Commit

Permalink
Added a keyword to allow the user to choose the extrapolation mode of…
Browse files Browse the repository at this point in the history
… the linear interpolation kernel. The default is not to extrapolate (any points outside the ranges will be masked).
  • Loading branch information
duncanwp committed Aug 28, 2015
1 parent 8f0ce85 commit 3785c54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cis/collocation/col_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,11 @@ class li(Kernel):
Linear Interpolation Kernel
"""

def __init__(self):
def __init__(self, extrapolate=False):
self.coord_names = []
self.hybrid_ht = False
self.interpolator = None
self.extrapolation_mode = 'linear' if extrapolate else 'error'

def get_value(self, point, data):
"""
Expand All @@ -559,12 +560,12 @@ def get_value(self, point, data):
if len(data.coords('altitude', dim_coords=False)) > 0:
self.hybrid_ht = True

self.interpolator = iris.analysis.Linear().interpolator(data, self.coord_names)
self.interpolator = iris.analysis.Linear(self.extrapolation_mode).interpolator(data, self.coord_names)

# Return the data from the result of interpolating over those coordinates which are on the cube.
slice = self.interpolator([getattr(point,c) for c in self.coord_names])
if self.hybrid_ht:
val = slice.interpolate([('altitude', point.altitude)], iris.analysis.Linear()).data
val = slice.interpolate([('altitude', point.altitude)], iris.analysis.Linear(self.extrapolation_mode)).data
else:
val = slice.data
return val
Expand Down
3 changes: 3 additions & 0 deletions doc/collocation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ where:
other separation constraints.

* ``lin`` For use with gridded source data only. A value is calculated by linear interpolation for each sample point.
The extrapolation mode can be controlled with the ``extrapolate`` keyword. The default mode is not to extrapolate values
to points outside of the gridded data source (masking them in the output instead). Setting ``extrapolate=True``
will instruct the kernel to extrapolate these values outside of the data source instead.

* ``nn`` For use with gridded source data only. The data point closest to each sample point is found, and the
data value is set at the sample point.
Expand Down

0 comments on commit 3785c54

Please sign in to comment.