Skip to content

Commit

Permalink
Update plot_structures
Browse files Browse the repository at this point in the history
  • Loading branch information
jungtaekkim committed Mar 28, 2024
1 parent f13ecde commit d956ec1
Showing 1 changed file with 78 additions and 15 deletions.
93 changes: 78 additions & 15 deletions src/plot_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
from matplotlib.patches import Polygon
from matplotlib.ticker import AutoMinorLocator

import plot_pareto_frontiers as ppf


path_results = '../results'
path_figures = '../figures'

num_layerss = [2, 4, 6, 8]
seeds = np.arange(42, 421, 42)
num_init = 10
num_iter = 500


def get_color(material):
if material == 'Ag':
Expand Down Expand Up @@ -60,7 +68,7 @@ def plot_structure(materials, thicknesses, show_figure, save_figure, str_figure)
grid_size = 100

plt.rc('text', usetex=True)
fig = plt.figure(figsize=(4, 8))
fig = plt.figure(figsize=(6, 8))
ax = fig.gca()

thickness_total = np.sum(thicknesses)
Expand All @@ -82,35 +90,31 @@ def plot_structure(materials, thicknesses, show_figure, save_figure, str_figure)
polygon = Polygon(points, facecolor=color)
ax.add_patch(polygon)

ax.text(0, cur_thickness_lower + (max_height - cur_thickness_lower) / 2 / 2, get_label_material(material),
ha='center', va='center', fontsize=16)
ax.text(0, cur_thickness_lower + thickness / 2, get_label_material(material),
ha='center', va='center', fontsize=22)

cur_thickness_lower += thickness

ax.set_xlim([-grid_size / 2, grid_size / 2])
# ax.set_ylim([-max_height / 2 + thickness_total / 2, max_height / 2 + thickness_total / 2])
ax.set_ylim([0, max_height / 2 + thickness_total / 2])
ax.set_ylim([-max_height / 2 + thickness_total / 2, max_height / 2 + thickness_total / 2])

# ax.xaxis.set_minor_locator(AutoMinorLocator())
ax.yaxis.set_minor_locator(AutoMinorLocator())

ax.tick_params(axis='both', which='major', labelsize=16)
ax.tick_params(axis='both', which='major', labelsize=22)

ax.tick_params(which='major', direction='out', length=8)
ax.tick_params(which='minor', direction='out', length=4)

ax.get_xaxis().set_visible(False)

ax2.spines['top'].set_visible(False)
ax2.spines['right'].set_visible(False)
ax2.spines['bottom'].set_visible(False)
ax2.spines['left'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)

fontsize_label = 24
ax2.set_xlabel(r'$x$ \textrm{(nm)}', fontsize=fontsize_label)
ax2.set_ylabel(r'$z$ \textrm{(nm)}', fontsize=fontsize_label)
fontsize_label = 28
ax.set_ylabel(r'\textrm{Thickness (nm)}', fontsize=fontsize_label)

ax2.invert_yaxis()
plt.tight_layout()

if save_figure:
Expand All @@ -121,4 +125,63 @@ def plot_structure(materials, thicknesses, show_figure, save_figure, str_figure)

if show_figure:
plt.show()

plt.close('all')

if __name__ == '__main__':
show_figure = True
save_figure = False

for num_layers in num_layerss:
materials_all = []
thicknesses_all = []
transparencies_all = []
shielding_effectivenesses_all = []

for seed in seeds:
str_file = f'mobo_layers_{num_layers}_init_{num_init}_iter_{num_iter}_seed_{seed:04d}.npy'

results = np.load(os.path.join(path_results, str_file), allow_pickle=True)
results = results[()]

materials = results['materials']
thicknesses = results['thicknesses']

negative_transparencies = results['negative_transparencies']
negative_shielding_effectivenesses = results['negative_shielding_effectivenesses']

transparencies = -1.0 * negative_transparencies
shielding_effectivenesses = -1.0 * negative_shielding_effectivenesses

materials_all += list(materials)
thicknesses_all += list(thicknesses)
transparencies_all += list(transparencies)
shielding_effectivenesses_all += list(shielding_effectivenesses)

materials_all = np.array(materials_all)
thicknesses_all = np.array(thicknesses_all)
Y = np.array([transparencies_all, shielding_effectivenesses_all]).T
print(materials_all.shape)
print(thicknesses_all.shape)
print(Y.shape)

is_pf = ppf.is_pareto_frontier(Y)

materials_all = materials_all[is_pf]
thicknesses_all = thicknesses_all[is_pf]
pareto_frontier = Y[is_pf]
print(materials_all.shape)
print(thicknesses_all.shape)
print(pareto_frontier.shape)

indices = []
for ind, pareto in enumerate(pareto_frontier):
if pareto[0] >= 0.65 and pareto[1] >= 30:
indices.append(ind)
print(len(indices))

for ind, elem in enumerate(zip(materials_all, thicknesses_all)):
materials, thicknesses = elem
str_figure = f'structure_layers_{num_layers}_{ind + 1:03d}'

plot_structure(materials, thicknesses, show_figure, save_figure, str_figure)

0 comments on commit d956ec1

Please sign in to comment.