Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
# References
# Create a cell with a component that is used repeatedly
contact = gdspy.Cell("CONTACT")
contact.add([p1, p2, p3, p4])
# Create a cell with the complete device
device = gdspy.Cell("DEVICE")
device.add(cutout)
# Add 2 references to the component changing size and orientation
ref1 = gdspy.CellReference(contact, (3.5, 1), magnification=0.25)
ref2 = gdspy.CellReference(contact, (1, 3.5), magnification=0.25, rotation=90)
device.add([ref1, ref2])
# The final layout has several repetitions of the complete device
main = gdspy.Cell("MAIN")
main.add(gdspy.CellArray(device, 3, 2, (6, 7)))
draw(main, "references")
# Polygonal-Only Paths
# Start a path at (0, 0) with width 1
path1 = gdspy.Path(1, (0, 0))
# Add a segment to the path goin in the '+y' direction
path1.segment(4, "+y")
# Further segments or turns will folow the current path direction
# to ensure continuity
path1.turn(2, "r")
path1.segment(1)
path1.turn(3, "rr")
draw(gdspy.Cell("polygonal-only_paths").add(path1))
self.portlist["input"] = {"port": self.input_port, "direction": "WEST"}
self.portlist["output_top"] = {
"port": self.output_port_top,
"direction": "EAST",
}
self.portlist["output_bot"] = {
"port": self.output_port_bot,
"direction": "EAST",
}
if __name__ == "__main__":
# from . import *
import picwriter.components as pc
top = gdspy.Cell("top")
wgt = pc.WaveguideTemplate(bend_radius=50, wg_width=0.5, resist="+")
# Values from Publication
spline_widths = [0.5, 0.5, 0.6, 0.7, 0.9, 1.26, 1.4, 1.4, 1.4, 1.4, 1.31, 1.2, 1.2]
ysplitter = SplineYSplitter(
wgt,
length=2,
widths=spline_widths,
taper_width=None,
taper_length=None,
output_length=10,
output_wg_sep=5,
output_width=0.5,
port=(0, 0),
direction="EAST",
)
slice_cell.add(result[1])
# If the cut needs to be at an angle we can rotate the geometry, slice
# it, and rotate back.
original = gdspy.PolyPath([(12, 0), (12, 8), (28, 8), (28, -8), (12, -8), (12, 0)], 1, 3, 2)
original.rotate(numpy.pi / 3, center=(20, 0))
result = gdspy.slice(original, 7, 1, layer=2)
result[0].rotate(-numpy.pi / 3, center=(20, 0))
slice_cell.add(result[0])
# ------------------------------------------------------------------ #
# REFERENCES AND TEXT
# ------------------------------------------------------------------ #
# Cells can contain references to other cells.
ref_cell = gdspy.Cell('REFS')
ref_cell.add(gdspy.CellReference(poly_cell, (0, 30), x_reflection=True))
ref_cell.add(gdspy.CellReference(poly_cell, (25, 0), rotation=180))
# References can be whole arrays. Add an array of the operations cell
# with 2 lines and 3 columns and 1st element at (25, 10).
ref_cell.add(gdspy.CellArray('OPERATIONS', 3, 2, (35, 30), (25, 10), magnification=1.5))
# Text are also sets of polygons. They have edges parallel to 'x' and
# 'y' only.
ref_cell.add(gdspy.Text('Created with gsdpy ' + gdspy.__version__, 7, (-7, -35), layer=6))
# Labels are special text objects which don't define any actual
# geometry, but can be used to annotate the drawing. Rotation,
# magnification and reflection of the text are not supported by the
# included GUI, but they are included in the resulting GDSII file.
ref_cell.add(gdspy.Label('Created with gdspy ' + gdspy.__version__, (-7, -36), 'nw', layer=6))