gdspy is a Python module that allows the creation of GDSII stream files.
Many features of the GDSII format are implemented, such as cell references and arrays, but the support for fonts is quite limited. Text is only available through polygonal objects.
If the Python Imaging Library is installed, it can be used to output the geometry created to an image file.
Collection of elements, both geometric objects and references to other cells.
Parameters : | name : string
|
---|
Methods
add | |
area | |
copy | |
flatten | |
get_polygons | |
to_gds |
Add a new element or list of elements to this cell.
Parameters : | element : object, list
|
---|---|
Returns : | out : Cell
|
Calculate the total area of the elements on this cell, including cell references and arrays.
Parameters : | by_layer : bool
|
---|---|
Returns : | out : number, dictionary
|
List of all cells created.
This list is updated automatically whenever a new Cell object is created.
Creates a copy of this cell.
Parameters : | name : string
|
---|---|
Returns : | out : Cell
|
Flatten all CellReference and CellArray elements in this cell into real polygons, instead of references.
Parameters : | single_layer : integer or None
|
---|---|
Returns : | out : Cell
|
Returns a list of polygons in this cell.
Parameters : | by_layer : bool
|
---|---|
Returns : | out : list of array-like[N][2] or dictionary
|
Convert this cell to a GDSII structure.
Parameters : | multiplier : number
|
---|---|
Returns : | out : string
|
Simple reference to an existing cell.
Parameters : | ref_cell : Cell
origin : array-like[2]
rotation : number
magnification : number
x_reflection : bool
|
---|
Methods
area | |
get_polygons | |
to_gds |
Calculate the total area of the referenced cell with the magnification factor included.
Parameters : | by_layer : bool
|
---|---|
Returns : | out : number, dictionary
|
Returns a list of polygons created by this reference.
Parameters : | by_layer : bool
|
---|---|
Returns : | out : list of array-like[N][2] or dictionary
|
Convert this object to a GDSII element.
Parameters : | multiplier : number
|
---|---|
Returns : | out : string
|
Multiple references to an existing cell in an array format.
Parameters : | ref_cell : Cell
columns : positive integer
rows : positive integer
spacing : array-like[2]
origin : array-like[2]
rotation : number
magnification : number
x_reflection : bool
|
---|
Methods
area | |
get_polygons | |
to_gds |
Calculate the total area of the cell array with the magnification factor included.
Parameters : | by_layer : bool
|
---|---|
Returns : | out : number, dictionary
|
Returns a list of polygons created by this reference.
Parameters : | by_layer : bool
|
---|---|
Returns : | out : list of array-like[N][2] or dictionary
|
Convert this object to a GDSII element.
Parameters : | multiplier : number
|
---|---|
Returns : | out : string
|
Polygonal geometric object.
Parameters : | layer : integer
points : array-like[N][2]
datatype : integer
|
---|
Notes
The last point should not be equal to the first (polygons are automatically closed).
The GDSII specification supports only a maximum of 199 vertices per polygon.
Examples
>>> triangle_pts = [(0, 40), (15, 40), (10, 50)]
>>> triangle = gdspy.Polygon(1, triangle_pts)
>>> myCell.add(triangle)
Methods
area | |
fillet | |
fracture | |
rotate | |
to_gds |
Calculate the total area of this object.
Parameters : | by_layer : bool
|
---|---|
Returns : | out : number, dictionary
|
Round the corners of this polygon and fractures it into polygons with less vertices if necessary.
Parameters : | radius : number
points_per_2pi : integer
max_points : integer
|
---|---|
Returns : | out : Polygon or PolygonSet
|
Slice this polygon in the horizontal and vertical directions so that each resulting piece has at most max_points.
Parameters : | max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Rotate this object.
Parameters : | angle : number
center : array-like[2]
|
---|---|
Returns : | out : Polygon
|
Convert this object to a GDSII element.
Parameters : | multiplier : number
|
---|---|
Returns : | out : string
|
Bases: gdspy.Polygon
Rectangular geometric object.
Parameters : | layer : integer
point1 : array-like[2]
point2 : array-like[2]
datatype : integer
|
---|
Examples
>>> rectangle = gdspy.Rectangle(1, (0, 0), (10, 20))
>>> myCell.add(rectangle)
Methods
area | |
fillet | |
fracture | |
rotate | |
to_gds |
Calculate the total area of this object.
Parameters : | by_layer : bool
|
---|---|
Returns : | out : number, dictionary
|
Round the corners of this polygon and fractures it into polygons with less vertices if necessary.
Parameters : | radius : number
points_per_2pi : integer
max_points : integer
|
---|---|
Returns : | out : Polygon or PolygonSet
|
Slice this polygon in the horizontal and vertical directions so that each resulting piece has at most max_points.
Parameters : | max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Rotate this object.
Parameters : | angle : number
center : array-like[2]
|
---|---|
Returns : | out : Polygon
|
Convert this object to a GDSII element.
Parameters : | multiplier : number
|
---|---|
Returns : | out : string
|
Bases: gdspy.PolygonSet
Circular geometric object. Represent a circle, a circular section, a ring or a ring section.
Parameters : | layer : integer
center : array-like[2]
radius : number
inner_radius : number
initial_angle : number
final_angle : number
number_of_points : integer
max_points : integer
datatype : integer
|
---|
Notes
The GDSII specification supports only a maximum of 199 vertices per polygon.
Examples
>>> circle = gdspy.Round(2, (30, 5), 8)
>>> ring = gdspy.Round(2, (50, 5), 8, inner_radius=5)
>>> pie_slice = gdspy.Round(2, (30, 25), 8, initial_angle=0,
... final_angle=-5.0*numpy.pi/6.0)
>>> arc = gdspy.Round(2, (50, 25), 8, inner_radius=5,
... initial_angle=-5.0*numpy.pi/6.0,
... final_angle=0)
Methods
area | |
fillet | |
fracture | |
rotate | |
to_gds |
Calculate the total area of the path(s).
Parameters : | by_layer : bool
|
---|---|
Returns : | out : number, dictionary
|
Round the corners of these polygons and fractures them into polygons with less vertices if necessary.
Parameters : | radius : number
points_per_2pi : integer
max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most max_points. This opertaion occur in place.
Parameters : | max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Rotate this object.
Parameters : | angle : number
center : array-like[2]
|
---|---|
Returns : | out : PolygonSet
|
Convert this object to a series of GDSII elements.
Parameters : | multiplier : number
|
---|---|
Returns : | out : string
|
Set of polygonal objects.
Parameters : | layer : integer
polygons : list of array-like[N][2]
datatype : integer
|
---|
Notes
The last point should not be equal to the first (polygons are automatically closed).
The GDSII specification supports only a maximum of 199 vertices per polygon.
Methods
area | |
fillet | |
fracture | |
rotate | |
to_gds |
Calculate the total area of the path(s).
Parameters : | by_layer : bool
|
---|---|
Returns : | out : number, dictionary
|
Round the corners of these polygons and fractures them into polygons with less vertices if necessary.
Parameters : | radius : number
points_per_2pi : integer
max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most max_points. This opertaion occur in place.
Parameters : | max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Rotate this object.
Parameters : | angle : number
center : array-like[2]
|
---|---|
Returns : | out : PolygonSet
|
Convert this object to a series of GDSII elements.
Parameters : | multiplier : number
|
---|---|
Returns : | out : string
|
Bases: gdspy.PolygonSet
Series of geometric objects that form a path or a collection of parallel paths.
Parameters : | width : number
initial_point : array-like[2]
number_of_paths : positive integer
distance : number
|
---|
Attributes
x | number | Current position of the path in the x direction. |
y | number | Current position of the path in the y direction. |
w | number | Half-width of each path. |
n | integer | Number of parallel paths. |
direction | {‘+x’, ‘-x’, ‘+y’, ‘-y’} or number | Direction or angle (in radians) the path points to. |
distance | number | Distance between the centers of adjacent paths. |
length | number | Length of the central path axis. If only one path is created, this is the real length of the path. |
Methods
arc | |
area | |
fillet | |
fracture | |
parametric | |
rotate | |
segment | |
to_gds | |
turn |
Add a curved section to the path.
Parameters : | layer : integer, list
radius : number
initial_angle : number
final_angle : number
number_of_points : integer
max_points : integer
final_width : number
final_distance : number
datatype : integer, list
|
---|---|
Returns : | out : Path
|
Notes
The GDSII specification supports only a maximum of 199 vertices per polygon.
Calculate the total area of the path(s).
Parameters : | by_layer : bool
|
---|---|
Returns : | out : number, dictionary
|
Round the corners of these polygons and fractures them into polygons with less vertices if necessary.
Parameters : | radius : number
points_per_2pi : integer
max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most max_points. This opertaion occur in place.
Parameters : | max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Add a parametric curve to the path.
Parameters : | layer : integer, list
curve_function : function
curve_derivative : function
number_of_evaluations : integer
max_points : integer
final_width : number
final_distance : number
datatype : integer, list
|
---|---|
Returns : | out : Path
|
Notes
The norm of the vector returned by curve_derivative is not important. Only the direction is used.
The GDSII specification supports only a maximum of 199 vertices per polygon.
Examples
>>> def my_parametric_curve(t):
... return (2**t, t**2)
>>> def my_parametric_curve_derivative(t):
... return (0.69315 * 2**t, 2 * t)
>>> my_path.parametric(1, my_parametric_curve,
... my_parametric_curve_derivative)
Rotate this object.
Parameters : | angle : number
center : array-like[2]
|
---|---|
Returns : | out : Path
|
Add a straight section to the path.
Parameters : | layer : integer, list
length : number
direction : {‘+x’, ‘-x’, ‘+y’, ‘-y’} or number
final_width : number
final_distance : number
datatype : integer, list
|
---|---|
Returns : | out : Path
|
Convert this object to a series of GDSII elements.
Parameters : | multiplier : number
|
---|---|
Returns : | out : string
|
Add a curved section to the path.
Parameters : | layer : integer, list
radius : number
angle : {‘r’, ‘l’, ‘rr’, ‘ll’} or number
number_of_points : integer
max_points : integer
final_width : number
final_distance : number
datatype : integer, list
|
---|---|
Returns : | out : Path
|
Notes
The GDSII specification supports only a maximum of 199 vertices per polygon.
Bases: gdspy.PolygonSet
Series of geometric objects that form a polygonal path or a collection of parallel polygonal paths.
Parameters : | layer : integer, list
points : array-like[N][2]
width : number or array-like[N]
number_of_paths : positive integer
distance : number or array-like[N]
corners : positive integer
max_points : integer
datatype : integer, list
|
---|---|
Returns : | out : PolyPath
|
Notes
The bevel joint will give strange results if the number of paths is greater than 1.
Methods
area | |
fillet | |
fracture | |
rotate | |
to_gds |
Calculate the total area of the path(s).
Parameters : | by_layer : bool
|
---|---|
Returns : | out : number, dictionary
|
Round the corners of these polygons and fractures them into polygons with less vertices if necessary.
Parameters : | radius : number
points_per_2pi : integer
max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most max_points. This opertaion occur in place.
Parameters : | max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Rotate this object.
Parameters : | angle : number
center : array-like[2]
|
---|---|
Returns : | out : PolygonSet
|
Convert this object to a series of GDSII elements.
Parameters : | multiplier : number
|
---|---|
Returns : | out : string
|
Bases: gdspy.PolygonSet
Series of geometric objects that form a path or a collection of parallel paths with Manhattan geometry.
Parameters : | layer : integer, list
initial_point : array-like[2]
direction : {‘+x’, ‘+y’, ‘-x’, ‘-y’}
width : number
length : array-like
turn : array-like
number_of_paths : positive integer
distance : number
datatype : integer, list
|
---|---|
Returns : | out : L1Path
|
Examples
>>> length = [10, 30, 15, 15, 15, 15, 10]
>>> turn = [1, -1, -1, 3, -1, 1]
>>> l1path = gdspy.L1Path(5, (0, 0), '+x', 2, length, turn)
>>> myCell.add(l1path)
Attributes
x | number | Final position of the path in the x direction. |
y | number | Final position of the path in the y direction. |
direction | {‘+x’, ‘-x’, ‘+y’, ‘-y’} or number | Direction or angle (in radians) the path points to. The numerical angle is returned only after a rotation of the object. |
Methods
area | |
fillet | |
fracture | |
rotate | |
to_gds |
Calculate the total area of the path(s).
Parameters : | by_layer : bool
|
---|---|
Returns : | out : number, dictionary
|
Round the corners of these polygons and fractures them into polygons with less vertices if necessary.
Parameters : | radius : number
points_per_2pi : integer
max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most max_points. This opertaion occur in place.
Parameters : | max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Rotate this object.
Parameters : | angle : number
center : array-like[2]
|
---|---|
Returns : | out : L1Path
|
Convert this object to a series of GDSII elements.
Parameters : | multiplier : number
|
---|---|
Returns : | out : string
|
Bases: gdspy.PolygonSet
Polygonal text object.
Each letter is formed by a series of polygons.
Parameters : | layer : integer
text : string
size : number
position : array-like[2]
horizontal : bool
angle : number
datatype : integer
|
---|
Examples
>>> text = gdspy.Text(8, 'Sample text', 20, (-10, -100))
>>> myCell.add(text)
Methods
area | |
fillet | |
fracture | |
rotate | |
to_gds |
Calculate the total area of the path(s).
Parameters : | by_layer : bool
|
---|---|
Returns : | out : number, dictionary
|
Round the corners of these polygons and fractures them into polygons with less vertices if necessary.
Parameters : | radius : number
points_per_2pi : integer
max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most max_points. This opertaion occur in place.
Parameters : | max_points : integer
|
---|---|
Returns : | out : PolygonSet
|
Rotate this object.
Parameters : | angle : number
center : array-like[2]
|
---|---|
Returns : | out : PolygonSet
|
Convert this object to a series of GDSII elements.
Parameters : | multiplier : number
|
---|---|
Returns : | out : string
|
Execute any boolean operation on polygons and polygon sets.
Parameters : | layer : integer
objects : array-like
operation : function
precision : number
max_points : integer
datatype : integer
|
---|---|
Returns : | out : PolygonSet
|
Notes
Since operation receives a list of integers as input, it can be somewhat more general than boolean operations only. See the examples below.
Examples
>>> circle = gdspy.Round(0, 10, (0, 0))
>>> triangle = gdspy.Round(0, 12, (0, 0), number_of_points=3)
>>> bad_poly = gdspy.L1Path(1, (0, 0), '+y', 2,
[6, 4, 4, 8, 4, 5, 10], [-1, -1, -1, 1, 1, 1])
>>> union = gdspy.boolean(1, [circle, triangle],
lambda p: p[0] or p[1], precision=1.0e-09)
>>> intersection = gdspy.boolean(1, [circle, triangle],
lambda p: p[0] and p[1], precision=1.0e-09)
>>> subtraction = gdspy.boolean(1, [circle, triangle],
lambda p: p[0] - p[1], precision=1.0e-09)
>>> multi_xor = gdspy.boolean(1, [badPath], lambda p: p[0] % 2))
Slice polygons and polygon sets at given positions along an axis.
Parameters : | layer : integer, list
objects : Polygon, PolygonSet, or list
position : number or list of numbers
axis : 0 or 1
datatype : integer
|
---|---|
Returns : | out : list[N] of PolygonSet
|
Examples
>>> ring = gdspy.Round(1, (0, 0), 10, inner_radius = 5)
>>> result = gdspy.slice(1, ring, [-7, 7], 0)
>>> cell.add(result[1])