Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
JintaoLee-Roger committed Sep 3, 2024
1 parent a8fdaf0 commit 8c215f9
Show file tree
Hide file tree
Showing 13 changed files with 1,529 additions and 1,302 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ For local installation, clone the repository from GitHub and then install it usi
```shell
git clone https://github.com/JintaoLee-Roger/cigvis.git
# Minimal installation
pip install -e .
pip install -e . --config-settings editable_mode=strict

# include plotly
pip install -e ".[plotly]"
pip install -e ".[plotly]" --config-settings editable_mode=strict

# include viser
pip install -e ".[viser]"
pip install -e ".[viser]" --config-settings editable_mode=strict

# install all dependencies
pip install -e ".[all]"
pip install -e ".[all]" --config-settings editable_mode=strict
```

## Core Features
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog


### v0.1.2

- added `blue_white_purple` colormap
- added `nancolor` to set nan color in viser
- added `extract_arbitrary_line_by_view` function to a extract arbitrary line by clicking


### v0.1.1

Expand Down
10 changes: 6 additions & 4 deletions cigvis/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
from .customcmap import *


def arrs_to_image(arr, cmap, clim, as_uint8=False):
def arrs_to_image(arr, cmap, clim, as_uint8=False, nancolor=None):

def _to_image(arr, cmap, clim):
def _to_image(arr, cmap, clim, nancolor=None):
norm = plt.Normalize(vmin=clim[0], vmax=clim[1])
cmap = cmap_to_mpl(cmap)
if nancolor is not None:
cmap.set_bad(nancolor)
img = cmap(norm(arr))
return img

Expand All @@ -46,9 +48,9 @@ def _to_image(arr, cmap, clim):
if len(arr) != len(cmap) or len(arr) != len(clim):
raise RuntimeError("(len(arr) != len(cmap)) or (len(arr) != len(clim))")

out = _to_image(arr[0], cmap[0], clim[0])
out = _to_image(arr[0], cmap[0], clim[0], nancolor)
for i in range(1, len(arr)):
img = _to_image(arr[i], cmap[i], clim[i])
img = _to_image(arr[i], cmap[i], clim[i], nancolor)

bgRGB = out[:, :, :3]
fgRGB = img[:, :, :3]
Expand Down
2,603 changes: 1,336 additions & 1,267 deletions cigvis/customcmap.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cigvis/gui/custom_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def __init__(self, interps=None, parent=None) -> None:
colormap_label = qtw.QLabel('cmap:')
self.colormap_combo = EditableComboBox()
colormaps = [
'gray', 'seismic', 'Petrel', 'stratum', 'jet', 'od_seismic1',
'gray', 'seismic', 'Petrel', 'stratum', 'jet', 'od_seismic1', 'bwp',
'od_seismic2', 'od_seismic3'
]
self.colormap_combo.addItems(colormaps)
Expand Down
6 changes: 6 additions & 0 deletions cigvis/gui/gui2d/control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,18 @@ def __init__(self,
row_tab.addWidget(self.tab_widget)
row_tab.setStretch(0, 1)

value_tab = qtw.QHBoxLayout()
self.status_label = qtw.QLabel('')
self.status_label.setStyleSheet("font-size: 12px; padding: 5px;")
value_tab.addWidget(self.status_label)

self.addlayout(layout, [
row1_layout,
row_folder,
row2_layout,
rowl_layout,
row_tab,
value_tab,
])

layout.addStretch(1)
Expand Down
11 changes: 9 additions & 2 deletions cigvis/gui/gui2d/plot_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ def on_mouse_move(self, event):
self.scrib_list[-1][1])
self.draw()

if event.inaxes and self.data is not None:
v = self.data[round(event.xdata), round(event.ydata)]
self.parent().parent().controlP.status_label.setText(
f'x={event.xdata:.1f}, y={event.ydata:.1f}, v={v:.1f}')

def on_mouse_release(self, event):
if self.box_mode > 0 and event.inaxes:
self.rect = None
Expand Down Expand Up @@ -359,7 +364,7 @@ def __init__(self, parent=None, width=5, height=4, dpi=100):
self.fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = self.fig.add_subplot(111)
self.axes.set_axis_off()
self.fig.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.05)
self.fig.subplots_adjust(left=0.08, right=0.98, top=0.98, bottom=0.05)
super().__init__(self.fig)
self.setParent(parent)
self.controlP = self.parent().controlP
Expand Down Expand Up @@ -408,7 +413,9 @@ def plot(self):
self.axes.axis('off')
self.baseim = None
else:
self.baseim = self.axes.imshow(self.data.T, **self.params)
self.baseim = self.axes.imshow(self.data.T,
**self.params,
aspect='auto')
self.draw()

def clear(self):
Expand Down
127 changes: 127 additions & 0 deletions cigvis/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import numpy as np
import matplotlib.pyplot as plt
from cigvis.utils.surfaceutils import arbitray_line


def extract_arbitrary_line_by_view(data: np.ndarray,
bmap: str = 'data',
draw_arb: bool = True,
*,
line: bool = True,
idx: int = 50,
cline='#F3AA3C'):
"""
extract arbitrary line from seismic data by clicking
Parameters
----------
- data: np.ndarray
3D seismic data
- bmap: str
background map, 'data' or 'blank'
- line : bool
whether to draw the broken line
- idx: int
the slice index of the seismic data if bmap is 'data'
- cline: str
color of the line
Returns
-------
- out: np.ndarray
extracted arbitrary line
- p: np.ndarray
extracted arbitrary line path
- coords: np.ndarray
the coordinates by clicking
"""
fig, ax = plt.subplots()
if bmap == 'data':
img = data[:, :, idx]
ax.imshow(img.T, cmap='gray', aspect='auto')
else:
img = np.zeros((data.shape[1], data.shape[0], 4), dtype=np.uint8)
img = img + int(0.9 * 255)
ax.imshow(img, aspect='auto')
ax.grid(True)

