Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Aug 9, 2024
1 parent d4ddb4b commit 41951d2
Show file tree
Hide file tree
Showing 15 changed files with 1,504 additions and 1,257 deletions.
50 changes: 50 additions & 0 deletions backend_py/primary/primary/routers/seismic/converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from typing import List

import orjson
import numpy as np
import xtgeo

from . import schemas


def surface_to_float32_array(values: np.ndarray) -> List[float]:
values = values.astype(np.float32)
values.fill_value = np.nan
values = np.ma.filled(values)

# Rotate 90 deg left.
# This will cause the width of to run along the X axis
# and height of along Y axis (starting from bottom.)
values = np.rot90(values)

return values.flatten().tolist()


def to_api_surface_data(
xtgeo_surf: xtgeo.RegularSurface, property_values: np.ndarray
) -> schemas.SurfaceMeshAndProperty:
"""
Create API SurfaceData from xtgeo regular surface
"""
float32_mesh = surface_to_float32_array(xtgeo_surf.values)
float32_property = surface_to_float32_array(property_values)

return schemas.SurfaceMeshAndProperty(
x_ori=xtgeo_surf.xori,
y_ori=xtgeo_surf.yori,
x_count=xtgeo_surf.ncol,
y_count=xtgeo_surf.nrow,
x_inc=xtgeo_surf.xinc,
y_inc=xtgeo_surf.yinc,
x_min=xtgeo_surf.xmin,
x_max=xtgeo_surf.xmax,
y_min=xtgeo_surf.ymin,
y_max=xtgeo_surf.ymax,
mesh_value_min=xtgeo_surf.values.min(),
mesh_value_max=xtgeo_surf.values.max(),
property_value_min=property_values.min(),
property_value_max=property_values.max(),
rot_deg=xtgeo_surf.rotation,
mesh_data=orjson.dumps(float32_mesh), # pylint: disable=maybe-no-member
property_data=orjson.dumps(float32_property), # pylint: disable=maybe-no-member
)
49 changes: 48 additions & 1 deletion backend_py/primary/primary/routers/seismic/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
from webviz_pkg.core_utils.b64 import b64_encode_float_array_as_float32

from primary.auth.auth_helper import AuthHelper
from primary.services.sumo_access.surface_access import SurfaceAccess
from primary.services.sumo_access.seismic_access import SeismicAccess, VdsHandle
from primary.services.utils.authenticated_user import AuthenticatedUser
from primary.services.vds_access.request_types import VdsCoordinates, VdsCoordinateSystem
from primary.services.vds_access.response_types import VdsMetadata
from primary.services.vds_access.vds_access import VdsAccess

from . import schemas
from . import converters, schemas

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -99,3 +100,49 @@ async def post_get_seismic_fence(
min_fence_depth=depth_axis_meta.min,
max_fence_depth=depth_axis_meta.max,
)


"""
@router.get("/get_seismic_attribute_near_surface/")
async def get_seismic_attribute_near_surface(
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"),
surface_name: str = Query(description="Surface name"),
surface_attribute: str = Query(description="Surface attribute"),
) -> schemas.SurfaceMeshAndProperty:
""
Get a directory of surface names, attributes and time/interval strings for simulated dynamic surfaces.
""
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: Optional[VdsHandle] = None
try:
vds_handle = await seismic_access.get_vds_handle_async(
realization=1,
iteration=ensemble_name,
cube_tagname=seismic_cube_attribute,
timestep=timestep,
timestamp=timestamp,
)
except ValueError as err:
raise HTTPException(status_code=404, detail=str(err)) from err
surface_access = SurfaceAccess(authenticated_user.get_sumo_access_token(), case_uuid, ensemble_name)
xtg_surf = surface_access.get_static_surf(real_num=1, name=surface_name, attribute=surface_attribute).copy()
vdsaccess = VdsAccess(sas_token=vds_handle.sas_token, vds_url=vds_handle.vds_url)
seismic_values = vdsaccess.get_surface_values(xtgeo_surf=xtg_surf, above=5, below=5, attribute="mean")
return converters.to_api_surface_data(xtg_surf, seismic_values)
"""
20 changes: 20 additions & 0 deletions backend_py/primary/primary/routers/seismic/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,23 @@ class SeismicFenceData(BaseModel):
num_samples_per_trace: int
min_fence_depth: float
max_fence_depth: float


class SurfaceMeshAndProperty(BaseModel):
x_ori: float
y_ori: float
x_count: int
y_count: int
x_inc: float
y_inc: float
x_min: float
x_max: float
y_min: float
y_max: float
mesh_value_min: float
mesh_value_max: float
property_value_min: float
property_value_max: float
rot_deg: float
mesh_data: str
property_data: str
Loading

0 comments on commit 41951d2

Please sign in to comment.