Gdspy is a Python module for creation and manipulation of GDSII stream files. Key features for the creation of complex CAD layouts are included:
- Boolean operations on polygons (AND, OR, NOT, XOR) based on clipping algorithm
- Polygon offset (inward and outward rescaling of polygons)
- Efficient point-in-polygon solutions for large array sets
Gdspy also includes a simple layout viewer.
Typical applications of Gdspy are in the fields of electronic chip design, planar lightwave circuit design, and mechanical engineering.
In trying to improve the performance of Gdspy for large layouts, we ended up concluding that the best way to reach our goal was to rewrite the critical parts of the library as a C extension. It turns out that beside obvious functions, method calling has a big impact in performance due to the overhead it introduces. The best solution was to re-design the whole project as a C++ library with a thin Python wrapper: thus was born Gdstk, the GDSII Tool Kit.
Therefore, version 1.6 will be the last major release of Gdspy, with development focused only on bug fixes. Users are encouraged to move from Gdspy to Gdstk: although their API is not 100% compatible, the new module should be familiar enough to allow a quick transition.
- Python (tested with versions 2.7, 3.6, 3.7, and 3.8)
- Numpy
- C compiler (needed only if built from source)
- Tkinter (optional: needed for the
LayoutViewerGUI) - Sphinx (optional: to build the documentation)
Option 1: using pip:
python -m pip install --user gdspyOption 2: download the source from github and build/install with:
python setup.py installThe preferred option is to install pre-compiled binaries from here.
Installation via pip and building from source as above are also possible, but an appropriate build environment is required for compilation of the C extension modules.
The complete documentation is available here.
The source files can be found in the docs directory.
Help support Gdspy development by donating via PayPal or sponsoring me on GitHub
- Allow ill-formed GDSII label anchors to be correctly loaded.
- Fix in
Cell.get_texttypes. - Allow labels to inherit transforms through
get_labels.
- Fix in
Cell.write_svgwhen missing references. - Speed improvements in
Cell.remove_polygons(thanks Troy for the contribution).
- Fix in
Cell.get_polygons
- Fix in
Cell.get_polygonswith specified layer and datatype. - Raise error for duplicate cells when reading a GDSII file.
- Fix in
booleanfor complex geometries that freeze the operation.
- Fixes in
booleanfor bugs with self-intersecting holes and holes horizontal edges. - Fix bug in warning message.
- Fix error in
Path.smoothnot finding_hobbyfunction. - Allow precision specification in SVG output.
- Support GDSII files with 0-padding at the end.
- Allow fixing and modifying GDSII file timestamps.
- Thanks Troy Tamas and Joaquin Matres for the fixes
- Fix missing module import (thanks Troy Tamas for the fix).
- Fix bounding box edge case (thanks Troy Tamas for the fix).
- More efficient bounding box calculation (thanks to Troy Tamas for the contribution).
- Fix Label creation bug.
- Fix SVG output when
Labelcontains special characters.
- Added support for element properties.
- Added transformation support to
Cell.copy. - Layer/datatype filtering in
get_polygonsforCell,CellReferenceandCellArray. - Layer/datatype filtering in
LayoutViewer. - Removed global cache
_bounding_boxes. Only cells cache their bounding boxes. - Bug fixes (thanks Daniel Hwang for the contributions).
- Bug fix in
Cell.copywhere the whole dependency tree would be copied on a deep copy creation.
- Added support for importing GDSII files containing BOX elements.
- Bug fix in
GdsLibrary.extract(thanks collineps for finding the problem).
- New
Cell.write_svgfunction to export an SVG image of the cell. - New
GdsLibrary.new_cellfunction to quickly create and add cells to a library. GdsLibrary.addcan update references when a cell is overwritten.- Added
GdsLibrary.removeto allow cells to be properly removed from libraries. - Added
GdsLibrary.rename_cellto rename cells in libraries. - Added
GdsLibrary.replace_referencesto easily replace referenced cells in libraries. GdsLibrary.addcan add dependencies recursively.- Iterating over
GdsLibraryobjects yields all its cells. - Iterating over
Cellobjects yield all its polygons, paths, labels and references. - Breaking change to
*.to_gdsfunctions in order to improve write efficiency (this should not be a problem for most users, sincegdspy.write_gdsandCell.write_gdsremain the same). - Breaking change: renamed
GdsLibrary.cell_dicttoGdsLibrary.cells. - Deprecated:
gdspy.current_library,gdspy.write_gds,gdspy.fast_boolen,GdsLibrary.extract. - Bug fixes and better tests for
FlexPathandRobustPath.
- Bug fix for
FlexPathandRobustPathreferences.
- Bug fix in
FlexPath.
- Bug fixes (thanks to DerekK88 and Sequencer for the patches).
- Revised documentation.
- New
FlexPathandRobustPathclasses: more efficient path generation when using the original GDSII path specification. - New
Curveclass: SVG-like polygon creation. - Added
PolygonSet.mirror(thanks to Daan Waardenburg for the contribution). - Added
Path.bezierto create paths based on Bézier curves. - Added
Path.smoothto create paths based on smooth interpolating curves. - Added
get_gds_unitsto get units used in a GDSII file without loading. - Added
get_binary_cellsto load only the binary GDSII representation of cell from a file. - Added argument
tolerancetoRound,Path.arc,Path.turn, andPath.parametricto automatically control the number of points in the final polygons. - Added argument
binary_cellsto GDSII writing functions to supportget_binary_cells. - Added argument
rename_templatetoGdsLibrary.read_gdsfor flexible cell renaming (thanks to @yoshi74ls181 for the contribution). - Changed return value of
sliceto avoid creating emptyPolygonSet. - Added argument
timestampto GDSII writing functions. - Improved
Roundto support creating ellipses. - Added support for unlimited number of points per polygon.
- Added support for BGNEXTN and ENDEXTN when reading a GDSII file.
- Polygon creation warnings are now controlled by
poly_warnings. - Incorrect
anchorinLabelnow raises an error, instead of emitting a warning. - Added correct support for radius in
PolygonSet.filleton a per-vertex basis. - Speed improvements in GDSII file generation (thanks to @fbeutel for the contribution) and geometry creation.
- Font rendering example using matplotlib (thanks Hernan Pastoriza for the contribution).
- Expanded test suite.
- Small fix for building on Mac OS X Mojave.
PolygonSetbecomes the base class for all polygons, in particularPolygonandRectangle.- Added
Cell.remove_polygonsandCell.remove_labelsfunctions to allow filtering a cell contents based, for example, on each element's layer. - Added
PolygonSet.scaleutility method. - Added
PolygonSet.get_bounding_boxutility method. - Added argument
timestamptoCell.to_gds,GdsLibrary.write_gdsandGdsWriter. - Added
unitandprecisionarguments toGdsLibraryinitialization and removed from itswrite_gdsmethod. - Changed the meaning of argument
unitinGdsLibrary.read_gds. - Improved
sliceto avoid errors when slicing in multiple positions at once. - Improved
PolygonSet.fractureto reduce number of function calls. - Removed incorrect absolute flags for magnification and rotation in
CellReferenceandCellArray. - Minor bug fixes.
- Documentation fixes.
- Removed deprecated classes and functions.
GdsLibrarycan be created directly from a GDSII file- Added return value to
GdsLibrary.read_gds - Fixed return value of
GdsLibrary.add
- Added new
gdsii_hashfunction. - Added
precisionparameter to_chop,Polygon.fracture,Polygon.fillet,PolygonSet.fracture,PolygonSet.fillet, andslice. - Included labels in flatten operations (added
get_labelstoCell,CellReference, andCellArray). - Fixed bug in the bounding box cache of reference copies.
- Fixed bug in
_chopthat affectedPolygon.fracture,PolygonSet.fracture, andslice. - Other minor bug fixes.
- Update clipper library to 6.4.2 to fix bugs introduced in the last update.
- License change to Boost Software License v1.0.
- Patch to fix installation issue (missing README file in zip).
- Introduction of
GdsLibraryto allow user to work with multiple library simultaneously. - Deprecated
GdsImportin favor ofGdsLibrary. - Renamed
gds_printtowrite_gdsandGdsPrinttoGdsWriter. - Development changed to Python 3 (Python 2 supported via python-future).
- Added photonics example.
- Added test suite.
- Clipper library updated to last version.
- Fixed
insidefunction sometimes reversing the order of the output. - Fixed rounding error in
fast_boolean. - Fixed argument
deep_copybeing inverted inCell.copy. - Bug fixes introduced by numpy (thanks to Adam McCaughan for the contribution).
- Changed to "new style" classes (thanks to Adam McCaughan for the contribution).
- Added a per-point radius specification for
Polygon.fillet(thanks to Adam McCaughan for the contribution). - Added
insidefucntion to perform point-in-polygon tests (thanks to @okianus for the contribution). - Moved from distutils to setuptools for better Windows support.
- Added option to join polygons before applying an
offset. - Added a
translatemethod to geometric entities (thanks John Bell for the commit). - Bug fixes.
- New
fast_booleanfunction based on the Clipper library with much better performance than the oldboolean. - Changed
offsetsignature to also use the Clipper library (this change breaks compatibility with previous versions). - Bug fix for error when importing some labels from GDSII files.
- Rebased to GitHub.
- Changed source structure and documentation.
- New feature:
offsetfunction. - New
GdsPrintclass for incremental GDSII creation (thanks to Jack Sankey for the contribution).
- Default number of points for
Round,Path.arc, andPath.turnchanged to resolution of 0.01 drawing units. Path.parametricaccepts callablefinal_distanceandfinal_widthfor non-linear tapering.- Added argument
endstoPolyPath. - Added (limited) support for PATHTYPE in
GdsImport. - A warning is issued when a
Pathcurve has width larger than twice its radius (self-intersecting polygon). - Added a random offset to the patterns in
LayoutViewer. LayoutViewershows cell labels for referenced cells.get_polygonsreturns (referenced) cell name ifdepth< 1 andby_specis True.- Bug fix in
get_bounding_boxwhen empty cells are referenced. - Bug fixes in
GdsImportand many speed improvements in bounding box calculations (thanks to Gene Hilton for the patch).
- Major
LayoutViewerimprovements (not backwards compatible). - The layer argument has been repositioned in the argument list in all functions (not backwards compatible).
- Renamed argument
by_layertoby_spec(not backwards compatible). - Error is raised for polygons with more vertices than possible in the GDSII format.
- Removed the global state variable for default datatype.
- Added
get_datatypestoCell. - Added argument
single_datatypetoCell.flatten. - Removed
gds_imageand dropped the optional PIL dependency.
- Added argument
axis_offsettoPath.segmentallowing creation of asymmetric tapers. - Added missing argument
x_reflectiontoLabel. - Created a global state variable to override the default datatype.
- Bug fix in
CellArray.get_bounding_box(thanks to George McLean for the fix)
Cell.get_bounding_boxreturnsNonefor empty cells.- Added a cache for bounding boxes for faster computation, especially for references.
- Added support for text elements with
Labelclass. - Improved the emission of warnings.
- Added a tolerance parameter to
boolean. - Added better print descriptions to classes.
- Bug fixes in boolean involving results with multiple holes.
- Bug fix in the fracture method for
PolygonSet.
- Bug fix in the fracture method for
PolygonandPolygonSet.
- Support for Python 3.2 and 2.7
- Further improvements to the
booleanfunction via caching. - Added methods
get_bounding_boxandget_layerstoCell. - Added method
top_leveltoGdsImport. - Added support for importing GDSII path elements.
- Added an argument to control the verbosity of the import function.
- Layer -1 (referenced cells) sent to the bottom of the layer list by default in
LayoutViewer - The text and background of the layer list in
LayoutViewernow reflect the colors of the outlines and canvas backgroung. - Changed default background color in
LayoutViewer - Thanks to Gene Hilton for the contributions!
- Attribute
Cell.cell_listchanged toCell.cell_dict. - Changed the signature of the operation in
boolean. - Order of cells passed to
LayoutVieweris now respected in the GUI. - Complete re-implementation of the boolean function as a C extension for improved performance.
- Removed precision argument in
boolean. It is fixed at 1e-13 for merging close points, otherwise machine precision is used. gds_imagenow accepts cell names as input.- Added optional argument
depthtoget_polygons - Added option to convert layers and datatypes in imported GDSII cells.
- Argument
exclude_layersfromLayoutViewerchanged tohidden_layersand behavior changed accordingly. - Shift + Right-clicking on a layer the layer-list of
LayoutVIewerhides/unhides all other layers. - New buttons to zoom in and out in
LayoutViewer. - Referenced cells below a configurable depth are now represented by theirs bounding boxes in
LayoutViewer.
- GDSII file import
- GDSII output automatically include required referenced cells.
gds_printalso accepts file name as input.- Outlines are visible by default in
LayoutViewer. - Added background color option in
LayoutViewer. - Right-clicking on the layer list hides/unhides the target layer in
LayoutViewer. Cell.cell_listis now a dictionary indexed by name, instead of a list.- Added option to exclude created cells from the global list of cells kept in
Cell.cell_list. CellReferenceandCellArrayaccept name of cells as input.- Submodules lost their own
__version__.
- Bug fixed in the
boolean, which affected the way polygons with more vertices then the maximum were fractured. gds_imageaccepts an extra color argument for the image background.- Screenshots takes from
LayoutViewerhave the same background color as the viewer. - The functions
booleanandslicenow also acceptCellReferenceandCellArrayas input. - Added the method
fracturetoPolygonandPolygonSetto automatically slice polygons into parts with a predefined maximal number of vertices. - Added the method
fillettoPolygonandPolygonSetto round corners of polygons.
- When saving a GDSII file,
ValueErroris raised if cell names are duplicated. - Save screenshot from
LayoutViewer. gds_imageaccepts cells, instead of lists.- Outlines supported by
gds_image. LayoutViewerstores bounding box information for all visited layers to save rendering time.
- Empty cells no longer break the LayoutViewer.
- Removed the
gds_viewfunction, superseded by the LayoutViewer, along with all dependencies to matplotlib. - Fixed a bug in
booleanwhich affected polygons with series of collinear vertices. - Added a function to
slicepolygons along straight lines parallel to an axis.
- Added shortcut to Extents in LayoutViewer:
Homeorakeys. PolygonSetis the new base class forRound, which might bring some incompatibility issues with older scripts.Roundelements,PolyPath,L1Path, andPath arc,turnandparametricsections are now automatically fractured into pieces defined by a maximal number of points.- Default value for
max_pointsin boolean changed to 199. - Removed the flag to disable the warning about polygons with more than 199 vertices. The warning is shown only for
PolygonandPolygonSet. - Fixed a bug impeding parallel
parametricpaths to change their distance to each other.
- Added the
PolyPathclass to easily create paths with sharp corners. - Allow
Noneas item in the colors parameter ofLayoutViewerto make layers invisible. - Added color outline mode to
LayoutViewer(change outline color with the shift key pressed) - Increased the scroll region of the
LayoutViewercanvas - Added a fast scroll mode: control + drag 2nd mouse button
- Created a new sample script
- Changed the cursor inside
LayoutViewerto standard arrow. - Fixed bugs with the windows version of
LayoutViewer(mouse wheel and ruler tool).
- Bug fix:
gds_imagedisplays an error message instead of crashing whenPILis not found. - Added class
LayoutViewer, which uses Tkinter (included in all Python distributions) to display the GDSII layout with better controls then thegds_viewfunction. This eliminates thematplotlibrequirement for the viewer functionality. - New layer colors extending layers 0 to 63.
- Fixed a bug on the
turnmethod ofPath. - Fixed a bug on the
booleanfunction that would give an error when not usingPolygonorPolygonSetas input objects. - Added the method
get_polygonstoCell,CellReferenceandCellArray. - Added a copy method to
Cell. - Added a
flattenmethod toCellto remove references (or array references) to other cells. - Fracture
booleanoutput polygons based on the number of vertices to respect the 199 GDSII limit.
- Added
L1Pathclass for Manhattan geometry (L1 norm) paths.
- Removed the argument
fillfromgds_viewand added a more flexible one:style. - Fixed a rounding error on the
booleanoperator affecting polygons with holes. - Added a rotate method to
PolygonSet. - Added a warning when
PolygonSethas more than 199 points - Added a flag to disable the warning about polygons with more than 199 points.
- Added a
turnmethod toPath, which is easier to use thanarc. - Added a direction attribute to
Pathto keep the information used by thesegmentandturnmethods.
- New visualization option: save the geometry directly to an image file (lower memory use).
- New functionality added: boolean operations on polygons (polygon clipping).
- All classes were adapted to work with the boolean operations.
- The attribute size in the initializer of class
Textdoes not have a default value any longer. - The name of the argument
formatin the functiongds_viewwas changed tofill(to avoid confusion with the built-in functionformat).
- Sample script now include comments and creates an easier to understand GDSII example.
- Improved floating point to integer rounding, which fixes the unit errors at the last digit of the precision in the GDSII file.
- Fixed the font for character 5.
- Added a flag to
gds_viewto avoid the automatic call tomatplotlib.pyplot.show(). - In
gds_view, if a layer number is greater than the number of formats defined, the formats are cycled.
- Class Text correctly interprets
\nand\tcharacters. - Better documentation format, using the Sphinx engine and the numpy format.
- Class
Textre-written with a different font with no overlaps and correct size.
- Fixed the function
to_gdsof classRectangle.
- Added the datatype field to all elements of the GDSII structure.
- Added the
gds_viewfunction to display the GDSII structure using the matplotlib module. - Fixed a rotation bug in the CellArray class.
- Module published under the GNU General Public License (GPL)
- Added attribute
cell_listto class Cell to hold a list of all Cell created. - Set the default argument
cells=Cell.cell_listin the functiongds_print. - Added member to calculate the area for each element type.
- Added member to calculate the total area of a Cell or the area by layer.
- Included the possibility of creating objects in user-defined units, not only nanometers.
- Initial release.