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

Relative permeability #820

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions backend_py/primary/primary/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from primary.routers.parameters.router import router as parameters_router
from primary.routers.polygons.router import router as polygons_router
from primary.routers.pvt.router import router as pvt_router
from primary.routers.relperm.router import router as relperm_router
from primary.routers.rft.router import router as rft_router
from primary.routers.seismic.router import router as seismic_router
from primary.routers.surface.router import router as surface_router
Expand Down Expand Up @@ -79,6 +80,7 @@ def custom_generate_unique_id(route: APIRoute) -> str:
app.include_router(grid3d_router, prefix="/grid3d", tags=["grid3d"])
app.include_router(group_tree_router, prefix="/group_tree", tags=["group_tree"])
app.include_router(pvt_router, prefix="/pvt", tags=["pvt"])
app.include_router(relperm_router, prefix="/relperm", tags=["relperm"])
app.include_router(well_completions_router, prefix="/well_completions", tags=["well_completions"])
app.include_router(well_router, prefix="/well", tags=["well"])
app.include_router(seismic_router, prefix="/seismic", tags=["seismic"])
Expand Down
100 changes: 100 additions & 0 deletions backend_py/primary/primary/routers/relperm/converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from primary.services.relperm_assembler.relperm_assembler import (
RelPermTableInfo,
RelPermSaturationAxis,
RelPermRealizationDataForSaturation,
RelPermStatisticalDataForSaturation,
RealizationCurveData,
Statistic,
)

from . import schemas


def to_api_relperm_table_info(table_info: RelPermTableInfo) -> schemas.RelPermTableInfo:

return schemas.RelPermTableInfo(
table_name=table_info.table_name,
saturation_axes=[to_api_relperm_saturation_axis(axis) for axis in table_info.saturation_axes],
satnums=table_info.satnums,
)


def to_api_relperm_saturation_axis(axis: RelPermSaturationAxis) -> schemas.RelPermSaturationAxis:

return schemas.RelPermSaturationAxis(
saturation_name=axis.saturation_name,
relperm_curve_names=axis.relperm_curve_names,
capillary_pressure_curve_names=axis.capillary_pressure_curve_names,
)


def to_api_relperm_realization_data(
data: RelPermRealizationDataForSaturation,
) -> schemas.RelPermRealizationDataForSaturation:

return schemas.RelPermRealizationDataForSaturation(
saturation_axis_data=schemas.CurveData(
curve_name=data.saturation_axis_data.curve_name,
curve_values=data.saturation_axis_data.curve_values,
unit=data.saturation_axis_data.unit,
),
saturation_number=data.saturation_number,
relperm_curve_data=[
schemas.RealizationCurveData(
curve_name=curve_data.curve_name,
curve_values=curve_data.curve_values.tolist(),
realization_id=curve_data.realization_id,
)
for curve_data in data.relperm_curve_data
],
)


def _convert_statistic_values_dict_to_schema(
statistic_values: dict[Statistic, list[float]],
) -> dict[schemas.Statistic, list[float]]:
"""Converts the statistic values dictionary from the service layer format to API format"""
return {
_convert_statistic_enum_to_statistic_enum(statistic): values for statistic, values in statistic_values.items()
}


def _convert_statistic_enum_to_statistic_enum(
statistic: Statistic,
) -> schemas.Statistic:
"""Converts the statistic enum from the service layer format to API enum"""
if statistic == Statistic.MEAN:
return schemas.Statistic.MEAN
if statistic == Statistic.STD_DEV:
return schemas.Statistic.STD_DEV
if statistic == Statistic.MIN:
return schemas.Statistic.MIN
if statistic == Statistic.MAX:
return schemas.Statistic.MAX
if statistic == Statistic.P10:
return schemas.Statistic.P10
if statistic == Statistic.P90:
return schemas.Statistic.P90

raise ValueError(f"Unknown statistic value: {statistic.value}")


def to_api_relperm_statistical_data(
data: RelPermStatisticalDataForSaturation,
) -> schemas.RelPermStatisticalDataForSaturation:
print(data)
return schemas.RelPermStatisticalDataForSaturation(
saturation_axis_data=schemas.CurveData(
curve_name=data.saturation_axis_data.curve_name,
curve_values=data.saturation_axis_data.curve_values,
unit=data.saturation_axis_data.unit,
),
saturation_number=data.saturation_number,
relperm_curve_data=[
schemas.StatisticalCurveData(
curve_name=curve_data.curve_name,
curve_values=_convert_statistic_values_dict_to_schema(curve_data.curve_values),
)
for curve_data in data.relperm_curve_data
],
)
84 changes: 84 additions & 0 deletions backend_py/primary/primary/routers/relperm/router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import logging
from typing import Annotated, List, Any

