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
13 changes: 9 additions & 4 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,7 @@ def cell(self, index):

return Cell(point, bound)

def collapsed(self, dims_to_collapse=None):
def collapsed(self, dims_to_collapse=None, points_func=None):
"""
Returns a copy of this coordinate, which has been collapsed along
the specified dimensions.
Expand Down Expand Up @@ -2003,7 +2003,10 @@ def serialize(x):
],
axis=-1,
)
points = al.array(bounds.sum(axis=-1) * 0.5, dtype=self.dtype)
if points_func is None:
points = al.array(bounds.sum(axis=-1) * 0.5, dtype=self.dtype)
else:
points = points_func(self.core_points(), axis=dims_to_collapse)

# Create the new collapsed coordinate.
coord = self.copy(points=points, bounds=bounds)
Expand Down Expand Up @@ -2497,8 +2500,10 @@ def __getitem__(self, key):
coord.circular = self.circular and coord.shape == self.shape
return coord

def collapsed(self, dims_to_collapse=None):
coord = Coord.collapsed(self, dims_to_collapse=dims_to_collapse)
def collapsed(self, dims_to_collapse=None, points_func=None):
coord = Coord.collapsed(
self, dims_to_collapse=dims_to_collapse, points_func=points_func
)
if self.circular and self.units.modulus is not None:
bnds = coord.bounds.copy()
bnds[0, 1] = coord.bounds[0, 0] + self.units.modulus
Expand Down
8 changes: 6 additions & 2 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -3414,7 +3414,7 @@ def __neg__(self):

# END OPERATOR OVERLOADS

def collapsed(self, coords, aggregator, **kwargs):
def collapsed(self, coords, aggregator, points_funcs=dict(), **kwargs):
"""
Collapse one or more dimensions over the cube given the coordinate/s
and an aggregation.
Expand Down Expand Up @@ -3568,7 +3568,11 @@ def collapsed(self, coords, aggregator, **kwargs):
for dim in dims_to_collapse
if dim in coord_dims
]
collapsed_cube.replace_coord(coord.collapsed(local_dims))
collapsed_cube.replace_coord(
coord.collapsed(
local_dims, points_func=points_funcs.get(coord.name())
)
)

untouched_dims = sorted(untouched_dims)

Expand Down