How to use the gdspy.CellReference function in gdspy

To help you get started, we’ve selected a few gdspy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heitzmann / gdspy / tests / gdswriter.py View on Github external
def test_writer_gds(tmpdir):
    lib = gdspy.GdsLibrary()
    c1 = gdspy.Cell("gw_rw_gds_1", True)
    c1.add(gdspy.Rectangle((0, -1), (1, 2), 2, 4))
    c1.add(gdspy.Label("label", (1, -1), "w", 45, 1.5, True, 5, 6))
    c2 = gdspy.Cell("gw_rw_gds_2", True)
    c2.add(gdspy.Round((0, 0), 1, number_of_points=32, max_points=20))
    c3 = gdspy.Cell("gw_rw_gds_3", True)
    c3.add(gdspy.CellReference(c1, (0, 1), -90, 2, True))
    c4 = gdspy.Cell("gw_rw_gds_4", True)
    c4.add(gdspy.CellArray(c2, 2, 3, (1, 4), (-1, -2), 180, 0.5, True))
    lib.add((c1, c2, c3, c4))

    fname1 = str(tmpdir.join("test1.gds"))
    writer1 = gdspy.GdsWriter(fname1, name="lib", unit=2e-3, precision=1e-5)
    for c in lib.cell_dict.values():
        writer1.write_cell(c)
    writer1.close()
    lib1 = gdspy.GdsLibrary(unit=1e-3)
    lib1.read_gds(
        fname1,
        units="convert",
        rename={"gw_rw_gds_1": "1"},
        layers={2: 4},
        datatypes={4: 2},
github heitzmann / gdspy / tests / gdslibrary.py View on Github external
def test_remove():
    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):
        r6 = gdspy.CellReference("C2")
    main.add(r6)
    lib.add([main, c1, c2], include_dependencies=False)
    assert lib.remove("C3") == 1
github heitzmann / gdspy / tests / cell.py View on Github external
def tree():
    p1 = gdspy.Polygon(((0, 0), (0, 1), (1, 0)), 0, 0)
    p2 = gdspy.Polygon(((2, 0), (2, 1), (1, 0)), 1, 1)
    l1 = gdspy.Label("label1", (0, 0), layer=11)
    l2 = gdspy.Label("label2", (2, 1), layer=12)
    c1 = gdspy.Cell("tree_" + unique())
    c1.add(p1)
    c1.add(l1)
    c2 = gdspy.Cell("tree_" + unique())
    c2.add(l2)
    c2.add(p2)
    c2.add(gdspy.CellReference(c1))
    c3 = gdspy.Cell("tree_" + unique())
    c3.add(gdspy.CellArray(c2, 3, 2, (3, 3)))
    return c3, c2, c1
github heitzmann / gdspy / tests / gdslibrary.py View on Github external
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):
        r6 = gdspy.CellReference("C2")
    main.add(r6)
    lib.add([main, c1, c2], include_dependencies=False)
    lib.add(c3, include_dependencies=False, overwrite_duplicate=True)
    assert r1.ref_cell is c3
    assert r2.ref_cell is c3
    assert r3.ref_cell is c2
    assert r4.ref_cell is c3
    assert r5.ref_cell == "C3"
    assert r6.ref_cell == "C2"
github heitzmann / gdspy / tests / cellreference.py View on Github external
def test_noreference():
    name = "cr_noreference"
    with pytest.warns(UserWarning):
        ref = gdspy.CellReference(name, (1, -1), 90, 2, True)
    ref.translate(-1, 1)
    assert ref.ref_cell == name
    assert ref.area() == 0
    assert ref.area(True) == dict()
    assert ref.get_bounding_box() is None
    assert ref.get_polygons() == []
    assert ref.get_polygons(True) == dict()
    assert ref.origin[0] == ref.origin[1] == 0
github heitzmann / gdspy / tests / gdslibrary.py View on Github external
def test_rw_gds(tmpdir):
    lib = gdspy.GdsLibrary("lib", unit=2e-3, precision=1e-5)
    c1 = gdspy.Cell("gl_rw_gds_1")
    c1.add(gdspy.Rectangle((0, -1), (1, 2), 2, 4))
    c1.add(gdspy.Label("label", (1, -1), "w", 45, 1.5, True, 5, 6))
    c2 = gdspy.Cell("gl_rw_gds_2")
    c2.add(gdspy.Round((0, 0), 1, number_of_points=32, max_points=20))
    c3 = gdspy.Cell("gl_rw_gds_3")
    c3.add(gdspy.CellReference(c1, (0, 1), -90, 2, True))
    c4 = gdspy.Cell("gl_rw_gds_4")
    c4.add(gdspy.CellArray(c2, 2, 3, (1, 4), (-1, -2), 180, 0.5, True))
    lib.add((c1, c2, c3, c4))

    fname1 = str(tmpdir.join("test1.gds"))
    lib.write_gds(fname1)
    lib1 = gdspy.GdsLibrary(
        infile=fname1,
        unit=1e-3,
        precision=1e-6,
        units="convert",
        rename={"gl_rw_gds_1": "1"},
        layers={2: 4},
        datatypes={4: 2},
        texttypes={6: 7},
    )
