Skip to content

Implement unique selection reduction and add to statistics methods #1163

@peanutfun

Description

@peanutfun

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions