Skip to content

Commit

Permalink
Add ecl2df as utility (#198)
Browse files Browse the repository at this point in the history
* Add utilities submodule

* Add reek test data from ecl2df

* Add module ecl2csv to utilities

* Rename to sim2sumo

* Add code for installing SIM2SUMO in ert

* Add ecl2df and ert as requirement

* Add sim2sumo as console script

* Add tidy func to clean up ecl2dfs mess when rft is exctracted

Co-authored-by: Runar Ask Johannessen <[email protected]>
Co-authored-by: Ådne Jacobsen <[email protected]>
  • Loading branch information
3 people authored Aug 31, 2023
1 parent fd70c50 commit e348f5b
Show file tree
Hide file tree
Showing 29 changed files with 72,146 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,6 @@ _venv
src/fmu/sumo/version.py

# local expermentation
testing.ipynb
testing.ipynb
# files generated during testing
*.csv
4 changes: 3 additions & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ sumo-wrapper-python
xtgeo
azure-core
pyarrow; python_version > "3.6.1"
# ert
ert
ecl2df
fmu-dataio
OpenVDS; sys_platform != 'darwin'
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def parse_requirements(fname):
"sumo_upload = fmu.sumo.uploader.scripts.sumo_upload",
],
"console_scripts": [
"sumo_upload=fmu.sumo.uploader.scripts.sumo_upload:main"
"sumo_upload=fmu.sumo.uploader.scripts.sumo_upload:main",
"sim2sumo=fmu.sumo.utilities.scripts.sim2sumo:main",
],
},
cmdclass=CMDCLASS,
Expand Down
25 changes: 25 additions & 0 deletions src/fmu/sumo/config_jobs/SIM2SUMO
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- This forward model uploads results from reservoir simulators eclipse or opm
-- to sumo. It is called from the ERT config file as a regular forward model

-- Arguments:
-- S2S_CONF_PATH: path to config
-- SUMO_ENV: sumo environment to upload to

DEFAULT <S2S_CONF_PATH> fmuconfig/output/global_variables.yml
DEFAULT <SUMO_ENV> prod

STDERR sim2sumo.stderr
STDOUT sim2sumo.stdout


EXECUTABLE sim2sumo

ARGLIST execute "--config_path" <S2S_CONF_PATH> "--env" <SUMO_ENV>

MIN_ARG 5
MAX_ARG 5
ARG_TYPE 0 STRING
ARG_TYPE 1 STRING
ARG_TYPE 2 STRING
ARG_TYPE 3 STRING
ARG_TYPE 4 STRING
Empty file.
91 changes: 91 additions & 0 deletions src/fmu/sumo/utilities/scripts/sim2sumo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env python

"""Upload data to Sumo from FMU."""

import warnings
import os
import argparse
import logging
from pathlib import Path
from ert.shared.plugins.plugin_manager import hook_implementation
from ert.shared.plugins.plugin_response import plugin_response
from ert import ErtScript
from fmu.sumo.utilities.sim2sumo import parse_args, upload_with_config

LOGGER = logger = logging.getLogger(__name__)

DESCRIPTION = """SIM2SUMO uploads results from reservoir simulators directly to sumo.
Typically this is run per realization. The upload is controlled by a yaml config file
SIM2SUMO is implemented both as a FORWARD_JOB and can be called only from this context
when running ERT."""

EXAMPLES = """
FOR full blown example add this to your ert config:
FORWARD_MODEL SIM2SUMO(<S2S_CONF_PATH>= <your config location>, <SUMO_ENV>=<sumo env to upload to>)
<S2S_CONFIG_PATH> refers to the config file that controls the upload. This file can be a regular
fmu config file, or a completely separate file, but needs to be in yaml format, and contain
a section called sim2sumo to produce any results. Defaults to fmuconfig/output/global_variables.yml
<SUMO_ENV> refers to the sumo environment to upload to. Defaults to prod
For minimum amount of clutter in your ert config utilize the defaults. This means that if you
add section sim2sumo to the fmu config file, and store it at the recommendation and upload to
the prod environment for sumo then your call in the ert config can be reduced to
FORWARD_MODEL SIM2SUMO."""


class Sim2Sumo(ErtScript):
"""A class with a run() function that can be registered as an ERT plugin.
This is used for the ERT workflow context."""

# pylint: disable=too-few-public-methods
def run(self):
# pylint: disable=no-self-use
"""Parse with a simplified command line parser, for ERT only,
call sumo_upload_main()"""
logger.debug("Calling run() on Sim2Sumo")
args = parse_args()

upload_with_config(args.config_path, args.env)


# @hook_implementation
# def legacy_ertscript_workflow(config):
# """Hook the Sim2Sumo class into ERT with the name SIM2SUMO,
# and inject documentation"""
# workflow = config.add_workflow(Sim2Sumo, "SIM2SUMO")
# workflow.parser = _get_parser
# workflow.description = DESCRIPTION
# workflow.examples = EXAMPLES
# workflow.category = "export"


def main():
"""Main function, to be executed as console script"""
args = parse_args()
upload_with_config(args.config_path, args.env)


@hook_implementation
@plugin_response(plugin_name="SIM2SUMO")
def job_documentation(job_name):
"""Add job documentation for forward model
Args:
job_name (str): name of job
Returns:
dict: the documentation to be provided
"""
if job_name != "SIM2SUMO":
return None

return {
"description": DESCRIPTION,
"examples": EXAMPLES,
"category": "export",
}
Loading

0 comments on commit e348f5b

Please sign in to comment.