-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAINT: Port forward_models to new ERT Plugin system
- Loading branch information
Showing
15 changed files
with
262 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from __future__ import annotations | ||
|
||
from .grid3d_aggregate_map import Grid3dAggregateMap | ||
from .grid3d_average_map import Grid3dAverageMap | ||
from .grid3d_hc_thickness import Grid3dHcThickness | ||
from .grid3d_migration_time import Grid3dMigrationTime | ||
|
||
__all__ = [ | ||
"Grid3dAggregateMap", | ||
"Grid3dAverageMap", | ||
"Grid3dHcThickness", | ||
"Grid3dMigrationTime", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import annotations | ||
|
||
from ert import ( | ||
ForwardModelStepDocumentation, | ||
ForwardModelStepJSON, | ||
ForwardModelStepPlugin, | ||
) | ||
|
||
from grid3d_maps.aggregate.grid3d_aggregate_map import DESCRIPTION | ||
|
||
|
||
class Grid3dAggregateMap(ForwardModelStepPlugin): | ||
def __init__(self) -> None: | ||
super().__init__( | ||
name="GRID3D_AGGREGATE_MAP", | ||
command=[ | ||
"grid3d_aggregate_map", | ||
"--config", | ||
"<CONFIG_AGGREGATE>", | ||
"--eclroot", | ||
"<ECLROOT>", | ||
], | ||
) | ||
|
||
def validate_pre_realization_run( | ||
self, fm_step_json: ForwardModelStepJSON | ||
) -> ForwardModelStepJSON: | ||
return fm_step_json | ||
|
||
def validate_pre_experiment(self, fm_step_json: ForwardModelStepJSON) -> None: | ||
return fm_step_json | ||
|
||
@staticmethod | ||
def documentation() -> ForwardModelStepDocumentation | None: | ||
return ForwardModelStepDocumentation( | ||
category="modelling.reservoir", | ||
source_package="grid3d_maps", | ||
source_function_name="Grid3dAggregateMap", | ||
description=DESCRIPTION, | ||
examples=""" | ||
.. code-block:: console | ||
FORWARD_MODEL GRID3D_AGGREGATE_MAP(<CONFIG_AGGREGATE>=conf.yml, <ECLROOT>=<ECLBASE>) | ||
""", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import annotations | ||
|
||
from ert import ( | ||
ForwardModelStepDocumentation, | ||
ForwardModelStepJSON, | ||
ForwardModelStepPlugin, | ||
) | ||
|
||
from grid3d_maps.avghc.grid3d_average_map import DESCRIPTION | ||
|
||
|
||
class Grid3dAverageMap(ForwardModelStepPlugin): | ||
def __init__(self) -> None: | ||
super().__init__( | ||
name="GRID3D_AVERAGE_MAP", | ||
command=[ | ||
"grid3d_average_map", | ||
"--config", | ||
"<CONFIG_AVGMAP>", | ||
"--eclroot", | ||
"<ECLROOT>", | ||
], | ||
) | ||
|
||
def validate_pre_realization_run( | ||
self, fm_step_json: ForwardModelStepJSON | ||
) -> ForwardModelStepJSON: | ||
return fm_step_json | ||
|
||
def validate_pre_experiment(self, fm_step_json: ForwardModelStepJSON) -> None: | ||
return fm_step_json | ||
|
||
@staticmethod | ||
def documentation() -> ForwardModelStepDocumentation | None: | ||
return ForwardModelStepDocumentation( | ||
category="modelling.reservoir", | ||
source_package="grid3d_maps", | ||
source_function_name="Grid3dAverageMap", | ||
description=DESCRIPTION, | ||
examples=""" | ||
.. code-block:: console | ||
FORWARD_MODEL GRID3D_AVERAGE_MAP(<CONFIG_AVGMAP>=conf.yml, <ECLROOT>=<ECLBASE>) | ||
""", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import annotations | ||
|
||
from ert import ( | ||
ForwardModelStepDocumentation, | ||
ForwardModelStepJSON, | ||
ForwardModelStepPlugin, | ||
) | ||
|
||
from grid3d_maps.avghc.grid3d_hc_thickness import DESCRIPTION | ||
|
||
|
||
class Grid3dHcThickness(ForwardModelStepPlugin): | ||
def __init__(self) -> None: | ||
super().__init__( | ||
name="GRID3D_HC_THICKNESS", | ||
command=[ | ||
"grid3d_hc_thickness", | ||
"--config", | ||
"<CONFIG_HCMAP>", | ||
"--eclroot", | ||
"<ECLROOT>", | ||
], | ||
) | ||
|
||
def validate_pre_realization_run( | ||
self, fm_step_json: ForwardModelStepJSON | ||
) -> ForwardModelStepJSON: | ||
return fm_step_json | ||
|
||
def validate_pre_experiment(self, fm_step_json: ForwardModelStepJSON) -> None: | ||
return fm_step_json | ||
|
||
@staticmethod | ||
def documentation() -> ForwardModelStepDocumentation | None: | ||
return ForwardModelStepDocumentation( | ||
category="modelling.reservoir", | ||
source_package="grid3d_maps", | ||
source_function_name="Grid3dHcThickness", | ||
description=DESCRIPTION, | ||
examples=""" | ||
.. code-block:: console | ||
FORWARD_MODEL GRID3D_HC_THICKNESS(<CONFIG_HCMAP>=conf.yml, <ECLROOT>=<ECLBASE>) | ||
""", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import annotations | ||
|
||
from ert import ( | ||
ForwardModelStepDocumentation, | ||
ForwardModelStepJSON, | ||
ForwardModelStepPlugin, | ||
) | ||
|
||
from grid3d_maps.aggregate.grid3d_migration_time import DESCRIPTION | ||
|
||
|
||
class Grid3dMigrationTime(ForwardModelStepPlugin): | ||
def __init__(self) -> None: | ||
super().__init__( | ||
name="GRID3D_MIGRATION_TIME", | ||
command=[ | ||
"grid3d_migration_time", | ||
"--config", | ||
"<CONFIG_MIGTIME>", | ||
"--eclroot", | ||
"<ECLROOT>", | ||
], | ||
) | ||
|
||
def validate_pre_realization_run( | ||
self, fm_step_json: ForwardModelStepJSON | ||
) -> ForwardModelStepJSON: | ||
return fm_step_json | ||
|
||
def validate_pre_experiment(self, fm_step_json: ForwardModelStepJSON) -> None: | ||
return fm_step_json | ||
|
||
@staticmethod | ||
def documentation() -> ForwardModelStepDocumentation | None: | ||
return ForwardModelStepDocumentation( | ||
category="modelling.reservoir", | ||
source_package="grid3d_maps", | ||
source_function_name="Grid3dMigrationTime", | ||
description=DESCRIPTION, | ||
examples=""" | ||
.. code-block:: console | ||
FORWARD_MODEL GRID3D_MIGRATION_TIME(<CONFIG_MIGTIME>=conf.yml, <ECLROOT>=<ECLBASE>) | ||
""", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,27 @@ | ||
import importlib | ||
import os | ||
import sys | ||
from pathlib import Path | ||
from __future__ import annotations | ||
|
||
try: | ||
from ert.shared.plugins.plugin_manager import hook_implementation | ||
from ert.shared.plugins.plugin_response import plugin_response | ||
except ModuleNotFoundError: | ||
from ert_shared.plugins.plugin_manager import hook_implementation | ||
from ert_shared.plugins.plugin_response import plugin_response | ||
|
||
PLUGIN_NAME = "grid3d_maps" | ||
|
||
|
||
def _get_jobs_from_directory(directory): | ||
resource_directory = Path(sys.modules[PLUGIN_NAME].__file__).parent / directory | ||
|
||
all_files = [ | ||
os.path.join(resource_directory, f) | ||
for f in os.listdir(resource_directory) | ||
if os.path.isfile(os.path.join(resource_directory, f)) | ||
] | ||
return {os.path.basename(path): path for path in all_files} | ||
import ert | ||
|
||
from grid3d_maps.forward_models import ( | ||
Grid3dAggregateMap, | ||
Grid3dAverageMap, | ||
Grid3dHcThickness, | ||
Grid3dMigrationTime, | ||
) | ||
|
||
@hook_implementation | ||
@plugin_response(plugin_name=PLUGIN_NAME) | ||
def installable_jobs(): | ||
return _get_jobs_from_directory("config_jobs") | ||
PLUGIN_NAME = "grid3d_maps" | ||
|
||
|
||
@hook_implementation | ||
@plugin_response(plugin_name=PLUGIN_NAME) | ||
def installable_workflow_jobs(): | ||
@ert.plugin(name=PLUGIN_NAME) | ||
def installable_workflow_jobs() -> dict[str, str]: | ||
return {} | ||
|
||
|
||
def _get_module_if_exists(module_name): | ||
try: | ||
script_module = importlib.import_module(module_name) | ||
except ImportError: | ||
return None | ||
return script_module | ||
|
||
|
||
@hook_implementation | ||
@plugin_response(plugin_name=PLUGIN_NAME) | ||
def job_documentation(job_name): | ||
subscript_jobs = set(installable_jobs().data.keys()) | ||
if job_name not in subscript_jobs: | ||
return None | ||
|
||
for sm in ["avghc", "aggregate"]: | ||
module_name = f"{PLUGIN_NAME}.{sm}.{job_name.lower()}" | ||
module = _get_module_if_exists(module_name) | ||
if module is not None: | ||
print(module_name) | ||
return { | ||
"description": getattr(module, "DESCRIPTION", ""), | ||
"examples": getattr(module, "EXAMPLES", ""), | ||
"category": getattr(module, "CATEGORY", "other"), | ||
} | ||
return None | ||
@ert.plugin(name=PLUGIN_NAME) | ||
def installable_forward_model_steps() -> list[ert.ForwardModelStepPlugin]: | ||
return [ | ||
Grid3dHcThickness, | ||
Grid3dAggregateMap, | ||
Grid3dAverageMap, | ||
Grid3dMigrationTime, | ||
] |
Oops, something went wrong.