Skip to content

Commit

Permalink
Move forward model docs to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Yngve S. Kristiansen authored and yngve-sk committed Jun 21, 2024
1 parent f26cc2e commit f8ff2ec
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 63 deletions.
141 changes: 140 additions & 1 deletion src/semeio/forward_models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from typing import Optional

from ert import ForwardModelStepJSON, ForwardModelStepPlugin
from ert.config.forward_model_step import ForwardModelStepDocumentation

from .scripts.design2params import description as design2params_description
from .scripts.design_kw import description as design_kw_description


class Design2Params(ForwardModelStepPlugin):
Expand All @@ -22,6 +28,15 @@ def validate_pre_realization_run(
def validate_pre_experiment(self, fm_step_json: ForwardModelStepJSON) -> None:
return fm_step_json

@staticmethod
def documentation() -> Optional[ForwardModelStepDocumentation]:
return ForwardModelStepDocumentation(
category="utility.templating",
source_package="semeio",
source_function_name="Design2Params",
description=design2params_description,
)


class DesignKW(ForwardModelStepPlugin):
def __init__(self):
Expand All @@ -38,6 +53,18 @@ def validate_pre_realization_run(
def validate_pre_experiment(self, fm_step_json: ForwardModelStepJSON) -> None:
pass

@staticmethod
def documentation() -> Optional[ForwardModelStepDocumentation]:
return ForwardModelStepDocumentation(
category="utility.templating",
source_package="semeio",
source_function_name="DesignKW",
description=design_kw_description,
)


from .scripts.gendata_rft import description as gendata_rft_description


class GenDataRFT(ForwardModelStepPlugin):
def __init__(self):
Expand Down Expand Up @@ -65,6 +92,53 @@ def __init__(self):
},
)

@staticmethod
def documentation() -> Optional[ForwardModelStepDocumentation]:
return ForwardModelStepDocumentation(
category="utility.transformation",
source_package="semeio",
source_function_name="GenDataRFT",
examples="""
Setup a file with well-names and associated date of RFT data in a file called
e.g. ``well_date_rft.txt``::
-- well YYYY-MM-DD report_step
A-1 2000-02-01 0
A directory with trajectory files must be prepared, which must contain one
file for each well mentioned in the file above. A file in this directory
could look like::
-- utmx utmy depth_MD depth_TVD zone
462608.57 5934210.96 1674.44 1624.38 Upper -- cell 29 28 2
(add more lines for more points).
A zonemap-file is a text-file with k-index and zone-name pr line, e.g a file
named ``layer_zone_table.txt``::
1 Upper
2 Upper
3 Lower
4 Lower
In the ert config, after running the Eclipse (or similiar) forward model, add::
DEFINE RFT_INPUT <CONFIG_PATH>/../input/observations/rft
FORWARD_MODEL MAKE_DIRECTORY(<DIRECTORY>=gendata_rft)
FORWARD_MODEL GENDATA_RFT(<PATH_TO_TRAJECTORY_FILES>=<RFT_INPUT>/rft/, <WELL_AND_TIME_FILE>=<RFT_INPUT>/well_date_rft.txt, <ZONEMAP>=<RFT_INPUT>/layer_zone_table.txt, <OUTPUTDIRECTORY>=gendata_rft)
For assisted history matching, add ``GEN_DATA`` statements to the ert config::
GEN_DATA A-1 RESULT_FILE:gendata_rft/RFT_A-1_%d INPUT_FORMAT:ASCII REPORT_STEPS:0
""",
description=gendata_rft_description,
)


from .scripts.overburden_timeshift import description as ots_description


class OTS(ForwardModelStepPlugin):
def __init__(self):
Expand All @@ -73,6 +147,18 @@ def __init__(self):
command=["overburden_timeshift", "-c", "<CONFIG>"],
)

@staticmethod
def documentation() -> Optional[ForwardModelStepDocumentation]:
return ForwardModelStepDocumentation(
category="modelling.surface",
source_package="semeio",
source_function_name="OTS",
description=ots_description,
)


from .scripts.fm_pyscal import description as pyscal_description


class Pyscal(ForwardModelStepPlugin):
def __init__(self):
Expand All @@ -98,6 +184,24 @@ def __init__(self):
},
)

