|
1 | 1 | from datetime import datetime |
| 2 | +from itertools import starmap |
2 | 3 |
|
3 | 4 | import pandas as pd |
4 | 5 | import polars as pl |
@@ -149,27 +150,54 @@ def test_that_misfit_conversion_for_summary_converts_to_equivalent_long_polars_d |
149 | 150 | assert_frame_equal(result_df, expected_df) |
150 | 151 |
|
151 | 152 |
|
| 153 | +@pytest.mark.parametrize( |
| 154 | + ("data_origin", "key", "ensemble_specs", "ensemble_frames", "observation_data"), |
| 155 | + [ |
| 156 | + pytest.param( |
| 157 | + "summary", |
| 158 | + "FOPR", |
| 159 | + [("ensemble",)], |
| 160 | + [{"2023-01-01": [12.0]}], |
| 161 | + {0: [1.0, 10.0, "2023-01-02"]}, |
| 162 | + id="summary_key_index_mismatch", |
| 163 | + ), |
| 164 | + pytest.param( |
| 165 | + "seismic", |
| 166 | + "SEISMIC_KEY", |
| 167 | + [ |
| 168 | + ("ensemble_empty_1", "ensemble_empty_id_1"), |
| 169 | + ("ensemble_empty_2", "ensemble_empty_id_2"), |
| 170 | + ], |
| 171 | + [{"99": [1.0], "100": [2.0]}, {"99": [3.0], "100": [4.0]}], |
| 172 | + {0: [10.0, 100.0, "0"], 1: [10.0, 200.0, "5"]}, |
| 173 | + id="seismic_key_index_mismatch_all_ensembles", |
| 174 | + ), |
| 175 | + ], |
| 176 | +) |
152 | 177 | def test_that_misfits_plot_is_empty_when_no_misfit_data_is_available( |
153 | | - make_ensemble, make_plot_context, make_key_def |
| 178 | + data_origin, |
| 179 | + key, |
| 180 | + ensemble_specs, |
| 181 | + ensemble_frames, |
| 182 | + observation_data, |
| 183 | + make_ensemble, |
| 184 | + make_plot_context, |
| 185 | + make_key_def, |
154 | 186 | ): |
155 | | - ensemble = make_ensemble("ensemble") |
156 | | - plot_context = make_plot_context([ensemble]) |
157 | | - key_def = make_key_def() |
| 187 | + ensembles = list(starmap(make_ensemble, ensemble_specs)) |
| 188 | + plot_context = make_plot_context(ensembles, key=key) |
| 189 | + key_def = make_key_def(key=key, data_origin=data_origin) |
158 | 190 | figure = Figure() |
159 | 191 |
|
160 | 192 | MisfitsPlot().plot( |
161 | 193 | figure, |
162 | 194 | plot_context, |
163 | 195 | { |
164 | | - ensemble: pd.DataFrame( |
165 | | - {"2023-01-01": [12.0]}, |
166 | | - index=pd.Index([0], name="Realization"), |
167 | | - ) |
| 196 | + ensemble: pd.DataFrame(frame, index=pd.Index([0], name="Realization")) |
| 197 | + for ensemble, frame in zip(ensembles, ensemble_frames, strict=True) |
168 | 198 | }, |
169 | 199 | observation_data=pd.DataFrame( |
170 | | - data={ |
171 | | - 0: [1.0, 10.0, "2023-01-02"], |
172 | | - }, |
| 200 | + data=observation_data, |
173 | 201 | index=["STD", "OBS", "key_index"], |
174 | 202 | ), |
175 | 203 | std_dev_images={}, |
@@ -561,46 +589,3 @@ def test_that_seismic_misfit_plot_skips_ensembles_with_no_misfit_data( |
561 | 589 | assert xtick_labels == ["ensemble"] |
562 | 590 | assert len(figure.axes[0].patches) == 1 |
563 | 591 | assert figure.axes[0].get_xlim() == (-0.5, 0.5) |
564 | | - |
565 | | - |
566 | | -def test_that_seismic_misfit_plot_is_empty_when_no_ensemble_has_misfits( |
567 | | - make_ensemble, make_plot_context, make_key_def |
568 | | -): |
569 | | - ensembles = [ |
570 | | - make_ensemble("ensemble_empty_1", "ensemble_empty_id_1"), |
571 | | - make_ensemble("ensemble_empty_2", "ensemble_empty_id_2"), |
572 | | - ] |
573 | | - plot_context = make_plot_context( |
574 | | - ensembles, key="SEISMIC_KEY", plot_config=PlotConfig(title=None) |
575 | | - ) |
576 | | - key_def = make_key_def(key="SEISMIC_KEY", data_origin="seismic") |
577 | | - |
578 | | - figure = Figure() |
579 | | - |
580 | | - MisfitsPlot().plot( |
581 | | - figure, |
582 | | - plot_context, |
583 | | - { |
584 | | - ensembles[0]: pd.DataFrame( |
585 | | - {"99": [1.0], "100": [2.0]}, |
586 | | - index=pd.Index([0], name="Realization"), |
587 | | - ), |
588 | | - ensembles[1]: pd.DataFrame( |
589 | | - {"99": [3.0], "100": [4.0]}, |
590 | | - index=pd.Index([0], name="Realization"), |
591 | | - ), |
592 | | - }, |
593 | | - observation_data=pd.DataFrame( |
594 | | - data={ |
595 | | - 0: [10.0, 100.0, "0"], |
596 | | - 1: [10.0, 200.0, "5"], |
597 | | - }, |
598 | | - index=["STD", "OBS", "key_index"], |
599 | | - ), |
600 | | - std_dev_images={}, |
601 | | - obs_loc=None, |
602 | | - key_def=key_def, |
603 | | - ) |
604 | | - |
605 | | - assert len(figure.axes) == 1 |
606 | | - assert figure.axes[0].texts[0].get_text() == "No misfit data available" |
0 commit comments