How to use the gdspy.Polygon 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 DerekK88 / PICwriter / picwriter / components / ysplitter.py View on Github external
""" 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 """
github heitzmann / gdspy / tests / cell.py View on Github external
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
github BerkeleyPhotonicsGenerator / BPG / BPG / compiler / poly_simplify.py View on Github external
def shapely_to_gdspy_polygon(polygon_shapely: Polygon) -> gdspy.Polygon:
    if not isinstance(polygon_shapely, Polygon):
        raise ValueError("input must be a Shapely Polygon")
    else:
        ext_coord_list = list(zip(*polygon_shapely.exterior.coords.xy))
        polygon_gdspy = gdspy.Polygon(ext_coord_list)
        if len(polygon_shapely.interiors):
            for interior in polygon_shapely.interiors:
                int_coord_list = list(zip(*interior.coords.xy))
                polygon_gdspy_int = gdspy.Polygon(int_coord_list)

                polygon_gdspy = dataprep_cleanup_gdspy(gdspy.fast_boolean(polygon_gdspy, polygon_gdspy_int, 'not',
                                                                          max_points=MAX_POINTS,
                                                                          precision=GLOBAL_OPERATION_PRECISION),
                                                       do_cleanup=GLOBAL_DO_CLEANUP)
        else:
            pass
        return polygon_gdspy
github HelgeGehring / gdshelpers / gdshelpers / geometry / shapely_adapter.py View on Github external
exports_objs.append(gdspy.PolyPath(obj.coords, layer=layer, datatype=datatype, width=path_width,
                                                       ends=path_pathtype))
                elif library == 'oasis':
                    rounded_coords = np.multiply(obj.coords, grid_steps_per_micron).astype(np.int)
                    exports_objs.append(
                        fatamorgana.records.Path((rounded_coords[1:] - rounded_coords[:-1]).tolist(), layer=layer,
                                                 datatype=datatype, half_width=int(path_width * grid_steps_per_micron),
                                                 extension_start=path_pathtype, extension_end=path_pathtype,
                                                 x=rounded_coords[0][0], y=rounded_coords[0][1]))

        elif type(obj) == shapely.geometry.Polygon:
            assert len(obj.interiors) <= 1, 'No polygons with more than one hole allowed, got %i' % len(obj.interiors)
            if library == 'gdscad':
                exports_objs.append(gdsCAD.core.Boundary(obj.exterior.coords, layer=layer, datatype=datatype))
            elif library == 'gdspy':
                exports_objs.append(gdspy.Polygon(obj.exterior.coords, layer=layer, datatype=datatype))
            elif library == 'oasis':
                rounded_coords = np.multiply(obj.exterior.coords, grid_steps_per_micron).astype(np.int)
                exports_objs.append(
                    fatamorgana.records.Polygon((rounded_coords[1:] - rounded_coords[:-1]).tolist(),
                                                layer=layer, datatype=datatype, x=rounded_coords[0][0],
                                                y=rounded_coords[0][1]))

        else:
            raise TypeError('Unhandled type "%s"' % type(obj))
    return exports_objs
