Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert SCORE well trajectory to alfacase #1

Merged
merged 7 commits into from
Jun 17, 2024
Merged
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
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
with open("CHANGELOG.rst", encoding="UTF-8") as changelog_file:
history = changelog_file.read()

requirements = ["attrs>=18.1.0", "numpy>=1.11.0", "oop-ext>=1.1", "typing_extensions"]
requirements = [
"alfasim-sdk==0.20.0",
"attrs>=18.1.0",
"numpy>=1.11.0",
"pandas>=2.0.0",
carlosnewmar marked this conversation as resolved.
Show resolved Hide resolved
"oop-ext>=1.1",
"typing_extensions",
]
gabrielantao marked this conversation as resolved.
Show resolved Hide resolved
extras_require = {
"testing": [
"codecov",
Expand All @@ -16,6 +23,7 @@
"pytest",
"pytest-cov",
"pytest-mock",
"pytest-regressions",
"tox",
],
}
Expand Down
3 changes: 3 additions & 0 deletions src/alfasim_score/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WELLBORE_TOP_NODE = "WELBORE_TOP_NODE"
WELLBORE_BOTTOM_NODE = "WELBORE_BOTTOM_NODE"
ANNULUS_TOP_NODE_NAME = "WELLBORE_ANNULUS_TOP_NODE"
Empty file.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import Any

import json
import pytest
from pathlib import Path
from pytest_regressions.num_regression import NumericRegressionFixture

from alfasim_score.converter.alfacase.convert_alfacase import ScoreAlfacaseConverter
from alfasim_score.converter.alfacase.score_input_reader import ScoreInputReader


@pytest.fixture
def score_input_example(shared_datadir: Path) -> ScoreInputReader:
return ScoreInputReader(shared_datadir / "score_input_example.json")


def test_convert_well_trajectory(
num_regression: NumericRegressionFixture,
score_input_example: ScoreInputReader,
) -> None:
builder = ScoreAlfacaseConverter(score_input_example)
well_description = builder.build_well()
num_regression.check(
{
"x": well_description.profile.x_and_y.x.GetValues("m"),
"y": well_description.profile.x_and_y.y.GetValues("m"),
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
,x,y
0,0,-2072
1,0.73287082896792399,-2099.9872078220192
2,76.096647818807043,-3538.0137378686054
3,77.752992985225475,-3567.9679367851122
4,80.017903235804596,-3597.8807902103954
5,83.32537729373297,-3627.6963773057687
6,87.671385511348291,-3657.3783723710953
7,93.050632947088673,-3686.8906124675491
8,99.456565816563227,-3716.1971414765844
9,106.88137947732878,-3745.2622539069289
10,115.31602793764459,-3774.0505383962231
11,124.75023487761972,-3802.5269208543127
12,135.172506169326,-3830.6567071956224
13,146.57014388062231,-3858.4056256085569
14,158.92926174562896,-3885.7398683104229
15,171.9795438608509,-3912.1277131463253
16,1111.9130083432817,-5733.2154388877443
45 changes: 45 additions & 0 deletions src/alfasim_score/converter/alfacase/convert_alfacase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from alfasim_sdk import AnnulusDescription
from alfasim_sdk import FormationDescription
from alfasim_sdk import ProfileDescription
from alfasim_sdk import WellDescription
from alfasim_sdk import XAndYDescription
from barril.units import Scalar

from alfasim_score.constants import ANNULUS_TOP_NODE_NAME
from alfasim_score.constants import WELLBORE_BOTTOM_NODE
from alfasim_score.constants import WELLBORE_TOP_NODE
from alfasim_score.converter.alfacase.score_input_reader import ScoreInputReader
from alfasim_score.units import LENGTH_UNIT


class ScoreAlfacaseConverter:
def __init__(self, score_reader: ScoreInputReader):
self.score_input = score_reader
self.well_name = score_reader.input_content["name"]

def _convert_well_trajectory(self) -> ProfileDescription:
"""
Convert the trajectory for the imported well.
NOTE: all positions don't start to count as zero at ANM, but they use the same values
from the input SCORE file.
"""
x, y = self.score_input.read_well_trajectory()
gabrielantao marked this conversation as resolved.
Show resolved Hide resolved
return ProfileDescription(x_and_y=XAndYDescription(x=x, y=y))

# TODO PWPA-1937: implement this method
def _convert_annulus(self) -> AnnulusDescription:
return AnnulusDescription(has_annulus_flow=False, top_node=ANNULUS_TOP_NODE_NAME)

# TODO PWPA-1934: implement this method
def _convert_formation(self) -> AnnulusDescription:
return FormationDescription(reference_y_coordinate=Scalar(0.0, "m", "length"))

def build_well(self) -> WellDescription:
return WellDescription(
name=self.well_name,
profile=self._convert_well_trajectory(),
annulus=self._convert_annulus(),
formation=self._convert_formation(),
top_node=WELLBORE_TOP_NODE,
bottom_node=WELLBORE_BOTTOM_NODE,
)
19 changes: 19 additions & 0 deletions src/alfasim_score/converter/alfacase/score_input_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json
from barril.units import Array
from pathlib import Path
from typing import Tuple

from alfasim_score.units import LENGTH_UNIT


class ScoreInputReader:
def __init__(self, score_filepath: Path):
self.score_filepath = score_filepath
with open(score_filepath) as f:
self.input_content = json.load(f)

def read_well_trajectory(self) -> Tuple[Array, Array]:
"""Create the arrays with the x and y positions."""
x = [entry["displacement"] for entry in self.input_content["trajectory"]["data"]]
y = [-entry["vertical_depth"] for entry in self.input_content["trajectory"]["data"]]
return Array(x, LENGTH_UNIT), Array(y, LENGTH_UNIT)
1 change: 1 addition & 0 deletions src/alfasim_score/units.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LENGTH_UNIT = "m"
Loading