github BerkeleyPhotonicsGenerator / BPG / gdspy / examples / tutorial.py View on Github external
trans_cell = gdspy.Cell('TRANS')

# Any geometric object can be translated by providing the distance to
# translate in the x-direction and y-direction:  translate(dx, dy)
rect1 = gdspy.Rectangle((80, 0), (81, 1), 1)
rect1.translate(2, 0)
trans_cell.add(rect1)

# Translatable objects can also be copied & translated in the same way.
rect2 = gdspy.Rectangle((80, 0), (81, 1), 2)
rect3 = gdspy.copy(rect2, 0, 3)
trans_cell.add(rect2)
trans_cell.add(rect3)

# Reference Cells are also translatable, and thus copyable.
ref1 = gdspy.CellReference(poly_cell, (25, 0), rotation=180)
ref2 = gdspy.copy(ref1, 30, 30)
trans_cell.add(ref1)
trans_cell.add(ref2)

# Same goes for Labels & Text
text1 = gdspy.Text(
    'Created with gsdpy ' + gdspy.__version__, 7, (-7, -35), layer=6)
text2 = gdspy.copy(text1, 0, -20)
label1 = gdspy.Label(
    'Created with gdspy ' + gdspy.__version__, (-7, -36), 'nw', layer=6)
label2 = gdspy.copy(label1, 0, -20)
trans_cell.add(text1)
trans_cell.add(text2)
trans_cell.add(label1)
trans_cell.add(label2)
github DerekK88 / PICwriter / picwriter / components / spiral2.py View on Github external
""" Generate the waveguide """
        wg = Waveguide(waypoints, self.wgt)

        dist = self.width
        if self.direction=="WEST":
            wgr = gdspy.CellReference(wg, rotation=180)
            self.portlist_output = (self.port[0]-dist, self.port[1])
        elif self.direction=="SOUTH":
            wgr = gdspy.CellReference(wg, rotation=-90)
            self.portlist_output = (self.port[0], self.port[1]-dist)
        elif self.direction=="EAST":
            wgr = gdspy.CellReference(wg, rotation=0.0)
            self.portlist_output = (self.port[0]+dist, self.port[1])
        elif self.direction=="NORTH":
            wgr = gdspy.CellReference(wg, rotation=90)
            self.portlist_output = (self.port[0], self.port[1]+dist)
        elif isinstance(self.direction, float) or isinstance(self.direction, int):
            wgr = gdspy.CellReference(wg, rotation=(float(self.direction)*180/np.pi))
            self.portlist_output = (self.port[0]+dist*np.cos(float(self.direction)), self.port[1]+dist*np.sin(float(self.direction)))

        wgr.translate(self.port[0], self.port[1])
        self.add(wgr)
github BerkeleyPhotonicsGenerator / BPG / BPG / gds / core.py View on Github external
gds_lib.add(gds_cell)

            # add instances
            for inst_info in content_list.inst_list:  # type: InstanceInfo
                if inst_info.params is not None:
                    raise ValueError('Cannot instantiate PCells in GDS.')
                num_rows = inst_info.num_rows
                num_cols = inst_info.num_cols
                angle, reflect = inst_info.angle_reflect
                if num_rows > 1 or num_cols > 1:
                    cur_inst = gdspy.CellArray(cell_dict[inst_info.cell], num_cols, num_rows,
                                               (inst_info.sp_cols, inst_info.sp_rows),
                                               origin=inst_info.loc, rotation=angle,
                                               x_reflection=reflect)
                else:
                    cur_inst = gdspy.CellReference(cell_dict[inst_info.cell], origin=inst_info.loc,
                                                   rotation=angle, x_reflection=reflect)
                gds_cell.add(cur_inst)

            # add rectangles
            for rect in content_list.rect_list:
                nx, ny = rect.get('arr_nx', 1), rect.get('arr_ny', 1)
                (x0, y0), (x1, y1) = rect['bbox']
                lay_id, purp_id = lay_map[tuple(rect['layer'])]

                if nx > 1 or ny > 1:
                    spx, spy = rect['arr_spx'], rect['arr_spy']
                    for xidx in range(nx):
                        dx = xidx * spx
                        for yidx in range(ny):
                            dy = yidx * spy
                            cur_rect = gdspy.Rectangle((x0 + dx, y0 + dy), (x1 + dx, y1 + dy),
github BerkeleyPhotonicsGenerator / BPG / gdspy / examples / tutorial.py View on Github external
# 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