Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Oct 15, 2024
1 parent 5ca22c7 commit fe7c1fe
Show file tree
Hide file tree
Showing 43 changed files with 1,363 additions and 971 deletions.
20 changes: 20 additions & 0 deletions backend_py/primary/primary/routers/surface/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from primary.services.utils.surface_intersect_with_polyline import XtgeoSurfaceIntersectionResult
from primary.services.utils.surface_to_float32 import surface_to_float32_numpy_array
from primary.services.utils.surface_to_png import surface_to_png_bytes_optimized
from primary.services.smda_access import StratigraphicUnit

from . import schemas

Expand Down Expand Up @@ -174,3 +175,22 @@ def to_api_surface_intersection(
z_points=xtgeo_surface_intersection.zval,
cum_lengths=xtgeo_surface_intersection.distance,
)


def to_api_stratigraphic_unit(
stratigraphic_unit: StratigraphicUnit,
) -> schemas.StratigraphicUnit:
return schemas.StratigraphicUnit(
identifier=stratigraphic_unit.identifier,
top=stratigraphic_unit.top,
base=stratigraphic_unit.base,
stratUnitLevel=stratigraphic_unit.strat_unit_level,
stratUnitType=stratigraphic_unit.strat_unit_type,
topAge=stratigraphic_unit.top_age,
baseAge=stratigraphic_unit.base_age,
stratUnitParent=stratigraphic_unit.strat_unit_parent,
colorR=stratigraphic_unit.color_r,
colorG=stratigraphic_unit.color_g,
colorB=stratigraphic_unit.color_b,
lithologyType=stratigraphic_unit.lithology_type,
)
20 changes: 19 additions & 1 deletion backend_py/primary/primary/routers/surface/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,24 @@ async def get_misfit_surface_data(
raise HTTPException(status.HTTP_501_NOT_IMPLEMENTED)


@router.get("/stratigraphic_units")
async def get_stratigraphic_units(
# fmt:off
response: Response,
authenticated_user: Annotated[AuthenticatedUser, Depends(AuthHelper.get_authenticated_user)],
case_uuid: Annotated[str, Query(description="Sumo case uuid")],
# fmt:on
) -> list[schemas.StratigraphicUnit]:
perf_metrics = ResponsePerfMetrics(response)

strat_units = await _get_stratigraphic_units_for_case_async(authenticated_user, case_uuid)
api_strat_units = [converters.to_api_stratigraphic_unit(strat_unit) for strat_unit in strat_units]

LOGGER.info(f"Got stratigraphic units in: {perf_metrics.to_string()}")

return api_strat_units


async def _get_stratigraphic_units_for_case_async(
authenticated_user: AuthenticatedUser, case_uuid: str
) -> list[StratigraphicUnit]:
Expand All @@ -309,7 +327,7 @@ async def _get_stratigraphic_units_for_case_async(
if strat_column_identifier == "DROGON_HAS_NO_STRATCOLUMN":
smda_access = DrogonSmdaAccess()
else:
smda_access = SmdaAccess(authenticated_user.get_smda_access_token(),field_identifier=field_identifiers[0])
smda_access = SmdaAccess(authenticated_user.get_smda_access_token(), field_identifier=field_identifiers[0])

strat_units = await smda_access.get_stratigraphic_units(strat_column_identifier)
perf_metrics.record_lap("get-strat-units")
Expand Down
17 changes: 16 additions & 1 deletion backend_py/primary/primary/routers/surface/schemas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import List, Literal
from typing import List, Literal, Optional

from pydantic import BaseModel, ConfigDict
from webviz_pkg.core_utils.b64 import B64FloatArray
Expand Down Expand Up @@ -164,3 +164,18 @@ class SurfaceRealizationSampleValues(BaseModel):
class PointSetXY(BaseModel):
x_points: list[float]
y_points: list[float]


class StratigraphicUnit(BaseModel):
identifier: str
top: str
base: str
stratUnitLevel: int
stratUnitType: str
topAge: int | float
baseAge: int | float
stratUnitParent: str | None
colorR: int
colorG: int
colorB: int
lithologyType: int | float | str = "unknown"
7 changes: 5 additions & 2 deletions backend_py/primary/primary/routers/well/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ def convert_wellbore_header_to_schema(
wellNorthing=drilled_wellbore_header.well_northing,
depthReferencePoint=drilled_wellbore_header.depth_reference_point,
depthReferenceElevation=drilled_wellbore_header.depth_reference_elevation,
wellborePurpose=drilled_wellbore_header.wellbore_purpose if drilled_wellbore_header.wellbore_purpose else "", # TODO: Handle None
wellborePurpose=(
drilled_wellbore_header.wellbore_purpose if drilled_wellbore_header.wellbore_purpose else ""
), # TODO: Handle None
wellboreStatus=drilled_wellbore_header.wellbore_status if drilled_wellbore_header.wellbore_status else "",
)
slotIdentifier=drilled_wellbore_header.slot_identifier if drilled_wellbore_header.slot_identifier else "",
)


def convert_well_trajectory_to_schema(
Expand Down
40 changes: 30 additions & 10 deletions backend_py/primary/primary/routers/well/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def get_drilled_wellbore_headers(
# Handle DROGON
well_access = DrogonSmdaAccess()
else:
well_access = SmdaAccess(authenticated_user.get_smda_access_token(),field_identifier=field_identifier)
well_access = SmdaAccess(authenticated_user.get_smda_access_token(), field_identifier=field_identifier)

wellbore_headers = await well_access.get_wellbore_headers()

Expand All @@ -54,15 +54,14 @@ async def get_well_trajectories(
else:
well_access = SmdaAccess(authenticated_user.get_smda_access_token(), field_identifier=field_identifier)

wellbore_trajectories = await well_access.get_wellbore_trajectories(
wellbore_uuids=wellbore_uuids
)
wellbore_trajectories = await well_access.get_wellbore_trajectories(wellbore_uuids=wellbore_uuids)

return [
converters.convert_well_trajectory_to_schema(wellbore_trajectory)
for wellbore_trajectory in wellbore_trajectories
]


@router.get("/wellbore_pick_identifiers/")
async def get_wellbore_pick_identifiers(
# fmt:off
Expand All @@ -76,15 +75,16 @@ async def get_wellbore_pick_identifiers(
if field_identifier == "DROGON":
# Handle DROGON
well_access = DrogonSmdaAccess()

else:
well_access = SmdaAccess(authenticated_user.get_smda_access_token(), field_identifier=field_identifier)

wellbore_picks = await well_access.get_wellbore_pick_identifiers_in_stratigraphic_column(
strat_column_identifier=strat_column_identifier
strat_column_identifier=strat_column_identifier
)
return [wellbore_pick.name for wellbore_pick in wellbore_picks]


@router.get("/wellbore_picks_for_pick_identifier/")
async def get_wellbore_picks_for_pick_identifier(
# fmt:off
Expand All @@ -98,15 +98,35 @@ async def get_wellbore_picks_for_pick_identifier(
if field_identifier == "DROGON":
# Handle DROGON
well_access = DrogonSmdaAccess()

else:
well_access = SmdaAccess(authenticated_user.get_smda_access_token(), field_identifier=field_identifier)

wellbore_picks = await well_access.get_wellbore_picks_for_pick_identifier(
pick_identifier=pick_identifier
)
wellbore_picks = await well_access.get_wellbore_picks_for_pick_identifier(pick_identifier=pick_identifier)
return [converters.convert_wellbore_pick_to_schema(wellbore_pick) for wellbore_pick in wellbore_picks]


@router.get("/wellbore_picks_for_wellbore/")
async def get_wellbore_picks_for_wellbore(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
field_identifier: str = Query(description="Official field identifier"),
wellbore_uuid: str = Query(description="Wellbore uuid")
# fmt:on
) -> List[schemas.WellborePick]:
"""Get wellbore picks for field and pick identifier"""
well_access: Union[SmdaAccess, DrogonSmdaAccess]
if field_identifier == "DROGON":
# Handle DROGON
well_access = DrogonSmdaAccess()

else:
well_access = SmdaAccess(authenticated_user.get_smda_access_token(), field_identifier=field_identifier)

wellbore_picks = await well_access.get_wellbore_picks_for_wellbore(wellbore_uuid=wellbore_uuid)
return [converters.convert_wellbore_pick_to_schema(wellbore_pick) for wellbore_pick in wellbore_picks]


@router.get("/wellbore_completions/")
async def get_wellbore_completions(
# fmt:off
Expand Down
4 changes: 3 additions & 1 deletion backend_py/primary/primary/routers/well/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class WellboreHeader(BaseModel):
depthReferenceElevation: float
wellborePurpose: str
wellboreStatus: str
slotIdentifier: str


class WellboreTrajectory(BaseModel):
wellboreUuid: str
Expand All @@ -58,7 +60,7 @@ class WellborePick(BaseModel):
md: float
mdMsl: float
uniqueWellboreIdentifier: str
wellboreUuid:str
wellboreUuid: str
pickIdentifier: str
confidence: Optional[str] = None
depthReferencePoint: str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def get_wellbore_headers(self) -> List[WellboreHeader]:
if not survey_header_results:
raise NoDataError(f"No wellbore headers found for {self._field_identifier=}.", Service.SMDA)

projection = ["unique_wellbore_identifier", "wellbore_purpose", "wellbore_status"]
projection = ["unique_wellbore_identifier", "wellbore_purpose", "wellbore_status", "slot_identifier"]
params = {
"_projection": ",".join(projection),
"_sort": "unique_wellbore_identifier",
Expand All @@ -89,6 +89,7 @@ async def get_wellbore_headers(self) -> List[WellboreHeader]:
if survey_header["unique_wellbore_identifier"] == wellbore_header["unique_wellbore_identifier"]:
survey_header["wellbore_purpose"] = wellbore_header.get("wellbore_purpose")
survey_header["wellbore_status"] = wellbore_header.get("wellbore_status")
survey_header["slot_identifier"] = wellbore_header.get("slot_identifier")
break

return [WellboreHeader(**result) for result in survey_header_results]
Expand Down
3 changes: 2 additions & 1 deletion backend_py/primary/primary/services/smda_access/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class WellborePick(BaseModel):
md: float
md_msl: float
unique_wellbore_identifier: str
wellbore_uuid:str
wellbore_uuid: str
pick_identifier: str
confidence: Optional[str] = None
depth_reference_point: str
Expand All @@ -44,6 +44,7 @@ class WellboreHeader(BaseModel):
depth_reference_elevation: float
wellbore_purpose: str | None
wellbore_status: str | None
slot_identifier: str | None


class StratigraphicUnit(BaseModel):
Expand Down
Loading

0 comments on commit fe7c1fe

Please sign in to comment.