How to use the gdspy.GdsLibrary 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 / tutils.py View on Github external
def target():
    return gdspy.GdsLibrary(infile="tests" + os.sep + "test.gds").cell_dict
github heitzmann / gdspy / tests / functions.py View on Github external
assert c.references[0].origin[0] == -2 and c.references[0].origin[1] == -4
    assert c.references[0].rotation == 180
    assert c.references[0].magnification == 0.5
    assert c.references[0].x_reflection == True
    assert c.references[0].spacing[0] == 2 and c.references[0].spacing[1] == 8
    assert c.references[0].columns == 2
    assert c.references[0].rows == 3

    fname2 = str(tmpdir.join("test2.gds"))
    library.name = "lib2"
    library.unit = 2e-3
    library.precision = 1e-5
    with open(fname2, "wb") as fout:
        library.write_gds(fout)
    with open(fname2, "rb") as fin:
        lib2 = gdspy.GdsLibrary()
        lib2.read_gds(fin)
    assert lib2.name == "lib2"
    assert len(lib2.cells) == 4
github heitzmann / gdspy / tests / gdslibrary.py View on Github external
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)
github heitzmann / gdspy / tests / gdswriter.py View on Github external
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},
        texttypes={6: 7},
    )
    assert lib1.name == "lib"
    assert len(lib1.cell_dict) == 4
    assert set(lib1.cell_dict.keys()) == {
        "1",
        "gw_rw_gds_2",
        "gw_rw_gds_3",
        "gw_rw_gds_4",
    }
github heitzmann / gdspy / tests / robustpath.py View on Github external
rp = gdspy.RobustPath(
        (0, 0),
        0.1,
        layer=5,
        tolerance=1e-5,
        max_points=0,
        max_evals=1e6,
        gdsii_path=True,
    )
    rp.segment((1, 0))
    rp.turn(2, "ll")
    rp.turn(1, "rr")
    rp.turn(2, "l")
    cell.add(rp)
    fname = str(tmpdir.join("test.gds"))
    gdspy.GdsLibrary(unit=1, precision=1e-7).add(cell).write_gds(fname)
    lib = gdspy.GdsLibrary(infile=fname, rename={"robustpath": "file"})
    assertsame(lib.cells["file"], cell, tolerance=1e-3)
github DerekK88 / PICwriter / picwriter / toolkit.py View on Github external
def reset_database():
    """ Resets the gdspy library, and resets the CURRENT_CELLS and CURRENT_CELL_NAMES dicts
    """
    gdspy.current_library = gdspy.GdsLibrary()
    
    global CURRENT_CELLS
    CURRENT_CELLS = {}
    
    global CURRENT_CELL_NAMES
    CURRENT_CELL_NAMES = {}
github BerkeleyPhotonicsGenerator / BPG / BPG / gds / io.py View on Github external
gdspy turns all input shapes into polygons, so we only need to care about importing into
        the polygon list. Currently we only import labels at the top level of the hierarchy

        Parameters
        ----------
        gds_filepath : str
            Path to the gds to be imported
        """
        # Import information from the layermap
        with open(self.gds_layermap, 'r') as f:
            lay_info = yaml.load(f)
            lay_map = lay_info['layer_map']

        # Import the GDS from the file
        gds_lib = gdspy.GdsLibrary()
        gds_lib.read_gds(infile=gds_filepath, units='convert')

        # Get the top cell in the GDS and flatten its contents
        top_cell = gds_lib.top_level()
        if len(top_cell) != 1:
            raise ValueError("Cannot import a GDS with multiple top level cells")
        top_cell = top_cell[0]  # top_cell returns a list, so just grab the only element
        top_cell.flatten()

        # TODO: This currently accesses an internal attr polygons, instead of the get_polygons() method, may be unstable
        for polyset in top_cell.polygons:
            for count in range(len(polyset.polygons)):
                points = polyset.polygons[count]
                layer = polyset.layers[count]
                datatype = polyset.datatypes[count]
github BerkeleyPhotonicsGenerator / BPG / BPG / gds / core.py View on Github external
gdspy turns all input shapes into polygons, so we only need to care about importing into
        the polygon list. Currently we only import labels at the top level of the hierarchy

        Parameters
        ----------
        gds_filepath : str
            Path to the gds to be imported
        """
        # Import information from the layermap
        with open(self.gds_layermap, 'r') as f:
            lay_info = yaml.load(f)
            lay_map = lay_info['layer_map']

        # Import the GDS from the file
        gds_lib = gdspy.GdsLibrary()
        gds_lib.read_gds(infile=gds_filepath)

        # Get the top cell in the GDS and flatten its contents
        # TODO: Currently we do not support importing GDS with multiple top cells
        top_cell = gds_lib.top_level()
        if len(top_cell) != 1:
            raise ValueError("Cannot import a GDS with multiple top level cells")
        top_cell = top_cell[0]
        top_cell.flatten()

        # Lists of components we will import from the GDS
        polygon_list = []
        pin_list = []

        for polyset in top_cell.elements:
            for count in range(len(polyset.polygons)):
github HelgeGehring / gdshelpers / gdshelpers / parts / pattern_import.py View on Github external
def __init__(self, filename, cell_name, layer=None, datatype=None):
        """
        Imports a GDSII-pattern and makes it usable like a gdshelpers part.

        :param filename: Name of the GDSII-file
        :param cell_name: Name of the cell
        :param layer: Layer which should be imported, ´None´ means all layers
        :param datatype: Datatype which should be imported, ´None´ means all datatypes
        """
        self.gdslib = gdspy.GdsLibrary(infile=filename)
        self.cell_name = cell_name
        self.layer = layer
        self.datatype = datatype
github ucb-bar / hammer / src / hammer-vlsi / technology / asap7 / __init__.py View on Github external
def generate_multi_vt_gds(self) -> None:
        """
        PDK GDS only contains SLVT cells.
        This patch will generate the other 3(LVT, RVT, SRAM) VT GDS files.
        """
        import gdspy # TODO: why did module import get lost above for some users?

        self.logger.info("Generate GDS for Multi-VT cells")

        orig_gds = os.path.join(self.extracted_tarballs_dir, "ASAP7_PDKandLIB.tar/ASAP7_PDKandLIB_v1p5/asap7libs_24.tar.bz2/asap7libs_24/gds/asap7sc7p5t_24.gds")
        # load original_gds
        asap7_original_gds = gdspy.GdsLibrary().read_gds(infile=orig_gds, units='import')
        original_cells = asap7_original_gds.cell_dict
        # This is an extra cell in the original GDS that has no geometry inside
        del original_cells['m1_template']
        # required libs
        multi_libs = {
            "R": {
                "lib": gdspy.GdsLibrary(),
                "mvt_layer": None,
                },
            "L": {
                "lib": gdspy.GdsLibrary(),
                "mvt_layer": 98
                },
            "SL": {
                "lib": gdspy.GdsLibrary(),
                "mvt_layer": 97