AISDL-SNU-Admin commited on
Commit
645beaf
·
verified ·
1 Parent(s): c91543d

Add visualization utils

Browse files
.gitattributes CHANGED
@@ -58,3 +58,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
61
+ vis/Metal_I_cell1550.html filter=lfs diff=lfs merge=lfs -text
62
+ vis/vis_SMO.ipynb filter=lfs diff=lfs merge=lfs -text
vis/Metal_I_cell1550.html ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:733b9f6e981a4adc8657fd40c9cd92e919019817f46d4f88075c828828999e07
3
+ size 37023874
vis/utils_PW.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import plotly.graph_objects as go
3
+ import plotly.express as px
4
+ from plotly.subplots import make_subplots
5
+ from skimage import measure
6
+
7
+
8
+ def get_color_gradient(start_hex, end_hex, n):
9
+ def hex_to_rgb(h):
10
+ h = h.lstrip('#')
11
+ return tuple(int(h[i:i+2], 16) for i in (0, 2, 4))
12
+
13
+ if n <= 1:
14
+ return [f'rgb{hex_to_rgb(end_hex)}']
15
+
16
+ s, e = hex_to_rgb(start_hex), hex_to_rgb(end_hex)
17
+ return [
18
+ f'rgb({int(s[0] + (e[0]-s[0])*i/(n-1))}, {int(s[1] + (e[1]-s[1])*i/(n-1))}, {int(s[2] + (e[2]-s[2])*i/(n-1))})'
19
+ for i in range(n)
20
+ ]
21
+
22
+
23
+ def plot_focus_exposure(data_list, dose_ary, cmap_idx, **kwargs):
24
+ dpi = kwargs.get('dpi', 600)
25
+ fig_w = kwargs.get('fig_width_cm', 5) / 2.54 * dpi
26
+ fig_h = kwargs.get('fig_height_cm', 1.5) / 2.54 * dpi
27
+ text_px = int(kwargs.get('text_font_size', 1.5) / 72 * dpi)
28
+ tick_px = int(kwargs.get('ticklabel_font_size', 2) / 72 * dpi)
29
+
30
+ show_x_ticks = kwargs.get('show_x_ticks', True)
31
+ show_x_ticklabels = kwargs.get('show_x_ticklabels', True)
32
+ show_y_ticks = kwargs.get('show_y_ticks', True)
33
+ show_y_ticklabels = kwargs.get('show_y_ticklabels', True)
34
+
35
+ n = len(data_list)
36
+ fig = make_subplots(rows=1, cols=n, subplot_titles=[title for _, title in data_list])
37
+
38
+ target_color = px.colors.qualitative.Plotly[cmap_idx]
39
+ sorted_doses = sorted(dose_ary)
40
+ colors = get_color_gradient("#D0D0D0", target_color, len(sorted_doses))
41
+ dose_color = {dose: colors[i] for i, dose in enumerate(sorted_doses)}
42
+
43
+ for col_idx, (data, title) in enumerate(data_list, start=1):
44
+ for dose in dose_ary:
45
+ if dose not in data:
46
+ continue
47
+ focus_p, cd_p = data[dose]
48
+ fig.add_trace(go.Scatter(
49
+ x=focus_p, y=cd_p, mode='lines',
50
+ name=f'{dose} mJ/cm²',
51
+ line=dict(color=dose_color[dose], width=4),
52
+ legendgroup=f'{dose}', showlegend=(col_idx == 1),
53
+ ), row=1, col=col_idx)
54
+
55
+ axis_common = dict(
56
+ showline=True, linecolor='black', mirror=True, linewidth=1,
57
+ tickfont=dict(size=tick_px, color='black'),
58
+ )
59
+
60
+ for col_idx in range(1, n + 1):
61
+ s = '' if col_idx == 1 else str(col_idx)
62
+ fig.update_layout(**{
63
+ f'xaxis{s}': dict(
64
+ **axis_common,
65
+ title=dict(text=kwargs.get('x_label', 'Focus [nm]')),
66
+ range=[-160, 160], nticks=5,
67
+ ticks='inside' if show_x_ticks else '',
68
+ showticklabels=show_x_ticklabels,
69
+ ),
70
+ f'yaxis{s}': dict(
71
+ **axis_common,
72
+ title=dict(text=kwargs.get('y_label', 'CD [nm]') if col_idx == 1 else '', standoff=text_px * 0.8),
73
+ range=[0, 310],
74
+ ticks='inside' if show_y_ticks else '',
75
+ showticklabels=show_y_ticklabels if col_idx == 1 else False,
76
+ ),
77
+ })
78
+
79
+ fig.update_layout(
80
+ autosize=False, width=int(fig_w), height=int(fig_h),
81
+ paper_bgcolor='rgba(255,255,255,1)', plot_bgcolor='rgba(255,255,255,1)',
82
+ font=dict(family='Arial, sans-serif', size=text_px, color='black'),
83
+ showlegend=kwargs.get('showlegend', False),
84
+ )
85
+ fig.update_annotations(font=dict(family='Arial, sans-serif', size=text_px, color='black'))
86
+ return fig
87
+
88
+
89
+ def plot_profiles(bot, top, sem, **kwargs):
90
+ dpi = kwargs.get('dpi', 600)
91
+ text_px = int(kwargs.get('text_font_size', 1.5) / 72 * dpi)
92
+ scale = kwargs.get('scale', 1.5)
93
+
94
+ dose_ary = kwargs.get('dose_ary', [34, 26, 18])
95
+ focus_ary = kwargs.get('focus_ary', [-100 + 20*i for i in range(11)])
96
+ ny, nx = kwargs.get('ny', 50), kwargs.get('nx', 35)
97
+ nc = 512 // 2 - 1
98
+
99
+ n_rows, n_cols = len(dose_ary), len(focus_ary)
100
+ cell_h, cell_w = 2*ny + 1, 2*nx + 1
101
+ margin_l = kwargs.get('margin_l', text_px * 10)
102
+ margin_t = kwargs.get('margin_t', text_px * 4)
103
+
104
+ to_np = lambda t: t.float().numpy() if hasattr(t, 'numpy') else np.array(t, dtype=float)
105
+
106
+ fig = make_subplots(
107
+ rows=n_rows, cols=n_cols,
108
+ subplot_titles=[f'{focus_ary[c]} nm' if r == 0 else '' for r in range(n_rows) for c in range(n_cols)],
109
+ horizontal_spacing=0.01, vertical_spacing=0.01,
110
+ )
111
+
112
+ for row_idx, dose in enumerate(dose_ary):
113
+ for col_idx, focus in enumerate(focus_ary):
114
+ r, c = row_idx + 1, col_idx + 1
115
+ crop = lambda d: to_np(d[dose][focus][nc-ny:nc+ny+1, nc-nx:nc+nx+1])
116
+ bot_c, top_c, sem_c = crop(bot), crop(top), crop(sem)
117
+
118
+ fig.add_trace(go.Heatmap(
119
+ z=sem_c, colorscale=[[0, 'black'], [1, 'white']],
120
+ zmin=0, zmax=255, showscale=False,
121
+ ), row=r, col=c)
122
+
123
+ for contour in measure.find_contours(bot_c, 0.5):
124
+ fig.add_trace(go.Scatter(
125
+ x=contour[:, 1], y=contour[:, 0], mode='lines',
126
+ line=dict(color='rgba(255,0,0,0.5)', width=4), showlegend=False,
127
+ ), row=r, col=c)
128
+
129
+ for contour in measure.find_contours(top_c, 0.5):
130
+ fig.add_trace(go.Scatter(
131
+ x=contour[:, 1], y=contour[:, 0], mode='lines',
132
+ line=dict(color='rgba(0,0,255,0.5)', width=4), showlegend=False,
133
+ ), row=r, col=c)
134
+
135
+ for row_idx in range(n_rows):
136
+ for col_idx in range(n_cols):
137
+ idx = row_idx * n_cols + col_idx + 1
138
+ s = '' if idx == 1 else str(idx)
139
+ fig.update_layout(**{
140
+ f'xaxis{s}': dict(showline=False, showticklabels=False, ticks='', showgrid=False, zeroline=False, range=[-0.5, cell_w - 0.5]),
141
+ f'yaxis{s}': dict(showline=False, showticklabels=False, ticks='', showgrid=False, zeroline=False, range=[cell_h - 0.5, -0.5]),
142
+ })
143
+
144
+ for row_idx, dose in enumerate(dose_ary):
145
+ fig.add_annotation(
146
+ x=0, y=1 - (row_idx + 0.5) / n_rows,
147
+ xref='paper', yref='paper',
148
+ xanchor='right', yanchor='middle', xshift=-4,
149
+ text=f'{dose} mJ/cm²', showarrow=False,
150
+ )
151
+
152
+ fig.update_layout(
153
+ width=int(n_cols * cell_w * scale + margin_l),
154
+ height=int(n_rows * cell_h * scale + margin_t),
155
+ autosize=False,
156
+ paper_bgcolor='white', plot_bgcolor='white',
157
+ font=dict(family='Arial, sans-serif', size=text_px, color='black'),
158
+ title_text='Resist profiles [Red: Bottom, Blue: Top, Background: SEM]',
159
+ title_x=0.5, showlegend=False,
160
+ margin=dict(l=margin_l, t=margin_t, r=10, b=10),
161
+ )
162
+ fig.update_annotations(font=dict(family='Arial, sans-serif', size=text_px, color='black'))
163
+ return fig
vis/utils_SMO.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ import numpy as np
4
+ import plotly.graph_objects as go
5
+ from stl import mesh
6
+ from skimage import measure
7
+ from torch.fft import fftfreq, fftshift
8
+
9
+
10
+ def _make_ground_plane(xmin, xmax, ymin, ymax, z0=0.0, color="#1653D0", grid_color="black", grid_size=10):
11
+ return go.Surface(
12
+ x=[[xmin, xmax]] * 2, y=[[ymin, ymin], [ymax, ymax]], z=[[z0, z0]] * 2,
13
+ showscale=False, colorscale=[[0, color], [1, color]],
14
+ contours=dict(
15
+ x=dict(show=True, color=grid_color, start=xmin, end=xmax, size=(xmax - xmin) / grid_size, width=16),
16
+ y=dict(show=True, color=grid_color, start=ymin, end=ymax, size=(ymax - ymin) / grid_size, width=16),
17
+ z=dict(show=False),
18
+ ),
19
+ )
20
+
21
+
22
+ def plot_stl(
23
+ stl_path, z_th=0.5, scale_mode="auto", isotropic_view=True,
24
+ camera_distance=0.9, below_color="rgba(0,0,0,0)", above_color="#86CDFF",
25
+ flat_shading=False, ambient=0.20, diffuse=0.70, specular=0.45,
26
+ roughness=0.35, fresnel=0.06, light_xyz=None, width=800, height=600, margin=0,
27
+ ):
28
+ tri = mesh.Mesh.from_file(str(stl_path)).vectors
29
+ vertices, reindex = np.unique(tri.reshape(-1, 3), axis=0, return_inverse=True)
30
+ i, j, k = reindex.reshape(-1, 3).T
31
+
32
+ if scale_mode == "auto":
33
+ diag_len = np.linalg.norm(np.ptp(vertices, axis=0))
34
+ vertices = vertices / diag_len
35
+ elif isinstance(scale_mode, (int, float)):
36
+ vertices = vertices * float(scale_mode)
37
+
38
+ vmin, vmax = vertices.min(0), vertices.max(0)
39
+ center, diag_vec = (vmin + vmax) / 2, vmax - vmin
40
+ diag_len = np.linalg.norm(diag_vec)
41
+
42
+ z_centroids = tri.mean(axis=1)[:, 2]
43
+ if scale_mode == "auto":
44
+ z_centroids = z_centroids / diag_len
45
+ face_colors = np.where(z_centroids < z_th, below_color, above_color)
46
+
47
+ light_pos = light_xyz or (center + 2 * diag_vec)
48
+ mesh3d = go.Mesh3d(
49
+ x=vertices[:, 0], y=vertices[:, 1], z=vertices[:, 2],
50
+ i=i, j=j, k=k, facecolor=face_colors, flatshading=flat_shading,
51
+ lighting=dict(ambient=ambient, diffuse=diffuse, specular=specular, roughness=roughness, fresnel=fresnel),
52
+ lightposition=dict(x=light_pos[0], y=light_pos[1], z=light_pos[2]),
53
+ showscale=False, name="",
54
+ )
55
+
56
+ p = 0.05 * vmax[0]
57
+ ground = _make_ground_plane(p, vmax[0] - p, p, vmax[1] - p, z0=0.003, color="rgba(200,200,255,1)", grid_color="black")
58
+
59
+ eye_pos = center + camera_distance * diag_len * (
60
+ np.array([1.5, -2, 1.7]) / 4 * 5 if isotropic_view else np.array([0, 0, 1])
61
+ )
62
+
63
+ fig = go.Figure(mesh3d)
64
+ fig.add_trace(ground)
65
+ fig.update_layout(
66
+ width=width, height=height,
67
+ margin=dict(l=margin, r=margin, t=margin, b=margin),
68
+ paper_bgcolor="rgba(0,0,0,0)",
69
+ scene=dict(
70
+ aspectmode="data",
71
+ camera=dict(eye=dict(x=eye_pos[0], y=eye_pos[1], z=eye_pos[2])),
72
+ xaxis=dict(visible=False), yaxis=dict(visible=False), zaxis=dict(visible=False),
73
+ ),
74
+ )
75
+ return fig
76
+
77
+
78
+ def vis_time_resist(traveltime, level=30.):
79
+ traveltime = traveltime.permute(1, 2, 0).flip(dims=(2,))
80
+ bo = traveltime[:, :, 0]
81
+ bo[bo < level] = level + 0.1
82
+ traveltime[:, :, 0] = bo
83
+
84
+ vertices, faces, _, _ = measure.marching_cubes(traveltime.numpy(), level=level)
85
+ surf_mesh = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype))
86
+ surf_mesh.vectors = vertices[faces]
87
+ surf_mesh.save('tmp.stl')
88
+
89
+ fig = plot_stl('tmp.stl')
90
+ os.remove('tmp.stl')
91
+ return fig
92
+
93
+
94
+ def export_scatter_plotly(
95
+ coords, intensity,
96
+ scatter_width_cm=2.0, scatter_height_cm=2.0, dpi=300, scale=1.0,
97
+ marker_size=4.0, background_color="rgba(249, 240, 255, 1.0)",
98
+ text_font_size=7, ticklabel_font_size=5,
99
+ show_x_ticks=True, show_x_ticklabels=True,
100
+ show_y_ticks=True, show_y_ticklabels=True,
101
+ x_unit=0.004, y_unit=0.004,
102
+ x_ticktext=None, y_ticktext=None,
103
+ x_ticks=[-125, 0, 125], y_ticks=[-125, 0, 125],
104
+ boundary_linewidth=1, tick_width=1,
105
+ x_label='sx', y_label='sy',
106
+ ticklen=16, outer_margin_cm=0.2,
107
+ ):
108
+ if isinstance(coords, torch.Tensor):
109
+ coords = coords.detach().cpu().numpy()
110
+ if isinstance(intensity, torch.Tensor):
111
+ intensity = intensity.detach().cpu().numpy()
112
+
113
+ def cm2px(v): return v / 2.54 * dpi
114
+
115
+ data_w = cm2px(scatter_width_cm)
116
+ data_h = cm2px(scatter_height_cm)
117
+ text_px = int(text_font_size / 72 * dpi * scale)
118
+ tick_px = int(ticklabel_font_size / 72 * dpi * scale)
119
+ pad = int(5 * scale)
120
+ outer = cm2px(outer_margin_cm)
121
+
122
+ ml = outer + boundary_linewidth + show_y_ticks * ticklen + show_y_ticklabels * tick_px + (1 if y_label else 0) * text_px + pad
123
+ mr = outer + boundary_linewidth + pad
124
+ mb = outer + boundary_linewidth + show_x_ticks * ticklen + show_x_ticklabels * tick_px + (1 if x_label else 0) * text_px * 3 + pad
125
+ mt = outer + boundary_linewidth + pad
126
+
127
+ fig_w = ml + mr + data_w
128
+ fig_h = mt + mb + data_h
129
+
130
+ border = dict(showline=True, linecolor='lightgray', linewidth=boundary_linewidth, mirror=True, fixedrange=True)
131
+ tick_cfg = dict(tickcolor='black', tickfont=dict(size=tick_px, color='black'), tickwidth=tick_width, ticklen=ticklen)
132
+
133
+ def make_axis(label, domain, anchor, show_ticks, show_labels, ticks, ticktext, unit):
134
+ ax = dict(
135
+ domain=domain, anchor=anchor, **border, **tick_cfg,
136
+ ticks='outside' if show_ticks else '',
137
+ showticklabels=show_labels,
138
+ title=dict(text=label or '', font=dict(size=text_px, color='black'), standoff=tick_px + ticklen),
139
+ range=[-1.1, 1.1],
140
+ )
141
+ if ticks is not None:
142
+ ax.update(
143
+ tickmode='array', tickvals=ticks,
144
+ ticktext=[str(int(v * unit)) for v in ticks] if ticktext is None else ticktext,
145
+ )
146
+ return ax
147
+
148
+ fig = go.Figure(data=go.Scatter(
149
+ x=coords[:, 0], y=coords[:, 1], mode='markers',
150
+ marker=dict(size=marker_size, color='rgba(128,0,128,1.0)', opacity=intensity, line=dict(width=0)),
151
+ ))
152
+ fig.update_layout(
153
+ autosize=False, width=int(fig_w), height=int(fig_h),
154
+ margin=dict(l=0, r=0, t=0, b=0),
155
+ paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor=background_color,
156
+ font=dict(family="Arial, sans-serif", size=text_px, color='black'),
157
+ xaxis=make_axis(x_label, [ml / fig_w, (ml + data_w) / fig_w], 'y', show_x_ticks, show_x_ticklabels, x_ticks, x_ticktext, x_unit),
158
+ yaxis=make_axis(y_label, [mb / fig_h, (mb + data_h) / fig_h], 'x', show_y_ticks, show_y_ticklabels, y_ticks, y_ticktext, y_unit),
159
+ )
160
+ return fig
161
+
162
+
163
+ def vis_source(y_src, Nx=512, dx=4, Ny=512, dy=4, sigma=[0.5, 0.9], NA=1.35, wavelength=193):
164
+ fx_v, fy_v = fftfreq(Nx, dx), fftfreq(Ny, dy)
165
+ FY, FX = torch.meshgrid(fy_v, fx_v, indexing='ij')
166
+ fx_grid, fy_grid = fftshift(FX), fftshift(FY)
167
+
168
+ rb = (fx_grid**2 + fy_grid**2)**0.5 / (NA / wavelength)
169
+ mask = (sigma[0] < rb) & (rb < sigma[1])
170
+ coords = torch.stack([fx_grid[mask].view(-1), fy_grid[mask].view(-1)], dim=1)
171
+ coords = coords / (sigma[1] * NA / wavelength)
172
+
173
+ return export_scatter_plotly(
174
+ coords, y_src,
175
+ x_ticks=[-1, 0, 1], y_ticks=[-1, 0, 1],
176
+ x_ticktext=['-1.0', '0.0', '1.0'], y_ticktext=['-1.0', '0.0', '1.0'],
177
+ )
vis/utils_data.py ADDED
@@ -0,0 +1,422 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import numpy as np
3
+ import plotly.graph_objects as go
4
+ from stl import mesh as stl_mesh
5
+ from matplotlib import cm
6
+
7
+
8
+ def _cm2px(cm, dpi):
9
+ return int(cm / 2.54 * dpi)
10
+
11
+ def _pt2px(pt, dpi):
12
+ return int(pt / 72 * dpi)
13
+
14
+ def _rgb_colorscale(cmap_name):
15
+ cmap = cm.get_cmap(cmap_name) if isinstance(cmap_name, str) else cmap_name
16
+ return [[i / 255, "rgb({},{},{})".format(*[int(c * 255) for c in cmap(i / 255)[:3]])] for i in range(256)]
17
+
18
+ def _alpha_colorscale(cmap_name, a_min, a_max):
19
+ cmap = cm.get_cmap(cmap_name) if isinstance(cmap_name, str) else cmap_name
20
+ scale = []
21
+ for i in range(256):
22
+ t = i / 255
23
+ r, g, b, _ = cmap(t)
24
+ a = a_min + (a_max - a_min) * t ** 5
25
+ scale.append([t, f"rgba({int(r*255)},{int(g*255)},{int(b*255)},{a:.3f})"])
26
+ return scale
27
+
28
+
29
+ def plot_2d(
30
+ data, heatmap_width_cm=2., heatmap_height_cm=2., dpi=300, scale=1.0,
31
+ use_colorbar=True, colorbar_thickness=24, text_font_size=7,
32
+ ticklabel_font_size=5, show_x_ticks=True, show_x_ticklabels=True,
33
+ show_y_ticks=True, show_y_ticklabels=True, x_unit=0.004, y_unit=0.004,
34
+ x_ticks=[0, 250, 500], y_ticks=[0, 250, 500], boundary_linewidth=1,
35
+ tick_width=1, x_label='x [μm]', y_label='y [μm]', cmap="Jet",
36
+ ticklen=16, colorbar_min=None, colorbar_max=None, outer_margin_cm=0.2,
37
+ colorbar_title=None,
38
+ ):
39
+ is_grid = data.ndim == 4 and data.shape[:2] == (2, 2)
40
+ panels = data if is_grid else data[np.newaxis, np.newaxis]
41
+ rows, cols = (2, 2) if is_grid else (1, 1)
42
+
43
+ def cm2px(v): return v / 2.54 * dpi
44
+
45
+ N = panels[0, 0].shape[0]
46
+ if N > 1000:
47
+ x_ticks = [0, 500, 1000]; y_ticks = [0, 500, 1000]
48
+ heatmap_width_cm *= 2; heatmap_height_cm *= 2
49
+ colorbar_thickness *= 2
50
+
51
+ data_w = cm2px(heatmap_width_cm)
52
+ data_h = cm2px(heatmap_height_cm)
53
+ text_px = int(text_font_size / 72 * dpi * scale)
54
+ tick_px = int(ticklabel_font_size / 72 * dpi * scale)
55
+ pad = int(5 * scale)
56
+ gap = pad * 5
57
+ outer = cm2px(outer_margin_cm)
58
+ cb_gap = pad * 4
59
+ cb_tick_w = tick_px * 8
60
+
61
+ ml = outer + boundary_linewidth + show_y_ticks * ticklen + show_y_ticklabels * tick_px + (1 if y_label else 0) * text_px + pad
62
+ mr = outer + boundary_linewidth + pad + use_colorbar * (cb_gap + colorbar_thickness + cb_tick_w)
63
+ mb = outer + boundary_linewidth + show_x_ticks * ticklen + show_x_ticklabels * tick_px + (1 if x_label else 0) * text_px * 3 + pad
64
+ mt = outer + boundary_linewidth + pad
65
+
66
+ fig_w = ml + mr + cols * data_w + (cols - 1) * gap
67
+ fig_h = mt + mb + rows * data_h + (rows - 1) * gap
68
+ grid_y0 = mb / fig_h
69
+ grid_y1 = (mb + rows * data_h + (rows - 1) * gap) / fig_h
70
+
71
+ vmin = float(colorbar_min if colorbar_min is not None else min(panels[r, c].min() for r in range(rows) for c in range(cols)))
72
+ vmax = float(colorbar_max if colorbar_max is not None else max(panels[r, c].max() for r in range(rows) for c in range(cols)))
73
+
74
+ border = dict(showline=True, linecolor='lightgray', linewidth=boundary_linewidth, mirror=True, fixedrange=True)
75
+
76
+ def xname(i): return 'x' if i == 0 else f'x{i+1}'
77
+ def yname(i): return 'y' if i == 0 else f'y{i+1}'
78
+
79
+ def make_xaxis(domain, anchor, is_bottom):
80
+ ax = dict(domain=domain, anchor=anchor, **border)
81
+ if is_bottom:
82
+ ax.update(
83
+ ticks='outside' if show_x_ticks else '', ticklen=ticklen, tickwidth=tick_width,
84
+ tickcolor='black', tickfont=dict(size=tick_px, color='black'),
85
+ showticklabels=show_x_ticklabels,
86
+ title=dict(text=x_label or '', font=dict(size=text_px, color='black'), standoff=tick_px + ticklen),
87
+ tickmode='array', tickvals=x_ticks, ticktext=[f"{v * x_unit:.1f}" for v in x_ticks],
88
+ )
89
+ else:
90
+ ax.update(ticks='', ticklen=0, showticklabels=False, title=dict(text=''), showgrid=False)
91
+ return ax
92
+
93
+ def make_yaxis(domain, anchor, is_left):
94
+ ax = dict(domain=domain, anchor=anchor, **border)
95
+ if is_left:
96
+ ax.update(
97
+ ticks='outside' if show_y_ticks else '', ticklen=ticklen, tickwidth=tick_width,
98
+ tickcolor='black', tickfont=dict(size=tick_px, color='black'),
99
+ showticklabels=show_y_ticklabels,
100
+ title=dict(text=y_label or '', font=dict(size=text_px, color='black'), standoff=tick_px + ticklen),
101
+ tickmode='array', tickvals=y_ticks, ticktext=[f"{v * y_unit:.1f}" for v in y_ticks],
102
+ )
103
+ else:
104
+ ax.update(ticks='', ticklen=0, showticklabels=False, title=dict(text=''), showgrid=False)
105
+ return ax
106
+
107
+ fig = go.Figure()
108
+
109
+ for r in range(rows):
110
+ for c in range(cols):
111
+ idx = r * cols + c
112
+ x0 = (ml + c * (data_w + gap)) / fig_w
113
+ x1 = (ml + c * (data_w + gap) + data_w) / fig_w
114
+ y0 = (mb + (rows - 1 - r) * (data_h + gap)) / fig_h
115
+ y1 = (mb + (rows - 1 - r) * (data_h + gap) + data_h) / fig_h
116
+
117
+ fig.add_trace(go.Heatmap(
118
+ z=panels[r, c], colorscale=cmap, showscale=False,
119
+ zmin=vmin, zmax=vmax, xaxis=xname(idx), yaxis=yname(idx),
120
+ ))
121
+ fig.update_layout(**{
122
+ f'xaxis{"" if idx == 0 else idx+1}': make_xaxis([x0, x1], anchor=yname(idx), is_bottom=(r == rows - 1)),
123
+ f'yaxis{"" if idx == 0 else idx+1}': make_yaxis([y0, y1], anchor=xname(idx), is_left=(c == 0)),
124
+ })
125
+
126
+ if use_colorbar:
127
+ n_cb = 256
128
+ cb_idx = rows * cols
129
+ cb_data = np.linspace(vmin, vmax, n_cb).reshape(n_cb, 1)
130
+ cb_x0 = (ml + cols * data_w + (cols - 1) * gap + cb_gap) / fig_w
131
+ cb_x1 = cb_x0 + colorbar_thickness / fig_w
132
+ cb_tickvals = np.linspace(0, n_cb - 1, 5)
133
+ cb_ticktext = [f"{v:.2f}" for v in np.linspace(vmin, vmax, 5)]
134
+
135
+ fig.add_trace(go.Heatmap(
136
+ z=cb_data, colorscale=cmap, showscale=False,
137
+ zmin=vmin, zmax=vmax, xaxis=xname(cb_idx), yaxis=yname(cb_idx),
138
+ ))
139
+ fig.update_layout(**{
140
+ f'xaxis{"" if cb_idx == 0 else cb_idx+1}': dict(
141
+ domain=[cb_x0, cb_x1], anchor=yname(cb_idx), visible=False, fixedrange=True,
142
+ showline=True, linecolor='black', linewidth=boundary_linewidth, mirror=True,
143
+ ),
144
+ f'yaxis{"" if cb_idx == 0 else cb_idx+1}': dict(
145
+ domain=[grid_y0, grid_y1], anchor=xname(cb_idx), side='right', fixedrange=True,
146
+ tickmode='array', tickvals=cb_tickvals, ticktext=cb_ticktext,
147
+ tickfont=dict(size=tick_px, color='black'), tickcolor='black',
148
+ tickwidth=tick_width, ticklen=ticklen // 2,
149
+ showline=True, linecolor='black', linewidth=boundary_linewidth,
150
+ showgrid=False, mirror=False,
151
+ title=dict(text=colorbar_title or '', font=dict(size=text_px, color='black'), standoff=tick_px + ticklen // 2),
152
+ ),
153
+ })
154
+
155
+ fig.update_layout(
156
+ autosize=False, width=int(fig_w), height=int(fig_h),
157
+ margin=dict(l=0, r=0, t=0, b=0),
158
+ paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)',
159
+ font=dict(family="Arial, sans-serif", size=text_px, color='black'),
160
+ )
161
+ return fig
162
+
163
+
164
+ def vis_mask(data, cmap='gray'):
165
+ return plot_2d(torch.flip(data, dims=(0,)), cmap=cmap, use_colorbar=False)
166
+
167
+ def vis_sc(data, cmap='jet'):
168
+ return plot_2d(torch.flip(data, dims=(2,)), cmap=cmap, use_colorbar=True, colorbar_title='Amplitude [-]')
169
+
170
+
171
+ def plot_tensor_slices(
172
+ data, slice_indices=None, opacity=None, colorscale="jet",
173
+ vmin=None, vmax=None, alpha_at_cmin=0.1, alpha_at_cmax=1,
174
+ use_colorbar=True, colorbar_thickness=20, colorbar_title=None,
175
+ colorbar_title_side="right", use_dummy_colorbar=True, colorbar_length=0.6,
176
+ colorbar_font="Arial, sans-serif", colorbar_fontsize=7, colorbar_tick_fontsize=5,
177
+ colorbar_nticks=None, show_axes=True, isotropic_view=True,
178
+ camera_distance=1.5, fig_width_cm=6.0, fig_height_cm=4.0, dpi=300, png_path=None,
179
+ ):
180
+ if data.ndim != 3:
181
+ raise ValueError("`data` must be a 3-D array (Nx, Ny, Nz).")
182
+
183
+ N = data.shape[0]
184
+ sf = 2 if N >= 513 else 1
185
+ s, e = N // 2 - 128 * sf, N // 2 + 128 * sf
186
+ data = data[s:e, s:e, :]
187
+ fig_width_cm *= sf; fig_height_cm *= sf
188
+ camera_distance /= sf
189
+ colorbar_thickness = int(colorbar_thickness * sf)
190
+
191
+ Nx, Ny, Nz = data.shape
192
+ ix, iy, iz = map(int, slice_indices) if slice_indices else (Nx // 2, Ny // 2, Nz // 2)
193
+ vmin = float(np.nanmin(data)) if vmin is None else float(vmin)
194
+ vmax = float(np.nanmax(data)) if vmax is None else float(vmax)
195
+
196
+ custom_scale = _alpha_colorscale(colorscale, alpha_at_cmin, alpha_at_cmax)
197
+ dummy_scale = _rgb_colorscale(colorscale)
198
+
199
+ x, y, z = np.arange(Nx), np.arange(Ny), np.arange(Nz)
200
+
201
+ def cb_cfg():
202
+ cb = dict(
203
+ lenmode="fraction", len=colorbar_length, thickness=colorbar_thickness,
204
+ x=0.85, y=0.45,
205
+ tickfont=dict(family=colorbar_font, size=_pt2px(colorbar_tick_fontsize, dpi), color="black"),
206
+ tickwidth=1, tickcolor="black", outlinewidth=1, outlinecolor="black",
207
+ nticks=colorbar_nticks or 5,
208
+ )
209
+ if colorbar_title is not None:
210
+ cb["title"] = dict(
211
+ text=colorbar_title, side=colorbar_title_side,
212
+ font=dict(family=colorbar_font, size=_pt2px(colorbar_fontsize, dpi), color="black"),
213
+ )
214
+ return cb
215
+
216
+ surf_kw = dict(
217
+ colorscale=custom_scale, cmin=vmin, cmax=vmax,
218
+ lighting=dict(ambient=1.0), opacity=1.0 if opacity is None else opacity,
219
+ )
220
+
221
+ surfaces = []
222
+ for k_z in range(0, Nz, 4):
223
+ show_scale = use_colorbar and not use_dummy_colorbar and len(surfaces) == 0
224
+ surfaces.append(go.Surface(
225
+ x=np.tile(x[:, None], (1, Ny)), y=np.tile(y[None, :], (Nx, 1)),
226
+ z=np.full((Nx, Ny), k_z), surfacecolor=data[:, :, k_z],
227
+ showscale=show_scale, colorbar=cb_cfg() if show_scale else None,
228
+ name=f"XY @ z={k_z}", **surf_kw,
229
+ ))
230
+
231
+ surfaces.append(go.Surface(
232
+ x=np.full((Ny, Nz), Nx - 1), y=np.tile(y[:, None], (1, Nz)),
233
+ z=np.tile(z[None, :], (Ny, 1)), surfacecolor=data[Nx - 1, :, :],
234
+ showscale=False, name=f"YZ @ x={Nx-1}", **surf_kw,
235
+ ))
236
+ surfaces.append(go.Surface(
237
+ x=np.tile(x[:, None], (1, Nz)), y=np.full((Nx, Nz), Ny - 1),
238
+ z=np.tile(z[None, :], (Nx, 1)), surfacecolor=data[:, Ny - 1, :],
239
+ showscale=False, name=f"XZ @ y={Ny-1}", **surf_kw,
240
+ ))
241
+
242
+ fig = go.Figure(data=surfaces)
243
+
244
+ if use_colorbar and use_dummy_colorbar:
245
+ fig.add_trace(go.Scatter3d(
246
+ x=[0.0, 0.0], y=[0.0, 0.0], z=[0.0, 0.0],
247
+ mode="markers", showlegend=False, hoverinfo="skip",
248
+ marker=dict(
249
+ size=0.001, opacity=0.0, color=[vmin, vmax],
250
+ cmin=vmin, cmax=vmax, colorscale=dummy_scale,
251
+ showscale=True, colorbar=cb_cfg(),
252
+ ),
253
+ ))
254
+
255
+ bbox_x = [0, Nx-1, Nx-1, 0, 0, None, 0, Nx-1, Nx-1, 0, 0, None, 0, 0, None, Nx-1, Nx-1, None, Nx-1, Nx-1, None, 0, 0]
256
+ bbox_y = [0, 0, Ny-1, Ny-1, 0, None, 0, 0, Ny-1, Ny-1, 0, None, 0, 0, None, 0, 0, None, Ny-1, Ny-1, None, Ny-1, Ny-1]
257
+ bbox_z = [0, 0, 0, 0, 0, None, Nz-1, Nz-1, Nz-1, Nz-1, Nz-1, None, 0, Nz-1, None, 0, Nz-1, None, 0, Nz-1, None, 0, Nz-1]
258
+ fig.add_trace(go.Scatter3d(
259
+ x=bbox_x, y=bbox_y, z=bbox_z, mode="lines",
260
+ line=dict(color="black", width=1.5), showlegend=False,
261
+ ))
262
+
263
+ tick_px = int(2.5 / 72 * dpi)
264
+ unit = 0.004
265
+ sz = 1 if Nx < 257 else 2
266
+ axis_style = dict(visible=show_axes, showbackground=False, mirror=True, linecolor="black", linewidth=0, tickwidth=0, tickcolor="black")
267
+ title_font = dict(family="Arial, sans-serif", size=tick_px * 1.5, color="black")
268
+ tick_font = dict(family="Arial, sans-serif", size=tick_px, color="black")
269
+
270
+ centre = np.array([Nx / 2, Ny / 2, Nz / 2])
271
+ diag_len = np.linalg.norm([Nx, Ny, Nz]) / 2
272
+
273
+ if isotropic_view:
274
+ eye_dir = np.array([1.0, 1.0, 1.7 * (2.5 if sf == 2 else 1.0)])
275
+ eye_pos = centre + camera_distance * diag_len * eye_dir / np.linalg.norm(eye_dir) / 1.1
276
+ else:
277
+ eye_pos = centre + camera_distance * np.array([0.0, 0.0, diag_len])
278
+
279
+ fig.update_layout(
280
+ scene=dict(
281
+ xaxis=dict(**axis_style, title=dict(text="x", font=title_font), tickfont=tick_font,
282
+ tickmode="array", tickvals=[0, Nx//2, Nx-1],
283
+ ticktext=[f"{abs(sz - v * unit):.1f}" for v in [0, Nx//2, Nx-1]]),
284
+ yaxis=dict(**axis_style, title=dict(text="y", font=title_font), tickfont=tick_font,
285
+ tickmode="array", tickvals=[0, Ny//2, Ny-1],
286
+ ticktext=[f"{abs(sz - v * unit):.1f}" for v in [0, Ny//2, Ny-1]]),
287
+ zaxis=dict(**axis_style, title=dict(text="z", font=title_font), tickfont=tick_font,
288
+ tickmode="array", tickvals=[Nz-1], ticktext=[f"{abs(Nz * unit):.2f}"]),
289
+ aspectmode="data",
290
+ camera=dict(eye=dict(x=float(eye_pos[0]*0.01), y=float(eye_pos[1]*0.01), z=float(eye_pos[2]*0.01))),
291
+ ),
292
+ width=_cm2px(fig_width_cm, dpi), height=_cm2px(fig_height_cm, dpi),
293
+ paper_bgcolor="rgba(0,0,0,0)",
294
+ legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
295
+ )
296
+
297
+ if png_path is not None:
298
+ fig.write_image(png_path, width=_cm2px(fig_width_cm, dpi), height=_cm2px(fig_height_cm, dpi), scale=1.0)
299
+
300
+ return fig
301
+
302
+
303
+ def vis_field(data, cmap="jet", colorbar_title=None):
304
+ data = data.permute(2, 1, 0).flip(dims=(0, 2))
305
+ return plot_tensor_slices(data, colorscale=cmap, colorbar_title=colorbar_title)
306
+
307
+
308
+ def _make_ground_plane(xmin, xmax, ymin, ymax, z0=0.0, color="#1653D0", grid_color="black", grid_size=10):
309
+ return go.Surface(
310
+ x=[[xmin, xmax]] * 2, y=[[ymin, ymin], [ymax, ymax]], z=[[z0, z0]] * 2,
311
+ showscale=False, colorscale=[[0, color], [1, color]],
312
+ contours=dict(
313
+ x=dict(show=True, color=grid_color, start=xmin, end=xmax, size=(xmax - xmin) / grid_size, width=16),
314
+ y=dict(show=True, color=grid_color, start=ymin, end=ymax, size=(ymax - ymin) / grid_size, width=16),
315
+ z=dict(show=False),
316
+ ),
317
+ )
318
+
319
+
320
+ def plot_stl(
321
+ stl_path, z_th=0.5, scale_mode="auto", isotropic_view=True,
322
+ camera_distance=0.9, below_color="rgba(0,0,0,0)", above_color="#86CDFF",
323
+ flat_shading=False, ambient=0.20, diffuse=0.70, specular=0.45,
324
+ roughness=0.35, fresnel=0.06, light_xyz=None, width=800, height=600, margin=0,
325
+ ):
326
+ tri = stl_mesh.Mesh.from_file(str(stl_path)).vectors
327
+ vertices, reindex = np.unique(tri.reshape(-1, 3), axis=0, return_inverse=True)
328
+ i, j, k = reindex.reshape(-1, 3).T
329
+
330
+ if scale_mode == "auto":
331
+ diag_len = np.linalg.norm(np.ptp(vertices, axis=0))
332
+ vertices = vertices / diag_len
333
+ elif isinstance(scale_mode, (int, float)):
334
+ vertices = vertices * float(scale_mode)
335
+
336
+ vmin, vmax = vertices.min(0), vertices.max(0)
337
+ center, diag_vec = (vmin + vmax) / 2, vmax - vmin
338
+ diag_len = np.linalg.norm(diag_vec)
339
+
340
+ z_centroids = tri.mean(axis=1)[:, 2]
341
+ if scale_mode == "auto":
342
+ z_centroids = z_centroids / diag_len
343
+ face_colors = np.where(z_centroids < z_th, below_color, above_color)
344
+
345
+ light_pos = light_xyz or (center + 2 * diag_vec)
346
+ mesh3d = go.Mesh3d(
347
+ x=vertices[:, 0], y=vertices[:, 1], z=vertices[:, 2],
348
+ i=i, j=j, k=k, facecolor=face_colors, flatshading=flat_shading,
349
+ lighting=dict(ambient=ambient, diffuse=diffuse, specular=specular, roughness=roughness, fresnel=fresnel),
350
+ lightposition=dict(x=light_pos[0], y=light_pos[1], z=light_pos[2]),
351
+ showscale=False, name="",
352
+ )
353
+
354
+ p = 0.05 * vmax[0]
355
+ ground = _make_ground_plane(p, vmax[0] - p, p, vmax[1] - p, z0=0.003, color="rgba(200,200,255,1)", grid_color="black")
356
+
357
+ eye_pos = center + camera_distance * diag_len * (
358
+ np.array([1.5, -2, 1.7]) / 4 * 5 if isotropic_view else np.array([0, 0, 1])
359
+ )
360
+
361
+ fig = go.Figure(mesh3d)
362
+ fig.add_trace(ground)
363
+ fig.update_layout(
364
+ width=width, height=height,
365
+ margin=dict(l=margin, r=margin, t=margin, b=margin),
366
+ paper_bgcolor="rgba(0,0,0,0)",
367
+ scene=dict(
368
+ aspectmode="data",
369
+ camera=dict(eye=dict(x=eye_pos[0], y=eye_pos[1], z=eye_pos[2])),
370
+ xaxis=dict(visible=False), yaxis=dict(visible=False), zaxis=dict(visible=False),
371
+ ),
372
+ )
373
+ return fig
374
+
375
+
376
+ _default_layout = [
377
+ {'row': 1, 'col': 1, 'title': 'Photomask (M)'},
378
+ {'row': 1, 'col': 2, 'title': 'Diffracted near field (E)'},
379
+ {'row': 2, 'col': 1, 'title': 'Photoacid (h)'},
380
+ {'row': 2, 'col': 2, 'title': 'Deprotection image (m)'},
381
+ {'row': 3, 'col': 1, 'title': 'Development rate (R)'},
382
+ {'row': 3, 'col': 2, 'title': 'Development time (T)'},
383
+ ]
384
+
385
+ def save_html(figures, filepath, title="Dashboard", layout=_default_layout, cols=2):
386
+ import plotly.io as pio
387
+
388
+ html_parts = [pio.to_html(fig, full_html=False, include_plotlyjs=(i == 0)) for i, fig in enumerate(figures)]
389
+
390
+ items_html = ""
391
+ for i, part in enumerate(html_parts):
392
+ L = layout[i] if layout and i < len(layout) else {}
393
+ row, col = L.get("row", "auto"), L.get("col", "auto")
394
+ rowspan, colspan = L.get("rowspan", 1), L.get("colspan", 1)
395
+ fig_title = L.get("title", "")
396
+ style = f"grid-row: {row} / span {rowspan}; grid-column: {col} / span {colspan};"
397
+ title_html = f'<div class="fig-title">{fig_title}</div>' if fig_title else ""
398
+ items_html += f'<div class="fig-item" style="{style}">{title_html}<div class="fig-inner">{part}</div></div>\n'
399
+
400
+ full_html = f"""<!DOCTYPE html>
401
+ <html>
402
+ <head>
403
+ <meta charset="utf-8">
404
+ <title>{title}</title>
405
+ <style>
406
+ body {{ font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; }}
407
+ h1 {{ margin-bottom: 20px; }}
408
+ .grid-container {{ display: grid; grid-template-columns: repeat({cols}, 1fr); gap: 16px; }}
409
+ .fig-item {{ background: white; border-radius: 8px; padding: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }}
410
+ .fig-title {{ font-size: 1em; font-weight: bold; color: #333; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 2px solid #e0e0e0; }}
411
+ .fig-inner {{ width: 100%; }}
412
+ </style>
413
+ </head>
414
+ <body>
415
+ <h1>{title}</h1>
416
+ <div class="grid-container">{items_html}</div>
417
+ </body>
418
+ </html>"""
419
+
420
+ with open(filepath, "w", encoding="utf-8") as f:
421
+ f.write(full_html)
422
+ print(f"Saved → {filepath}")
vis/vis_PW.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
vis/vis_SMO.ipynb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b7b95b76099c2bef1a6f4a8965dea13afcdc1bd3650f1e1332e2dc88bcb9bdb3
3
+ size 38513268
vis/vis_data.ipynb ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "95b596a0",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Data visualization"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": 12,
14
+ "id": "659ff786",
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "import torch\n",
19
+ "import os\n",
20
+ "from utils_data import vis_mask, vis_sc, vis_field, save_html\n",
21
+ "\n",
22
+ "BASE = '../LithoBench_PDE'"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 13,
28
+ "id": "a7b8b049",
29
+ "metadata": {},
30
+ "outputs": [],
31
+ "source": [
32
+ "# Load and visualize a data point (M, E), (h, m), (R, T)\n",
33
+ "layer_type = 'Metal_I'\n",
34
+ "cell_name = 'cell1550'\n",
35
+ "\n",
36
+ "data = torch.load(os.path.join(BASE, layer_type, f'{cell_name}.pt'))"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": 14,
42
+ "id": "cc776e33",
43
+ "metadata": {},
44
+ "outputs": [
45
+ {
46
+ "name": "stdout",
47
+ "output_type": "stream",
48
+ "text": [
49
+ "Saved → Metal_I_cell1550.html\n"
50
+ ]
51
+ }
52
+ ],
53
+ "source": [
54
+ "fig_M = vis_mask(data['M'], cmap='gray')\n",
55
+ "fig_E = vis_sc(data['E'].abs(), cmap='jet')\n",
56
+ "\n",
57
+ "fig_h = vis_field(data['h'], cmap='coolwarm', colorbar_title='Rel. conc. [-]')\n",
58
+ "fig_m = vis_field(data['m'], cmap='jet', colorbar_title='Rel. conc. [-]')\n",
59
+ "\n",
60
+ "fig_R = vis_field(data['R'], cmap='rainbow', colorbar_title='Dev. rate [nm/s]')\n",
61
+ "fig_T = vis_field(data['T'], cmap='plasma', colorbar_title='Traveltime [s]')\n",
62
+ "\n",
63
+ "figures = [fig_M, fig_E, fig_h, fig_m, fig_R, fig_T]\n",
64
+ "\n",
65
+ "filepath = f'{layer_type}_{cell_name}.html'\n",
66
+ "\n",
67
+ "save_html(figures, filepath, title=f'{layer_type} {cell_name}')"
68
+ ]
69
+ }
70
+ ],
71
+ "metadata": {
72
+ "kernelspec": {
73
+ "display_name": "neurolitho",
74
+ "language": "python",
75
+ "name": "python3"
76
+ },
77
+ "language_info": {
78
+ "codemirror_mode": {
79
+ "name": "ipython",
80
+ "version": 3
81
+ },
82
+ "file_extension": ".py",
83
+ "mimetype": "text/x-python",
84
+ "name": "python",
85
+ "nbconvert_exporter": "python",
86
+ "pygments_lexer": "ipython3",
87
+ "version": "3.11.14"
88
+ }
89
+ },
90
+ "nbformat": 4,
91
+ "nbformat_minor": 5
92
+ }