How to use the gdspy.Round 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"},
github BerkeleyPhotonicsGenerator / BPG / BPG / objects.py View on Github external
def polygon_pointlist_export(cls,
                                 rout: dim_type,
                                 rin: dim_type,
                                 theta0: dim_type,
                                 theta1: dim_type,
                                 center: coord_type,
                                 nx: int = 1,
                                 ny: int = 1,
                                 spx: dim_type = 0.0,
                                 spy: dim_type = 0.0,
                                 resolution: float = 0.001,
                                 ) -> Tuple[List[np.ndarray], List[np.ndarray]]:
        # Get the base polygons
        round_polygons = gdspy.Round(center=center,
                                     layer=0,
                                     radius=rout,
                                     inner_radius=rin,
                                     initial_angle=theta0 * np.pi / 180,
                                     final_angle=theta1 * np.pi / 180,
                                     number_of_points=cls.num_of_sparse_point_round(rout, resolution),
                                     max_points=sys.maxsize,
                                     datatype=0).polygons

        output_list_p: List[np.ndarray] = []
        output_list_n: List[np.ndarray] = []
        for x_count in range(nx):
            for y_count in range(ny):
                for polygon in round_polygons:
                    polygon_points = polygon
                    polygon_points[:, 0] += x_count * spx
github BerkeleyPhotonicsGenerator / BPG / BPG / gds / core.py View on Github external
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'],
                                                    initial_angle=round_obj['theta0'] * pi / 180,
                                                    final_angle=round_obj['theta1'] * pi / 180,
                                                    number_of_points=self.grid.resolution,
                                                    layer=lay_id, datatype=purp_id)
                            gds_cell.add(cur_round)
                else:
                    cur_round = gdspy.Round((x0, y0), radius=round_obj['rout'],
                                            inner_radius=round_obj['rin'],
                                            initial_angle=round_obj['theta0'] * pi / 180,
                                            final_angle=round_obj['theta1'] * pi / 180,
                                            number_of_points=self.grid.resolution,
                                            layer=lay_id, datatype=purp_id)
                    gds_cell.add(cur_round)

        gds_lib.write_gds(out_fname)

        end = time.time()
        logging.info(f'Layout gds instantiation took {end - start:.4g}s')
