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

Backend support for delta surfaces #760

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
44 changes: 23 additions & 21 deletions backend_py/primary/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend_py/primary/primary/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
logging.getLogger("primary.services.sumo_access").setLevel(logging.DEBUG)
logging.getLogger("primary.services.user_session_manager").setLevel(logging.DEBUG)
logging.getLogger("primary.services.user_grid3d_service").setLevel(logging.DEBUG)
logging.getLogger("primary.routers.surface").setLevel(logging.DEBUG)
logging.getLogger("primary.routers.grid3d").setLevel(logging.DEBUG)
logging.getLogger("primary.routers.dev").setLevel(logging.DEBUG)

Expand Down
43 changes: 23 additions & 20 deletions backend_py/primary/primary/routers/surface/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,24 @@
from . import schemas


def resample_to_surface_def(
def extract_surface_def_from_surface(xtgeo_surf: xtgeo.RegularSurface) -> schemas.SurfaceDef:
"""
Extract properties from xtgeo regular surface and populate new surface definition
"""
surface_def = schemas.SurfaceDef(
npoints_x=xtgeo_surf.ncol,
npoints_y=xtgeo_surf.nrow,
inc_x=xtgeo_surf.xinc,
inc_y=xtgeo_surf.yinc,
origin_utm_x=xtgeo_surf.xori,
origin_utm_y=xtgeo_surf.yori,
rot_deg=xtgeo_surf.rotation,
)

return surface_def


def resampled_to_surface_def_if_needed(
source_surface: xtgeo.RegularSurface, target_surface_def: schemas.SurfaceDef
) -> xtgeo.RegularSurface:
"""
Expand All @@ -32,7 +49,9 @@ def resample_to_surface_def(
rotation=target_surface_def.rot_deg,
)

if target_surface.compare_topology(source_surface):
# Ignore mask and compare only the grid definitions since target_surface will never have a mask set
if target_surface.compare_topology(source_surface, strict=False):
# Grid definitions are equal so no need to resample
return source_surface

target_surface.resample(source_surface)
Expand All @@ -47,15 +66,7 @@ def to_api_surface_data_float(xtgeo_surf: xtgeo.RegularSurface) -> schemas.Surfa
float32_np_arr: NDArray[np.float32] = surface_to_float32_numpy_array(xtgeo_surf)
values_b64arr = b64_encode_float_array_as_float32(float32_np_arr)

surface_def = schemas.SurfaceDef(
npoints_x=xtgeo_surf.ncol,
npoints_y=xtgeo_surf.nrow,
inc_x=xtgeo_surf.xinc,
inc_y=xtgeo_surf.yinc,
origin_utm_x=xtgeo_surf.xori,
origin_utm_y=xtgeo_surf.yori,
rot_deg=xtgeo_surf.rotation,
)
surface_def = extract_surface_def_from_surface(xtgeo_surf)

trans_bb_utm = schemas.BoundingBox2d(
min_x=xtgeo_surf.xmin, min_y=xtgeo_surf.ymin, max_x=xtgeo_surf.xmax, max_y=xtgeo_surf.ymax
Expand All @@ -79,15 +90,7 @@ def to_api_surface_data_png(xtgeo_surf: xtgeo.RegularSurface) -> schemas.Surface
png_bytes: bytes = surface_to_png_bytes_optimized(xtgeo_surf)
png_bytes_base64 = base64.b64encode(png_bytes).decode("ascii")

surface_def = schemas.SurfaceDef(
npoints_x=xtgeo_surf.ncol,
npoints_y=xtgeo_surf.nrow,
inc_x=xtgeo_surf.xinc,
inc_y=xtgeo_surf.yinc,
origin_utm_x=xtgeo_surf.xori,
origin_utm_y=xtgeo_surf.yori,
rot_deg=xtgeo_surf.rotation,
)
surface_def = extract_surface_def_from_surface(xtgeo_surf)

trans_bb_utm = schemas.BoundingBox2d(
min_x=xtgeo_surf.xmin, min_y=xtgeo_surf.ymin, max_x=xtgeo_surf.xmax, max_y=xtgeo_surf.ymax
Expand Down
Loading
Loading