Skip to content

Commit

Permalink
Fix for JASCIS-199. Aggregation now correctly uses the bounds supplie…
Browse files Browse the repository at this point in the history
…d by the user even when collapsing to length one coordinates.
  • Loading branch information
duncanwp committed Aug 19, 2015
1 parent 560684e commit 6d74222
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cis/aggregation/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,23 @@ def _make_partially_collapsed_coord(self, coord, grid, guessed_axis):
new_coordinate_grid = aggregation_grid_array(grid_start, grid_end, grid_delta, grid.is_time, coord)
new_coord = DimCoord(new_coordinate_grid, var_name=coord.name(), standard_name=coord.standard_name,
units=coord.units)
new_coord.guess_bounds()
if len(new_coord.points) == 1:
new_coord.bounds = [[grid_start, grid_end]]
else:
new_coord.guess_bounds()
return new_coord

def _add_max_min_bounds_for_collapsed_coords(self, aggregated_cube, source_cube):
"""
Add bounds onto all coordinates which have been full collapsed. These bounds will
be the maximum and minimum values of those coordinates
Add bounds onto all coordinates which have been full collapsed, and for which no explicit bounds have been
supplied (iris will have guessed these to be +/- inf). The new bounds will be the maximum and minimum values of
those coordinates
:param aggregated_cube: The aggregated cube to give new bounds
:param source_cube: The source cube which the aggregation was made from.
"""
from numpy import isinf, all
for coord in aggregated_cube.coords():
if len(coord.points) == 1:
if len(coord.points) == 1 and all(isinf(coord.bounds)):
source_coord = source_cube.coord(coord.name())
coord_start, coord_end, coord_centre = self._get_coord_start_end_centre(source_coord)
coord.bounds = numpy.array([[coord_start, coord_end]])
Expand Down
15 changes: 15 additions & 0 deletions cis/test/unit/aggregation/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,21 @@ def test_collapsed_coords_get_max_min_bounds(self):
lon = output.coord('longitude')
assert_arrays_equal(lon.bounds, [[-5, 5]])

def test_aggregating_coord_to_length_one_with_explicit_bounds_gets_output_as_length_one(self):
data = make_regular_2d_ungridded_data()
grid = {'x': AggregationGrid(-180, 180, 360, False), 'y': AggregationGrid(-90, 90, 10, False), }
agg = Aggregator(data, grid)
output = agg.aggregate_ungridded(self.kernel)
lon = output.coord('longitude')
assert_that(lon.points, is_([0]))

def test_aggregating_to_length_one_with_explicit_bounds_get_correct_bounds(self):
data = make_regular_2d_ungridded_data()
grid = {'x': AggregationGrid(-180, 180, 360, False), 'y': AggregationGrid(-90, 90, 10, False), }
agg = Aggregator(data, grid)
output = agg.aggregate_ungridded(self.kernel)
lon = output.coord('longitude')
assert_arrays_equal(lon.bounds, [[-180, 180]])

class TestUngriddedListAggregation(TestCase):

Expand Down

0 comments on commit 6d74222

Please sign in to comment.