@staticmethod
def documentation() -> Optional[ForwardModelStepDocumentation]:
return ForwardModelStepDocumentation(
category="modelling.reservoir",
source_package="semeio",
source_function_name="Pyscal",
description=pyscal_description,
examples="""
.. code-block:: none
FORWARD_MODEL PYSCAL(<PARAMETER_FILE>=scalinput.xlsx, <RESULT_FILE>=eclipse/include/props/relperm.inc, <SHEETNAME>=alternativerecommendation)
FORWARD_MODEL PYSCAL(<PARAMETER_FILE>=scalinput.xlsx, <RESULT_FILE>=eclipse/include/props/relperm.inc, <INT_PARAM_WO_NAME>=RELPERM_INTERP)
FORWARD_MODEL PYSCAL(<PARAMETER_FILE>=scalinput.xlsx, <RESULT_FILE>=eclipse/include/props/relperm.inc, <INT_PARAM_WO_NAME>=RELPERM_INTERP_WO, <INT_PARAM_GO_NAME>=RELPERM_INTERP_GO)
FORWARD_MODEL PYSCAL(<PARAMETER_FILE>=scalinput.xlsx, <RESULT_FILE>=eclipse/include/props/relperm.inc, <FAMILY>=2) -- for Eclipse family 2 output
""",
)


class InsertNoSim(ForwardModelStepPlugin):
def __init__(self):
Expand All @@ -111,6 +215,17 @@ def __init__(self):
],
)

@staticmethod
def documentation() -> Optional[ForwardModelStepDocumentation]:
return ForwardModelStepDocumentation(
category="utility.file_system",
source_package="semeio",
source_function_name="InsertNoSim",
description="""
Inserts a NOSIM for every RUNSPEC occurrence in the file
""",
)


class RemoveNoSim(ForwardModelStepPlugin):
def __init__(self):
Expand All @@ -119,13 +234,37 @@ def __init__(self):
command=["sed", "-i", "/^NOSIM/d", "<ECLBASE>.DATA"],
)

@staticmethod
def documentation() -> Optional[ForwardModelStepDocumentation]:
return ForwardModelStepDocumentation(
category="utility.file_system",
source_package="semeio",
source_function_name="RemoveNoSim",
description="Remove all NOSIM lines from <ECLBASE>.DATA file",
)


class ReplaceStringConfig(ForwardModelStepPlugin):
from .scripts.replace_string import description as replace_string_description


class ReplaceString(ForwardModelStepPlugin):
def __init__(self):
super().__init__(
name="REPLACE_STRING",
command=["replace_string", "-o", "<FROM>", "-n", "<TO>", "-f", "<FILE>"],
)

@staticmethod
def documentation() -> Optional[ForwardModelStepDocumentation]:
return ForwardModelStepDocumentation(
category="utility.file_system",
source_package="semeio",
source_function_name="ReplaceString",
description=replace_string_description,
examples="""
| REPLACE_STRING(<FROM>=hello,<TO>=world,<FILE>=some_file.txt
""",
)


__all__ = ["Design2Params"]
2 changes: 0 additions & 2 deletions src/semeio/forward_models/scripts/design2params.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
before you run DESIGN_KW.
"""

category = "utility.templating"


def create_parser():
parser = argparse.ArgumentParser(description=description)
Expand Down
2 changes: 0 additions & 2 deletions src/semeio/forward_models/scripts/design_kw.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
``0.001``.
"""

category = "utility.templating"


