Skip to content

Instantly share code, notes, and snippets.

@2iw31Zhv
Created December 5, 2019 18:29
Show Gist options
  • Save 2iw31Zhv/c30e8d239566a07b25264495f2e25a39 to your computer and use it in GitHub Desktop.
Save 2iw31Zhv/c30e8d239566a07b25264495f2e25a39 to your computer and use it in GitHub Desktop.
some working code to generate gds from pickle file
import pickle
import numpy as np
import matplotlib.pyplot as plt
import gdspy
import cv2
index_low = 1.445*1.445
index_hi = 3.48*3.48
thr = 0.5
SizePerPixel = 0.04
offset_x = 0.0
offset_y = -0.04
index_thr = index_low * (1 - thr) + index_hi * thr
a = open("step82.pkl", "rb")
b = pickle.load(a)
epsilon = b["monitor_data"]["epsilon"]
epsilon0 = epsilon[0].real
epsshape = epsilon0.shape
epsilon0 = np.transpose(np.reshape(epsilon0, [epsshape[0], epsshape[1]]))
[rows, cols] = epsilon0.shape
plt.matshow(epsilon0)
plt.show()
left = -SizePerPixel * cols / 2 + offset_x
bottom = -SizePerPixel * rows / 2 + offset_y
for i in range(rows):
for j in range(cols):
if epsilon0[i][j] >= index_thr:
epsilon0[i][j] = index_hi
else:
epsilon0[i][j] = index_low
plt.matshow(epsilon0)
plt.show()
rect_list = []
for i in range(rows):
for j in range(cols):
if epsilon0[i][j] >= index_thr:
y1 = bottom + SizePerPixel * i
x1 = left + SizePerPixel * j
x2 = x1 + SizePerPixel
y2 = y1 + SizePerPixel
r = gdspy.Rectangle((x1, y1), (x2, y2), layer=100)
rect_list.append(r)
joined = gdspy.boolean(rect_list, None, 'or', precision=0.001, max_points=100000000, layer = 100)
cell = gdspy.Cell('FIRST')
cell.add(joined)
# Save all created cells in file 'first.gds'.
gdspy.write_gds('first.gds')
# Optionally, display all cells using the internal viewer.
gdspy.LayoutViewer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment