Пример #1
0
    return gdstk.Cell("commands").add(polygon)


def tolerance_image():
    curve = gdstk.Curve((-2.5, 0), tolerance=1e-1)
    curve.arc((2, 3), 0, numpy.pi)
    polygon_1 = gdstk.Polygon(curve.points())
    # print(polygon_1.size)

    curve = gdstk.Curve((2.5, 0), tolerance=1e-3)
    curve.arc((2, 3), 0, numpy.pi)
    polygon_2 = gdstk.Polygon(curve.points())
    # print(polygon_2.size)
    return gdstk.Cell("tolerance").add(polygon_1, polygon_2)


if __name__ == "__main__":
    path = pathlib.Path(__file__).parent.absolute() / "curve"
    path.mkdir(parents=True, exist_ok=True)

    draw(init_image(), path)
    draw(segment_image(), path)
    draw(cubic_image(), path)
    draw(cubic_smooth_image(), path)
    draw(bezier_image(), path)
    draw(interpolation_image(), path)
    draw(arc_image(), path)
    draw(parametric_image(), path)
    draw(commands_image(), path)
    draw(tolerance_image(), path)
Пример #2
0
    x = width / 2
    w = period * fill_frac
    result.add(
        gdstk.rectangle((-x, y * period), (x, y * period + w),
                        layer=layer,
                        datatype=datatype)
        for y in range(int(length / period)))
    return result


if __name__ == "__main__":
    lib = gdstk.Library()

    length = 20
    grat1 = grating(3.5, length=length, layer=1, cell_name="Grating 1")
    grat2 = grating(3.0, length=length, layer=1, cell_name="Grating 2")
    lib.add(grat1, grat2)

    main = lib.new_cell("Main")
    main.add(gdstk.rectangle((0, -10), (150, 10)))
    main.add(gdstk.Reference(grat1, (length, 0), rotation=numpy.pi / 2))
    main.add(gdstk.Reference(grat2, (150 - length, 0), rotation=-numpy.pi / 2))

    path = pathlib.Path(__file__).parent.absolute()
    lib.write_gds(path / "pcell.gds")

    main.name = "parametric_cell"
    path = pathlib.Path(__file__).parent.absolute() / "how-tos"
    path.mkdir(parents=True, exist_ok=True)
    draw(main, path)
Пример #3
0
        4,
        "A",
        2,
        numpy.arctan2(3, -4),
        numpy.pi / 2,
        "h",
        0.5,
        "a",
        3,
        -numpy.pi,
    )
    return gdstk.Cell("commands").add(path)


if __name__ == "__main__":
    path = pathlib.Path(__file__).parent.absolute() / "_static/flexpath"
    path.mkdir(parents=True, exist_ok=True)

    draw(init_image(), path)
    draw(init0_image(), path)
    draw(init1_image(), path)
    draw(horizontal_image(), path)
    draw(segment_image(), path)
    draw(cubic_image(), path)
    draw(cubic_smooth_image(), path)
    draw(bezier_image(), path)
    draw(interpolation_image(), path)
    draw(arc_image(), path)
    draw(parametric_image(), path)
    draw(commands_image(), path)
Пример #4
0
if __name__ == "__main__":
    path = pathlib.Path(__file__).parent.absolute()

    unit = gdstk.Cell("Unit")
    unit.add(gdstk.cross((0, 0), 1, 0.2))

    main = gdstk.Cell("Main")

    # Create repeating pattern using references
    d = 2
    ref1 = gdstk.Reference(unit, columns=11, rows=6, spacing=(d, d * 3**0.5))
    ref2 = gdstk.Reference(unit, (d / 2, d * 3**0.5 / 2),
                           columns=10,
                           rows=5,
                           spacing=(d, d * 3**0.5))
    main.add(ref1, ref2)
    main.flatten()

    hole = gdstk.text("PY", 8 * d, (0.5 * d, 0), layer=1)
    test = gdstk.inside([pol.points for pol in main.polygons], hole, "any")
    for pol, inside in zip(main.polygons, test):
        if inside:
            main.remove(pol)

    main.add(*hole)

    gdstk.Library().add(main).write_gds(path / "pos_filtering.gds")

    main.name = "pos_filtering"
    draw(main, path / "how-tos")
