# Import and Output

## Classes

### LayoutViewer

class `gdspy.``LayoutViewer`(library=None, 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: | library (`GdsLibrary`) – GDSII library to display. If `None`, the current library is used. cells (Cell, string or array-like) – The array of cells to be included in the view. If `None`, all cells listed in the current library 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'})

### GdsWriter

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

  Bases: `object`

  GDSII strem library writer.

  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

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

  `close`()

    Finalize the GDSII stream library.

  `write_cell`(cell)

    Write the specified cell to the file.

    Parameters: | cell (`Cell`) – Cell to be written.

    Notes

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

    Returns: | out – This object.
    Return type: | `GdsWriter`

## Functions

### write_gds

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

  Write the current GDSII library to a file.

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