Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
""" Add the Coupler region """
x_widths = np.linspace(0, self.length, len(self.widths))
x_positions = np.linspace(0, self.length, int(self.length // 0.0025))
spl = scipy.interpolate.CubicSpline(
x_widths, self.widths, bc_type="clamped"
) # Spline mode still unclear.
y_positions = spl(x_positions)
coupler_pts = np.concatenate(
(
[x_positions, y_positions / 2],
[x_positions[::-1], -y_positions[::-1] / 2],
),
axis=1,
).T
coupler_region = gdspy.Polygon(coupler_pts, **self.wg_spec)
self.add(coupler_region)
(x, y) = (x + self.length, y)
clad_region = gdspy.Polygon(
[
(x_positions[0], y_positions[0] / 2.0 + self.wgt.clad_width),
(x_positions[-1], y_positions[-1] / 2.0 + self.wgt.clad_width),
(x_positions[-1], -y_positions[-1] / 2.0 - self.wgt.clad_width),
(x_positions[0], -y_positions[0] / 2.0 - self.wgt.clad_width),
],
**self.clad_spec
)
self.add(clad_region)
""" Add the output tapers """
**self.wg_spec
)
)
""" And add the 'fins' if self.fins==True """
if self.fins:
num_fins = self.wgt.wg_width // (2 * self.fin_size[1])
x0, y0 = (
0,
-num_fins * (2 * self.fin_size[1]) / 2.0 + self.fin_size[1] / 2.0,
)
xend = 2 * self.taper_length + self.length
for i in range(int(num_fins)):
y = y0 + i * 2 * self.fin_size[1]
block_list.append(
gdspy.Rectangle(
(x0, y),
(x0 + self.fin_size[0], y + self.fin_size[1]),
**self.fin_spec
)
)
block_list.append(
gdspy.Rectangle(
(xend - self.fin_size[0], y),
(xend, y + self.fin_size[1]),
**self.fin_spec
)
)
for block in block_list:
self.add(block)
def test_duplicate():
lib = gdspy.GdsLibrary()
name = "c_duplicate"
c = gdspy.Cell(name)
lib.add(c)
with pytest.raises(ValueError) as e:
lib.add(gdspy.Cell(name), overwrite_duplicate=False)
assert name in str(e.value)
def test_hobby4(target):
cell = gdspy.Cell("test", True)
c = gdspy.Curve(0, 3, tolerance=1e-3)
c.i([(1, 2), (2, 1), (3, 2), (4, 0)], cycle=True)
cell.add(gdspy.Polygon(c.get_points(), layer=10))
c = gdspy.Curve(0, 3, tolerance=1e-3)
c.i(
[(1, 2), (2, 1), (3, 2), (4, 0)],
t_in=[2, 1, 1, 1, 1],
t_out=[1, 1, 1, 1, 2],
cycle=True,
)
cell.add(gdspy.Polygon(c.get_points(), layer=11))
c = gdspy.Curve(0, 3, tolerance=1e-3)
c.i(
[(1, 2), (2, 1), (3, 2), (4, 0)],
t_in=[1, 1, 2, 1, 1],
t_out=[1, 2, 1, 1, 1],
def test_robustpath2(target):
cell = gdspy.Cell("test")
rp = gdspy.RobustPath((0, 0), [0.1, 0.2, 0.1], 0.15, layer=[1, 2, 3])
assert len(rp) == 0
rp.segment((1, 0))
rp.segment((1, 1), 0.1, 0.05)
rp.segment((1, 1), [0.2, 0.1, 0.1], -0.05, True)
rp.segment((-1, 1), 0.2, [-0.2, 0, 0.3], True)
rp.arc(2, 0, 0.5 * numpy.pi)
rp.arc(3, 0.7 * numpy.pi, numpy.pi, 0.1, 0)
rp.arc(2, 0.4 * numpy.pi, -0.4 * numpy.pi, [0.1, 0.2, 0.1], [0.2, 0, -0.2])
rp.turn(1, -0.3 * numpy.pi)
rp.turn(1, "rr", 0.15)
rp.turn(0.5, "l", [0.05, 0.1, 0.05], [0.15, 0, -0.15])
assert len(rp) == 10
cell.add(rp)
rp = gdspy.RobustPath((-5, 6), 0.8, layer=20, ends="round", tolerance=1e-4)
rp.segment((1, 1), 0.1, relative=True)
def test_add_update():
lib = gdspy.GdsLibrary()
main = gdspy.Cell("MAIN")
c1 = gdspy.Cell("C1")
c2 = gdspy.Cell("C2")
c3 = gdspy.Cell("C1")
r1 = gdspy.CellReference(c1)
main.add(r1)
with pytest.warns(UserWarning):
r2 = gdspy.CellArray("C1", 1, 1, (1, 1))
main.add(r2)
r3 = gdspy.CellReference(c2)
main.add(r3)
r4 = gdspy.CellReference(c3)
c2.add(r4)
with pytest.warns(UserWarning):
r5 = gdspy.CellReference("C3")
c1.add(r5)
with pytest.warns(UserWarning):
def test_flexpath3(target):
cell = gdspy.Cell("test", True)
pts = numpy.array(
[
(0, 0),
(0.5, 0),
(1, 0),
(1, 2),
(3, 0),
(2, -1),
(2, -2),
(0, -1),
(1, -2),
(1, -3),
]
)
fp = gdspy.FlexPath(
pts + numpy.array((0, 5)),
def test_duplicate():
lib = gdspy.GdsLibrary()
name = "c_duplicate"
c = gdspy.Cell(name)
lib.add(c)
with pytest.raises(ValueError) as e:
lib.add(gdspy.Cell(name), overwrite_duplicate=False)
assert name in str(e.value)
def test_copy():
name = "c_copy"
p = gdspy.Polygon(((0, 0), (1, 0), (0, 1)))
lbl = gdspy.Label("label", (0, 0))
c1 = gdspy.Cell(name)
c1.add(p)
c1.add(lbl)
c3 = c1.copy(name, False)
assert c3.polygons == c1.polygons and c3.polygons is not c1.polygons
assert c3.labels == c1.labels and c3.labels is not c1.labels
cref = gdspy.Cell("c_ref").add(gdspy.Rectangle((-1, -1), (-2, -2)))
c1.add(gdspy.CellReference(cref))
c1.get_bounding_box()
c4 = c1.copy("c_copy_1", True)
assert c4.polygons != c1.polygons
assert c4.labels != c1.labels
assert c1._bb_valid
assert cref._bb_valid
assert not c4._bb_valid
def test_copy():
name = "c_copy"
p = gdspy.Polygon(((0, 0), (1, 0), (0, 1)))
lbl = gdspy.Label("label", (0, 0))
c1 = gdspy.Cell(name)
c1.add(p)
c1.add(lbl)
c3 = c1.copy(name, False)
assert c3.polygons == c1.polygons and c3.polygons is not c1.polygons
assert c3.labels == c1.labels and c3.labels is not c1.labels
cref = gdspy.Cell("c_ref").add(gdspy.Rectangle((-1, -1), (-2, -2)))
c1.add(gdspy.CellReference(cref))
c1.get_bounding_box()
c4 = c1.copy("c_copy_1", True)
assert c4.polygons != c1.polygons
assert c4.labels != c1.labels
assert c1._bb_valid
assert cref._bb_valid
assert not c4._bb_valid