@@ -61,80 +61,91 @@ def _mock_summary_response(realization: int) -> pl.DataFrame:
6161 )
6262
6363
64- @pytest .fixture
65- def plot_figure (use_tmpdir , qtbot : QtBot ):
66- config = _breakthrough_config ()
67-
68- def dump_all (configurations ):
69- return [c .model_dump (mode = "json" ) for c in configurations ]
70-
71- with open_storage (config .ens_path , mode = "w" ) as storage :
72- experiment = storage .create_experiment (
73- experiment_config = {
74- "parameter_configuration" : dump_all (
75- config .ensemble_config .parameter_configuration
76- ),
77- "response_configuration" : dump_all (
78- config .ensemble_config .response_configuration
79- ),
80- "derived_response_configuration" : dump_all (
81- config .ensemble_config .derived_response_configuration
82- ),
83- "observations" : dump_all (config .observation_declarations ),
84- "ert_templates" : config .ert_templates ,
85- },
86- name = "breakthrough-experiment" ,
87- )
88- ensemble = experiment .create_ensemble (
89- ensemble_size = config .runpath_config .num_realizations ,
90- name = "prior" ,
91- )
92-
93- for realization in range (config .runpath_config .num_realizations ):
94- ensemble .save_response (
95- "summary" , _mock_summary_response (realization ), realization
64+ def create_breakthrough_figure (plot_tab_name : str ):
65+ @pytest .fixture
66+ def plot_figure (use_tmpdir , qtbot : QtBot ):
67+ config = _breakthrough_config ()
68+
69+ def dump_all (configurations ):
70+ return [c .model_dump (mode = "json" ) for c in configurations ]
71+
72+ with open_storage (config .ens_path , mode = "w" ) as storage :
73+ experiment = storage .create_experiment (
74+ experiment_config = {
75+ "parameter_configuration" : dump_all (
76+ config .ensemble_config .parameter_configuration
77+ ),
78+ "response_configuration" : dump_all (
79+ config .ensemble_config .response_configuration
80+ ),
81+ "derived_response_configuration" : dump_all (
82+ config .ensemble_config .derived_response_configuration
83+ ),
84+ "observations" : dump_all (config .observation_declarations ),
85+ "ert_templates" : config .ert_templates ,
86+ },
87+ name = "breakthrough-experiment" ,
9688 )
97- breakthrough_response = experiment .derived_response_configuration [
98- "breakthrough"
99- ].derive_from_storage (0 , realization , ensemble )
100- ensemble .save_response ("breakthrough" , breakthrough_response , realization )
101-
102- open_storage (config .ens_path , mode = "r" )
103-
104- with ErtServerController .init_service (
105- project = config .ens_path ,
106- ):
107- args_mock = Mock ()
108- args_mock .config = "breakthrough.ert"
109- gui = _setup_main_window (config , args_mock , Mock (), config .ens_path )
110- qtbot .addWidget (gui )
111-
112- button_plot_tool = get_child (gui , QToolButton , name = "button_Create_plot" )
113-
114- qtbot .mouseClick (button_plot_tool , Qt .MouseButton .LeftButton )
115- plot_window = get_child (gui , PlotWindow )
116- central_tab = plot_window ._central_tab
117-
118- data_types = get_child (plot_window , DataTypeKeysWidget )
119- key_list = data_types .data_type_keys_widget
120- key_model = key_list .model ()
121-
122- for key_index in range (key_model .rowCount ()):
123- to_select = data_types .model .itemAt (data_types .model .index (key_index , 0 ))
124- assert to_select is not None
125- if to_select .key == "BREAKTHROUGH:WWCT:OP1" :
126- key_list .setCurrentIndex (key_model .index (key_index , 0 ))
127- selected_key = to_select
128- for tab_index , tab in enumerate (plot_window ._plot_widgets ):
129- if tab .name == ENSEMBLE :
130- assert central_tab .isTabEnabled (tab_index )
131- central_tab .setCurrentWidget (tab )
132- assert (
133- selected_key .dimensionality == tab ._plotter .dimensionality
134- )
135- yield tab ._figure .figure
136-
137- plot_window .close ()
89+ ensemble = experiment .create_ensemble (
90+ ensemble_size = config .runpath_config .num_realizations ,
91+ name = "prior" ,
92+ )
93+
94+ for realization in range (config .runpath_config .num_realizations ):
95+ ensemble .save_response (
96+ "summary" , _mock_summary_response (realization ), realization
97+ )
98+ breakthrough_response = experiment .derived_response_configuration [
99+ "breakthrough"
100+ ].derive_from_storage (0 , realization , ensemble )
101+ ensemble .save_response (
102+ "breakthrough" , breakthrough_response , realization
103+ )
104+
105+ open_storage (config .ens_path , mode = "r" )
106+
107+ with ErtServerController .init_service (
108+ project = config .ens_path ,
109+ ):
110+ args_mock = Mock ()
111+ args_mock .config = "breakthrough.ert"
112+ gui = _setup_main_window (config , args_mock , Mock (), config .ens_path )
113+ qtbot .addWidget (gui )
114+
115+ button_plot_tool = get_child (gui , QToolButton , name = "button_Create_plot" )
116+
117+ qtbot .mouseClick (button_plot_tool , Qt .MouseButton .LeftButton )
118+ plot_window = get_child (gui , PlotWindow )
119+ central_tab = plot_window ._central_tab
120+
121+ data_types = get_child (plot_window , DataTypeKeysWidget )
122+ key_list = data_types .data_type_keys_widget
123+ key_model = key_list .model ()
124+
125+ for key_index in range (key_model .rowCount ()):
126+ to_select = data_types .model .itemAt (
127+ data_types .model .index (key_index , 0 )
128+ )
129+ assert to_select is not None
130+ if to_select .key == "BREAKTHROUGH:WWCT:OP1" :
131+ key_list .setCurrentIndex (key_model .index (key_index , 0 ))
132+ selected_key = to_select
133+ for tab_index , tab in enumerate (plot_window ._plot_widgets ):
134+ if tab .name == plot_tab_name :
135+ assert central_tab .isTabEnabled (tab_index )
136+ central_tab .setCurrentWidget (tab )
137+ assert (
138+ selected_key .dimensionality
139+ == tab ._plotter .dimensionality
140+ )
141+ yield tab ._figure .figure
142+
143+ plot_window .close ()
144+
145+ return plot_figure
146+
147+
148+ plot_figure = create_breakthrough_figure (ENSEMBLE )
138149
139150
140151@pytest .mark .mpl_image_compare (tolerance = 10.0 )
0 commit comments