Import and Output

Classes

GdsImport

class gdspy.GdsImport(infile, unit=None, rename={}, layers={}, datatypes={}, texttypes={}, verbose=True)

Bases: object

Object used to import structures from a GDSII stream file.

Parameters:

infile : file or string

GDSII stream file (or path) to be imported. It must be opened for reading in binary format.

unit : number

Unit (in meters) to use for the imported structures. If None, the units used to create the GDSII file will be used.

rename : dictionary

Dictionary used to rename the imported cells. Keys and values must be strings.

layers : dictionary

Dictionary used to convert the layers in the imported cells. Keys and values must be integers.

datatypes : dictionary

Dictionary used to convert the datatypes in the imported cells. Keys and values must be integers.

texttypes : dictionary

Dictionary used to convert the text types in the imported cells. Keys and values must be integers.

verbose: bool

If False, suppresses warnings about unsupported elements in the imported file. Also supresses polygon generation warnings.

Notes

Not all features from the GDSII specification are currently supported. A warning will be produced if any unsuported features are found in the imported file.

Examples

>>> gdsii = gdspy.GdsImport('gdspy-sample.gds')
>>> for cell_name in gdsii.cell_dict:
...     gdsii.extract(cell_name)

Attributes

cell_dict (dictionary) Dictionary will all imported cells, indexed by name.

Methods

extract(cell)

Extract a cell from the imported GDSII file and include it in the current scope, including referenced dependencies.

Parameters:

cell : Cell or string

Cell or name of the cell to be extracted from the imported file. Referenced cells will be automatically extracted as well.

Returns:

out : Cell

The extracted cell.

top_level()

Output the top level cells from the GDSII data. Top level cells are those that are not referenced by any other cells.

GdsPrint

class gdspy.GdsPrint(outfile, name='library', unit=1e-06, precision=1e-09)

Bases: object

GDSII strem library printer.

The dimensions actually written on the GDSII file will be the dimensions of the objects created times the ratio unit/precision. For example, if a circle with radius 1.5 is created and we set unit=1.0e-6 (1 um) and precision=1.0e-9 (1 nm), the radius of the circle will be 1.5 um and the GDSII file will contain the dimension 1500 nm.

Parameters:

outfile : file or string

The file (or path) where the GDSII stream will be written. It must be opened for writing operations in binary format.

cells : array-like

The list of cells or cell names to be included in the library. If None, all cells listed in Cell.cell_dict are used.

name : string

Name of the GDSII library (file).

unit : number

Unit size for the objects in the library (in meters).

precision : number

Precision for the dimensions of the objects in the library (in meters).

Notes

This class can be used for incremental output of the geometry in case the complete layout is too large to be kept in memory all at once.

Examples

>>> prt = gdspy.GdsPrint('out-file.gds', unit=1.0e-6, precision=1.0e-9)
>>> for i in range(10):
...     cell = gdspy.Cell('C{}'.format(i))
...     # Add the contents of this cell...
...     prt.write_cell(cell)
...     # Clear the memory: erase Cell objects and any other objects
...     # that won't be needed.
...     gdspy.Cell.cell_dict.clear()
>>> prt.close()

Methods

close()

Finalize the GDSII stream library.

write_cell(cell)

Write the specified cell to the file.

Parameters:

cell : Cell

Cell to be written.

Returns:

out : GdsPrint

This object.

Notes

Only the specified cell is written. Unlike in gds_print, cell dependencies are not automatically included.

LayoutViewer

class gdspy.LayoutViewer(cells=None, hidden_types=[], depth=0, color={}, pattern={}, background='#202020', width=800, height=600)

Provide a GUI where the layout can be viewed.

The view can be scrolled vertically with the mouse wheel, and horizontally by holding the shift key and using the mouse wheel. Dragging the 2nd mouse button also scrolls the view, and if control is held down, it scrolls 10 times faster.

You can zoom in or out using control plus the mouse wheel, or drag a rectangle on the window with the 1st mouse button to zoom into that area.

A ruler is available by clicking the 1st mouse button anywhere on the view and moving the mouse around. The distance is shown in the status area.

Double-clicking on any polygon gives some information about it.

Color and pattern for each layer/datatype specification can be changed by left and right clicking on the icon in the layer/datatype list. Left and right clicking the text label changes the visibility.

Parameters:

cells : Cell, string or array-like

The array of cells to be included in the view. If None, all cells listed in Cell.cell_dict are used.

hidden_types : array-like

The array of tuples (layer, datatype) to start in hidden state.

depth : integer

Initial depth of referenced cells to be displayed.

color : dictionary

Dictionary of colors for each tuple (layer, datatype). The colors must be strings in the format #rrggbb. A value with key default will be used as default color.

pattern : dictionary

Dictionary of patterns for each tuple (layer, datatype). The patterns must be integers between 0 and 9, inclusive. A value with key default will be used as default pattern.

background : string

Canvas background color in the format #rrggbb.

width : integer

Horizontal size of the viewer canvas.

height : integer

Vertical size of the viewer canvas.

Examples

White background, filled shapes:

>>> gdspy.LayoutViewer(pattern={'default':8}, background='#FFFFFF')

No filling, black color for layer 0, datatype 1, automatic for others:

>>> gdspy.LayoutViewer(pattern={'default':9}, color={(0,1):'#000000'})

Methods

Functions

gds_print

gdspy.gds_print(outfile, cells=None, name='library', unit=1e-06, precision=1e-09)

Output a list of cells as a GDSII stream library.

The dimensions actually written on the GDSII file will be the dimensions of the objects created times the ratio unit/precision. For example, if a circle with radius 1.5 is created and we set unit=1.0e-6 (1 um) and precision=1.0e-9 (1 nm), the radius of the circle will be 1.5 um and the GDSII file will contain the dimension 1500 nm.

Parameters:

outfile : file or string

The file (or path) where the GDSII stream will be written. It must be opened for writing operations in binary format.

cells : array-like

The list of cells or cell names to be included in the library. If None, all cells listed in Cell.cell_dict are used.

name : string

Name of the GDSII library (file).

unit : number

Unit size for the objects in the library (in meters).

precision : number

Precision for the dimensions of the objects in the library (in meters).

Examples

>>> gdspy.gds_print('out-file.gds', unit=1.0e-6, precision=1.0e-9)