ax.set_title('Obtain a path by clicking, press "u" to undo, "enter" to finish') # yapf: disable
ax.set_xlabel('Inline')
ax.set_ylabel('Crossline')
coords = []
lines = []
points = []
out = None
p = None
indices = None

def _draw_arbline():
if (len(coords) > 0):
ax.clear()
nonlocal out, p, indices
out, p, indices = arbitray_line(data, coords)
ax.grid(False)
ax.imshow(out.T, cmap='gray', aspect='auto')
if line:
for i in range(len(indices)):
ax.plot([indices[i]] * out.shape[1],
range(out.shape[1]),
'w--',
lw=0.5)
if i > 0 and i < len(indices) - 1:
ax.text(indices[i] - out.shape[0] / 50,
30,
str(indices[i]),
color='w',
fontsize=10)
ax.set_title("Arbitrary Line")
ax.set_ylabel('Time')
fig.canvas.draw()
# plt.close()

def _click_event(event):
if event.inaxes:
coords.append((round(event.xdata, 2), round(event.ydata, 2)))
p = ax.plot(event.xdata, event.ydata, 'ro')[0]
points.append(p)
if len(coords) > 1:
x_coords, y_coords = zip(*coords[-2:])
line, = ax.plot(x_coords, y_coords, c=cline)
lines.append(line)
fig.canvas.draw()

def _undo_last(event):
if event.key == 'u':
if coords:
coords.pop()
p = points.pop()
p.remove()
if len(lines) > 0:
l = lines.pop()
l.remove()
fig.canvas.draw()
if event.key in ('enter', 'return', 'escape'):
if draw_arb:
fig.canvas.mpl_disconnect(cid_click)
fig.canvas.mpl_disconnect(cid_key)
_draw_arbline()
else:
plt.close(fig)

cid_click = fig.canvas.mpl_connect('button_press_event', _click_event)
cid_key = fig.canvas.mpl_connect('key_press_event', _undo_last)

plt.show()

return out, p, indices, np.array(coords)


if __name__ == '__main__':
from cigsegy import SegyNP
d = SegyNP('/Volumes/T7/DATA/cnooc_bj/data/FEF.segy')
out, p, ind, c = extract_arbitrary_line_by_view(
d,
bmap='data',
draw_arb=True,
)
print(c.shape)
18 changes: 7 additions & 11 deletions cigvis/utils/surfaceutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ def interp_surf(volume: np.ndarray,
return out




def interp_arb(p: np.ndarray, d: np.ndarray) -> np.ndarray:
"""
Interpolates a 1d series in 3d space by **linear** interpolation.
Expand All @@ -253,10 +251,9 @@ def interp_arb(p: np.ndarray, d: np.ndarray) -> np.ndarray:
f11 = d[:, 3, :]

# linear interpolation
out = (f00 * (1 - x)[:, None] * (1 - y)[:, None] +
f01 * (1 - x)[:, None] * y[:, None] +
f10 * x[:, None] * (1 - y)[:, None] +
f11 * x[:, None] * y[:, None])
out = (f00 * (1 - x)[:, None] * (1 - y)[:, None] + f01 *
(1 - x)[:, None] * y[:, None] + f10 * x[:, None] *
(1 - y)[:, None] + f11 * x[:, None] * y[:, None])

return out

Expand All @@ -276,8 +273,9 @@ def interpolate_path(points, di=1):
x_points = np.interp(distances_interp, cum_distances, points[:, 0])
y_points = np.interp(distances_interp, cum_distances, points[:, 1])

return np.column_stack((x_points, y_points))
indices = np.searchsorted(distances_interp, cum_distances)

return np.column_stack((x_points, y_points)), indices


def extract_data(data, p):
Expand Down Expand Up @@ -324,19 +322,17 @@ def extract_data(data, p):
unique, inverse = np.unique(all_points, axis=0, return_inverse=True)
unique_data = np.array([data[i, j] for i, j in unique])


return pout, unique_data[inverse].reshape(N, 4, n3)



def arbitray_line(data, points, di: float = 1):
"""
data : SegyNP or np.ndarray
points : the points to interpolate a path
di : step
"""
p = interpolate_path(points, di)
p, indices = interpolate_path(points, di)
pout, pdata = extract_data(data, p)
out = interp_arb(pout, pdata)

return out, p
return out, p, indices
6 changes: 4 additions & 2 deletions cigvis/visernodes/volume_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def __init__(self,
pos=0,
cmap='gray',
clim=None,
scale=-1):
scale=-1,
nancolor=None):
self._server = None # viser.ViserServer
self.volume = volume
self.axis = axis
Expand All @@ -31,6 +32,7 @@ def __init__(self,
]

self.init_scale = [8 / max(volume.shape)] * 3
self.nancolor = nancolor

if isinstance(scale, (int, float)):
if scale < 0:
Expand Down Expand Up @@ -105,7 +107,7 @@ def to_img(self):
fg = [mask[:, :, self.pos] for mask in self.masks]

img = colormap.arrs_to_image([bg] + fg, [self.cmap] + self.fg_cmaps,
[self.clim] + self.fg_clims, True)
[self.clim] + self.fg_clims, True, self.nancolor)
return img

def update_node(self, pos):
Expand Down
Loading

0 comments on commit 8c215f9

Please sign in to comment.