Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv committed Aug 30, 2023
1 parent 01c8196 commit 3cd5d0c
Show file tree
Hide file tree
Showing 30 changed files with 810 additions and 688 deletions.
2 changes: 2 additions & 0 deletions backend/src/backend/primary/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
41 changes: 1 addition & 40 deletions backend/src/backend/primary/routers/grid/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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,
Expand Down
Empty file.
131 changes: 131 additions & 0 deletions backend/src/backend/primary/routers/intersection/router.py
Original file line number Diff line number Diff line change
@@ -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
)
24 changes: 24 additions & 0 deletions backend/src/backend/primary/routers/intersection/schemas.py
Original file line number Diff line number Diff line change
@@ -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
48 changes: 0 additions & 48 deletions backend/src/backend/primary/routers/seismic/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
5 changes: 0 additions & 5 deletions backend/src/backend/primary/routers/seismic/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
80 changes: 2 additions & 78 deletions backend/src/backend/primary/routers/surface/router.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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())
# )
10 changes: 0 additions & 10 deletions backend/src/backend/primary/routers/surface/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 3cd5d0c

Please sign in to comment.