Skip to content

Commit

Permalink
Remove the output section from the well_trajectory config
Browse files Browse the repository at this point in the history
  • Loading branch information
verveerpj committed Jul 6, 2024
1 parent 1d6ff09 commit c0336e6
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 3,514 deletions.
33 changes: 5 additions & 28 deletions docs/reference/well_trajectory/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,43 +211,20 @@ wells:
# Default: null
platform: null

# Datatype: OutputsConfig map
# Datatype: Path
# Examples: /path/to/file.ext, /path/to/directory/
# Required: False
# Default: null
outputs:

# Datatype: boolean
# Choices: true, false
# Required: False
# Default: False
save_paths: false

# Datatype: Path
# Examples: /path/to/file.ext, /path/to/directory/
# Required: False
# Default: null
guide_points: null

# Datatype: Path
# Examples: /path/to/file.ext, /path/to/directory/
# Required: False
# Default: null
geometry: null

# Datatype: Path
# Examples: /path/to/file.ext, /path/to/directory/
# Required: False
# Default: null
npv_input: null
eclipse_model: null

# Datatype: Path
# Examples: /path/to/file.ext, /path/to/directory/
# Required: False
# Default: null
eclipse_model: null
resinsight_binary: null

# Datatype: Path
# Examples: /path/to/file.ext, /path/to/directory/
# Required: False
# Default: null
resinsight_binary: null
npv_input_file: null
8 changes: 4 additions & 4 deletions src/everest_models/jobs/fm_well_trajectory/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import logging
from pathlib import Path

from .outputs import write_guide_points
from .parser import build_argument_parser
Expand All @@ -24,15 +25,14 @@ def main_entry_point(args=None):
options.config.wells,
options.config.platforms,
)
if options.config.outputs.guide_points is not None:
logger.info(f"Writing guide points to: {options.config.outputs.guide_points}")
write_guide_points(guide_points, options.config.outputs.guide_points)
logger.info("Writing guide points to 'guide_points.json'")
write_guide_points(guide_points, Path("guide_points.json"))

if options.config.interpolation.type == "simple":
well_trajectory_simple(
options.config.wells,
options.config.interpolation,
options.config.outputs,
options.config.npv_input_file,
guide_points,
)

Expand Down
9 changes: 1 addition & 8 deletions src/everest_models/jobs/fm_well_trajectory/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ class WellConfig(ModelConfig):
platform: Annotated[str, Field(default=None, description="")]


class OutputsConfig(ModelConfig):
save_paths: Annotated[bool, Field(default=False, description="")]
guide_points: Annotated[Path, Field(default=None, description="")]
geometry: Annotated[Path, Field(default=None, description="")]
npv_input: Annotated[Path, Field(default=None, description="")]


class ConfigSchema(ModelConfig):
scales: Annotated[ScalesConfig, Field(description="")]
references: Annotated[ReferencesConfig, Field(description="")]
Expand All @@ -118,13 +111,13 @@ class ConfigSchema(ModelConfig):
Tuple[PlatformConfig, ...], Field(default_factory=tuple, description="")
]
wells: Annotated[Tuple[WellConfig, ...], Field(description="")]
outputs: Annotated[OutputsConfig, Field(description="", default=None)]
eclipse_model: Annotated[
Path,
AfterValidator(validate_eclipse_path),
Field(description="", default=None),
]
resinsight_binary: Annotated[FilePath, Field(default=None, description="")]
npv_input_file: Annotated[FilePath, Field(default=None, description="")]

