Import and Output

Classes

GdsImport

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

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.

Attributes

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

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)
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.

Outputs

out: List
List of top level cells.

LayoutViewer

class viewer.LayoutViewer(cells=None, hidden_layers=[], width=800, height=600, colors=None, outlines=None, background=(32, 32, 32), depth=0)

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.

Layer visibility is toggled by right-clicking on the layer list.

Layer colors can be changed by double-clicking on the layer list or clicking the 3rd mouse button on any polygon. On the color chooser, clicking cancel will make the selected layer transparent. To change the outline color, use shift + double click on the layer list, or shift + click with the 3rd button on any polygon.

The background color can be changed by clicking on the background with the 3rd mouse button.

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_layers : array-like
The array of layers to start in hidden state.
width : integer
Horizontal size of the viewer window.
height : integer
Vertical size of the viewer window.
colors : array-like
Colors (RGB tuple) for each GDSII layer, with components from 0 to 255. Any colors set to None will set that layer to transparent.
outlines : array-like
Colors (RGB tuple) for each GDSII layer, with components from 0 to 255. Any colors set to None will set that layer to transparent.
depth : integer
Initial depth of referenced cells to be displayed.

Examples

All layers filled (in red, green, and blue) and with light outlines:

>>> LayoutViewer(colors=[(255, 0, 0), (0, 255, 0), (0, 0, 255)],
...                              outlines=[(192, 192, 192)])

No filling, colored outlines:

>>> LayoutViewer(colors=[None] * 64)

Colored layers, black outlines, white background:

>>> LayoutViewer(outlines=[(0, 0, 0)], background=(255, 255, 255))

Functions

gds_image

viewer.gds_image(cells=None, exclude_layers=[], image_name=None, image_format='png', colors=None, outlines=None, resolution=1, bounding_box=None, antialias=0, background=(0, 0, 0))

Generates an image from each cell and saves them to files.

Parameters

cells : gdspy.Cell, string or list
Cell, cell name, or list of cells/names to be included in the plot. If None, all cells listed in Cell.cell_dict are used.
exclude_layers : array-like
The array of layers to be excluded from the plot.
image_name : string
Name of the output image without extension. If None, the cell names will be used. If cells contains more than 1 element, the name of the output file will be the corresponding cell name with image_name as a prefix.
image_format : string
The supported image formats are bmp, gif, jpg, pcx, png, ppm, and tiff.
colors : array-like
Colors (RGB tuple) for each layer.
outlines : array-like
Outline colors (RGB tuple) for each layer.
resolution : number
Geometry scaling in pixels per user units.
bounding_box : array-like[4]
Area of the geometry to be draw on the output file in the format (min_x, max_x, min_y, max_y). If None, the whole extent of each cell will be used.
antialias : non-negative integer
Level of anti-aliasing to be used when drawing the image.
background : array-like[3]
RGB tuple for the background color.

Examples

>>> colors = [(255,0,0), (0,255,0), (0,0,255)]
>>> gds_image(image_name='/output_folder/layout', colors=colors)

gds_print

gdspy.gds_print(outfile, cells=None, name='library', unit=1.0e-06, precision=1.0e-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-06 (1 um) and precision=1.0e-09 (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)

Table Of Contents

Previous topic

Main API

This Page