from fastapi import APIRouter, Depends, Query

from primary.auth.auth_helper import AuthHelper
from primary.services.sumo_access.relperm_access import RelPermAccess
from primary.services.relperm_assembler.relperm_assembler import RelPermAssembler
from primary.services.utils.authenticated_user import AuthenticatedUser

from . import schemas
from . import converters

LOGGER = logging.getLogger(__name__)

router = APIRouter()


@router.get("/table_names")
async def get_table_names(
authenticated_user: Annotated[AuthenticatedUser, Depends(AuthHelper.get_authenticated_user)],
case_uuid: Annotated[str, Query(description="Sumo case uuid")],
ensemble_name: Annotated[str, Query(description="Ensemble name")],
) -> List[str]:
access = await RelPermAccess.from_case_uuid_async(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
return await access.get_relperm_table_names()


@router.get("/table_info")
async def get_table_info(
authenticated_user: Annotated[AuthenticatedUser, Depends(AuthHelper.get_authenticated_user)],
case_uuid: Annotated[str, Query(description="Sumo case uuid")],
ensemble_name: Annotated[str, Query(description="Ensemble name")],
table_name: Annotated[str, Query(description="Table name")],
) -> schemas.RelPermTableInfo:
access = await RelPermAccess.from_case_uuid_async(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
assembler = RelPermAssembler(access)
relperm_table_info = await assembler.get_relperm_table_info(table_name)

return converters.to_api_relperm_table_info(relperm_table_info)


@router.get("/realizations_curve_data")
async def get_realizations_curve_data(
authenticated_user: Annotated[AuthenticatedUser, Depends(AuthHelper.get_authenticated_user)],
case_uuid: Annotated[str, Query(description="Sumo case uuid")],
ensemble_name: Annotated[str, Query(description="Ensemble name")],
table_name: Annotated[str, Query(description="Table name")],
saturation_axis_name: Annotated[str, Query(description="Saturation axis name")],
curve_names: Annotated[List[str], Query(description="Curve names")],
satnums: Annotated[List[int], Query(description="Satnums")],
) -> schemas.RelPermRealizationDataForSaturation:

access = await RelPermAccess.from_case_uuid_async(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
assembler = RelPermAssembler(access)
relperm_data = await assembler.get_relperm_realization_data(table_name, saturation_axis_name, curve_names, satnums)

return converters.to_api_relperm_realization_data(relperm_data)


@router.get("/statistical_curve_data")
async def get_statistical_curve_data(
authenticated_user: Annotated[AuthenticatedUser, Depends(AuthHelper.get_authenticated_user)],
case_uuid: Annotated[str, Query(description="Sumo case uuid")],
ensemble_name: Annotated[str, Query(description="Ensemble name")],
table_name: Annotated[str, Query(description="Table name")],
saturation_axis_name: Annotated[str, Query(description="Saturation axis name")],
curve_names: Annotated[List[str], Query(description="Curve names")],
satnums: Annotated[List[int], Query(description="Satnums")],
) -> schemas.RelPermStatisticalDataForSaturation:

access = await RelPermAccess.from_case_uuid_async(
authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name
)
assembler = RelPermAssembler(access)
relperm_data = await assembler.get_relperm_statistics_data(table_name, saturation_axis_name, curve_names, satnums)

return converters.to_api_relperm_statistical_data(relperm_data)
58 changes: 58 additions & 0 deletions backend_py/primary/primary/routers/relperm/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from enum import StrEnum
from typing import List, Dict

from pydantic import BaseModel


class RelPermSaturationAxis(BaseModel):
saturation_name: str
relperm_curve_names: List[str]
capillary_pressure_curve_names: List[str]


class RelPermTableInfo(BaseModel):
table_name: str
saturation_axes: List[RelPermSaturationAxis]
satnums: List[int]


class CurveData(BaseModel):
curve_name: str
curve_values: List[float]
unit: str | None = None


class RealizationCurveData(BaseModel):
curve_name: str
curve_values: List[float]
realization_id: int


class RelPermRealizationDataForSaturation(BaseModel):
saturation_number: int
saturation_axis_data: CurveData
relperm_curve_data: List[RealizationCurveData]


class Statistic(StrEnum):
"""
Definition of possible statistics
"""

MEAN = "mean"
STD_DEV = "stddev"
MAX = "max"
MIN = "min"
P10 = "p10"
P90 = "p90"


class StatisticalCurveData(BaseModel):
curve_name: str
curve_values: Dict[Statistic, List[float]]


class RelPermStatisticalDataForSaturation(BaseModel):
saturation_axis_data: CurveData
saturation_number: int
relperm_curve_data: List[StatisticalCurveData]
Loading
Loading