@field_validator("wells")
def _validate_wells(
Expand Down
34 changes: 1 addition & 33 deletions src/everest_models/jobs/fm_well_trajectory/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
from pathlib import Path
from typing import Dict, Iterable, Tuple

import pandas

from everest_models.jobs.shared import io_utils as io

from .models.config import ConfigSchema, WellConfig
from .models.config import WellConfig
from .models.data_structs import CalculatedTrajectory, Trajectory


Expand Down Expand Up @@ -99,36 +97,6 @@ def write_guide_points(guide_points: Dict[str, Trajectory], filename: Path) -> N
raise RuntimeError("guide points file format not supported")


def write_well_geometry(config: ConfigSchema) -> None:
with open("well_geometry.txt", "w") as fp_well_geometry:
for well in config.wells:
# Read .dev file
with open(f"wellpaths/{well.name}.dev", "r") as fp_dev:
path = pandas.read_csv(
fp_dev,
delim_whitespace=True,
skiprows=2,
skipfooter=2,
names=["X", "Y", "TVDMSL", "MDMSL"],
engine="python",
)
for idx, _ in enumerate(path.index[:-1]):
line = (
f"{well.name}\t"
f"{path.iloc[idx]['X']}\t"
f"{path.iloc[idx]['Y']}\t"
f"{path.iloc[idx]['TVDMSL']}\t"
f"{path.iloc[idx+1]['X']}\t"
f"{path.iloc[idx+1]['Y']}\t"
f"{path.iloc[idx+1]['TVDMSL']}\t"
f"{path.iloc[idx]['MDMSL']}\t"
f"{path.iloc[idx+1]['MDMSL']}\t"
f"{well.radius}\t"
f"{well.skin}\n"
)
fp_well_geometry.write(line)


def write_well_costs(costs: Dict[str, float], npv_file: Path) -> None:
output = io.load_yaml(npv_file)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import rips

from .models.config import ConfigSchema, ResInsightInterpolationConfig
from .outputs import write_well_costs, write_well_geometry
from .outputs import write_well_costs
from .resinsight import create_well, create_well_logs, make_perforations, read_wells
from .well_costs import compute_well_costs
from .well_trajectory_simple import Trajectory
Expand Down Expand Up @@ -77,8 +77,6 @@ def well_trajectory_resinsight(
project,
project_path,
)

write_well_geometry(config)
else:
# Simple interpolation, use saved trajectories:
project = read_wells(
Expand Down Expand Up @@ -107,10 +105,10 @@ def well_trajectory_resinsight(
for well_path in project.well_paths()
),
)
if config.outputs.npv_input is not None:
if config.npv_input_file is not None:
write_well_costs(
costs=compute_well_costs(wells),
npv_file=config.outputs.npv_input,
npv_file=config.npv_input_file,
)
else:
all(wells) # consume generator without collecting yields
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
import pathlib
from typing import Dict, Iterable, Iterator, Tuple
from typing import Dict, Iterable, Iterator, Optional, Tuple

import numpy
from numpy.typing import NDArray

from .dogleg import compute_dogleg_severity, try_fixing_dog_leg
from .geometry import compute_geometry
from .interpolation import interpolate_points
from .models.config import OutputsConfig, SimpleInterpolationConfig, WellConfig
from .models.config import SimpleInterpolationConfig, WellConfig
from .models.data_structs import CalculatedTrajectory, Trajectory
from .outputs import write_path_files, write_resinsight, write_well_costs, write_wicalc
from .well_costs import compute_well_costs
Expand Down Expand Up @@ -72,26 +72,24 @@ def _compute_well_trajectory(
def well_trajectory_simple(
wells: Iterable[WellConfig],
interpolation: SimpleInterpolationConfig,
outputs: OutputsConfig,
npv_input_file: Optional[pathlib.Path],
guide_points: Dict[str, Trajectory],
) -> None:
points = _compute_well_trajectory(wells, interpolation, guide_points)
if outputs.geometry is not None:
logger.info(f"Writing interpolation results to: {outputs.geometry}")
write_wicalc(
results=points,
path=outputs.geometry,
wells={well.name: well for well in wells},
)
logger.info("Writing interpolation results to 'well_geometry.txt;")
write_wicalc(
results=points,
path=pathlib.Path("well_geometry.txt"),
wells={well.name: well for well in wells},
)
logger.info("Writing ResInsight files")
write_resinsight(points)
if outputs.npv_input is not None:
if npv_input_file is not None:
costs = compute_well_costs(wells)
logger.info("Writing well costs")
write_well_costs(costs, outputs.npv_input)
if outputs.save_paths:
logger.info("Writing PATH files")
write_path_files(
(pathlib.Path(f"PATH_{well}").with_suffix(".txt"), trajectory)
for well, trajectory in points.items()
)
write_well_costs(costs, npv_input_file)
logger.info("Writing PATH files")
write_path_files(
(pathlib.Path(f"PATH_{well}").with_suffix(".txt"), trajectory)
for well, trajectory in points.items()
)
31 changes: 12 additions & 19 deletions tests/jobs/well_trajectory/test_well_trajectory_resinsight.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import filecmp
import logging
from pathlib import Path

Expand All @@ -12,18 +13,6 @@ def well_trajectory_arguments():
return ("-c config.yml -E SPE1CASE1").split()


@pytest.fixture(scope="module")
def well_trajectory_output_files():
return (
"well_geometry.txt",
"wellpaths/INJ.dev",
"wellpaths/PROD.dev",
"INJ.SCH",
"PROD.SCH",
"guide_points.json",
)


@pytest.mark.resinsight
def test_failing_start_resinsight(caplog):
caplog.set_level(logging.INFO)
Expand All @@ -45,22 +34,26 @@ def test_start_resinsight(caplog):

@pytest.mark.resinsight
def test_well_trajectory_resinsight_main_entry_point(
well_trajectory_arguments, well_trajectory_output_files, copy_testdata_tmpdir
well_trajectory_arguments, copy_testdata_tmpdir
):
copy_testdata_tmpdir(Path(TEST_DATA) / "spe1case1")
main_entry_point(well_trajectory_arguments)
assert all(
path.read_bytes() == (Path("expected") / path).read_bytes()
for path in map(Path, well_trajectory_output_files)
)

for expected in Path("expected").glob("**/*"):
if expected.is_file():
output = expected.relative_to("expected")
assert output.is_file()
assert filecmp.cmp(expected, output, shallow=False)


@pytest.mark.resinsight
def test_well_trajectory_resinsight_main_entry_point_lint(
well_trajectory_arguments, well_trajectory_output_files, copy_testdata_tmpdir
well_trajectory_arguments, copy_testdata_tmpdir
):
copy_testdata_tmpdir(Path(TEST_DATA) / "spe1case1")
with pytest.raises(SystemExit):
main_entry_point([*well_trajectory_arguments, "--lint"])

assert not any(path.exists() for path in map(Path, well_trajectory_output_files))
assert not any(
path.relative_to("expected").exists() for path in Path("expected").glob("**/*")
)
30 changes: 11 additions & 19 deletions tests/jobs/well_trajectory/test_well_trajectory_simple.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import filecmp
from pathlib import Path

import pytest
Expand All @@ -10,35 +11,26 @@ def well_trajectory_arguments():
return ("-c config.yml").split()


@pytest.fixture(scope="module")
def well_trajectory_output_files():
return (
"well_geometry.txt",
"wellpaths/OP_4.dev",
"wellpaths/WI_1.dev",
"PATH_OP_4.txt",
"PATH_WI_1.txt",
"guide_points.json",
)


def test_well_trajectory_simple_main_entry_point(
well_trajectory_arguments, well_trajectory_output_files, copy_testdata_tmpdir
well_trajectory_arguments, copy_testdata_tmpdir
):
copy_testdata_tmpdir(Path(TEST_DATA) / "simple")
main_entry_point(well_trajectory_arguments)

assert all(
path.read_bytes() == (Path("expected") / path).read_bytes()
for path in map(Path, well_trajectory_output_files)
)
for expected in Path("expected").glob("**/*"):
if expected.is_file():
output = expected.relative_to("expected")
assert output.is_file()
assert filecmp.cmp(expected, output, shallow=False)


def test_well_trajectory_simple_main_entry_point_lint(
well_trajectory_arguments, well_trajectory_output_files, copy_testdata_tmpdir
well_trajectory_arguments, copy_testdata_tmpdir
):
copy_testdata_tmpdir(Path(TEST_DATA) / "simple")
with pytest.raises(SystemExit):
main_entry_point([*well_trajectory_arguments, "--lint"])

assert not any(path.exists() for path in map(Path, well_trajectory_output_files))
assert not any(
path.relative_to("expected").exists() for path in Path("expected").glob("**/*")
)
5 changes: 0 additions & 5 deletions tests/testdata/well_trajectory/simple/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,3 @@ platforms:
y: 5933608.04
z: 0.0
k: 200.0

outputs:
save_paths: True
geometry: well_geometry.txt
guide_points: guide_points.json
3 changes: 0 additions & 3 deletions tests/testdata/well_trajectory/spe1case1/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,3 @@ platforms:
y: 7500
z: 0
k: 50
outputs:
save_paths: true
guide_points: guide_points.json
Loading

0 comments on commit c0336e6

Please sign in to comment.