Skip to content

Commit

Permalink
Fix for JASCIS-342. gridded->gridded collocation now won't exrapolate…
Browse files Browse the repository at this point in the history
… by default, and the collocation argument will be passed through properly.
  • Loading branch information
duncanwp committed Aug 9, 2016
1 parent ff03c00 commit 7e0c6e1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
16 changes: 11 additions & 5 deletions cis/collocation/col.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def get_collocator_instances_for_method(self, method_name, kernel_name, collocat
:param data_gridded: Is the collocation data gridded?
:return: Collocator, Constrain and Kernel instances
"""
import cis.collocation.col_implementations as ci

col_cls, constraint_cls, kernel_cls = self._get_collocator_classes_for_method(method_name, kernel_name,
sample_gridded, data_gridded)
collocator_params, constraint_params = self._get_collocator_params(collocator_params)
collocator_params, constraint_params = self._get_collocator_params(collocator_params, col_cls)
col = self._instantiate_with_params(col_cls, collocator_params)
con = self._instantiate_with_params(constraint_cls, constraint_params)
kernel = self._instantiate_with_params(kernel_cls, kernel_params)
Expand Down Expand Up @@ -104,17 +104,23 @@ def _get_collocator_classes_for_method(self, method_name, kernel_name, sample_gr
'A kernel cannot be specified for collocator "{}"'.format(method_name))
return option

def _get_collocator_params(self, params):
def _get_collocator_params(self, params, col_cls):
"""
Separates the parameters understood by the collocator from those for the constraint.
:param params: combined collocator/constraint parameters
:param col_cls: The collocator class to check for parameters against
:return: tuple containing (dict of collocator parameters, dict of constraint parameters)
"""
col_param_names = ['fill_value', 'var_name', 'var_long_name', 'var_units', 'missing_data_for_missing_sample']
import inspect
# Python 2/3 compatibility
if hasattr(inspect, 'signature'):
args = inspect.signature(col_cls.__init__).parameters
else:
args = inspect.getargspec(col_cls.__init__).args
col_params = {}
con_params = {}
for key, value in params.items():
if key in col_param_names:
if key in args:
col_params[key] = value
else:
con_params[key] = value
Expand Down
13 changes: 10 additions & 3 deletions cis/collocation/col_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,12 @@ class nn_t(nn_time):

class GriddedCollocator(Collocator):

def __init__(self, fill_value=np.nan, var_name='', var_long_name='', var_units='',
missing_data_for_missing_sample=False, extrapolate=False):
super(GriddedCollocator, self).__init__(fill_value, var_name, var_long_name, var_units,
missing_data_for_missing_sample)
self.extrapolate = 'extrapolate' if extrapolate else 'mask'

@staticmethod
def _check_for_valid_kernel(kernel):
from cis.exceptions import ClassNotFoundError
Expand Down Expand Up @@ -667,7 +673,7 @@ def collocate(self, points, data, constraint, kernel):

output_cube = self._iris_interpolate(coord_names_and_sizes_for_output_grid,
coord_names_and_sizes_for_sample_grid, data,
kernel, output_mask, points)
kernel, output_mask, points, self.extrapolate)

if not isinstance(output_cube, list):
return GriddedDataList([output_cube])
Expand Down Expand Up @@ -700,7 +706,7 @@ def _make_output_mask(coord_names_and_sizes_for_sample_grid, output_shape, point

@staticmethod
def _iris_interpolate(coord_names_and_sizes_for_output_grid, coord_names_and_sizes_for_sample_grid, data, kernel,
output_mask, points):
output_mask, points, extrapolate):
""" Collocates using iris.analysis.interpolate
"""
coordinate_point_pairs = []
Expand All @@ -712,7 +718,8 @@ def _iris_interpolate(coord_names_and_sizes_for_output_grid, coord_names_and_siz

# The result here will be a cube with the correct dimensions for the output, so interpolated over all points
# in coord_names_and_sizes_for_output_grid.
output_cube = make_from_cube(data.interpolate(coordinate_point_pairs, kernel.interpolater()))
output_cube = make_from_cube(data.interpolate(coordinate_point_pairs,
kernel.interpolater(extrapolation_mode=extrapolate)))

# Iris outputs interpolated cubes with the dimensions in the order of the data grid, not the sample grid,
# so we need to rearrange the order of the dimensions.
Expand Down
Binary file removed cis/test/integration/test_integration_out.nc
Binary file not shown.
9 changes: 6 additions & 3 deletions doc/whats_new_1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ CIS 1.4 features
================

* CIS now includes full support for Python 3, as well as Python 2.7
* New verbose and quiet flags allow for control over how much CIS commands output to the screen. The default verbosity
has also changed so that by default only warnings and errors will be output to the screen. The full debug output
remains for the cis.log file.
* Significant optimizations have been made in gridded -> ungridded collocation which should now be considerably faster.
Also, when collocating multiple gridded source datasets the interpolation indices are now cached internally leading
to further time savings.
Expand All @@ -26,9 +29,9 @@ CIS 1.4 features
``valid_min`` or ``valid_max`` attributes is also masked appropriately.
* CloudSat ``missing`` and ``missop`` attributes are now read and combined to mask out values which don't conform to the
inequality defined.
* New verbose and quiet flags allow for control over how much CIS commands output to the screen. The default verbosity
has also changed so that by default only warnings and errors will be output to the screen. The full debug output
remains for the cis.log file.
* [JASCIS-342] The extrapolation modes are now consistent across both gridded->gridded and gridded->ungridded collocation
modes. The default is no extrapolation (gridded->gridded would previously extrapolate). This can still be overridden
by the user.

Bugs fixed
==========
Expand Down

0 comments on commit 7e0c6e1

Please sign in to comment.