Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer committed Oct 1, 2023
1 parent 09f4c17 commit 0f55e06
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 118 deletions.
12 changes: 5 additions & 7 deletions backend/src/backend/primary/routers/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from pydantic import BaseModel

from src.backend.auth.auth_helper import AuthHelper
from src.services.sumo_access.case_inspector import CaseInspector
from src.services.sumo_access.iteration_inspector import IterationInspector
from src.services.sumo_access.sumo_explore import SumoExplore
from src.services.utils.authenticated_user import AuthenticatedUser
from src.services.sumo_access._helpers import SumoEnsemble

router = APIRouter()

Expand Down Expand Up @@ -89,16 +88,15 @@ def get_ensembles(


@router.get("/cases/{case_uuid}/ensembles/{ensemble_name}")
def get_ensemble_details(
async def get_ensemble_details(
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Path(description="Sumo case uuid"),
ensemble_name: str = Path(description="Ensemble name"),
) -> EnsembleDetails:
"""Get more detailed information for an ensemble"""
case_inspector = CaseInspector(authenticated_user.get_sumo_access_token(), case_uuid)
case_name = case_inspector.get_case_name()

iteration_inspector: IterationInspector = case_inspector.create_iteration_inspector(ensemble_name)
realizations = iteration_inspector.get_realizations()
iteration = await SumoEnsemble.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
case_name = iteration.get_case_name()
realizations = iteration.get_realizations()

return EnsembleDetails(name=ensemble_name, case_name=case_name, case_uuid=case_uuid, realizations=realizations)
2 changes: 1 addition & 1 deletion backend/src/backend/primary/routers/parameters/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ async def get_sensitivities(

access = await ParameterAccess.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)

sensitivities = access.get_parameters_and_sensitivities().sensitivities
sensitivities = await access.get_parameters_and_sensitivities().sensitivities
return sensitivities if sensitivities else []
4 changes: 2 additions & 2 deletions backend/src/backend/primary/routers/surface/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@


from src.services.sumo_access.surface_access import SurfaceAccess
from src.services.sumo_access.case_inspector import CaseInspector
from src.services.smda_access.stratigraphy_access import StratigraphyAccess
from src.services.smda_access.stratigraphy_utils import sort_stratigraphic_names_by_hierarchy
from src.services.smda_access.mocked_drogon_smda_access import _mocked_stratigraphy_access
from src.services.utils.statistic_function import StatisticFunction
from src.services.utils.authenticated_user import AuthenticatedUser
from src.services.utils.perf_timer import PerfTimer
from src.backend.auth.auth_helper import AuthHelper
from src.services.sumo_access._helpers import SumoCase


from . import converters
Expand All @@ -38,7 +38,7 @@ async def get_surface_directory(
)
sumo_surf_dir = surface_access.get_surface_directory()

case_inspector = CaseInspector(authenticated_user.get_sumo_access_token(), case_uuid)
case_inspector = await SumoCase.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid)
strat_column_identifier = case_inspector.get_stratigraphic_column_identifier()
strat_access: Union[StratigraphyAccess, _mocked_stratigraphy_access.StratigraphyAccess]

Expand Down
11 changes: 5 additions & 6 deletions backend/src/backend/primary/routers/well/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

from src.services.smda_access import mocked_drogon_smda_access
from src.services.smda_access.well_access import WellAccess
from src.services.sumo_access.case_inspector import CaseInspector
from src.services.utils.authenticated_user import AuthenticatedUser
from src.backend.auth.auth_helper import AuthHelper

from src.services.sumo_access._helpers import SumoCase
from src.services.smda_access.types import WellBoreHeader, WellBoreTrajectory

LOGGER = logging.getLogger(__name__)
Expand All @@ -17,7 +16,7 @@


@router.get("/well_headers/")
def get_well_headers(
async def get_well_headers(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"),
Expand All @@ -26,7 +25,7 @@ def get_well_headers(
) -> List[WellBoreHeader]:
"""Get well headers for all wells in the field"""

case_inspector = CaseInspector(authenticated_user.get_sumo_access_token(), case_uuid)
case_inspector = await SumoCase.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid)
field_identifier = case_inspector.get_field_identifiers()[0]
well_access: Union[WellAccess, mocked_drogon_smda_access.WellAccess]
if field_identifier == "DROGON":
Expand All @@ -39,15 +38,15 @@ def get_well_headers(


@router.get("/field_well_trajectories/")
def get_field_well_trajectories(
async def get_field_well_trajectories(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
case_uuid: str = Query(description="Sumo case uuid"), # Should be field identifier?
unique_wellbore_identifiers:List[str] = Query(None, description="Optional subset of well names")
# fmt:on
) -> List[WellBoreTrajectory]:
"""Get well trajectories for field"""
case_inspector = CaseInspector(authenticated_user.get_sumo_access_token(), case_uuid)
case_inspector = await SumoCase.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid)
field_identifier = case_inspector.get_field_identifiers()[0]
well_access: Union[WellAccess, mocked_drogon_smda_access.WellAccess]
if field_identifier == "DROGON":
Expand Down
57 changes: 47 additions & 10 deletions backend/src/services/sumo_access/_helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import os
from typing import List, Sequence, Tuple

from sumo.wrapper import SumoClient
from fmu.sumo.explorer.objects import CaseCollection, Case

from .queries.case import get_stratigraphic_column_identifier, get_field_identifiers


SUMO_ENV = os.getenv("WEBVIZ_SUMO_ENV", "dev")

Expand All @@ -12,19 +15,53 @@ def create_sumo_client_instance(access_token: str) -> SumoClient:
return sumo_client


class SumoAccess:
def __init__(self, sumo_client: SumoClient, case: Case, case_uuid: str, iteration_name: str):
async def _init_helper(access_token: str, case_uuid: str) -> Tuple[SumoClient, Case]:
sumo_client: SumoClient = create_sumo_client_instance(access_token)
case_collection = CaseCollection(sumo_client).filter(uuid=case_uuid)

if await case_collection.length_async() != 1:
raise ValueError(f"None or multiple sumo cases found {case_uuid=}")

case = case_collection[0]

return sumo_client, case


class SumoCase:
def __init__(self, sumo_client: SumoClient, case: Case, case_uuid: str):
self._sumo_client = sumo_client
self._case: Case = case
self._case = case
self._case_uuid = case_uuid
self._iteration_name: str = iteration_name

@classmethod
async def from_case_uuid(cls, access_token: str, case_uuid: str, iteration_name: str): # type: ignore # wait on Python 3.11
sumo_client: SumoClient = create_sumo_client_instance(access_token)
case_collection = CaseCollection(sumo_client).filter(uuid=case_uuid)
if await case_collection.length_async() != 1:
raise ValueError(f"None or multiple sumo cases found {case_uuid=}")
async def from_case_uuid(cls, access_token: str, case_uuid: str): # type: ignore # wait on Python 3.11
sumo_client, case = await _init_helper(access_token, case_uuid)
return SumoCase(sumo_client=sumo_client, case=case, case_uuid=case_uuid)

def get_case_name(self) -> str:
"""Get name of the case"""
return self._case.name

case = case_collection[0]
def get_stratigraphic_column_identifier(self) -> str:
"""Retrieve the stratigraphic column identifier for a case"""
return get_stratigraphic_column_identifier(self._sumo_client, self._case_uuid)

def get_field_identifiers(self) -> List[str]:
"""Retrieve the field identifiers for a case"""
return get_field_identifiers(self._sumo_client, self._case_uuid)


class SumoEnsemble(SumoCase):
def __init__(self, sumo_client: SumoClient, case: Case, case_uuid: str, iteration_name: str):
super().__init__(sumo_client=sumo_client, case=case, case_uuid=case_uuid)
self._iteration_name: str = iteration_name

@classmethod
async def from_case_uuid(cls, access_token: str, case_uuid: str, iteration_name: str): # type: ignore # wait on Python 3.11 # pylint: disable=arguments-differ
sumo_client, case = await _init_helper(access_token, case_uuid)
return cls(sumo_client=sumo_client, case=case, case_uuid=case_uuid, iteration_name=iteration_name)

def get_realizations(self) -> Sequence[int]:
"""Get list of realizations for this iteration"""
realizations = self._case.get_realizations(self._iteration_name)
return sorted([int(real) for real in realizations])
41 changes: 0 additions & 41 deletions backend/src/services/sumo_access/case_inspector.py

This file was deleted.

4 changes: 2 additions & 2 deletions backend/src/services/sumo_access/grid_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from src.services.utils.perf_timer import PerfTimer

from ._helpers import SumoAccess
from ._helpers import SumoEnsemble
from .queries.cpgrid import (
get_grid_geometry_blob_id,
get_grid_names,
Expand All @@ -18,7 +18,7 @@
LOGGER = logging.getLogger(__name__)


class GridAccess(SumoAccess):
class GridAccess(SumoEnsemble):
async def grid_model_names(self) -> List[str]:
"""Get a list of grid model names"""
return await get_grid_names(self._sumo_client, self._case_uuid, self._iteration_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from fmu.sumo.explorer.objects import TableCollection
from pydantic import BaseModel

from ._helpers import SumoAccess
from ._helpers import SumoEnsemble
from .generic_types import EnsembleScalarResponse

# from fmu.sumo.explorer.objects.table import AggregatedTable
Expand Down Expand Up @@ -71,7 +71,7 @@ class Config:
orm_mode = True


class InplaceVolumetricsAccess(SumoAccess):
class InplaceVolumetricsAccess(SumoEnsemble):
def get_table_names_and_metadata(self) -> List[InplaceVolumetricsTableMetaData]:
"""Retrieve the available volumetric tables names and corresponding metadata for the case"""
vol_table_collections: TableCollection = self._case.tables.filter(
Expand Down
35 changes: 0 additions & 35 deletions backend/src/services/sumo_access/iteration_inspector.py

This file was deleted.

4 changes: 2 additions & 2 deletions backend/src/services/sumo_access/parameter_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pandas as pd

from .queries.parameters import get_parameters_for_iteration, SumoEnsembleParameter
from ._helpers import SumoAccess
from ._helpers import SumoEnsemble
from .parameter_types import (
EnsembleParameter,
EnsembleParameters,
Expand All @@ -17,7 +17,7 @@
LOGGER = logging.getLogger(__name__)


class ParameterAccess(SumoAccess):
class ParameterAccess(SumoEnsemble):
def get_parameters_and_sensitivities(self) -> EnsembleParameters:
"""Retrieve parameters for an ensemble"""

Expand Down
4 changes: 2 additions & 2 deletions backend/src/services/sumo_access/seismic_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from fmu.sumo.explorer import TimeFilter, TimeType
from fmu.sumo.explorer.objects.cube_collection import CubeCollection

from ._helpers import SumoAccess
from ._helpers import SumoEnsemble
from .seismic_types import SeismicCubeMeta, VdsHandle

LOGGER = logging.getLogger(__name__)


class SeismicAccess(SumoAccess):
class SeismicAccess(SumoEnsemble):
def get_seismic_directory(self) -> List[SeismicCubeMeta]:
seismic_cube_collection: CubeCollection = self._case.cubes.filter(iteration=self._iteration_name, realization=0)
seismic_cube_metas: List[SeismicCubeMeta] = []
Expand Down
4 changes: 2 additions & 2 deletions backend/src/services/sumo_access/summary_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from src.services.utils.perf_timer import PerfTimer

from ._field_metadata import create_vector_metadata_from_field_meta
from ._helpers import SumoAccess
from ._helpers import SumoEnsemble
from ._resampling import resample_segmented_multi_real_table
from .generic_types import EnsembleScalarResponse
from .summary_types import Frequency, VectorInfo, RealizationVector, HistoricalVector, VectorMetadata

LOGGER = logging.getLogger(__name__)


class SummaryAccess(SumoAccess):
class SummaryAccess(SumoEnsemble):
async def get_available_vectors(self) -> List[VectorInfo]:
timer = PerfTimer()

Expand Down
4 changes: 2 additions & 2 deletions backend/src/services/sumo_access/surface_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from src.services.utils.perf_timer import PerfTimer
from src.services.utils.statistic_function import StatisticFunction

from ._helpers import SumoAccess
from ._helpers import SumoEnsemble
from .surface_types import SurfaceMeta
from .generic_types import SumoContent

LOGGER = logging.getLogger(__name__)


class SurfaceAccess(SumoAccess):
class SurfaceAccess(SumoEnsemble):
def get_surface_directory(self) -> List[SurfaceMeta]:
surface_collection: SurfaceCollection = self._case.surfaces.filter(
iteration=self._iteration_name,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/services/sumo_access/table_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import pyarrow as pa

from ._helpers import SumoAccess
from ._helpers import SumoEnsemble
from .generic_types import SumoTableSchema

LOGGER = logging.getLogger(__name__)


class TableAccess(SumoAccess):
class TableAccess(SumoEnsemble):
"""Generic access to Sumo tables"""

def get_table_schemas_single_realization(self, realization: int = 0) -> List[SumoTableSchema]:
Expand Down
Loading

0 comments on commit 0f55e06

Please sign in to comment.