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

Refactor: Make smda access use field ident only when neccessary #823

Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions backend_py/primary/primary/routers/polygons/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ async def get_polygons_directory(
polygons_dir = await access.get_polygons_directory_async()

case_inspector = CaseInspector.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid)
field_identifiers = await case_inspector.get_field_identifiers_async()
strat_column_identifier = await case_inspector.get_stratigraphic_column_identifier_async()
smda_access: Union[SmdaAccess, DrogonSmdaAccess]

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())
strat_units = await smda_access.get_stratigraphic_units(strat_column_identifier)
sorted_stratigraphic_surfaces = sort_stratigraphic_names_by_hierarchy(strat_units)

Expand Down
3 changes: 1 addition & 2 deletions backend_py/primary/primary/routers/surface/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,14 @@ async def _get_stratigraphic_units_for_case_async(
perf_metrics = PerfMetrics()

case_inspector = CaseInspector.from_case_uuid(authenticated_user.get_sumo_access_token(), case_uuid)
field_identifiers = await case_inspector.get_field_identifiers_async()
strat_column_identifier = await case_inspector.get_stratigraphic_column_identifier_async()
perf_metrics.record_lap("get-strat-ident")

smda_access: SmdaAccess | DrogonSmdaAccess
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())

strat_units = await smda_access.get_stratigraphic_units(strat_column_identifier)
perf_metrics.record_lap("get-strat-units")
Expand Down
28 changes: 16 additions & 12 deletions backend_py/primary/primary/routers/well/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ 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())

wellbore_headers = await well_access.get_wellbore_headers()
wellbore_headers = await well_access.get_wellbore_headers(field_identifier)

return [converters.convert_wellbore_header_to_schema(wellbore_header) for wellbore_header in wellbore_headers]

