fips.aggregators.ObsAggregator#
- class fips.aggregators.ObsAggregator(by=None, level=None, freq=None, func='mean', blocks=None)[source]#
Aggregates the observation space of an inverse problem.
Builds a sparse (n_agg x n_obs) weight matrix W and applies it to each component of the problem:
z_agg = W @ z # aggregated observations H_agg = W @ H # aggregated forward operator S_z_agg = W @ S_z @ W.T # covariance propagation c_agg = W @ c # aggregated constant (if vector)
For
func='mean'each non-zero entry in row i equals 1/nᵢ (the reciprocal of the group size), soW @ zyields group means andW @ S_z @ W.Tscales variances by 1/nᵢ². Forfunc='sum'every entry is 1. Only'mean'and'sum'are supported because other functions do not have a well-defined covariance propagation rule.Grouping interface#
Exactly one of
byorlevelmust be provided:by: an index level name (str), a list of level names, or a callable that accepts the obspd.Indexand returns group labels.level+freq: resample a datetime index level at the given pandas offset alias (e.g.level='obs_time', freq='D'). All other index levels are preserved as exact-match grouping keys.
When the obs index has a
'block'level it is always prepended as a grouping key, ensuring observations from different blocks are never merged.Partial aggregation#
blocksrestricts aggregation to the named block(s). Observations belonging to other blocks are passed through unchanged via identity rows in W, so the returned arrays cover the full observation space.- type by:
- param by:
Explicit grouping specification. Mutually exclusive with
level.- type by:
str | list[str] | Callable, optional
- type level:
- param level:
Index level to group / resample. Requires either a matching level name in the obs index or use alongside
freq.- type level:
str, optional
- type freq:
- param freq:
Pandas offset alias for resampling
level(e.g.'D','h').- type freq:
str, optional
- type func:
- param func:
Aggregation function. Default
'mean'.- type func:
{‘mean’, ‘sum’}
- type blocks:
- param blocks:
Block name(s) to aggregate. Unlisted blocks pass through as-is.
- type blocks:
str | list[str], optional
- param Apply to inverse problem components:
- param ———————————–:
- param apply(obs:
Apply the aggregation to the inverse problem components.
- param forward_operator:
Apply the aggregation to the inverse problem components.
- param modeldata_mismatch:
Apply the aggregation to the inverse problem components.
- param constant):
Apply the aggregation to the inverse problem components.
Attributes
byExplicit grouping specification.
levelIndex level to group / resample.
freqPandas offset alias for resampling 'level' (e.g. 'D', 'h').
funcAggregation function, either 'mean' or 'sum'.
blocksBlock name(s) to aggregate.
Methods
apply(obs, forward_operator, modeldata_mismatch)Apply W to the inverse problem components.