Пример #5
0
def read_rawcells_example():
    cell1 = gdstk.Cell("CELL_1")
    cell1.add(gdstk.rectangle((0, 0), (2, 1)))
    cell2 = gdstk.Cell("CELL_2")
    cell2.add(gdstk.Reference(cell1, (-1, 0)))
    library = gdstk.Library()
    library.add(cell1, cell2)
    library.write_gds("test.gds")
    raw_cells = gdstk.read_rawcells("test.gds")
    print(raw_cells.keys())
    print(len(raw_cells["CELL_1"].dependencies(True)))
    print(len(raw_cells["CELL_2"].dependencies(True)))
    deps = raw_cells["CELL_2"].dependencies(True)
    print(deps[0] is raw_cells["CELL_1"])


if __name__ == "__main__":
    path = pathlib.Path(__file__).parent.absolute() / "_static/function"
    path.mkdir(parents=True, exist_ok=True)

    draw(cross_image(), path)
    draw(regular_polygon_image(), path)
    draw(ellipse_image(), path)
    draw(racetrack_image(), path)
    draw(text_image(), path)
    draw(offset_image(), path)
    draw(boolean_image(), path)
    draw(slice_image(), path)
    # inside_example()
    # read_rawcells_example()
Пример #6
0
    cell = gdstk.Cell("SVG")
    cell.add(poly1, poly2)
    # cell.write_svg(
    #     "example.svg",
    #     background="none",
    #     style={(0, 1): {"fill": "none", "stroke": "black", "stroke-dasharray": "8,8"}},
    #     pad="5%",
    # )
    cell.name = "write_svg"
    return cell


def remove_image():
    polygons = gdstk.text("Filter dots\nin i and j!", 8, (0, 0))
    cell = gdstk.Cell("FILTERED")
    cell.add(*polygons)
    dots = [poly for poly in cell.polygons if poly.area() < 2]
    cell.remove(*dots)
    cell.name = "remove"
    return cell


if __name__ == "__main__":
    path = pathlib.Path(__file__).parent.absolute() / "cell"
    path.mkdir(parents=True, exist_ok=True)

    draw(bounding_box_image(), path)
    draw(flatten_image(), path)
    draw(write_svg_image(), path)
    draw(remove_image(), path)
