Commit 58be214d authored by Klaus Zimmermann's avatar Klaus Zimmermann
Browse files

Fix output unit handling by moving it to post_process (fixes #67)

parent cbe0371a
......@@ -38,15 +38,21 @@ class PointLocalAggregator(Aggregator):
super().update_metadata(cube, coords, **kwargs)
cube.var_name = self.output_metadata['var_name']
cube.long_name = self.output_metadata['long_name']
cube.standard_name = self.index_function.standard_name
cube.units = self.index_function.units
cube.standard_name = self.output_metadata['standard_name']
unit_standard_name = cube.standard_name
try:
proposed_standard_name = self.output_metadata['proposed_standard_name']
cube.attributes['proposed_standard_name'] = proposed_standard_name
if unit_standard_name is None:
unit_standard_name = proposed_standard_name
except KeyError:
pass
def post_process(self, collapsed_cube, data_result, coords, **kwargs):
cube = super().post_process(collapsed_cube, data_result, coords,
**kwargs)
standard_name = self.output_metadata['standard_name']
unit_standard_name = standard_name
proposed_standard_name = self.output_metadata.get(
'proposed_standard_name', None)
if unit_standard_name is None:
unit_standard_name = proposed_standard_name
units = self.output_metadata['units']
change_units(cube, units, unit_standard_name)
cube.standard_name = standard_name
if proposed_standard_name is not None:
cube.attributes['proposed_standard_name'] = proposed_standard_name
return cube
......@@ -10,6 +10,7 @@ class CountOccurences:
def __init__(self, threshold, condition):
self.threshold = threshold
self.condition = condition
self.standard_name = None
self.units = Unit('days')
def prepare(self, input_cube):
......@@ -26,6 +27,7 @@ class SpellLength:
self.threshold = threshold
self.condition = condition
self.reducer = reducer
self.standard_name = None
self.units = Unit('days')
def prepare(self, input_cube):
......
......@@ -7,6 +7,7 @@ PRECIPITATION_STANDARD_NAMES = [
'precipitation_flux',
]
def is_precipitation(standard_name):
return standard_name in PRECIPITATION_STANDARD_NAMES
......@@ -121,6 +122,6 @@ def change_pr_units(cube, new_unit=None, new_stname=None):
raise
c = unit_dict_old[new_stname]
conv = (old_unit2/Unit(c)).convert(1., new_unit2)
cube.data = cube.data * float(conv)
cube.data = cube.core_data() * float(conv)
cube.units = new_unit2
cube.standard_name = new_stname
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