Commit f43f715d authored by Klaus Zimmermann's avatar Klaus Zimmermann
Browse files

Add post processing hook for index functions (closes #100)

parent 66028efe
...@@ -27,6 +27,13 @@ class PointLocalAggregator(Aggregator): ...@@ -27,6 +27,13 @@ class PointLocalAggregator(Aggregator):
def post_process(self, collapsed_cube, data_result, coords, **kwargs): def post_process(self, collapsed_cube, data_result, coords, **kwargs):
cube = super().post_process(collapsed_cube, data_result, coords, cube = super().post_process(collapsed_cube, data_result, coords,
**kwargs) **kwargs)
try:
post_processor = self.index_function.post_process
except AttributeError:
# this index function does not require post processing
pass
else:
cube = post_processor(cube, data_result, coords, **kwargs)
standard_name = self.output_metadata['standard_name'] standard_name = self.output_metadata['standard_name']
unit_standard_name = standard_name unit_standard_name = standard_name
proposed_standard_name = self.output_metadata.get( proposed_standard_name = self.output_metadata.get(
......
...@@ -19,7 +19,8 @@ class Index: ...@@ -19,7 +19,8 @@ class Index:
coord_name = self.period.add_coord_categorisation(cube) coord_name = self.period.add_coord_categorisation(cube)
sub_cube = cube.extract(self.period.constraint) sub_cube = cube.extract(self.period.constraint)
self.index_function.prepare(sub_cube) self.index_function.prepare(sub_cube)
aggregated = sub_cube.aggregated_by(coord_name, self.aggregator) aggregated = sub_cube.aggregated_by(coord_name, self.aggregator,
period=self.period)
if sliced_mode: if sliced_mode:
results = [] results = []
for r in aggregated.slices_over(coord_name): for r in aggregated.slices_over(coord_name):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment