fips.Problem.aggregate#

Problem.aggregate(W)[source]#

Return the problem of aggregated observations.

Each input on the observations goes through the same aggregation \(W\): the observations \(W z\), the forward operator \(W H\), the model-data mismatch \(W S_z W^T\) and the offset \(W c\). Each keeps the cheapest form (a sparse \(W\) and a diagonal \(S_z\) give a sparse mismatch).

Parameters:

W (Operator) – The aggregation, such as fips.aggregate.mean()’s: its columns the observations’ labels (in any order), its rows the aggregated observations.

Returns:

The problem (of the same class) on the aggregated observations, with the same prior and prior covariance.

Return type:

Problem

Raises:
  • TypeError – If W is not an Operator.

  • ValueError – If the columns of W do not have exactly the observations’ labels.

Examples

>>> import numpy as np
>>> import pandas as pd
>>> import fips
>>> times = pd.date_range("2020-01-01", periods=4, freq="12h", name="obs_time")
>>> obs = fips.Vector.from_series(
...     pd.Series([1.0, 2.0, 3.0, 4.0], index=times), block="co2"
... )
>>> prior = fips.Vector.from_series(
...     pd.Series(0.0, index=pd.Index(["a"], name="cell")), block="flux"
... )
>>> problem = fips.Problem(
...     prior=prior,
...     prior_cov=fips.Independent().with_std(1.0),
...     obs=obs,
...     obs_cov=fips.Independent().with_std(1.0),
...     forward=fips.Operator(np.ones((4, 1)), obs.space, prior.space),
... )
>>> W = fips.aggregate.mean(
...     obs.space, by=pd.Grouper(level="obs_time", freq="1D")
... )
>>> daily = problem.aggregate(W)
>>> daily.obs.values, daily.obs_cov.variances.values
(array([1.5, 3.5]), array([0.5, 0.5]))