fips.aggregate.mean#
- fips.aggregate.mean(space, by, blocks=None, dropna=False)[source]#
Return the operator that averages the labels of space by group.
- Parameters:
space (
Space) – The labels to average: the observations’ or the state’s.blocks (
str|Sequence[str] |None) – The blocks to average, each on its own; every block by default. A block not named is passed through, one row for each of its labels (left out with dropna).dropna (
bool) – Leave out the labels a key cannot place and the blocks not named in blocks, assum()does; a mean is over the labels kept.
- Returns:
\(W\), sparse, with one row per group (
1/nfor each of itsnlabels) and space as its columns, its rows labeled assum()labels them. \(W S W^T\) divides the variance of independent errors byn.- Return type:
- Raises:
TypeError – If space is not a Space, or a key is of another kind.
ValueError – As
sum().
See also
sumThe operator that sums by group.
fips.Problem.aggregateThe problem of aggregated observations.
Examples
Hourly observations at two sites, to daily means at each:
>>> import numpy as np >>> import pandas as pd >>> import fips >>> labels = pd.MultiIndex.from_product( ... [["A", "B"], pd.date_range("2020-01-01", periods=4, freq="12h")], ... names=["site", "obs_time"], ... ) >>> obs = fips.Vector.from_series( ... pd.Series(np.arange(8.0), index=labels), block="co2" ... ) >>> W = fips.aggregate.mean( ... obs.space, by=["site", pd.Grouper(level="obs_time", freq="1D")] ... ) >>> W.rows.select("co2") MultiIndex([('A', '2020-01-01'), ('A', '2020-01-02'), ('B', '2020-01-01'), ('B', '2020-01-02')], names=['site', 'obs_time']) >>> (W @ obs).values array([0.5, 2.5, 4.5, 6.5])