Observations¶
Summary¶
File: src/observations.py
Standalone class (no inheritance). Generates or loads ground-truth data, applies a configurable manual bias, adds noise, and exposes observation time indices for the DA loop.
Key attributes:
| Attribute | Description |
|---|---|
y_true |
Clean biased truth signal (Nt, Nq, 1) |
y_raw |
Noisy observed signal (Nt, Nq, 1) |
b_true |
Applied bias (Nt, Nq, 1) |
t_true |
Full time vector |
y_obs, t_obs |
Observations at assimilation times |
obs_idx |
Indices into t_true at which observations are taken |
Nt_obs |
Subsampling rate (every Nt_obs steps) |
Noise options (noise_type): 'gauss, add', 'gauss, mult', coloured noise variants.
Manual bias options (manual_bias): 'linear', 'periodic', 'time', 'cosine', or any callable f(y_true, t_true) -> (b, name).
Key method: plot_truth(case) — five-panel figure (raw, truth, PDF, PSD, difference).
romda.observations.Observations(model=None, **kwargs)
¶
Reference truth and observations for (twin) data assimilation experiments.
The truth can be generated by integrating a Model (twin experiments), loaded
from a file (experimental data), or provided directly as arrays. A manual model
bias and measurement noise can be added on top, and the observations are sampled
from the raw data every Nt_obs time steps between t_start and t_stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
(Model, type[Model], str or None)
|
Source of the truth: a model instance/class to integrate, a filename to
load, or |
None
|
**kwargs
|
Time windows ( |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
y_raw |
ndarray
|
Raw (measured) data — biased truth plus noise — shape \((N_t, N_q, L)\), where \(L\) is the number of independent realizations. |
y_true |
ndarray
|
Biased truth (without measurement noise), shape \((N_t, N_q, L)\). |
b_true |
ndarray
|
Bias added to the truth (zero if no manual bias), shape \((N_t, N_q, L)\). |
t_true |
ndarray
|
Time points of the truth, shape \((N_t,)\). |
y_obs |
ndarray
|
Observations to assimilate (subset of |
t_obs |
ndarray
|
Observation times (subset of |
Notes
Measurement noise (kwargs add_noise, noise_level, noise_type) is drawn
either from a Gaussian, \(\epsilon_q(t) \sim \mathcal{N}(0, \texttt{noise\_level}^2)\),
or with a prescribed spectral colour (see colour_noise), and combined with the
(biased) truth \(\mathbf{y}\) as
selected via the 'add'/'mult' substring of noise_type.
Initializes the Observations object, loading or creating truth data, applying bias, adding noise, and interpolating to observation times.
Source code in src/observations.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
obs_idx
property
¶
Indices into t_true at which observations are sampled.
Raises:
| Type | Description |
|---|---|
AttributeError
|
If |
dt_obs
property
¶
Time between consecutive observations, Nt_obs * dt.
y_wash
property
¶
Raw data at the washout indices, shape \((N_\mathrm{wash}, N_q)\).
None unless include_washout=True was passed at construction.
t_wash
property
¶
Time points of the washout period, shape \((N_\mathrm{wash},)\).
None unless include_washout=True was passed at construction.
y_obs
property
¶
Observations to assimilate: y_raw sampled at obs_idx, shape \((N_\mathrm{obs}, N_q)\).
t_obs
property
¶
Observation times: t_true sampled at obs_idx, shape \((N_\mathrm{obs},)\).
y_raw
property
writable
¶
Raw (measured) data — biased truth plus noise. See class docstring for shape.
y_true
property
writable
¶
Biased truth (without measurement noise). See class docstring for shape.
t_true
property
writable
¶
Time points of the truth. See class docstring for shape.
name_truth
property
writable
¶
Descriptive name of the truth data (e.g. used to build result filenames).
update_obs_idx(t_start=None, t_stop=None, Nt_obs=None)
¶
Recompute obs_idx from a time window and sampling stride.
Any argument left as None falls back to the corresponding current
attribute (self.t_start, self.t_stop, self.Nt_obs); passing a
value updates that attribute in place before recomputing obs_idx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t_start
|
float
|
Start time of the observation window. |
None
|
t_stop
|
float
|
End time of the observation window. |
None
|
Nt_obs
|
int
|
Number of raw time steps between consecutive observations. |
None
|
Source code in src/observations.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
plot_truth(case, Nq=None, fig_width=12, window=None, f_max=None)
staticmethod
¶
Plot raw vs. true time series, PDFs, PSDs and their difference.
Produces a grid with one row per observable and 5 columns: raw signal, true signal, PDF, PSD, and the raw-minus-true difference (bias overlaid if present).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case
|
Observations
|
Instance providing |
required |
Nq
|
int
|
Number of observables to plot. Defaults to all observables in |
None
|
fig_width
|
float
|
Figure width in inches. Default 12. |
12
|
window
|
float
|
Length of the time window shown in the time-domain plots. Defaults to a fixed fraction of the available history. |
None
|
f_max
|
float
|
Maximum frequency shown on the PSD plots. |
None
|
Source code in src/observations.py
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | |