Skip to content

Commit

Permalink
Review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Jun 19, 2024
1 parent 86bd079 commit f57e396
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING, Any, List

import pandas as pd

from ert import ErtScript
from ert.exceptions import StorageError
Expand All @@ -22,13 +24,9 @@ class ExportMisfitDataJob(ErtScript):
"""

def run(
self,
ert_config: ErtConfig,
ensemble: Ensemble,
target_file: Optional[str] = None,
self, ert_config: ErtConfig, ensemble: Ensemble, workflow_args: List[Any]
) -> None:
if target_file is None:
target_file = "misfit.hdf"
target_file = "misfit.hdf" if not workflow_args else workflow_args[0]

realizations = ensemble.get_realization_with_responses()

Expand All @@ -38,6 +36,6 @@ def run(
misfit = facade.load_all_misfit_data(ensemble)
if realizations.size == 0 or misfit.empty:
raise StorageError("No responses loaded")
misfit.columns = [val.split(":")[1] for val in misfit.columns]
misfit.columns = pd.Index([val.split(":")[1] for val in misfit.columns])
misfit = misfit.drop("TOTAL", axis=1)
misfit.to_hdf(target_file, key="misfit", mode="w")
10 changes: 3 additions & 7 deletions src/ert/shared/hook_implementations/workflows/export_runpath.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, List, Optional, Tuple
from typing import TYPE_CHECKING, Any, List, Tuple

from ert.config import ErtScript
from ert.runpaths import Runpaths
Expand Down Expand Up @@ -33,12 +33,8 @@ class ExportRunpathJob(ErtScript):
file.
"""

def run(
self, ert_config: ErtConfig, workflow_args: Optional[List[str]] = None
) -> None:
input_ranges = workflow_args[0] if len(workflow_args) != 0 else None
input_ranges = [] if input_ranges is None else input_ranges
_args = " ".join(input_ranges).split() # Make sure args is a list of words
def run(self, ert_config: ErtConfig, workflow_args: List[Any]) -> None:
_args = " ".join(workflow_args).split() # Make sure args is a list of words
run_paths = Runpaths(
jobname_format=ert_config.model_config.jobname_format_string,
runpath_format=ert_config.model_config.runpath_format_string,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/all/plugins/test_export_misfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
reason="https://github.com/equinor/ert/issues/7533",
)
def test_export_misfit(snake_oil_case_storage, snake_oil_default_storage, snapshot):
ExportMisfitDataJob().run(snake_oil_case_storage, snake_oil_default_storage)
ExportMisfitDataJob().run(snake_oil_case_storage, snake_oil_default_storage, [])
result = pd.read_hdf("misfit.hdf").round(10)
snapshot.assert_match(
result.to_csv(),
Expand All @@ -25,7 +25,7 @@ def test_export_misfit(snake_oil_case_storage, snake_oil_default_storage, snapsh

def test_export_misfit_no_responses_in_storage(poly_case, new_ensemble):
with pytest.raises(StorageError, match="No responses loaded"):
ExportMisfitDataJob().run(poly_case, new_ensemble)
ExportMisfitDataJob().run(poly_case, new_ensemble, [])


def test_export_misfit_data_job_is_loaded():
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/all/plugins/test_export_runpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def writing_setup(setup_case):

def test_export_runpath_empty_range(writing_setup):
writing_setup, config = writing_setup
writing_setup.export_job.run(config)
writing_setup.export_job.run(config, [])

writing_setup.write_mock.assert_called_with(
[0],
Expand Down
5 changes: 4 additions & 1 deletion tests/unit_tests/gui/plottery/test_plotting_of_snake_oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ert.services import StorageService
from ert.storage import open_storage


# Use a fixture for the fligure in order for the lifetime
# of the c++ gui element to not go out before mpl_image_compare
@pytest.fixture(
Expand All @@ -40,7 +41,9 @@ def plot_figure(qtbot, snake_oil_case_storage, request):
with StorageService.init_service(
project=snake_oil_case_storage.ert_config.ens_path,
), open_storage(snake_oil_case_storage.ert_config.ens_path) as storage:
gui = _setup_main_window(snake_oil_case_storage, args_mock, log_handler, storage)
gui = _setup_main_window(
snake_oil_case_storage, args_mock, log_handler, storage
)
qtbot.addWidget(gui)

plot_tool = gui.tools["Create plot"]
Expand Down

0 comments on commit f57e396

Please sign in to comment.