def create_parser():
parser = argparse.ArgumentParser(description=description)
Expand Down
14 changes: 0 additions & 14 deletions src/semeio/forward_models/scripts/fm_pyscal.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@ def main_entry_point():
Run ``pyscal --help`` for syntax.
"""

examples = """
.. code-block:: none
FORWARD_MODEL PYSCAL(<PARAMETER_FILE>=scalinput.xlsx, <RESULT_FILE>=eclipse/include/props/relperm.inc, <SHEETNAME>=alternativerecommendation)
FORWARD_MODEL PYSCAL(<PARAMETER_FILE>=scalinput.xlsx, <RESULT_FILE>=eclipse/include/props/relperm.inc, <INT_PARAM_WO_NAME>=RELPERM_INTERP)
FORWARD_MODEL PYSCAL(<PARAMETER_FILE>=scalinput.xlsx, <RESULT_FILE>=eclipse/include/props/relperm.inc, <INT_PARAM_WO_NAME>=RELPERM_INTERP_WO, <INT_PARAM_GO_NAME>=RELPERM_INTERP_GO)
FORWARD_MODEL PYSCAL(<PARAMETER_FILE>=scalinput.xlsx, <RESULT_FILE>=eclipse/include/props/relperm.inc, <FAMILY>=2) -- for Eclipse family 2 output
""" # noqa


category = "modelling.reservoir"


def _get_args_parser():
"""Construct an argparse parser for fm_pyscal"""
Expand Down
37 changes: 0 additions & 37 deletions src/semeio/forward_models/scripts/gendata_rft.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,43 +46,6 @@
https://equinor.github.io/fmu-tools/create_rft_ertobs.html
"""

examples = """
Setup a file with well-names and associated date of RFT data in a file called
e.g. ``well_date_rft.txt``::
-- well YYYY-MM-DD report_step
A-1 2000-02-01 0
A directory with trajectory files must be prepared, which must contain one
file for each well mentioned in the file above. A file in this directory
could look like::
-- utmx utmy depth_MD depth_TVD zone
462608.57 5934210.96 1674.44 1624.38 Upper -- cell 29 28 2
(add more lines for more points).
A zonemap-file is a text-file with k-index and zone-name pr line, e.g a file
named ``layer_zone_table.txt``::
1 Upper
2 Upper
3 Lower
4 Lower
In the ert config, after running the Eclipse (or similiar) forward model, add::
DEFINE RFT_INPUT <CONFIG_PATH>/../input/observations/rft
FORWARD_MODEL MAKE_DIRECTORY(<DIRECTORY>=gendata_rft)
FORWARD_MODEL GENDATA_RFT(<PATH_TO_TRAJECTORY_FILES>=<RFT_INPUT>/rft/, <WELL_AND_TIME_FILE>=<RFT_INPUT>/well_date_rft.txt, <ZONEMAP>=<RFT_INPUT>/layer_zone_table.txt, <OUTPUTDIRECTORY>=gendata_rft)
For assisted history matching, add ``GEN_DATA`` statements to the ert config::
GEN_DATA A-1 RESULT_FILE:gendata_rft/RFT_A-1_%d INPUT_FORMAT:ASCII REPORT_STEPS:0
""" # noqa
category = "utility.transformation"


def _build_parser():
parser = argparse.ArgumentParser(description=description)
Expand Down
1 change: 0 additions & 1 deletion src/semeio/forward_models/scripts/overburden_timeshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
+ 2 * "\n"
+ _create_docs(OTSConfig.model_json_schema(by_alias=False, ref_template="{model}"))
)
category = "modelling.surface"


def _get_args_parser():
Expand Down
2 changes: 0 additions & 2 deletions src/semeio/forward_models/scripts/replace_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"""

category = "utility.templating"


def _get_args_parser():
parser = argparse.ArgumentParser(description=description)
Expand Down
4 changes: 2 additions & 2 deletions src/semeio/hook_implementations/forward_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
InsertNoSim,
Pyscal,
RemoveNoSim,
ReplaceStringConfig,
ReplaceString,
)


Expand Down Expand Up @@ -120,5 +120,5 @@ def installable_forward_model_steps():
Pyscal,
InsertNoSim,
RemoveNoSim,
ReplaceStringConfig,
ReplaceString,
]
4 changes: 2 additions & 2 deletions tests/hook_implementations/test_hook_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
InsertNoSim,
Pyscal,
RemoveNoSim,
ReplaceStringConfig,
ReplaceString,
)
from semeio.workflows.ahm_analysis import ahmanalysis
from semeio.workflows.csv_export2 import csv_export2
Expand All @@ -29,7 +29,7 @@ def test_that_installable_fm_steps_work_as_plugins():
assert OTS in fms
assert InsertNoSim in fms
assert RemoveNoSim in fms
assert ReplaceStringConfig in fms
assert ReplaceString in fms


def test_hook_implementations():
Expand Down

0 comments on commit f8ff2ec

Please sign in to comment.