Expand All @@ -52,9 +52,12 @@ async def get_well_trajectories(
# 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())

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

return [
converters.convert_well_trajectory_to_schema(wellbore_trajectory)
Expand All @@ -66,18 +69,17 @@ async def get_well_trajectories(
async def get_wellbore_pick_identifiers(
# fmt:off
authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user),
field_identifier: str = Query(description="Official field identifier"),
strat_column_identifier: str = Query(description="Stratigraphic column identifier")
# fmt:on
) -> List[str]:
"""Get wellbore pick identifiers for field and stratigraphic column"""
well_access: Union[SmdaAccess, DrogonSmdaAccess]
if field_identifier == "DROGON":
if strat_column_identifier == "DROGON_HAS_NO_STRATCOLUMN":
# 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())

wellbore_picks = await well_access.get_wellbore_pick_identifiers_in_stratigraphic_column(
strat_column_identifier=strat_column_identifier
Expand All @@ -100,28 +102,30 @@ async def get_wellbore_picks_for_pick_identifier(
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())

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(
field_identifier=field_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":
if wellbore_uuid in ["drogon_horizontal", "drogon_vertical"]:
# 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())

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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ def __init__(self) -> None:
async def get_stratigraphic_units(self, stratigraphic_column_identifier: str) -> List[StratigraphicUnit]:
return get_drogon_strat_units()

async def get_wellbore_headers(self) -> List[WellboreHeader]:
# pylint: disable=unused-argument
async def get_wellbore_headers(self, field_identififer: str) -> List[WellboreHeader]:
"""Get Drogon wellbore headers"""
return get_drogon_well_headers()

async def get_wellbore_trajectories(self, wellbore_uuids: Optional[List[str]] = None) -> List[WellboreTrajectory]:
async def get_wellbore_trajectories(
self, field_identifier: str, wellbore_uuids: Optional[List[str]] = None
) -> List[WellboreTrajectory]:
"""Get all Drogon trajectories"""
all_well_trajs = get_drogon_well_trajectories()
if wellbore_uuids:
Expand All @@ -40,6 +43,7 @@ async def get_wellbore_picks_for_wellbore(
# pylint: disable=unused-argument
async def get_wellbore_picks_for_pick_identifier(
self,
field_identifier: str,
pick_identifier: str,
interpreter: str = "STAT",
obs_no: Optional[int] = None,
Expand Down
26 changes: 13 additions & 13 deletions backend_py/primary/primary/services/smda_access/smda_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class SmdaEndpoints:


class SmdaAccess:
def __init__(self, access_token: str, field_identifier: str):
def __init__(self, access_token: str):
self._smda_token = access_token
self._field_identifier = field_identifier

async def _smda_get_request(self, endpoint: str, params: dict) -> List[dict]:
return await smda_get_request(access_token=self._smda_token, endpoint=endpoint, params=params)
Expand All @@ -46,7 +45,7 @@ async def get_stratigraphic_units(self, strat_column_identifier: str) -> List[St
units = [StratigraphicUnit(**result) for result in results]
return units

async def get_wellbore_headers(self) -> List[WellboreHeader]:
async def get_wellbore_headers(self, field_identifier: str) -> List[WellboreHeader]:
"""
Get wellbore header information for all wellbores in a field.
We need the wellbores with actual survey data, so we must use the wellbore-survey-headers endpoint.
Expand All @@ -65,21 +64,21 @@ async def get_wellbore_headers(self) -> List[WellboreHeader]:
params = {
"_projection": ",".join(projection),
"_sort": "unique_wellbore_identifier",
"field_identifier": self._field_identifier,
"field_identifier": field_identifier,
}

survey_header_results = await self._smda_get_request(
endpoint=SmdaEndpoints.WELLBORE_SURVEY_HEADERS, params=params
)

if not survey_header_results:
raise NoDataError(f"No wellbore headers found for {self._field_identifier=}.", Service.SMDA)
raise NoDataError(f"No wellbore headers found for {field_identifier=}.", Service.SMDA)

projection = ["unique_wellbore_identifier", "wellbore_purpose", "wellbore_status"]
params = {
"_projection": ",".join(projection),
"_sort": "unique_wellbore_identifier",
"field_identifier": self._field_identifier,
"field_identifier": field_identifier,
}

wellbore_headers_results = await self._smda_get_request(endpoint=SmdaEndpoints.WELLHEADERS, params=params)
Expand All @@ -101,24 +100,24 @@ async def get_wellbore_headers(self) -> List[WellboreHeader]:

return [WellboreHeader(**result) for result in survey_header_results]

async def get_wellbore_trajectories(self, wellbore_uuids: Optional[List[str]] = None) -> List[WellboreTrajectory]:
async def get_wellbore_trajectories(
self, field_identifier: str, wellbore_uuids: Optional[List[str]] = None
) -> List[WellboreTrajectory]:
"""
Get wellbore trajectories (survey samples) for all wells in a field, optionally with a subset of wellbores.
"""
params = {
"_projection": "wellbore_uuid, unique_wellbore_identifier,easting,northing,tvd_msl,md",
"_sort": "unique_wellbore_identifier,md",
"field_identifier": self._field_identifier,
"field_identifier": field_identifier,
}
if wellbore_uuids:
params["wellbore_uuid"] = ", ".join(wellbore_uuids)

result = await self._smda_get_request(endpoint=SmdaEndpoints.WELLBORE_SURVEY_SAMPLES, params=params)

if not result:
raise NoDataError(
f"No wellbore surveys found for {self._field_identifier}, {wellbore_uuids=}.", Service.SMDA
)
raise NoDataError(f"No wellbore surveys found for {field_identifier=}, {wellbore_uuids=}.", Service.SMDA)

# Convert the result to polars for processing
resultdf = pl.DataFrame(result)
Expand Down Expand Up @@ -198,6 +197,7 @@ async def get_wellbore_picks_for_wellbore(

async def get_wellbore_picks_for_pick_identifier(
self,
field_identifier: str,
pick_identifier: str,
interpreter: str = "STAT",
obs_no: Optional[int] = None,
Expand All @@ -208,7 +208,7 @@ async def get_wellbore_picks_for_pick_identifier(
"""
params = {
"_sort": "unique_wellbore_identifier,md",
"field_identifier": self._field_identifier,
"field_identifier": field_identifier,
"pick_identifier": pick_identifier,
"interpreter": interpreter,
}
Expand All @@ -218,7 +218,7 @@ async def get_wellbore_picks_for_pick_identifier(
results = await self._smda_get_request(endpoint=SmdaEndpoints.WELLBORE_PICKS, params=params)
if not results:
raise NoDataError(
f"No wellbore picks found for {self._field_identifier=}, {pick_identifier=}, {interpreter=}, {obs_no=}.",
f"No wellbore picks found for {field_identifier=}, {pick_identifier=}, {interpreter=}, {obs_no=}.",
Service.SMDA,
)
picks: List[WellborePick] = []
Expand Down
6 changes: 0 additions & 6 deletions frontend/src/api/services/WellService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,17 @@ export class WellService {
/**
* Get Wellbore Pick Identifiers
* Get wellbore pick identifiers for field and stratigraphic column
* @param fieldIdentifier Official field identifier
* @param stratColumnIdentifier Stratigraphic column identifier
* @returns string Successful Response
* @throws ApiError
*/
public getWellborePickIdentifiers(
fieldIdentifier: string,
stratColumnIdentifier: string,
): CancelablePromise<Array<string>> {
return this.httpRequest.request({
method: 'GET',
url: '/well/wellbore_pick_identifiers/',
query: {
'field_identifier': fieldIdentifier,
'strat_column_identifier': stratColumnIdentifier,
},
errors: {
Expand Down Expand Up @@ -110,20 +107,17 @@ export class WellService {
/**
* Get Wellbore Picks For Wellbore
* Get wellbore picks for field and pick identifier
* @param fieldIdentifier Official field identifier
* @param wellboreUuid Wellbore uuid
* @returns WellborePick Successful Response
* @throws ApiError
*/
public getWellborePicksForWellbore(
fieldIdentifier: string,
wellboreUuid: string,
): CancelablePromise<Array<WellborePick>> {
return this.httpRequest.request({
method: 'GET',
url: '/well/wellbore_picks_for_wellbore/',
query: {
'field_identifier': fieldIdentifier,
'wellbore_uuid': wellboreUuid,
},
errors: {
Expand Down
12 changes: 2 additions & 10 deletions frontend/src/modules/Intersection/utils/layers/WellpicksLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,12 @@ export class WellpicksLayer extends BaseLayer<WellpicksLayerSettings, WellPicksL
}

protected async fetchData(queryClient: QueryClient): Promise<WellPicksLayerData> {
const queryKey = [
"getWellborePicksAndStratigraphicUnits",
this._settings.fieldIdentifier,
this._settings.wellboreUuid,
];
const queryKey = ["getWellborePicksAndStratigraphicUnits", this._settings.wellboreUuid];
this.registerQueryKey(queryKey);

const wellborePicksPromise = queryClient.fetchQuery({
queryKey,
queryFn: () =>
apiService.well.getWellborePicksForWellbore(
this._settings.fieldIdentifier ?? "",
this._settings.wellboreUuid ?? ""
),
queryFn: () => apiService.well.getWellborePicksForWellbore(this._settings.wellboreUuid ?? ""),
staleTime: STALE_TIME,
gcTime: CACHE_TIME,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ export const wellLogCurveHeadersQueryAtom = atomWithQuery((get) => {
});

export const wellborePicksQueryAtom = atomWithQuery((get) => {
const selectedFieldIdent = get(selectedFieldIdentifierAtom) ?? "";
const selectedWellboreUuid = get(selectedWellboreHeaderAtom)?.wellboreUuid ?? "";

return {
queryKey: ["getWellborePicksForWellbore", selectedFieldIdent, selectedWellboreUuid],
enabled: Boolean(selectedFieldIdent && selectedWellboreUuid),
queryFn: () => apiService.well.getWellborePicksForWellbore(selectedFieldIdent, selectedWellboreUuid),
queryKey: ["getWellborePicksForWellbore", selectedWellboreUuid],
enabled: Boolean(selectedWellboreUuid),
queryFn: () => apiService.well.getWellborePicksForWellbore(selectedWellboreUuid),
...SHARED_QUERY_OPTS,
};
});
Expand All @@ -61,7 +60,7 @@ export const wellboreStratigraphicUnitsQueryAtom = atomWithQuery((get) => {
const caseUuid = selectedEnsemble?.getCaseUuid() ?? "";

return {
queryKey: ["getWellborePicksForWellbore", caseUuid],
queryKey: ["getStratigraphicUnits", caseUuid],
enabled: Boolean(caseUuid),
queryFn: () => apiService.surface.getStratigraphicUnits(caseUuid),
...SHARED_QUERY_OPTS,
Expand Down
Loading