Skip to content

Commit

Permalink
Merge pull request #7 from JintaoLee-Roger/dev
Browse files Browse the repository at this point in the history
Dev 0.0.4
  • Loading branch information
JintaoLee-Roger authored Feb 5, 2024
2 parents c1ca0a7 + 4e8f01d commit 2dd60a7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 56 deletions.
3 changes: 2 additions & 1 deletion cigvis/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@

from .las import load_las
from .vds import VDSReader, create_vds_from_array
from .fault_skin import load_skins, load_one_skin
from .fault_skin import load_skins, load_one_skin
from . import horiz
21 changes: 21 additions & 0 deletions cigvis/io/horiz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import numpy as np
import re


def convert(hz, ni, nx, dt, istart, xstart, tstart=0):
hz = np.array([
list(map(float,
s.split('\t')[1:])) for s in hz.split('\n') if s.strip()
])
sorted_indices = np.lexsort((hz[:, 1], hz[:, 0]))
hz = hz[sorted_indices]
x = hz[:, 0].astype(int) - istart
y = hz[:, 1].astype(int) - xstart
hz[:, 2] = (hz[:, 2] - tstart) / dt

grid = np.full((ni, nx), -1.0)
valid_indices = (x < ni) & (y < nx)
grid[x[valid_indices], y[valid_indices]] = hz[valid_indices, 2]
grid = grid.astype(np.float32)

return grid
1 change: 1 addition & 0 deletions cigvis/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# All rights reserved.

from .utils import *
from .coord import *
from . import surfaceutils
from . import vispyutils
from . import plotlyutils
62 changes: 11 additions & 51 deletions cigvis/utils/surfaceutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,63 +18,31 @@
def get_vertices_and_faces(surf: np.ndarray,
mask: np.ndarray = None,
mask_type: str = 'e',
anti_rot: bool = True) -> Tuple:
"""
Get vertices and faces, which will be used in Mesh
Parameters
----------
surf : array-like
the input surface, shape as (ni, nx)
mask : bool, array-like
mask is a bool array, whose shape is same as `surf`,
mask is used to remove some points in the x-y meshgrid.
mask_type : str
Choice of {'e', 'i'},
'e' means the `surf[i, j]` will be remove if `mask[i, j]` is True,
'i' means the `surf[i, j]` will be kept if `mask[i, j]` is True.
anti_rot : bool
If True, is anticlock rotation.
a a, b, c is index of vertices
. . ==> If anticlock, face is [a, b, c]
. . ==> If not anticlock, face is [a, c, b]
b ... c
Returns
-------
vertices : array-like
shape as (n1*n2, 3), each row is (x, y, z) position
faces : array-like
shape as ((n1-1)*(n2-1)*2, 3), each row contains 3 points to
consist a face. Like:
a ... b a a ... b
. . => . . & . .
. . => . . & . .
c ... d c ... d c
vertices (4 points) = [[0, 0, a], [0, 1, b], [1, 0, c], [1, 1, d]]
faces (2 faces) = [[0, 2, 3], [0, 1, 3]] (clockwise),
or [[0, 3, 2], [0, 3, 2]] (anticlock)
In faces, x means x-th vertices
"""
anti_rot: bool = True,
step1=2,
step2=2) -> Tuple:
n1, n2 = surf.shape
surf = surf[::step1, ::step2]
mask = mask[::step1, ::step2] if mask is not None else None
n1g, n2g = surf.shape

if mask is not None and mask_type == 'e':
mask = ~mask

# set grid
if mask is None:
grid = np.arange(n1 * n2).reshape(n1, n2)
grid = np.arange(n1g * n2g).reshape(n1g, n2g)
else:
grid = np.zeros_like(surf) - 1
grid = -np.ones_like(mask, dtype=int)
grid[mask] = np.arange(mask.sum())

# get vertices
y, x = np.meshgrid(np.arange(n2), np.arange(n1))
y, x = np.meshgrid(np.arange(0, n2, step2), np.arange(0, n1, step1))
vertices = np.stack((x, y, surf), axis=-1).reshape(-1, 3)
if mask is not None:
vertices = vertices[mask.flatten()]

faces = np.zeros((n1 - 1, n2 - 1, 2, 3))
faces = np.zeros((n1g - 1, n2g - 1, 2, 3))
faces[:, :, 0, 0] = grid[:-1, :-1]
faces[:, :, 0, 1] = grid[1:, :-1]
faces[:, :, 0, 2] = grid[1:, 1:]
Expand Down Expand Up @@ -308,11 +276,3 @@ def interp_surf(volume: np.ndarray,

return out


def interp_scipy(volume, surf, order=1):
ni, nx, nt = volume.shape
x, y = np.meshgrid(np.arange(ni), np.arange(nx), indexing='ij')
coordinates = np.vstack((x.ravel(), y.ravel(), surf.ravel()))
out = map_coordinates(volume, coordinates, order=1, mode='reflect')
out = out.reshape(ni, nx)
return out
7 changes: 6 additions & 1 deletion cigvis/vispyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ def create_surfaces(surfs: List[np.ndarray],
shape: Union[Tuple, List] = None,
interp: bool = False,
return_cbar: bool = False,
step1=1,
step2=1,
**kwargs) -> List:
"""
create a surfaces node
Expand Down Expand Up @@ -396,11 +398,14 @@ def create_surfaces(surfs: List[np.ndarray],
for s, v, c in zip(surfaces, values, colors):
mask = np.logical_or(s < 0, np.isnan(s))
vertices, faces = surfaceutils.get_vertices_and_faces(
s, mask, anti_rot=anti_rot)
s, mask, anti_rot=anti_rot, step1=step1, step2=step2)
mask = mask[::step1, ::step2]
if v is not None:
v = v[::step1, ::step2]
v = v[~mask].flatten()
if c is not None:
channel = c.shape[-1]
c = c[::step1, ::step2, ...]
c = c[~mask].flatten().reshape(-1, channel)

mesh_kwargs = vispyutils.get_valid_kwargs('mesh', **kwargs)
Expand Down
15 changes: 12 additions & 3 deletions examples/more_demos/071-f3.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def load_wellLog(p):
unc2p = root + 'unc2.dat'
ni, nx, nt = 591, 951, 362
shape = (ni, nx, nt)
step1 = 2
step2 = 4

# seismic
seis = np.memmap(seisp, np.float32, 'c', shape=shape)
Expand All @@ -74,15 +76,22 @@ def load_wellLog(p):
nodes += cigvis.create_bodys(salt, 0.0, 0.0, color='cyan')

hz2 = np.fromfile(hz2p, np.float32).reshape(ni, nx)
nodes += cigvis.create_surfaces([hz2], color='yellow')
nodes += cigvis.create_surfaces([hz2],
color='yellow',
step1=step1,
step2=step2)

unc = np.fromfile(root + 'unc.dat', np.float32).reshape(shape)
unc2 = np.fromfile(unc2p, np.float32).reshape(ni, nx)
nodes += cigvis.create_surfaces([unc2], volume=unc, value_type='amp')
nodes += cigvis.create_surfaces([unc2],
volume=unc,
value_type='amp',
step1=step1,
step2=step2)

nodes += load_wellLog(root + 'logs.dat')

nodes += cigvis.create_fault_skin(root + 'skins/')
# nodes += cigvis.create_fault_skin(root + 'skins/')

cigvis.plot3D(nodes,
azimuth=-65.0,
Expand Down

0 comments on commit 2dd60a7

Please sign in to comment.