github BerkeleyPhotonicsGenerator / BPG / BPG / gds / core.py View on Github external
for path in content_list.path_list:
                # Photonic paths should be treated like polygons
                lay_id, purp_id = lay_map[path['layer']]
                cur_path = gdspy.Polygon(path['polygon_points'], layer=lay_id, datatype=purp_id,
                                         verbose=False)
                gds_cell.add(cur_path.fracture(precision=res))

            for blockage in content_list.blockage_list:
                pass

            for boundary in content_list.boundary_list:
                pass

            for polygon in content_list.polygon_list:
                lay_id, purp_id = lay_map[polygon['layer']]
                cur_poly = gdspy.Polygon(polygon['points'], layer=lay_id, datatype=purp_id,
                                         verbose=False)
                gds_cell.add(cur_poly.fracture(precision=res))

            for round_obj in content_list.round_list:
                nx, ny = round_obj.get('arr_nx', 1), round_obj.get('arr_ny', 1)
                lay_id, purp_id = lay_map[tuple(round_obj['layer'])]
                x0, y0 = round_obj['center']

                if nx > 1 or ny > 1:
                    spx, spy = round_obj['arr_spx'], round_obj['arr_spy']
                    for xidx in range(nx):
                        dx = xidx * spx
                        for yidx in range(ny):
                            dy = yidx * spy
                            cur_round = gdspy.Round((x0 + dx, y0 + dy), radius=round_obj['rout'],
                                                    inner_radius=round_obj['rin'],
github heitzmann / gdspy / docs / makeimages.py View on Github external
2,
        inner_radius=1,
        initial_angle=-0.2 * numpy.pi,
        final_angle=1.2 * numpy.pi,
        tolerance=0.01,
    )
    draw(gdspy.Cell("circles").add([circle, ellipse, arc]))

    # Curves
    # Construct a curve made of a sequence of line segments
    c1 = gdspy.Curve(0, 0).L(1, 0, 2, 1, 2, 2, 0, 2)
    p1 = gdspy.Polygon(c1.get_points())

    # Construct another curve using relative coordinates
    c2 = gdspy.Curve(3, 1).l(1, 0, 2, 1, 2, 2, 0, 2)
    p2 = gdspy.Polygon(c2.get_points())
    draw(gdspy.Cell("curves").add([p1, p2]))

    # Curves 1
    # Use complex numbers to facilitate writing polar coordinates
    c3 = gdspy.Curve(0, 2).l(4 * numpy.exp(1j * numpy.pi / 6))
    # Elliptical arcs have syntax similar to gdspy.Round
    c3.arc((4, 2), 0.5 * numpy.pi, -0.5 * numpy.pi)
    p3 = gdspy.Polygon(c3.get_points())
    draw(gdspy.Cell("curves_1").add(p3))

    # Curves 2
    # Cubic Bezier curves can be easily created with C and c
    c4 = gdspy.Curve(0, 0).c(1, 0, 1, 1, 2, 1)
    # Smooth continuation with S or s
    c4.s(1, 1, 0, 1).S(numpy.exp(1j * numpy.pi / 6), 0, 0)
    p4 = gdspy.Polygon(c4.get_points())
github BerkeleyPhotonicsGenerator / BPG / BPG / manh_gdspy.py View on Github external
manh_grid_size,      # type: float
                do_manh,             # type: bool
                ):

    if do_manh:
        manh_type = 'inc'
    else:
        manh_type = 'non'

    if isinstance(polygon_gdspy, gdspy.Polygon):
        coord_list = manh_skill(polygon_gdspy.points, manh_grid_size, manh_type)
        polygon_out = gdspy.offset(gdspy.Polygon(coord_list),
                                   0, tolerance=10, max_points=MAX_POINTS, join_first=True)
    elif isinstance(polygon_gdspy, gdspy.PolygonSet):
        coord_list = manh_skill(polygon_gdspy.polygons[0], manh_grid_size, manh_type)
        polygon_out = gdspy.offset(gdspy.Polygon(coord_list),
                                   0, tolerance=10, max_points=MAX_POINTS, join_first=True)
        for poly in polygon_gdspy.polygons:
            coord_list = manh_skill(poly, manh_grid_size, manh_type)
            polygon_append = gdspy.offset(gdspy.Polygon(coord_list),
                                          0, tolerance=10, max_points=MAX_POINTS, join_first=True)
            polygon_out = gdspy.offset(gdspy.fast_boolean(polygon_out, polygon_append, 'or'),
                                       0, tolerance=10, max_points=MAX_POINTS, join_first=True)
    else:
        raise ValueError('polygon_gdspy should be either a Polygon or PolygonSet')

    return polygon_out
github BerkeleyPhotonicsGenerator / BPG / BPG / compiler / dataprep_gdspy.py View on Github external
if polygon is None:
                clean_polygon = None
            elif isinstance(polygon, (gdspy.Polygon, gdspy.PolygonSet)):
                clean_polygon = gdspy.offset(
                    polygons=polygon,
                    distance=0,
                    tolerance=self.offset_tolerance,
                    max_points=MAX_SIZE,
                    join_first=True,
                    precision=self.global_clean_up_grid_size,
                )

                clean_coords = []
                if isinstance(clean_polygon, gdspy.Polygon):
                    clean_coords = self.global_grid_size * np.round(clean_polygon.points / self.global_grid_size, 0)
                    clean_polygon = gdspy.Polygon(points=clean_coords)
                elif isinstance(clean_polygon, gdspy.PolygonSet):
                    for poly in clean_polygon.polygons:
                        clean_coords.append(self.global_grid_size * np.round(poly / self.global_grid_size, 0))
                    clean_polygon = gdspy.PolygonSet(polygons=clean_coords)

            else:
                raise ValueError('input polygon must be a gdspy.Polygon, gdspy.PolygonSet or NonType')

        else:
            clean_polygon = polygon

        return clean_polygon