Пример #7
0
            c.quadratic(points.reshape(points.size // 2, 2))
        elif code == path.CURVE4:
            c.cubic(points.reshape(points.size // 2, 2))
        elif code == path.CLOSEPOLY:
            pts = c.points()
            if pts.size > 0:
                poly = gdstk.Polygon(pts)
                if pts[:, 0].min() < xmax:
                    i = len(polys) - 1
                    while i >= 0:
                        if polys[i].contain_any(*poly.points):
                            p = polys.pop(i)
                            poly = gdstk.boolean(p, poly, "xor", precision)[0]
                            break
                        elif poly.contain_any(*polys[i].points):
                            p = polys.pop(i)
                            poly = gdstk.boolean(p, poly, "xor", precision)[0]
                        i -= 1
                xmax = max(xmax, poly.points[:, 0].max())
                polys.append(poly)
    return polys


if __name__ == "__main__":
    cell = gdstk.Cell("fonts")
    fp = FontProperties(family="serif", style="italic")
    polygons = render_text("Text rendering", 10, font_prop=fp)
    cell.add(*polygons)
    path = pathlib.Path(__file__).parent.absolute() / "how-tos"
    draw(cell, path)
Пример #8
0
    # Main cell with 2 devices and lithography alignment marks
    main = gdstk.Cell("Main")
    main.add(gdstk.Reference(dev_cell, (250, 250)))
    main.add(gdstk.Reference(dev_cell, (250, 750)))
    main.add(
        gdstk.Reference(pdk["Alignment Mark"],
                        columns=2,
                        rows=3,
                        spacing=(500, 500)))

    lib = gdstk.Library()
    lib.add(main, *main.dependencies(True))
    lib.write_gds(path / "layout.gds")

    pdk_lib = gdstk.read_gds(path / "photonics.gds")
    pdk = {c.name: c for c in pdk_lib.cells}
    for cell in [dev_cell, main]:
        for x in cell.references:
            if isinstance(x.cell, gdstk.RawCell):
                cell.remove(x)
                cell.add(
                    gdstk.Reference(
                        pdk[x.cell.name],
                        x.origin,
                        columns=x.columns,
                        rows=x.rows,
                        spacing=x.spacing,
                    ))
    main.name = "layout"
    draw(main, path / "_static/how-tos")
Пример #9
0
def convex_hull_image():
    polygons = gdstk.text("F", 10, (0, 0))
    f_cell = gdstk.Cell("F_CELL")
    f_cell.add(*polygons)
    array_ref = gdstk.Reference(f_cell,
                                rotation=numpy.pi / 4,
                                columns=3,
                                rows=2,
                                spacing=(8, 10))
    hull = array_ref.convex_hull()
    error = hull - numpy.array([
        [1.14904852, 27.66555281],
        [-12.81631041, 13.70019389],
        [-0.88388348, 1.76776695],
        [11.3137085, 13.96535893],
        [9.98788328, 17.94283457],
        [8.66205807, 20.15254326],
    ])
    assert numpy.abs(error).max() < 1e-8
    polygon_hull = gdstk.Polygon(hull, datatype=1)
    return gdstk.Cell("convex_hull").add(array_ref, polygon_hull)


if __name__ == "__main__":
    path = pathlib.Path(__file__).parent.absolute() / "reference"
    path.mkdir(parents=True, exist_ok=True)

    draw(init_image(), path)
    draw(bounding_box_image(), path)
    draw(convex_hull_image(), path)
Пример #10
0
    polygon = gdstk.Polygon([(0, 1), (1, 2), (3, -1)])
    bbox = polygon.bounding_box()
    polygon_bb = gdstk.rectangle(*bbox, datatype=1)
    return gdstk.Cell("bounding_box").add(polygon, polygon_bb)


def fillet_image():
    points = [(0, 0), (1.2, 0), (1.2, 0.3), (1, 0.3), (1.5, 1), (0, 1.5)]
    polygon_1 = gdstk.Polygon(points, datatype=1)
    polygon_2 = gdstk.Polygon(points).fillet(0.3, tolerance=1e-3)
    return gdstk.Cell("fillet").add(polygon_2, polygon_1)


def fracture_image():
    polygon = gdstk.racetrack((0, 0), 30, 60, 40, tolerance=1e-3)
    poly_list = polygon.fracture()
    assert len(poly_list) == 10
    assert all(p.size == s for p, s in zip(
        poly_list, [102, 103, 103, 101, 101, 102, 102, 103, 103, 102]))
    return gdstk.Cell("fracture").add(*poly_list)


if __name__ == "__main__":
    path = pathlib.Path(__file__).parent.absolute() / "polygon"
    path.mkdir(parents=True, exist_ok=True)

    draw(init_image(), path)
    draw(bounding_box_image(), path)
    draw(fillet_image(), path)
    draw(fracture_image(), path)
Пример #11
0
def init_image():
    frame = gdstk.rectangle((-2, -1), (2, 1), datatype=1)
    label_o = gdstk.Label("Center", (0, 0), rotation=numpy.pi / 6)
    label_n = gdstk.Label("North", (0, 1), "n")
    label_s = gdstk.Label("South", (0, -1), "s")
    label_e = gdstk.Label("East", (2, 0), "e")
    label_w = gdstk.Label("West", (-2, 0), "w")
    label_ne = gdstk.Label("Northeast", (2, 1), "ne")
    label_se = gdstk.Label("Southeast", (2, -1), "se")
    label_nw = gdstk.Label("Northwest", (-2, 1), "nw")
    label_sw = gdstk.Label("Southwest", (-2, -1), "sw")
    return gdstk.Cell("init").add(
        frame,
        label_o,
        label_n,
        label_s,
        label_e,
        label_w,
        label_ne,
        label_se,
        label_nw,
        label_sw,
    )


if __name__ == "__main__":
    path = pathlib.Path(__file__).parent.absolute() / "_static/label"
    path.mkdir(parents=True, exist_ok=True)

    draw(init_image(), path)
Пример #12
0
def init_image():
    polygons = gdstk.text("F", 10, (0, 0))
    f_cell = gdstk.Cell("F_CELL")
    f_cell.add(*polygons)
    ref = gdstk.Reference(f_cell, rotation=numpy.pi / 2)
    array_ref = gdstk.Reference(f_cell, columns=3, rows=2, spacing=(8, 10))
    return gdstk.Cell("init").add(ref, array_ref)


def bounding_box_image():
    polygons = gdstk.text("F", 10, (0, 0))
    f_cell = gdstk.Cell("F_CELL")
    f_cell.add(*polygons)
    array_ref = gdstk.Reference(f_cell,
                                rotation=numpy.pi / 4,
                                columns=3,
                                rows=2,
                                spacing=(8, 10))
    bbox = array_ref.bounding_box()
    # print(bbox)
    polygon_bb = gdstk.rectangle(*bbox, datatype=1)
    return gdstk.Cell("bounding_box").add(array_ref, polygon_bb)


if __name__ == "__main__":
    path = pathlib.Path(__file__).parent.absolute() / "reference"
    path.mkdir(parents=True, exist_ok=True)

    draw(init_image(), path)
    draw(bounding_box_image(), path)