Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ classifiers = [
dynamic = ["version"]
dependencies = [
"resdata",
"res2df",
"ert>=10.2.0b13",
"fmu-tools",
"grid3d_maps",
"matplotlib",
"numpy",
"opm>=2023.04",
"pandas",
"pydantic",
"pyscal",
Expand All @@ -55,6 +53,9 @@ dependencies = [
]

[project.optional-dependencies]
res2df = ["res2df"]
opm = ["opm"]
all = [res2f, opm]
tests = [
"mypy",
"pytest",
Expand Down
16 changes: 0 additions & 16 deletions src/subscript/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import sys
from pathlib import Path

try:
from importlib import metadata
Expand All @@ -10,21 +9,6 @@
pass


def detect_os(release_file: Path = Path("/etc/redhat-release")) -> str:
"""Detect operating system string in runtime, just use default if not found."""
default_os_version = "x86_64_RH_7"

if release_file.is_file():
with open(release_file, encoding="utf-8") as buffer:
tokens = buffer.read().split()
for t in tokens:
if "." in t:
major = t.split(".")[0]
return f"x86_64_RH_{major}"
raise ValueError("Could not detect RHEL version")
return default_os_version


def getLogger(module_name="subscript"):
"""Provides a unified logger for subscript scripts.

Expand Down
12 changes: 11 additions & 1 deletion src/subscript/check_swatinit/check_swatinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
import numpy as np
import numpy.typing as npt
import pandas as pd
import res2df

try:
import res2df

_HAS_RES2DF = True
except ImportError:
_HAS_RES2DF = False

import subscript
from subscript.check_swatinit import plotter
Expand Down Expand Up @@ -42,6 +48,10 @@ def main() -> None:

Acts on command line arguments, loads data, performs qc and dumps to
CSV if requested."""
if not _HAS_RES2DF:
sys.exit(
"Error 'res2df' is required for 'check_swatinit' to work.\n Please install using 'pip install subscript[res2df]' or similar."
)
parser = get_parser()
args = parser.parse_args()

Expand Down
6 changes: 3 additions & 3 deletions src/subscript/fmu_copy_revision/fmu_copy_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from os.path import join
from pathlib import Path

import subscript
from subscript import getLogger, __version__

logger = subscript.getLogger(__name__)
logger = getLogger(__name__)

DESCRIPTION = """This is a simple interactive script for copying a FMU revision folder
with features:
Expand Down Expand Up @@ -293,7 +293,7 @@ def get_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--version",
action="version",
version="%(prog)s (subscript version " + subscript.__version__ + ")",
version="%(prog)s (subscript version " + __version__ + ")",
)

logger.info("Parsing commandline")
Expand Down
4 changes: 2 additions & 2 deletions src/subscript/fmuobs/fmuobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import yaml

from subscript import __version__, getLogger
from subscript.fmuobs.parsers import (
from .parsers import (
compute_date_from_days,
ertobs2df,
obsdict2df,
resinsight_df2df,
)
from subscript.fmuobs.writers import (
from .writers import (
CLASS_SHORTNAME,
df2ertobs,
df2obsdict,
Expand Down
2 changes: 1 addition & 1 deletion src/subscript/fmuobs/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pandas as pd

from subscript import getLogger
from subscript.fmuobs.util import (
from .util import (
ERT_ALT_DATE_FORMAT,
ERT_DATE_FORMAT,
ERT_ISO_DATE_FORMAT,
Expand Down
2 changes: 1 addition & 1 deletion src/subscript/fmuobs/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pandas as pd

from subscript import getLogger
from subscript.fmuobs.util import (
from .util import (
CLASS_SHORTNAME,
ERT_ISO_DATE_FORMAT,
lowercase_dictkeys,
Expand Down
6 changes: 3 additions & 3 deletions src/subscript/grav_subs_maps/grav_subs_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from resdata.grid import Grid
from resdata.resfile import ResdataFile

import subscript
from subscript import getLogger, __version__

logger = subscript.getLogger(__name__)
logger = getLogger(__name__)

# Constant for subsidence modelling, not influencing results
# since subsidence is calculated from porevolume change
Expand Down Expand Up @@ -111,7 +111,7 @@ def get_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--version",
action="version",
version="%(prog)s (subscript version " + subscript.__version__ + ")",
version="%(prog)s (subscript version " + __version__ + ")",
)
return parser

Expand Down
6 changes: 3 additions & 3 deletions src/subscript/grav_subs_points/grav_subs_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from resdata.grid import Grid
from resdata.resfile import ResdataFile

import subscript
from subscript import getLogger, __version__

logger = subscript.getLogger(__name__)
logger = getLogger(__name__)

# Constant for subsidence modelling, not influencing results
# since subsidence is calculated from porevolume change RPORV
Expand Down Expand Up @@ -133,7 +133,7 @@ def get_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--version",
action="version",
version="%(prog)s (subscript version " + subscript.__version__ + ")",
version="%(prog)s (subscript version " + __version__ + ")",
)
return parser

Expand Down
18 changes: 14 additions & 4 deletions src/subscript/interp_relperm/interp_relperm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
import pyscal
import yaml
from pydantic import BaseModel, Field, FilePath, model_validator
from res2df import satfunc

import subscript
try:
from res2df import satfunc

logger = subscript.getLogger(__name__)
_HAS_RES2DF = True
except ImportError:
_HAS_RES2DF = False

from subscript import getLogger, __version__

logger = getLogger(__name__)

DESCRIPTION = """Interpolation script for relperm tables.

Expand Down Expand Up @@ -288,13 +294,17 @@ def get_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--version",
action="version",
version="%(prog)s (subscript version " + subscript.__version__ + ")",
version="%(prog)s (subscript version " + __version__ + ")",
)
return parser


def main() -> None:
"""Invocated from the command line, parsing command line arguments"""
if not _HAS_RES2DF:
sys.exit(
"Error 'res2df' is required for 'interp_relperm' to work.\n Please install using 'pip install subscript[res2df]' or similar."
)
parser = get_parser()
args = parser.parse_args()

Expand Down
6 changes: 3 additions & 3 deletions src/subscript/merge_rft_ertobs/merge_rft_ertobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import numpy as np
import pandas as pd

import subscript
from subscript import getLogger, __version__

logger = subscript.getLogger(__name__)
logger = getLogger(__name__)

DESCRIPTION = """Collect ERT RFT observations and merge with CSV output
from GENDATA_RFT. Dump to CSV file for visualization in Webviz.
Expand Down Expand Up @@ -64,7 +64,7 @@ def get_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--version",
action="version",
version="%(prog)s (subscript version " + subscript.__version__ + ")",
version="%(prog)s (subscript version " + __version__ + ")",
)
return parser

Expand Down
14 changes: 12 additions & 2 deletions src/subscript/presentvalue/presentvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
import datetime
import logging
from pathlib import Path

import sys
import numpy as np
import pandas as pd
import res2df

try:
import res2df

_HAS_RES2DF = True
except ImportError:
_HAS_RES2DF = False
import scipy.optimize

from subscript import __version__, getLogger
Expand Down Expand Up @@ -124,6 +130,10 @@ def main() -> None:
"""Function for command line invocation.

Parses command line arguments, and writes output to file and/or terminal."""
if not _HAS_RES2DF:
sys.exit(
"Error 'res2df' is required for 'presentvalue' to work.\n Please install using 'pip install subscript[res2df]' or similar."
)
parser = get_parser()
args = parser.parse_args()

Expand Down
14 changes: 12 additions & 2 deletions src/subscript/prtvol2csv/prtvol2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
import warnings
from datetime import datetime
from pathlib import Path

import sys
import pandas as pd
import res2df

try:
import res2df

_HAS_RES2DF = True
except ImportError:
_HAS_RES2DF = False
from fmu.tools.fipmapper.fipmapper import FipMapper

from subscript import __version__, getLogger
Expand Down Expand Up @@ -327,6 +333,10 @@ def reservoir_volumes_from_prt(prt_file: str, fipname: str = "FIPNUM") -> pd.Dat

def main() -> None:
"""Function for command line invocation"""
if not _HAS_RES2DF:
sys.exit(
"Error 'res2df' is required for 'prtvol2csv' to work.\n Please install using 'pip install subscript[res2df]' or similar."
)
args = get_parser().parse_args()

tablesdir = prep_output_dir(args.dir)
Expand Down
8 changes: 6 additions & 2 deletions src/subscript/rmsecl_volumetrics/rmsecl_volumetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import logging
from pathlib import Path
from typing import Any, cast

import sys
import pandas as pd
import yaml
from fmu.tools.fipmapper import fipmapper
from fmu.tools.rms import volumetrics

from subscript import getLogger
from subscript.prtvol2csv.prtvol2csv import currently_in_place_from_prt
from subscript.prtvol2csv.prtvol2csv import currently_in_place_from_prt, _HAS_RES2DF

logger = getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -143,6 +143,10 @@ def _disjoint_sets_to_dict(

def main() -> None:
"""Parse command line arguments and run"""
if not _HAS_RES2DF:
sys.exit(
"Error 'res2df' is required for 'rmsecl_volumetrics' to work.\n Please install using 'pip install subscript[res2df]' or similar."
)
args = get_parser().parse_args()

if args.PRTFILE.endswith("csv"):
Expand Down
6 changes: 5 additions & 1 deletion src/subscript/sector2fluxnum/completions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from res2df import ResdataFiles, compdat
try:
from res2df import ResdataFiles, compdat
_HAS_RES2DF = True
except ImportError:
_HAS_RES2DF=False


def get_completion_list(ecl_data_file_name):
Expand Down
8 changes: 6 additions & 2 deletions src/subscript/sector2fluxnum/sector2fluxnum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import cwrap
from resdata.grid import Grid
from resdata.resfile import FortIO, ResdataFile

from subscript.sector2fluxnum import completions, datafile_obj, flux_obj, fluxfile_obj
import sys
from . import completions, datafile_obj, flux_obj, fluxfile_obj

DESCRIPTION = """
The script sector2fluxnum will execute different steps in a workflow
Expand Down Expand Up @@ -225,6 +225,10 @@ def main():
"""
main method
"""
if not completions._HAS_RES2DF:
sys.exit(
"Error 'res2df' is required for 'sector2fluxnum' to work.\n Please install using 'pip install subscript[res2df]' or similar."
)
parser = get_parser()
input_args = parser.parse_args()

Expand Down
12 changes: 6 additions & 6 deletions src/subscript/summaryplot/summaryplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@

# Get rid of FutureWarning from pandas/plotting.py
from pandas.plotting import register_matplotlib_converters
from resdata.grid import Grid # type: ignore
from resdata.resfile import ResdataFile # type: ignore
from resdata.summary import Summary # type: ignore
from resdata.grid import Grid
from resdata.resfile import ResdataFile
from resdata.summary import Summary

import subscript
from subscript import getLogger, __version__

logger = subscript.getLogger(__name__)
logger = getLogger(__name__)

register_matplotlib_converters()

Expand Down Expand Up @@ -120,7 +120,7 @@ def get_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--version",
action="version",
version="%(prog)s (subscript version " + subscript.__version__ + ")",
version="%(prog)s (subscript version " + __version__ + ")",
)
return parser

Expand Down
Loading
Loading