-
Notifications
You must be signed in to change notification settings - Fork 148
Open
Description
Add dim parameter to statistics methods controlling the dimension over which to reduce. If it is not None, select each unique value of the dimension, apply the reduction, and concatenate the results.
We need to distinguish values from select because some select parameters are named differently from their attributes (event_ids vs event_id)
class HazardForecast:
def max(self, dim=None):
if dim is not None:
return reduce_unique_selection(values=getattr(self.dim), select=dim, reduce_attr="max")
return ...
def reduce_unique_selection(self, values, select, reduce_attr):
return self.concat(
[
getattr(self.select(**{select: [val]}), reduce_attr)(dim=None)
for val in np.unique(values)
]
)NOTE: reduce_unique_selection need not be a method but can also be a free function. Then, it can be used by both HazardForecast and ImpactForecast