LithoBench-PDE / vis /utils_PW.py
AISDL-SNU-Admin's picture
Add visualization utils
645beaf verified
import numpy as np
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
from skimage import measure
def get_color_gradient(start_hex, end_hex, n):
def hex_to_rgb(h):
h = h.lstrip('#')
return tuple(int(h[i:i+2], 16) for i in (0, 2, 4))
if n <= 1:
return [f'rgb{hex_to_rgb(end_hex)}']
s, e = hex_to_rgb(start_hex), hex_to_rgb(end_hex)
return [
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))})'
for i in range(n)
]
def plot_focus_exposure(data_list, dose_ary, cmap_idx, **kwargs):
dpi = kwargs.get('dpi', 600)
fig_w = kwargs.get('fig_width_cm', 5) / 2.54 * dpi
fig_h = kwargs.get('fig_height_cm', 1.5) / 2.54 * dpi
text_px = int(kwargs.get('text_font_size', 1.5) / 72 * dpi)
tick_px = int(kwargs.get('ticklabel_font_size', 2) / 72 * dpi)
show_x_ticks = kwargs.get('show_x_ticks', True)
show_x_ticklabels = kwargs.get('show_x_ticklabels', True)
show_y_ticks = kwargs.get('show_y_ticks', True)
show_y_ticklabels = kwargs.get('show_y_ticklabels', True)
n = len(data_list)
fig = make_subplots(rows=1, cols=n, subplot_titles=[title for _, title in data_list])
target_color = px.colors.qualitative.Plotly[cmap_idx]
sorted_doses = sorted(dose_ary)
colors = get_color_gradient("#D0D0D0", target_color, len(sorted_doses))
dose_color = {dose: colors[i] for i, dose in enumerate(sorted_doses)}
for col_idx, (data, title) in enumerate(data_list, start=1):
for dose in dose_ary:
if dose not in data:
continue
focus_p, cd_p = data[dose]
fig.add_trace(go.Scatter(
x=focus_p, y=cd_p, mode='lines',
name=f'{dose} mJ/cm²',
line=dict(color=dose_color[dose], width=4),
legendgroup=f'{dose}', showlegend=(col_idx == 1),
), row=1, col=col_idx)
axis_common = dict(
showline=True, linecolor='black', mirror=True, linewidth=1,
tickfont=dict(size=tick_px, color='black'),
)
for col_idx in range(1, n + 1):
s = '' if col_idx == 1 else str(col_idx)
fig.update_layout(**{
f'xaxis{s}': dict(
**axis_common,
title=dict(text=kwargs.get('x_label', 'Focus [nm]')),
range=[-160, 160], nticks=5,
ticks='inside' if show_x_ticks else '',
showticklabels=show_x_ticklabels,
),
f'yaxis{s}': dict(
**axis_common,
title=dict(text=kwargs.get('y_label', 'CD [nm]') if col_idx == 1 else '', standoff=text_px * 0.8),
range=[0, 310],
ticks='inside' if show_y_ticks else '',
showticklabels=show_y_ticklabels if col_idx == 1 else False,
),
})
fig.update_layout(
autosize=False, width=int(fig_w), height=int(fig_h),
paper_bgcolor='rgba(255,255,255,1)', plot_bgcolor='rgba(255,255,255,1)',
font=dict(family='Arial, sans-serif', size=text_px, color='black'),
showlegend=kwargs.get('showlegend', False),
)
fig.update_annotations(font=dict(family='Arial, sans-serif', size=text_px, color='black'))
return fig
def plot_profiles(bot, top, sem, **kwargs):
dpi = kwargs.get('dpi', 600)
text_px = int(kwargs.get('text_font_size', 1.5) / 72 * dpi)
scale = kwargs.get('scale', 1.5)
dose_ary = kwargs.get('dose_ary', [34, 26, 18])
focus_ary = kwargs.get('focus_ary', [-100 + 20*i for i in range(11)])
ny, nx = kwargs.get('ny', 50), kwargs.get('nx', 35)
nc = 512 // 2 - 1
n_rows, n_cols = len(dose_ary), len(focus_ary)
cell_h, cell_w = 2*ny + 1, 2*nx + 1
margin_l = kwargs.get('margin_l', text_px * 10)
margin_t = kwargs.get('margin_t', text_px * 4)
to_np = lambda t: t.float().numpy() if hasattr(t, 'numpy') else np.array(t, dtype=float)
fig = make_subplots(
rows=n_rows, cols=n_cols,
subplot_titles=[f'{focus_ary[c]} nm' if r == 0 else '' for r in range(n_rows) for c in range(n_cols)],
horizontal_spacing=0.01, vertical_spacing=0.01,
)
for row_idx, dose in enumerate(dose_ary):
for col_idx, focus in enumerate(focus_ary):
r, c = row_idx + 1, col_idx + 1
crop = lambda d: to_np(d[dose][focus][nc-ny:nc+ny+1, nc-nx:nc+nx+1])
bot_c, top_c, sem_c = crop(bot), crop(top), crop(sem)
fig.add_trace(go.Heatmap(
z=sem_c, colorscale=[[0, 'black'], [1, 'white']],
zmin=0, zmax=255, showscale=False,
), row=r, col=c)
for contour in measure.find_contours(bot_c, 0.5):
fig.add_trace(go.Scatter(
x=contour[:, 1], y=contour[:, 0], mode='lines',
line=dict(color='rgba(255,0,0,0.5)', width=4), showlegend=False,
), row=r, col=c)
for contour in measure.find_contours(top_c, 0.5):
fig.add_trace(go.Scatter(
x=contour[:, 1], y=contour[:, 0], mode='lines',
line=dict(color='rgba(0,0,255,0.5)', width=4), showlegend=False,
), row=r, col=c)
for row_idx in range(n_rows):
for col_idx in range(n_cols):
idx = row_idx * n_cols + col_idx + 1
s = '' if idx == 1 else str(idx)
fig.update_layout(**{
f'xaxis{s}': dict(showline=False, showticklabels=False, ticks='', showgrid=False, zeroline=False, range=[-0.5, cell_w - 0.5]),
f'yaxis{s}': dict(showline=False, showticklabels=False, ticks='', showgrid=False, zeroline=False, range=[cell_h - 0.5, -0.5]),
})
for row_idx, dose in enumerate(dose_ary):
fig.add_annotation(
x=0, y=1 - (row_idx + 0.5) / n_rows,
xref='paper', yref='paper',
xanchor='right', yanchor='middle', xshift=-4,
text=f'{dose} mJ/cm²', showarrow=False,
)
fig.update_layout(
width=int(n_cols * cell_w * scale + margin_l),
height=int(n_rows * cell_h * scale + margin_t),
autosize=False,
paper_bgcolor='white', plot_bgcolor='white',
font=dict(family='Arial, sans-serif', size=text_px, color='black'),
title_text='Resist profiles [Red: Bottom, Blue: Top, Background: SEM]',
title_x=0.5, showlegend=False,
margin=dict(l=margin_l, t=margin_t, r=10, b=10),
)
fig.update_annotations(font=dict(family='Arial, sans-serif', size=text_px, color='black'))
return fig