github DerekK88 / PICwriter / picwriter / components / ring.py View on Github external
clad.segment(2 * self.radius, direction="+x", **self.clad_spec)

                # Ring resonator
                if self.parity == 1:
                    ring = gdspy.Round(
                        (
                            self.radius,
                            self.radius + self.wgt.wg_width + self.coupling_gap,
                        ),
                        self.radius + self.wgt.wg_width / 2.0,
                        self.radius - self.wgt.wg_width / 2.0,
                        number_of_points=2
                        * self.wgt.get_num_points_curve(2 * np.pi, self.radius),
                        **self.wg_spec
                    )
                    clad_ring = gdspy.Round(
                        (
                            self.radius,
                            self.radius + self.wgt.wg_width + self.coupling_gap,
                        ),
                        self.radius + self.wgt.wg_width / 2.0 + self.wgt.clad_width,
                        self.radius - self.wgt.wg_width / 2.0 - self.wgt.clad_width,
                        number_of_points=2
                        * self.wgt.get_num_points_curve(2 * np.pi, self.radius),
                        **self.clad_spec
                    )
                elif self.parity == -1:
                    ring = gdspy.Round(
                        (
                            self.radius,
                            -self.radius - self.wgt.wg_width - self.coupling_gap,
                        ),
github heitzmann / gdspy / docs / makeimages.py View on Github external
# Transformations
    poly = gdspy.Rectangle((-2, -2), (2, 2))
    poly.rotate(numpy.pi / 4)
    poly.scale(1, 0.5)
    draw(gdspy.Cell("transformations").add(poly))

    # Layer and Datatype
    # Layer/datatype definitions for each step in the fabrication
    ld_fulletch = {"layer": 1, "datatype": 3}
    ld_partetch = {"layer": 2, "datatype": 3}
    ld_liftoff = {"layer": 0, "datatype": 7}

    p1 = gdspy.Rectangle((-3, -3), (3, 3), **ld_fulletch)
    p2 = gdspy.Rectangle((-5, -3), (-3, 3), **ld_partetch)
    p3 = gdspy.Rectangle((5, -3), (3, 3), **ld_partetch)
    p4 = gdspy.Round((0, 0), 2.5, number_of_points=6, **ld_liftoff)
    draw(gdspy.Cell("layer_and_datatype").add([p1, p2, p3, p4]))

    # 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
github DerekK88 / PICwriter / picwriter / components / gratingcoupler.py View on Github external
def __build_cell(self):
        # Sequentially build all the geometric shapes using gdspy path functions
        # then add it to the Cell
        """ Create a straight grating GratingCoupler
        """

        # First the input taper
        taper = gdspy.Round(
            (0, 0),
            radius=self.taper_length,
            inner_radius=0,
            initial_angle=-self.theta / 2.0,
            final_angle=+self.theta / 2.0,
            number_of_points=self.wgt.get_num_points_curve(
                self.theta, self.taper_length
            )
            + 1,
            **self.wg_spec
        )

        if self.ridge:
            ridge_region = gdspy.Round(
                (0, 0),
                radius=self.length,
github DerekK88 / PICwriter / picwriter / components / alignmentmarker.py View on Github external
def build_cell(self):
        # Sequentially build all the geometric shapes, then add it to the Cell
        x0, y0 = (0, 0)
        spacing = self.diameter / (4.0 * self.num_rings)
        for i in range(self.num_rings):
            self.add(
                gdspy.Round(
                    (x0, y0),
                    2 * (i + 1) * spacing,
                    2 * (i + 1) * spacing - self.ring_width,
                    layer=self.layer,
                    datatype=self.datatype,
                    number_of_points=0.1,
                )
github DerekK88 / PICwriter / picwriter / components / disk.py View on Github external
rp,
                    -np.pi / 2.0 - theta,
                    -np.pi / 2.0 + theta,
                    number_of_points=2 * self.wgt.get_num_points_curve(2 * theta, rp),
                    **self.clad_spec
                )
                clad.arc(
                    rp,
                    np.pi / 2.0 + theta,
                    np.pi / 2.0,
                    number_of_points=2 * self.wgt.get_num_points_curve(theta, rp),
                    **self.clad_spec
                )

                # Make the disk resonator
                ring = gdspy.Round(
                    (
                        xcenter,
                        self.radius
                        + self.wgt.wg_width / 2.0
                        + self.coupling_gap
                        - 2 * dy,
                    ),
                    self.radius,
                    number_of_points=self.wgt.get_num_points_curve(
                        2 * np.pi, self.radius
                    ),
                    **self.wg_spec
                )
                clad_ring = gdspy.Round(
                    (
                        xcenter,
github BerkeleyPhotonicsGenerator / BPG / gdspy / examples / tutorial.py View on Github external
# Create another polygon from the same set of points, but rotate it
# 180 degrees and add it to the cell.
poly2 = gdspy.Polygon(points, 1).rotate(numpy.pi)
poly_cell.add(poly2)

# To create rectangles we don't need to give the 4 corners, only 2.
# Note that we don't need to create a variable if we are not going to
# use it, just add the rectangle directly to the cell.  Create a
# rectangle in layer 2.
poly_cell.add(gdspy.Rectangle((18, 1), (22, 2), 2))

# There are no circles in the GDSII specification, so rounded shapes
# are actually many-sided polygons.  Create a circle in layer 2,
# centered at (27, 2), and with radius 2.
poly_cell.add(gdspy.Round((27, 2), 2, layer=2))

# The Round class is quite versatile: it provides circles, pie slices,
# rings and ring sections, like this one in layer 2.
poly_cell.add(
    gdspy.Round(
        (23.5, 7),
        15,
        inner_radius=14,
        initial_angle=-2.0 * numpy.pi / 3.0,
        final_angle=-numpy.pi / 3.0,
        layer=2))

# ------------------------------------------------------------------ #
#      PATHS
# ------------------------------------------------------------------ #
github DerekK88 / PICwriter / picwriter / components / disk.py View on Github external
def __build_cell(self):
        # Sequentially build all the geometric shapes using gdspy path functions
        # for waveguide, then add it to the Cell

        if self.wrap_angle == 0:
            bus_length = 2 * self.radius
            # Add bus waveguide with cladding
            path = gdspy.Path(self.wgt.wg_width, (0, 0))
            path.segment(2 * self.radius, direction="+x", **self.wg_spec)
            clad = gdspy.Path(2 * self.wgt.clad_width + self.wgt.wg_width, (0, 0))
            clad.segment(2 * self.radius, direction="+x", **self.clad_spec)

            # Disk resonator
            if self.parity == 1:
                ring = gdspy.Round(
                    (
                        self.radius,
                        self.radius + self.wgt.wg_width / 2.0 + self.coupling_gap,
                    ),
                    self.radius,
                    number_of_points=self.wgt.get_num_points_curve(
                        2 * np.pi, self.radius
                    ),
                    **self.wg_spec
                )
                clad_ring = gdspy.Round(
                    (
                        self.radius,
                        self.radius + self.wgt.wg_width / 2.0 + self.coupling_gap,
                    ),
                    self.radius + self.wgt.clad_width,