diff --git a/backend/src/backend/primary/main.py b/backend/src/backend/primary/main.py index 1fb398d14..4f5b86514 100644 --- a/backend/src/backend/primary/main.py +++ b/backend/src/backend/primary/main.py @@ -21,6 +21,7 @@ from .routers.well.router import router as well_router from .routers.surface_polygons.router import router as surface_polygons_router from .routers.seismic.router import router as seismic_router +from .routers.intersection.router import router as intersection_router logging.basicConfig( level=logging.WARNING, @@ -57,6 +58,7 @@ def custom_generate_unique_id(route: APIRoute) -> str: app.include_router(well_router, prefix="/well", tags=["well"]) app.include_router(surface_polygons_router, prefix="/surface_polygons", tags=["surface_polygons"]) app.include_router(seismic_router, prefix="/seismic", tags=["seismic"]) +app.include_router(intersection_router, prefix="/intersection", tags=["intersection"]) authHelper = AuthHelper() app.include_router(authHelper.router) diff --git a/backend/src/backend/primary/routers/grid/router.py b/backend/src/backend/primary/routers/grid/router.py index dfe8fe1ab..f8c0e51bf 100644 --- a/backend/src/backend/primary/routers/grid/router.py +++ b/backend/src/backend/primary/routers/grid/router.py @@ -11,7 +11,7 @@ from src.services.sumo_access.grid_access import GridAccess from .schemas import GridSurface, B64EncodedNumpyArray, GridIntersection -from src.backend.primary.routers.seismic.schemas import FenceResponse + router = APIRouter() @@ -150,45 +150,6 @@ async def grid_parameter_intersection( return response -@router.get("/grid_parameter_intersectionv2") -async def grid_parameter_intersectionv2( - authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user), - case_uuid: str = Query(description="Sumo case uuid"), - ensemble_name: str = Query(description="Ensemble name"), - grid_name: str = Query(description="Grid name"), - parameter_name: str = Query(description="Grid parameter"), - realization: int = Query(description="Realization"), - easting_arr: List[float] = Query(description="Easting array"), - northing_arr: List[float] = Query(description="Northing array"), - hlen_arr: List[float] = Query(description="Hlen array"), -) -> FenceResponse: - """Get a grid parameter""" - grid_access = GridAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name) - grid_geometry = grid_access.get_grid_geometry(grid_name, int(realization)) - grid_property = grid_access.get_grid_parameter(grid_name, parameter_name, int(realization)) - grid_property.name = parameter_name - grid_geometry._filesrc = "grid" - grid_property._filesrc = "gridprop" - grid_geometry.append_prop(grid_property) - print("Starting to get random line") - from src.services.utils.perf_timer import PerfTimer - - timer = PerfTimer() - - fence_arr = np.array([easting_arr, northing_arr, np.zeros(len(northing_arr)), hlen_arr]).T - print(grid_property) - print(grid_geometry) - hmin, hmax, vmin, vmax, ndarray2d = grid_geometry.get_randomline(fence_arr, parameter_name) - print("Got random line", timer.lap_s()) - print(np.nanmin(ndarray2d), np.nanmax(ndarray2d)) - # ndarray2d = np.clip(ndarray2d, 0.25, 0.35) - - return FenceResponse( - xy_arr_string=json.dumps(ndarray2d.tolist()), - z_arr_string=json.dumps(np.linspace(vmin, vmax, len(ndarray2d)).tolist()), - ) - - @router.get("/statistical_grid_parameter_intersection") async def statistical_grid_parameter_intersection( request: Request, diff --git a/backend/src/backend/primary/routers/intersection/__init__.py b/backend/src/backend/primary/routers/intersection/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/backend/src/backend/primary/routers/intersection/router.py b/backend/src/backend/primary/routers/intersection/router.py new file mode 100644 index 000000000..b14c37a9b --- /dev/null +++ b/backend/src/backend/primary/routers/intersection/router.py @@ -0,0 +1,131 @@ +import logging +from typing import List +import numpy as np +from fastapi import APIRouter, Depends, HTTPException, Query, Body +import orjson as json + +from src.services.sumo_access import SurfaceAccess, SeismicAccess, GridAccess +from src.services.oneseismic_access.vds_access import VdsAccess + +from src.services.utils.authenticated_user import AuthenticatedUser + +from src.backend.auth.auth_helper import AuthHelper +from . import schemas + + +router = APIRouter() + + +@router.post("/surfaces/") +def get_surfaces( + authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user), + case_uuid: str = Query(description="Sumo case uuid"), + ensemble_name: str = Query(description="Ensemble name"), + realization_num: int = Query(description="Realization number"), + names: List[str] = Query(description="Surface names"), + attribute: str = Query(description="Surface attribute"), + cutting_plane: schemas.CuttingPlane = Body(alias="cuttingPlane", embed=True), +) -> List[schemas.SurfaceIntersectionData]: + access = SurfaceAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name) + intersections = [] + + fence_arr = np.array( + [cutting_plane.x_arr, cutting_plane.y_arr, np.zeros(len(cutting_plane.y_arr)), cutting_plane.h_arr] + ).T + + for name in names: + try: + xtgeo_surf = access.get_static_surf(real_num=realization_num, name=name, attribute=attribute) + line = xtgeo_surf.get_randomline(fence_arr) + intersections.append( + schemas.SurfaceIntersectionData(name=f"{name}", hlen_arr=line[:, 0].tolist(), z_arr=line[:, 1].tolist()) + ) + except AttributeError: + print(f"Could not find surface {name} with attribute {attribute}-{realization_num}") + + return intersections + + +@router.post("/grid_parameter/") +async def get_grid_parameter( + authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user), + case_uuid: str = Query(description="Sumo case uuid"), + ensemble_name: str = Query(description="Ensemble name"), + grid_name: str = Query(description="Grid name"), + parameter_name: str = Query(description="Grid parameter"), + realization: int = Query(description="Realization"), + cutting_plane: schemas.CuttingPlane = Body(alias="cuttingPlane", embed=True), +) -> schemas.CubeIntersectionData: + """Get a grid parameter""" + grid_access = GridAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name) + grid_geometry = grid_access.get_grid_geometry(grid_name, int(realization)) + grid_property = grid_access.get_grid_parameter(grid_name, parameter_name, int(realization)) + grid_property.name = parameter_name + grid_geometry._filesrc = "grid" + grid_property._filesrc = "gridprop" + grid_geometry.append_prop(grid_property) + print("Starting to get random line") + from src.services.utils.perf_timer import PerfTimer + + timer = PerfTimer() + + fence_arr = np.array( + [cutting_plane.x_arr, cutting_plane.y_arr, np.zeros(len(cutting_plane.y_arr)), cutting_plane.h_arr] + ).T + hmin, hmax, vmin, vmax, ndarray2d = grid_geometry.get_randomline(fence_arr, parameter_name) + print("Got random line", timer.lap_s()) + print(np.nanmin(ndarray2d), np.nanmax(ndarray2d)) + # ndarray2d = np.clip(ndarray2d, 0.25, 0.35) + + return schemas.CubeIntersectionData( + xy_arr_string=json.dumps(ndarray2d.tolist()), + z_arr_string=json.dumps(np.linspace(vmin, vmax, len(ndarray2d)).tolist()), + ) + + +@router.post("/seismic/") +def get_seismic( + authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user), + case_uuid: str = Query(description="Sumo case uuid"), + ensemble_name: str = Query(description="Ensemble name"), + realization_num: int = Query(description="Realization number"), + seismic_cube_attribute: str = Query(description="Seismic cube attribute"), + seismic_timestamp_or_timestep: str = Query(description="Timestamp or timestep"), + observed: bool = Query(description="Observed or simulated"), + cutting_plane: schemas.CuttingPlane = Body(alias="cuttingPlane", embed=True), +) -> schemas.CubeIntersectionData: + seismic_access = SeismicAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name) + timestamp = None + timestep = None + if "--" in seismic_timestamp_or_timestep: + timestep = seismic_timestamp_or_timestep + else: + timestamp = seismic_timestamp_or_timestep + + try: + vds_handle = seismic_access.get_vds_handle( + realization=realization_num, + iteration=ensemble_name, + cube_tagname=seismic_cube_attribute, + timestep=timestep, + timestamp=timestamp, + observed=observed, + ) + except ValueError as err: + raise HTTPException(status_code=404, detail=str(err)) from err + + vdsaccess = VdsAccess(vds_handle) + + vals, meta = vdsaccess.get_fence( + coordinate_system="cdp", coordinates=[[x, y] for x, y in zip(cutting_plane.x_arr, cutting_plane.y_arr)] + ) + + meta = vdsaccess.get_metadata() + tvd_meta = meta.get("axis")[2] + + tvd_values = np.linspace(tvd_meta["min"], tvd_meta["max"], tvd_meta["samples"]) + + return schemas.CubeIntersectionData( + xy_arr_string=json.dumps(vals.T.tolist()), # pylint: disable=no-member + z_arr_string=json.dumps(tvd_values.tolist()), # pylint: disable=no-member + ) diff --git a/backend/src/backend/primary/routers/intersection/schemas.py b/backend/src/backend/primary/routers/intersection/schemas.py new file mode 100644 index 000000000..f0e52a2fa --- /dev/null +++ b/backend/src/backend/primary/routers/intersection/schemas.py @@ -0,0 +1,24 @@ +from typing import List + +from pydantic import BaseModel + + +class CuttingPlane(BaseModel): + x_arr: List[float] + y_arr: List[float] + h_arr: List[float] + + +class SurfaceIntersectionData(BaseModel): + name: str + z_arr: List[float] + hlen_arr: List[float] + unit: str = "m" + depthReference: str = "MSL" + context: str = "depth" + stratigraphicalInterval: bool = True + + +class CubeIntersectionData(BaseModel): + xy_arr_string: str + z_arr_string: str diff --git a/backend/src/backend/primary/routers/seismic/router.py b/backend/src/backend/primary/routers/seismic/router.py index fb5158928..e6fe86c4c 100644 --- a/backend/src/backend/primary/routers/seismic/router.py +++ b/backend/src/backend/primary/routers/seismic/router.py @@ -116,51 +116,3 @@ def get_slice( ) vdsaccess = VdsAccess(vds_handle) vdsaccess.get_slice(lineno=lineno, direction=direction) - - -@router.get("/get_fence/") -def get_fence( - authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user), - case_uuid: str = Query(description="Sumo case uuid"), - ensemble_name: str = Query(description="Ensemble name"), - realization_num: int = Query(description="Realization number"), - seismic_cube_attribute: str = Query(description="Seismic cube attribute"), - seismic_timestamp_or_timestep: str = Query(description="Timestamp or timestep"), - observed: bool = Query(description="Observed or simulated"), - easting_arr: List[float] = Query(description="Easting array"), - northing_arr: List[float] = Query(description="Northing array"), -) -> schemas.FenceResponse: - seismic_access = SeismicAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name) - timestamp = None - timestep = None - if "--" in seismic_timestamp_or_timestep: - timestep = seismic_timestamp_or_timestep - else: - timestamp = seismic_timestamp_or_timestep - - try: - vds_handle = seismic_access.get_vds_handle( - realization=realization_num, - iteration=ensemble_name, - cube_tagname=seismic_cube_attribute, - timestep=timestep, - timestamp=timestamp, - observed=observed, - ) - except ValueError as err: - raise HTTPException(status_code=404, detail=str(err)) from err - vdsaccess = VdsAccess(vds_handle) - - vals, meta = vdsaccess.get_fence( - coordinate_system="cdp", coordinates=[[x, y] for x, y in zip(easting_arr, northing_arr)] - ) - - meta = vdsaccess.get_metadata() - tvd_meta = meta.get("axis")[2] - - tvd_values = np.linspace(tvd_meta["min"], tvd_meta["max"], tvd_meta["samples"]) - - return schemas.FenceResponse( - xy_arr_string=json.dumps(vals.T.tolist()), # pylint: disable=no-member - z_arr_string=json.dumps(tvd_values.tolist()), # pylint: disable=no-member - ) diff --git a/backend/src/backend/primary/routers/seismic/schemas.py b/backend/src/backend/primary/routers/seismic/schemas.py index 5dc9bde00..ce9107ed8 100644 --- a/backend/src/backend/primary/routers/seismic/schemas.py +++ b/backend/src/backend/primary/routers/seismic/schemas.py @@ -2,11 +2,6 @@ from pydantic import BaseModel -class FenceResponse(BaseModel): - xy_arr_string: str - z_arr_string: str - - class Seismic3DSurveyDirectory(BaseModel): attributes: List[str] timestamps: List[str] diff --git a/backend/src/backend/primary/routers/surface/router.py b/backend/src/backend/primary/routers/surface/router.py index b83e4600f..fa9beeec9 100644 --- a/backend/src/backend/primary/routers/surface/router.py +++ b/backend/src/backend/primary/routers/surface/router.py @@ -1,7 +1,8 @@ import logging from typing import List import numpy as np -from fastapi import APIRouter, Depends, HTTPException, Query +from fastapi import APIRouter, Depends, HTTPException, Query, Body +import json from src.services.sumo_access.surface_access import SurfaceAccess from src.services.sumo_access.iteration_inspector import IterationInspector @@ -253,80 +254,3 @@ def get_statistical_static_surface_data( LOGGER.debug(f"Calculated statistical static surface and created image, total time: {timer.elapsed_ms()}ms") return surf_data_response - - -@router.get("/get_intersection/") -def get_intersection( - authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user), - case_uuid: str = Query(description="Sumo case uuid"), - ensemble_name: str = Query(description="Ensemble name"), - realization_num: int = Query(description="Realization number"), - names: List[str] = Query(description="Surface names"), - attribute: str = Query(description="Surface attribute"), - easting_arr: List[float] = Query(description="Easting array"), - northing_arr: List[float] = Query(description="Northing array"), - hlen_arr: List[float] = Query(description="Hlen array"), -) -> List[schemas.SurfaceIntersection]: - access = SurfaceAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name) - - intersections = [] - fence_arr = np.array([easting_arr, northing_arr, np.zeros(len(northing_arr)), hlen_arr]).T - - for name in names: - try: - xtgeo_surf = access.get_static_surf(real_num=realization_num, name=name, attribute=attribute) - line = xtgeo_surf.get_randomline(fence_arr) - intersections.append( - schemas.SurfaceIntersection(name=f"{name}", hlen_arr=line[:, 0].tolist(), z_arr=line[:, 1].tolist()) - ) - except AttributeError: - print(f"Could not find surface {name} with attribute {attribute}-{realization_num}") - - return intersections - - -# @router.get("/get_statistical_fence_polyline/") -# def get_statistical_fence_polyline( -# authenticated_user: AuthenticatedUser = Depends(AuthHelper.get_authenticated_user), -# case_uuid: str = Query(description="Sumo case uuid"), -# ensemble_name: str = Query(description="Ensemble name"), -# realization_num: int = Query(description="Realization number"), -# seismic_cube_attribute: str = Query(description="Seismic cube attribute"), -# seismic_timestamp_or_timestep: str = Query(description="Timestamp or timestep"), -# easting_arr: List[float] = Query(description="Easting array"), -# northing_arr: List[float] = Query(description="Northing array"), -# hlen_arr: List[float] = Query(description="Hlen array"), -# ) -> schemas.FenceResponse: -# seismic_access = SeismicAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name) -# timestamp = None -# timestep = None -# if "--" in seismic_timestamp_or_timestep: -# timestep = seismic_timestamp_or_timestep -# else: -# timestamp = seismic_timestamp_or_timestep -# vds_handle = seismic_access.get_vds_handle( -# realization=realization_num, -# iteration=ensemble_name, -# cube_tagname=seismic_cube_attribute, -# timestep=timestep, -# timestamp=timestamp, -# ) -# vdsaccess = VdsAccess(vds_handle) - -# vals, meta = vdsaccess.get_fence( -# coordinate_system="cdp", coordinates=[[x, y] for x, y in zip(easting_arr, northing_arr)] -# ) -# # print(vals.T) - -# meta = vdsaccess.get_metadata() -# tvd_meta = meta.get("axis")[2] -# import numpy as np - -# print(meta) -# tvd_values = np.linspace(tvd_meta["min"], tvd_meta["max"], tvd_meta["samples"]) -# # print(tvd_values) -# # print(json.dumps(vals.T.tolist())) - -# return schemas.FenceResponse( -# xy_arr_string=json.dumps(vals.T.tolist()), z_arr_string=json.dumps(tvd_values.tolist()) -# ) diff --git a/backend/src/backend/primary/routers/surface/schemas.py b/backend/src/backend/primary/routers/surface/schemas.py index 4d5064f92..15ab10714 100644 --- a/backend/src/backend/primary/routers/surface/schemas.py +++ b/backend/src/backend/primary/routers/surface/schemas.py @@ -41,13 +41,3 @@ class SurfaceData(BaseModel): val_max: float rot_deg: float mesh_data: str - - -class SurfaceIntersection(BaseModel): - name: str - z_arr: List[float] - hlen_arr: List[float] - unit: str = "m" - depthReference: str = "MSL" - context: str = "depth" - stratigraphicalInterval: bool = True diff --git a/backend/src/services/oneseismic_access/vds_access.py b/backend/src/services/oneseismic_access/vds_access.py index b6b8e4182..3fae38f75 100644 --- a/backend/src/services/oneseismic_access/vds_access.py +++ b/backend/src/services/oneseismic_access/vds_access.py @@ -62,7 +62,8 @@ def get_fence(self, coordinates: List[List[float]], coordinate_system: str): "coordinates": coordinates, "vds": self.vds_url, "sas": self.sas, - "interpolation": "nearest", + "interpolation": "cubic", + "fillValue": -999.25, } response = self._query(endpoint, params) diff --git a/backend/src/services/sumo_access/__init__.py b/backend/src/services/sumo_access/__init__.py index e69de29bb..9866162f0 100644 --- a/backend/src/services/sumo_access/__init__.py +++ b/backend/src/services/sumo_access/__init__.py @@ -0,0 +1,6 @@ +from .surface_access import SurfaceAccess +from .seismic_access import SeismicAccess +from .grid_access import GridAccess +from .inplace_volumetrics_access import InplaceVolumetricsAccess +from .summary_access import SummaryAccess +from .table_access import TableAccess diff --git a/frontend/src/api/ApiService.ts b/frontend/src/api/ApiService.ts index 458e2a2af..7bf093634 100644 --- a/frontend/src/api/ApiService.ts +++ b/frontend/src/api/ApiService.ts @@ -10,6 +10,7 @@ import { DefaultService } from './services/DefaultService'; import { ExploreService } from './services/ExploreService'; import { GridService } from './services/GridService'; import { InplaceVolumetricsService } from './services/InplaceVolumetricsService'; +import { IntersectionService } from './services/IntersectionService'; import { ParametersService } from './services/ParametersService'; import { PvtService } from './services/PvtService'; import { SeismicService } from './services/SeismicService'; @@ -27,6 +28,7 @@ export class ApiService { public readonly explore: ExploreService; public readonly grid: GridService; public readonly inplaceVolumetrics: InplaceVolumetricsService; + public readonly intersection: IntersectionService; public readonly parameters: ParametersService; public readonly pvt: PvtService; public readonly seismic: SeismicService; @@ -55,6 +57,7 @@ export class ApiService { this.explore = new ExploreService(this.request); this.grid = new GridService(this.request); this.inplaceVolumetrics = new InplaceVolumetricsService(this.request); + this.intersection = new IntersectionService(this.request); this.parameters = new ParametersService(this.request); this.pvt = new PvtService(this.request); this.seismic = new SeismicService(this.request); diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index 392902c8f..3b6549bda 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -10,8 +10,13 @@ export { OpenAPI } from './core/OpenAPI'; export type { OpenAPIConfig } from './core/OpenAPI'; export type { B64EncodedNumpyArray as B64EncodedNumpyArray_api } from './models/B64EncodedNumpyArray'; +export type { Body_get_grid_parameter as Body_get_grid_parameter_api } from './models/Body_get_grid_parameter'; export type { Body_get_realizations_response as Body_get_realizations_response_api } from './models/Body_get_realizations_response'; +export type { Body_get_seismic as Body_get_seismic_api } from './models/Body_get_seismic'; +export type { Body_get_surfaces as Body_get_surfaces_api } from './models/Body_get_surfaces'; export type { CaseInfo as CaseInfo_api } from './models/CaseInfo'; +export type { CubeIntersectionData as CubeIntersectionData_api } from './models/CubeIntersectionData'; +export type { CuttingPlane as CuttingPlane_api } from './models/CuttingPlane'; export type { DynamicSurfaceDirectory as DynamicSurfaceDirectory_api } from './models/DynamicSurfaceDirectory'; export type { EnsembleCorrelations as EnsembleCorrelations_api } from './models/EnsembleCorrelations'; export type { EnsembleDetails as EnsembleDetails_api } from './models/EnsembleDetails'; @@ -21,7 +26,6 @@ export type { EnsembleParameterDescription as EnsembleParameterDescription_api } export type { EnsembleScalarResponse as EnsembleScalarResponse_api } from './models/EnsembleScalarResponse'; export type { EnsembleSensitivity as EnsembleSensitivity_api } from './models/EnsembleSensitivity'; export type { EnsembleSensitivityCase as EnsembleSensitivityCase_api } from './models/EnsembleSensitivityCase'; -export type { FenceResponse as FenceResponse_api } from './models/FenceResponse'; export type { FieldInfo as FieldInfo_api } from './models/FieldInfo'; export { Frequency as Frequency_api } from './models/Frequency'; export type { GridIntersection as GridIntersection_api } from './models/GridIntersection'; @@ -40,7 +44,7 @@ export type { StatisticValueObject as StatisticValueObject_api } from './models/ export type { StratigraphicUnit as StratigraphicUnit_api } from './models/StratigraphicUnit'; export { SumoContent as SumoContent_api } from './models/SumoContent'; export type { SurfaceData as SurfaceData_api } from './models/SurfaceData'; -export type { SurfaceIntersection as SurfaceIntersection_api } from './models/SurfaceIntersection'; +export type { SurfaceIntersectionData as SurfaceIntersectionData_api } from './models/SurfaceIntersectionData'; export type { SurfacePolygonDirectory as SurfacePolygonDirectory_api } from './models/SurfacePolygonDirectory'; export { SurfaceStatisticFunction as SurfaceStatisticFunction_api } from './models/SurfaceStatisticFunction'; export type { UserInfo as UserInfo_api } from './models/UserInfo'; @@ -60,6 +64,7 @@ export { DefaultService } from './services/DefaultService'; export { ExploreService } from './services/ExploreService'; export { GridService } from './services/GridService'; export { InplaceVolumetricsService } from './services/InplaceVolumetricsService'; +export { IntersectionService } from './services/IntersectionService'; export { ParametersService } from './services/ParametersService'; export { PvtService } from './services/PvtService'; export { SeismicService } from './services/SeismicService'; diff --git a/frontend/src/api/models/Body_get_grid_parameter.ts b/frontend/src/api/models/Body_get_grid_parameter.ts new file mode 100644 index 000000000..9d3f2b731 --- /dev/null +++ b/frontend/src/api/models/Body_get_grid_parameter.ts @@ -0,0 +1,10 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import type { CuttingPlane } from './CuttingPlane'; + +export type Body_get_grid_parameter = { + cuttingPlane: CuttingPlane; +}; + diff --git a/frontend/src/api/models/Body_get_seismic.ts b/frontend/src/api/models/Body_get_seismic.ts new file mode 100644 index 000000000..4dbc1e47f --- /dev/null +++ b/frontend/src/api/models/Body_get_seismic.ts @@ -0,0 +1,10 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import type { CuttingPlane } from './CuttingPlane'; + +export type Body_get_seismic = { + cuttingPlane: CuttingPlane; +}; + diff --git a/frontend/src/api/models/Body_get_surfaces.ts b/frontend/src/api/models/Body_get_surfaces.ts new file mode 100644 index 000000000..adbd103a2 --- /dev/null +++ b/frontend/src/api/models/Body_get_surfaces.ts @@ -0,0 +1,10 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +import type { CuttingPlane } from './CuttingPlane'; + +export type Body_get_surfaces = { + cuttingPlane: CuttingPlane; +}; + diff --git a/frontend/src/api/models/FenceResponse.ts b/frontend/src/api/models/CubeIntersectionData.ts similarity index 77% rename from frontend/src/api/models/FenceResponse.ts rename to frontend/src/api/models/CubeIntersectionData.ts index 885c76bd6..35e26085e 100644 --- a/frontend/src/api/models/FenceResponse.ts +++ b/frontend/src/api/models/CubeIntersectionData.ts @@ -2,7 +2,7 @@ /* tslint:disable */ /* eslint-disable */ -export type FenceResponse = { +export type CubeIntersectionData = { xy_arr_string: string; z_arr_string: string; }; diff --git a/frontend/src/api/models/CuttingPlane.ts b/frontend/src/api/models/CuttingPlane.ts new file mode 100644 index 000000000..30f633055 --- /dev/null +++ b/frontend/src/api/models/CuttingPlane.ts @@ -0,0 +1,10 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type CuttingPlane = { + x_arr: Array; + y_arr: Array; + h_arr: Array; +}; + diff --git a/frontend/src/api/models/SurfaceIntersection.ts b/frontend/src/api/models/SurfaceIntersectionData.ts similarity index 86% rename from frontend/src/api/models/SurfaceIntersection.ts rename to frontend/src/api/models/SurfaceIntersectionData.ts index b990b8c61..94f35c3a2 100644 --- a/frontend/src/api/models/SurfaceIntersection.ts +++ b/frontend/src/api/models/SurfaceIntersectionData.ts @@ -2,7 +2,7 @@ /* tslint:disable */ /* eslint-disable */ -export type SurfaceIntersection = { +export type SurfaceIntersectionData = { name: string; z_arr: Array; hlen_arr: Array; diff --git a/frontend/src/api/services/GridService.ts b/frontend/src/api/services/GridService.ts index 61bfd70ed..66bcfc665 100644 --- a/frontend/src/api/services/GridService.ts +++ b/frontend/src/api/services/GridService.ts @@ -2,7 +2,6 @@ /* tslint:disable */ /* eslint-disable */ import type { B64EncodedNumpyArray } from '../models/B64EncodedNumpyArray'; -import type { FenceResponse } from '../models/FenceResponse'; import type { GridIntersection } from '../models/GridIntersection'; import type { GridSurface } from '../models/GridSurface'; @@ -165,49 +164,6 @@ export class GridService { }); } - /** - * Grid Parameter Intersectionv2 - * Get a grid parameter - * @param caseUuid Sumo case uuid - * @param ensembleName Ensemble name - * @param gridName Grid name - * @param parameterName Grid parameter - * @param realization Realization - * @param eastingArr Easting array - * @param northingArr Northing array - * @param hlenArr Hlen array - * @returns FenceResponse Successful Response - * @throws ApiError - */ - public gridParameterIntersectionv2( - caseUuid: string, - ensembleName: string, - gridName: string, - parameterName: string, - realization: number, - eastingArr: Array, - northingArr: Array, - hlenArr: Array, - ): CancelablePromise { - return this.httpRequest.request({ - method: 'GET', - url: '/grid/grid_parameter_intersectionv2', - query: { - 'case_uuid': caseUuid, - 'ensemble_name': ensembleName, - 'grid_name': gridName, - 'parameter_name': parameterName, - 'realization': realization, - 'easting_arr': eastingArr, - 'northing_arr': northingArr, - 'hlen_arr': hlenArr, - }, - errors: { - 422: `Validation Error`, - }, - }); - } - /** * Statistical Grid Parameter Intersection * Get a grid parameter diff --git a/frontend/src/api/services/IntersectionService.ts b/frontend/src/api/services/IntersectionService.ts new file mode 100644 index 000000000..6b566335b --- /dev/null +++ b/frontend/src/api/services/IntersectionService.ts @@ -0,0 +1,132 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { Body_get_grid_parameter } from '../models/Body_get_grid_parameter'; +import type { Body_get_seismic } from '../models/Body_get_seismic'; +import type { Body_get_surfaces } from '../models/Body_get_surfaces'; +import type { CubeIntersectionData } from '../models/CubeIntersectionData'; +import type { SurfaceIntersectionData } from '../models/SurfaceIntersectionData'; + +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class IntersectionService { + + constructor(public readonly httpRequest: BaseHttpRequest) {} + + /** + * Get Surfaces + * @param caseUuid Sumo case uuid + * @param ensembleName Ensemble name + * @param realizationNum Realization number + * @param names Surface names + * @param attribute Surface attribute + * @param requestBody + * @returns SurfaceIntersectionData Successful Response + * @throws ApiError + */ + public getSurfaces( + caseUuid: string, + ensembleName: string, + realizationNum: number, + names: Array, + attribute: string, + requestBody: Body_get_surfaces, + ): CancelablePromise> { + return this.httpRequest.request({ + method: 'POST', + url: '/intersection/surfaces/', + query: { + 'case_uuid': caseUuid, + 'ensemble_name': ensembleName, + 'realization_num': realizationNum, + 'names': names, + 'attribute': attribute, + }, + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } + + /** + * Get Grid Parameter + * Get a grid parameter + * @param caseUuid Sumo case uuid + * @param ensembleName Ensemble name + * @param gridName Grid name + * @param parameterName Grid parameter + * @param realization Realization + * @param requestBody + * @returns CubeIntersectionData Successful Response + * @throws ApiError + */ + public getGridParameter( + caseUuid: string, + ensembleName: string, + gridName: string, + parameterName: string, + realization: number, + requestBody: Body_get_grid_parameter, + ): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/intersection/grid_parameter/', + query: { + 'case_uuid': caseUuid, + 'ensemble_name': ensembleName, + 'grid_name': gridName, + 'parameter_name': parameterName, + 'realization': realization, + }, + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } + + /** + * Get Seismic + * @param caseUuid Sumo case uuid + * @param ensembleName Ensemble name + * @param realizationNum Realization number + * @param seismicCubeAttribute Seismic cube attribute + * @param seismicTimestampOrTimestep Timestamp or timestep + * @param observed Observed or simulated + * @param requestBody + * @returns CubeIntersectionData Successful Response + * @throws ApiError + */ + public getSeismic( + caseUuid: string, + ensembleName: string, + realizationNum: number, + seismicCubeAttribute: string, + seismicTimestampOrTimestep: string, + observed: boolean, + requestBody: Body_get_seismic, + ): CancelablePromise { + return this.httpRequest.request({ + method: 'POST', + url: '/intersection/seismic/', + query: { + 'case_uuid': caseUuid, + 'ensemble_name': ensembleName, + 'realization_num': realizationNum, + 'seismic_cube_attribute': seismicCubeAttribute, + 'seismic_timestamp_or_timestep': seismicTimestampOrTimestep, + 'observed': observed, + }, + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } + +} diff --git a/frontend/src/api/services/SeismicService.ts b/frontend/src/api/services/SeismicService.ts index 7d4766a74..f7495c020 100644 --- a/frontend/src/api/services/SeismicService.ts +++ b/frontend/src/api/services/SeismicService.ts @@ -1,7 +1,6 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { FenceResponse } from '../models/FenceResponse'; import type { Seismic3DSurveyDirectory } from '../models/Seismic3DSurveyDirectory'; import type { Seismic4DSurveyDirectory } from '../models/Seismic4DSurveyDirectory'; @@ -141,46 +140,4 @@ export class SeismicService { }); } - /** - * Get Fence - * @param caseUuid Sumo case uuid - * @param ensembleName Ensemble name - * @param realizationNum Realization number - * @param seismicCubeAttribute Seismic cube attribute - * @param seismicTimestampOrTimestep Timestamp or timestep - * @param observed Observed or simulated - * @param eastingArr Easting array - * @param northingArr Northing array - * @returns FenceResponse Successful Response - * @throws ApiError - */ - public getFence( - caseUuid: string, - ensembleName: string, - realizationNum: number, - seismicCubeAttribute: string, - seismicTimestampOrTimestep: string, - observed: boolean, - eastingArr: Array, - northingArr: Array, - ): CancelablePromise { - return this.httpRequest.request({ - method: 'GET', - url: '/seismic/get_fence/', - query: { - 'case_uuid': caseUuid, - 'ensemble_name': ensembleName, - 'realization_num': realizationNum, - 'seismic_cube_attribute': seismicCubeAttribute, - 'seismic_timestamp_or_timestep': seismicTimestampOrTimestep, - 'observed': observed, - 'easting_arr': eastingArr, - 'northing_arr': northingArr, - }, - errors: { - 422: `Validation Error`, - }, - }); - } - } diff --git a/frontend/src/api/services/SurfaceService.ts b/frontend/src/api/services/SurfaceService.ts index 1909ebb98..d6c5aedc4 100644 --- a/frontend/src/api/services/SurfaceService.ts +++ b/frontend/src/api/services/SurfaceService.ts @@ -5,7 +5,6 @@ import type { DynamicSurfaceDirectory } from '../models/DynamicSurfaceDirectory' import type { StaticSurfaceDirectory } from '../models/StaticSurfaceDirectory'; import type { SumoContent } from '../models/SumoContent'; import type { SurfaceData } from '../models/SurfaceData'; -import type { SurfaceIntersection } from '../models/SurfaceIntersection'; import type { SurfaceStatisticFunction } from '../models/SurfaceStatisticFunction'; import type { CancelablePromise } from '../core/CancelablePromise'; @@ -288,46 +287,4 @@ export class SurfaceService { }); } - /** - * Get Intersection - * @param caseUuid Sumo case uuid - * @param ensembleName Ensemble name - * @param realizationNum Realization number - * @param names Surface names - * @param attribute Surface attribute - * @param eastingArr Easting array - * @param northingArr Northing array - * @param hlenArr Hlen array - * @returns SurfaceIntersection Successful Response - * @throws ApiError - */ - public getIntersection( - caseUuid: string, - ensembleName: string, - realizationNum: number, - names: Array, - attribute: string, - eastingArr: Array, - northingArr: Array, - hlenArr: Array, - ): CancelablePromise> { - return this.httpRequest.request({ - method: 'GET', - url: '/surface/get_intersection/', - query: { - 'case_uuid': caseUuid, - 'ensemble_name': ensembleName, - 'realization_num': realizationNum, - 'names': names, - 'attribute': attribute, - 'easting_arr': eastingArr, - 'northing_arr': northingArr, - 'hlen_arr': hlenArr, - }, - errors: { - 422: `Validation Error`, - }, - }); - } - } diff --git a/frontend/src/modules/Intersection/GridParameterAddress.ts b/frontend/src/modules/Intersection/GridParameterAddress.ts index a7ccdab59..a207447e6 100644 --- a/frontend/src/modules/Intersection/GridParameterAddress.ts +++ b/frontend/src/modules/Intersection/GridParameterAddress.ts @@ -5,4 +5,7 @@ export interface GridParameterAddress { gridName: string; parameterName: string; // timeString?: string; + lockColorRange: boolean; + colorMin?: number | null; + colorMax?: number | null; } diff --git a/frontend/src/modules/Intersection/IntersectionController.ts b/frontend/src/modules/Intersection/IntersectionController.ts index 11104b0d9..dac9c9946 100644 --- a/frontend/src/modules/Intersection/IntersectionController.ts +++ b/frontend/src/modules/Intersection/IntersectionController.ts @@ -1,4 +1,4 @@ -import { SurfaceIntersection_api, WellBorePicksAndStratUnits_api, WellBoreTrajectory_api } from "@api"; +import { SurfaceIntersectionData_api, WellBorePicksAndStratUnits_api, WellBoreTrajectory_api } from "@api"; import { Annotation, Axis, @@ -21,6 +21,9 @@ import { getSeismicOptions, transformFormationData, } from "@equinor/esv-intersection"; +import { UseQueryResult, useQuery } from "@tanstack/react-query"; + +import { generateGridSliceImage } from "./gridData"; export class ControllerHandler { public controller: Controller; @@ -29,12 +32,12 @@ export class ControllerHandler { this.controller = controller; } - public init() { + public init(zScale: number) { this.controller.addLayer(new GridLayer("grid")); this.controller.setBounds([0, 1000], [0, 3000]); this.controller.setViewport(1000, 1750, 5000); - this.controller.zoomPanHandler.zFactor = 5; + this.controller.zoomPanHandler.zFactor = zScale; } public destroy() { @@ -115,7 +118,7 @@ export class ControllerHandler { }); this.controller.addLayer(layer); } - public addSurfaceLayers(surfacIntersectionData: SurfaceIntersection_api[], pixiContext: PixiRenderApplication) { + public addSurfaceLayers(surfacIntersectionData: SurfaceIntersectionData_api[], pixiContext: PixiRenderApplication) { const geolayerdata = { areas: [], lines: surfacIntersectionData.map((surface) => { @@ -145,8 +148,15 @@ export class ControllerHandler { this.controller.addLayer(geomodelLabelsLayer); } - public update(width: number, height: number) { + public update(width: number, height: number, zScale: number, curtain: number[][] | null, extension: number) { + // Calculate midpoint for xAxis + // Need to calculate y... + const hMid: number = curtain ? (curtain[0][0] + curtain[curtain.length - 1][0]) / 2 - extension : 1000; + + this.controller.setViewport(hMid, 1750, 5000); + this.controller.adjustToSize(width, height); + this.controller.zoomPanHandler.zFactor = zScale; } private setReferenceSystem(coordinates: number[][]) { this.controller.setReferenceSystem(new IntersectionReferenceSystem(coordinates)); @@ -225,3 +235,91 @@ function addSeismicOverlay(instance: Controller, seismicData: number[][]) { elm.style.zIndex = "100"; } } + +export function makeExtendedTrajectory( + getWellTrajectoriesQuery: UseQueryResult, + extension: number +): Trajectory | null { + if (getWellTrajectoriesQuery.data && getWellTrajectoriesQuery.data.length > 0) { + const wellTrajectory = getWellTrajectoriesQuery.data[0]; + const eastingArr = wellTrajectory.easting_arr; + const northingArr = wellTrajectory.northing_arr; + const tvdArr = wellTrajectory.tvd_msl_arr; + const trajectory = eastingArr.map((easting: number, idx: number) => [ + parseFloat(easting.toFixed(3)), + parseFloat(northingArr[idx].toFixed(3)), + parseFloat(tvdArr[idx].toFixed(3)), + ]); + if ( + eastingArr[0] == eastingArr[eastingArr.length - 1] && + northingArr[0] == northingArr[northingArr.length - 1] + ) { + const addcoordatstart = eastingArr[0] - 100; + const addcoordatend = eastingArr[eastingArr.length - 1] + 100; + const addcoordatstart2 = northingArr[0] - 100; + const addcoordatend2 = northingArr[northingArr.length - 1] + 100; + const firstzcoord = tvdArr[0]; + const lastzcoord = tvdArr[tvdArr.length - 1]; + + trajectory.unshift([addcoordatstart, addcoordatstart2, firstzcoord]); + trajectory.push([addcoordatend, addcoordatend2, lastzcoord]); + } + + const referenceSystem = new IntersectionReferenceSystem(trajectory); + referenceSystem.offset = trajectory[0][2]; // Offset should be md at start of path + + const displacement = referenceSystem.displacement || 1; + // Number of samples. Needs some thought. + const samplingIncrement = 5; //meters + const steps = Math.min(1000, Math.floor((displacement + extension * 2) / samplingIncrement)); + console.debug("Number of samples for intersection ", steps); + const traj = referenceSystem.getExtendedTrajectory(steps, extension, extension); + traj.points = traj.points.map((point) => [parseFloat(point[0].toFixed(3)), parseFloat(point[1].toFixed(3))]); + return traj; + } + return null; +} +export function useSeismicImageQuery( + dataValues: number[][] | null, + yValues: number[] | null, + curtain: number[][] | null, + colorscale: string[] | null +): UseQueryResult { + return useQuery({ + queryKey: ["seismicImage", dataValues, yValues, curtain, colorscale], + queryFn: () => + generateSeismicSliceImage( + { datapoints: dataValues ?? [], yAxisValues: yValues ?? [] }, + curtain ?? [], + colorscale ?? [], + { + isLeftToRight: true, + } + ), + enabled: dataValues && yValues && curtain && colorscale ? true : false, + }); +} +export function useGridParameterImageQuery( + dataValues: number[][] | null, + yValues: number[] | null, + curtain: number[][] | null, + colorscale: string[] | null, + colorMin: number | null, + colorMax: number | null +): UseQueryResult { + return useQuery({ + queryKey: ["gridParameterImage", dataValues, yValues, curtain, colorscale, colorMin, colorMax], + queryFn: () => + generateGridSliceImage( + { datapoints: dataValues ?? [], yAxisValues: yValues ?? [] }, + curtain ?? [], + colorscale ?? [], + { + isLeftToRight: true, + seismicMin: colorMin ?? undefined, + seismicMax: colorMax ?? undefined, + } + ), + enabled: dataValues && yValues && curtain && colorscale ? true : false, + }); +} diff --git a/frontend/src/modules/Intersection/gridData.ts b/frontend/src/modules/Intersection/gridData.ts index 1070947be..b6b717869 100644 --- a/frontend/src/modules/Intersection/gridData.ts +++ b/frontend/src/modules/Intersection/gridData.ts @@ -127,15 +127,15 @@ export async function generateGridSliceImage( options?.seismicRange || dp.reduce((val: number, array: number[]) => Math.max(...array, val), 0); - const absMax = Math.max(Math.abs(min), Math.abs(max)); + // const absMax = Math.max(Math.abs(min), Math.abs(max)); - const dmin = -absMax; - const dmax = absMax; + // const dmin = -absMax; + // const dmax = absMax; const domain = { - min: 0, - max: 0.34, - difference: 0.34, + min: min, + max: max, + difference: max - min, }; const length = trajectory[0]?.[0]! - trajectory[trajectory.length - 1]?.[0]!; @@ -163,7 +163,6 @@ export async function generateGridSliceImage( let col: number[]; const black = [0, 0, 0]; let opacity: number; - console.log(domain); for (let x = 0; x < width; x++) { offset = x * 4; diff --git a/frontend/src/modules/Intersection/loadModule.tsx b/frontend/src/modules/Intersection/loadModule.tsx index 5465c91d7..c30c7fbb1 100644 --- a/frontend/src/modules/Intersection/loadModule.tsx +++ b/frontend/src/modules/Intersection/loadModule.tsx @@ -9,7 +9,14 @@ const defaultState: state = { surfaceAddress: null, seismicAddress: null, gridParameterAddress: null, - viewSettings: { showGridParameter: false, showSeismic: true, showSurfaces: true, showWellMarkers: true }, + viewSettings: { + showGridParameter: false, + showSeismic: true, + showSurfaces: true, + showWellMarkers: true, + extension: 1000, + zScale: 5, + }, }; const module = ModuleRegistry.initModule("Intersection", defaultState); diff --git a/frontend/src/modules/Intersection/queryHooks.tsx b/frontend/src/modules/Intersection/queryHooks.tsx index 64f6665ae..8da422688 100644 --- a/frontend/src/modules/Intersection/queryHooks.tsx +++ b/frontend/src/modules/Intersection/queryHooks.tsx @@ -1,10 +1,14 @@ import { - FenceResponse_api, + Body_get_grid_parameter_api, + Body_get_seismic_api, + Body_get_surfaces_api, + CubeIntersectionData_api, + CuttingPlane_api, Seismic3DSurveyDirectory_api, Seismic4DSurveyDirectory_api, StaticSurfaceDirectory_api, SumoContent_api, - SurfaceIntersection_api, + SurfaceIntersectionData_api, WellBoreHeader_api, WellBorePicksAndStratUnits_api, WellBoreTrajectory_api, @@ -63,57 +67,7 @@ export function useGetWellborePicksForWellbore( enabled: caseUuid && wellUuid ? true : false, }); } -export function useGridParameterIntersectionv2( - caseUuid: string | undefined, - ensembleUuid: string | undefined, - gridName: string | undefined, - parameterName: string | undefined, - realizationNum: number | undefined, - eastingArr: number[] | undefined, - northingArr: number[] | undefined, - hlenArr: number[] | undefined, - enabled: boolean -): UseQueryResult { - return useQuery({ - queryKey: [ - "gridParameterIntersectionv2", - caseUuid, - ensembleUuid, - gridName, - parameterName, - realizationNum, - eastingArr, - northingArr, - hlenArr, - ], - queryFn: () => - apiService.grid.gridParameterIntersectionv2( - caseUuid ?? "", - ensembleUuid ?? "", - gridName ?? "", - parameterName ?? "", - realizationNum ?? 0, - eastingArr ?? [], - northingArr ?? [], - hlenArr ?? [] - ), - staleTime: STALE_TIME, - cacheTime: CACHE_TIME, - enabled: - caseUuid && - ensembleUuid && - gridName && - parameterName && - realizationNum !== undefined && - eastingArr && - northingArr && - hlenArr && - enabled - ? true - : false, - }); -} export function useGetSeismic3DsurveyDirectory( caseUuid: string | undefined, ensembleUuid: string | undefined @@ -165,38 +119,40 @@ export function useGridParameterNames( }); } -export function useGetSeismicFence( +export function useSeismicIntersectionQuery( caseUuid: string | undefined, ensembleName: string | undefined, realizationNum: number | undefined, seismicCubeAttribute: string | undefined, seismicTimestampOrTimestep: string | undefined, observed: boolean | undefined, - eastingArr: number[] | undefined, - northingArr: number[] | undefined -): UseQueryResult { + cuttingPlane: CuttingPlane_api | null, + enabled: boolean +): UseQueryResult { + let bodyCuttingPlane: Body_get_seismic_api = cuttingPlane + ? { cuttingPlane } + : { cuttingPlane: { x_arr: [], y_arr: [], h_arr: [] } }; + return useQuery({ queryKey: [ - "GetSeismicFence", + "seismicIntersectionQuery", caseUuid, ensembleName, realizationNum, seismicCubeAttribute, seismicTimestampOrTimestep, observed, - eastingArr, - northingArr, + bodyCuttingPlane, ], queryFn: () => - apiService.seismic.getFence( + apiService.intersection.getSeismic( caseUuid ?? "", ensembleName ?? "", realizationNum ?? 0, seismicCubeAttribute ?? "", seismicTimestampOrTimestep ?? "", observed ?? false, - eastingArr ?? [], - northingArr ?? [] + bodyCuttingPlane ), staleTime: STALE_TIME, cacheTime: CACHE_TIME, @@ -207,60 +163,96 @@ export function useGetSeismicFence( seismicCubeAttribute && seismicTimestampOrTimestep && observed !== undefined && - eastingArr && - northingArr + enabled ? true : false, }); } +export function useGridParameterIntersectionQuery( + caseUuid: string | undefined, + ensembleUuid: string | undefined, + gridName: string | undefined, + parameterName: string | undefined, + realizationNum: number | undefined, + cuttingPlane: CuttingPlane_api | null, + enabled: boolean +): UseQueryResult { + let bodyCuttingPlane: Body_get_grid_parameter_api = cuttingPlane + ? { cuttingPlane } + : { cuttingPlane: { x_arr: [], y_arr: [], h_arr: [] } }; -export function useSurfaceDataQueryByAddress( + return useQuery({ + queryKey: [ + "gridParameterIntersectionQuery", + caseUuid, + ensembleUuid, + gridName, + parameterName, + realizationNum, + bodyCuttingPlane, + ], + queryFn: () => + apiService.intersection.getGridParameter( + caseUuid ?? "", + ensembleUuid ?? "", + gridName ?? "", + parameterName ?? "", + realizationNum ?? 0, + bodyCuttingPlane + ), + staleTime: STALE_TIME, + cacheTime: CACHE_TIME, + enabled: + caseUuid && ensembleUuid && gridName && parameterName && realizationNum !== undefined && enabled + ? true + : false, + }); +} +export function useSurfaceIntersectionsQuery( surfAddr: SurfAddr | null, - eastingArr: number[] | undefined, - northingArr: number[] | undefined, - hlenArr: number[] | undefined, + cuttingPlane: CuttingPlane_api | null, enabled: boolean -): UseQueryResult { - function dummyApiCall(): Promise { +): UseQueryResult { + function dummyApiCall(): Promise { return new Promise((_resolve, reject) => { reject(null); }); } - if (!surfAddr) { + if (!surfAddr || !cuttingPlane) { return useQuery({ - queryKey: ["getSurfaceData_DUMMY_ALWAYS_DISABLED"], + queryKey: ["surfaceIntersectionsQuery_DUMMY_ALWAYS_DISABLED"], queryFn: () => dummyApiCall, enabled: false, }); } - let queryFn: QueryFunction | null = null; + let queryFn: QueryFunction | null = null; let queryKey: QueryKey | null = null; + let bodyCuttingPlane: Body_get_surfaces_api = cuttingPlane + ? { cuttingPlane } + : { cuttingPlane: { x_arr: [], y_arr: [], h_arr: [] } }; + // Static, per realization surface if (surfAddr.addressType === "static") { queryKey = [ - "getStaticSurfaceIntersection", + "surfaceIntersectionsQuery", surfAddr.caseUuid, surfAddr.ensemble, surfAddr.realizationNum, surfAddr.names, surfAddr.attribute, - eastingArr, - northingArr, - hlenArr, + cuttingPlane, ]; queryFn = () => - apiService.surface.getIntersection( + apiService.intersection.getSurfaces( surfAddr.caseUuid, surfAddr.ensemble, surfAddr.realizationNum, surfAddr.names, surfAddr.attribute, - eastingArr || [], - northingArr || [], - hlenArr || [] + bodyCuttingPlane ); } else { throw new Error("Invalid surface address type"); diff --git a/frontend/src/modules/Intersection/settings.tsx b/frontend/src/modules/Intersection/settings.tsx index 0420c81dc..5e5112f28 100644 --- a/frontend/src/modules/Intersection/settings.tsx +++ b/frontend/src/modules/Intersection/settings.tsx @@ -41,7 +41,7 @@ type LabelledCheckboxProps = { function LabelledCheckbox(props: LabelledCheckboxProps): JSX.Element { return ( -