Main API

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.

Classes

Cell

class gdspy.Cell(name, exclude_from_global=False)

Collection of elements, both geometric objects and references to other cells.

Parameters

name : string
The name of the cell.
exclude_from_global : bool
If True, the cell will not be included in the global list of cells maintained by gdspy.
add(element)

Add a new element or list of elements to this cell.

Parameters

element : object, list
The element or list of elements to be inserted in this cell.

Returns

out : Cell
This cell.
area(by_layer=False)

Calculate the total area of the elements on this cell, including cell references and arrays.

Parameters

by_layer : bool
If True, the return value is a dictionary with the areas of each individual layer.

Returns

out : number, dictionary
Area of this cell.
cell_dict = {}

Dictionary containing all cells created, indexed by name. This dictionary is updated automatically whenever a new Cell object is created without the exclude_from_global flag.

copy(name, exclude_from_global=False)

Creates a copy of this cell.

Parameters

name : string
The name of the cell.

Returns

out : Cell
The new copy of this cell.
flatten(single_layer=None)

Flatten all CellReference and CellArray elements in this cell into real polygons, instead of references.

Parameters

single_layer : integer or None
If not None, all polygons will be transfered to the layer indicated by this number.

Returns

out : Cell
This cell.
get_bounding_box()

Returns the bounding box for this cell.

Returns

out : Numpy array[2,2] or None
Bounding box of this cell [[x_min, y_min], [x_max, y_max]], or None if the cell is empty.
get_dependencies()

Returns a list of the cells included in this cell as references.

Returns

out : list of Cell
List of the cells referenced by this cell.
get_layers()

Returns a list of layers in this cell.

Returns

out : list
List of the layers used in this cell.
get_polygons(by_layer=False, depth=None)

Returns a list of polygons in this cell.

Parameters

by_layer : bool
If True, the return value is a dictionary with the polygons of each individual layer.
depth : integer or None
If not None, defines from how many reference levels to retrieve polygons. References below this level will result in a bounding box in layer -1 (if by_layer=True).

Returns

out : list of array-like[N][2] or dictionary
List containing the coordinates of the vertices of each polygon, or dictionary with the list of polygons in each layer (if by_layer is True).
to_gds(multiplier)

Convert this cell to a GDSII structure.

Parameters

multiplier : number
A number that multiplies all dimensions written in the GDSII structure.

Returns

out : string
The GDSII binary string that represents this cell.

CellReference

class gdspy.CellReference(ref_cell, origin=(0, 0), rotation=None, magnification=None, x_reflection=False)

Simple reference to an existing cell.

Parameters

ref_cell : Cell or string
The referenced cell or its name.
origin : array-like[2]
Position where the reference is inserted.
rotation : number
Angle of rotation of the reference (in degrees).
magnification : number
Magnification factor for the reference.
x_reflection : bool
If True, the reference is reflected parallel to the x direction before being rotated.
area(by_layer=False)

Calculate the total area of the referenced cell with the magnification factor included.

Parameters

by_layer : bool
If True, the return value is a dictionary with the areas of each individual layer.

Returns

out : number, dictionary
Area of this cell.
get_bounding_box()

Returns the bounding box for this reference.

Returns

out : Numpy array[2,2] or None
Bounding box of this cell [[x_min, y_min], [x_max, y_max]], or None if the cell is empty.
get_polygons(by_layer=False, depth=None)

Returns a list of polygons created by this reference.

Parameters

by_layer : bool
If True, the return value is a dictionary with the polygons of each individual layer.
depth : integer or None
If not None, defines from how many reference levels to retrieve polygons. References below this level will result in a bounding box in layer -1 (if by_layer=True).

Returns

out : list of array-like[N][2] or dictionary
List containing the coordinates of the vertices of each polygon, or dictionary with the list of polygons in each layer (if by_layer is True).
to_gds(multiplier)

Convert this object to a GDSII element.

Parameters

multiplier : number
A number that multiplies all dimensions written in the GDSII element.

Returns

out : string
The GDSII binary string that represents this object.

CellArray

class gdspy.CellArray(ref_cell, columns, rows, spacing, origin=(0, 0), rotation=None, magnification=None, x_reflection=False)

Multiple references to an existing cell in an array format.

Parameters

ref_cell : Cell or string
The referenced cell or its name.
columns : positive integer
Number of columns in the array.
rows : positive integer
Number of columns in the array.
spacing : array-like[2]
distances between adjacent columns and adjacent rows.
origin : array-like[2]
Position where the cell is inserted.
rotation : number
Angle of rotation of the reference (in degrees).
magnification : number
Magnification factor for the reference.
x_reflection : bool
If True, the reference is reflected parallel to the x direction before being rotated.
area(by_layer=False)

Calculate the total area of the cell array with the magnification factor included.

Parameters

by_layer : bool
If True, the return value is a dictionary with the areas of each individual layer.

Returns

out : number, dictionary
Area of this cell.
get_bounding_box()

Returns the bounding box for this reference.

Returns

out : Numpy array[2,2] or None
Bounding box of this cell [[x_min, y_min], [x_max, y_max]], or None if the cell is empty.
get_polygons(by_layer=False, depth=None)

Returns a list of polygons created by this reference.

Parameters

by_layer : bool
If True, the return value is a dictionary with the polygons of each individual layer.
depth : integer or None
If not None, defines from how many reference levels to retrieve polygons. References below this level will result in a bounding box in layer -1 (if by_layer=True).

Returns

out : list of array-like[N][2] or dictionary
List containing the coordinates of the vertices of each polygon, or dictionary with the list of polygons in each layer (if by_layer is True).
to_gds(multiplier)

Convert this object to a GDSII element.

Parameters

multiplier : number
A number that multiplies all dimensions written in the GDSII element.

Returns

out : string
The GDSII binary string that represents this object.

Polygon

class gdspy.Polygon(layer, points, datatype=None, verbose=True)

Polygonal geometric object.

Parameters

layer : integer
The GDSII layer number for this element.
points : array-like[N][2]
Coordinates of the vertices of the polygon.
datatype : integer
The GDSII datatype for this element (between 0 and 255).
verbose : bool
If False, warnings about the number of vertices of the polygon will be suppressed.

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)
area(by_layer=False)

Calculate the total area of this object.

Parameters

by_layer : bool
If True, the return value is a dictionary {layer: area}.

Returns

out : number, dictionary
Area of this object.
fillet(radius, points_per_2pi=128, max_points=199)

Round the corners of this polygon and fractures it into polygons with less vertices if necessary.

Parameters

radius : number
Radius of the corners.
points_per_2pi : integer
Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi.
max_points : integer
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : Polygon or PolygonSet
If no fracturing occurs, return this object; otherwise return a PolygonSet with the fractured result (this object will have more than max_points vertices).
fracture(max_points=199)

Slice this polygon in the horizontal and vertical directions so that each resulting piece has at most max_points.

Parameters

max_points : integer
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
Resulting polygons from the fracture operation.
rotate(angle, center=(0, 0))

Rotate this object.

Parameters

angle : number
The angle of rotation (in radians).
center : array-like[2]
Center point for the rotation.

Returns

out : Polygon
This object.
to_gds(multiplier)

Convert this object to a GDSII element.

Parameters

multiplier : number
A number that multiplies all dimensions written in the GDSII element.

Returns

out : string
The GDSII binary string that represents this object.

Rectangle

class gdspy.Rectangle(layer, point1, point2, datatype=None)

Bases: gdspy.Polygon

Rectangular geometric object.

Parameters

layer : integer
The GDSII layer number for this element.
point1 : array-like[2]
Coordinates of a corner of the rectangle.
point2 : array-like[2]
Coordinates of the corner of the rectangle opposite to point1.
datatype : integer
The GDSII datatype for this element (between 0 and 255).

Examples

>>> rectangle = gdspy.Rectangle(1, (0, 0), (10, 20))
>>> myCell.add(rectangle)
area(by_layer=False)

Calculate the total area of this object.

Parameters

by_layer : bool
If True, the return value is a dictionary {layer: area}.

Returns

out : number, dictionary
Area of this object.
fillet(radius, points_per_2pi=128, max_points=199)

Round the corners of this polygon and fractures it into polygons with less vertices if necessary.

Parameters

radius : number
Radius of the corners.
points_per_2pi : integer
Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi.
max_points : integer
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : Polygon or PolygonSet
If no fracturing occurs, return this object; otherwise return a PolygonSet with the fractured result (this object will have more than max_points vertices).
fracture(max_points=199)

Slice this polygon in the horizontal and vertical directions so that each resulting piece has at most max_points.

Parameters

max_points : integer
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
Resulting polygons from the fracture operation.
rotate(angle, center=(0, 0))

Rotate this object.

Parameters

angle : number
The angle of rotation (in radians).
center : array-like[2]
Center point for the rotation.

Returns

out : Polygon
This object.
to_gds(multiplier)

Convert this object to a GDSII element.

Parameters

multiplier : number
A number that multiplies all dimensions written in the GDSII element.

Returns

out : string
The GDSII binary string that represents this object.

Round

class gdspy.Round(layer, center, radius, inner_radius=0, initial_angle=0, final_angle=0, number_of_points=199, max_points=199, datatype=None)

Bases: gdspy.PolygonSet

Circular geometric object. Represent a circle, a circular section, a ring or a ring section.

Parameters

layer : integer
The GDSII layer number for this element.
center : array-like[2]
Coordinates of the center of the circle/ring.
radius : number
Radius of the circle/outer radius of the ring.
inner_radius : number
Inner radius of the ring.
initial_angle : number
Initial angle of the circular/ring section (in radians).
final_angle : number
Final angle of the circular/ring section (in radians).
number_of_points : integer
number of vertices that form the object (polygonal approximation).
max_points : integer
if number_of_points > max_points, the element will be fractured in smaller polygons with at most max_points each.
datatype : integer
The GDSII datatype for this element (between 0 and 255).

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)
area(by_layer=False)

Calculate the total area of the path(s).

Parameters

by_layer : bool
If True, the return value is a dictionary C{{layer: area}}.

Returns

out : number, dictionary
Area of this object.
fillet(radius, points_per_2pi=128, max_points=199)

Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

Parameters

radius : number
Radius of the corners.
points_per_2pi : integer
Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi.
max_points : integer
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
fracture(max_points=199)

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
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
rotate(angle, center=(0, 0))

Rotate this object.

Parameters

angle : number
The angle of rotation (in radians).
center : array-like[2]
Center point for the rotation.

Returns

out : PolygonSet
This object.
to_gds(multiplier)

Convert this object to a series of GDSII elements.

Parameters

multiplier : number
A number that multiplies all dimensions written in the GDSII elements.

Returns

out : string
The GDSII binary string that represents this object.

PolygonSet

class gdspy.PolygonSet(layer, polygons, datatype=None, verbose=True)

Set of polygonal objects.

Parameters

layer : integer
The GDSII layer number for this element.
polygons : list of array-like[N][2]
List containing the coordinates of the vertices of each polygon.
datatype : integer
The GDSII datatype for this element (between 0 and 255).
verbose : bool
If False, warnings about the number of vertices of the polygons will be suppressed.

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.

area(by_layer=False)

Calculate the total area of the path(s).

Parameters

by_layer : bool
If True, the return value is a dictionary C{{layer: area}}.

Returns

out : number, dictionary
Area of this object.
fillet(radius, points_per_2pi=128, max_points=199)

Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

Parameters

radius : number
Radius of the corners.
points_per_2pi : integer
Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi.
max_points : integer
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
fracture(max_points=199)

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
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
rotate(angle, center=(0, 0))

Rotate this object.

Parameters

angle : number
The angle of rotation (in radians).
center : array-like[2]
Center point for the rotation.

Returns

out : PolygonSet
This object.
to_gds(multiplier)

Convert this object to a series of GDSII elements.

Parameters

multiplier : number
A number that multiplies all dimensions written in the GDSII elements.

Returns

out : string
The GDSII binary string that represents this object.

Path

class gdspy.Path(width, initial_point=(0, 0), number_of_paths=1, distance=0)

Bases: gdspy.PolygonSet

Series of geometric objects that form a path or a collection of parallel paths.

Parameters

width : number
The width of each path.
initial_point : array-like[2]
Starting position of the path.
number_of_paths : positive integer
Number of parallel paths to create simultaneously.
distance : number
Distance between the centers of adjacent paths.

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.
arc(layer, radius, initial_angle, final_angle, number_of_points=199, max_points=199, final_width=None, final_distance=None, datatype=None)

Add a curved section to the path.

Parameters

layer : integer, list
The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated.
radius : number
Central radius of the section.
initial_angle : number
Initial angle of the curve (in radians).
final_angle : number
Final angle of the curve (in radians).
number_of_points : integer
Number of vertices that form the object (polygonal approximation).
max_points : integer
if number_of_points > max_points, the element will be fractured in smaller polygons with at most max_points each.
final_width : number
If set, the paths of this segment will have their widths linearly changed from their current value to this one.
final_distance : number
If set, the distance between paths is linearly change from its current value to this one along this segment.
datatype : integer, list
The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.

Returns

out : Path
This object.

Notes

The GDSII specification supports only a maximum of 199 vertices per polygon.

area(by_layer=False)

Calculate the total area of the path(s).

Parameters

by_layer : bool
If True, the return value is a dictionary C{{layer: area}}.

Returns

out : number, dictionary
Area of this object.
fillet(radius, points_per_2pi=128, max_points=199)

Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

Parameters

radius : number
Radius of the corners.
points_per_2pi : integer
Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi.
max_points : integer
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
fracture(max_points=199)

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
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
parametric(layer, curve_function, curve_derivative=None, number_of_evaluations=99, max_points=199, final_width=None, final_distance=None, datatype=None)

Add a parametric curve to the path.

Parameters

layer : integer, list
The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated.
curve_function : function
Function that defines the curve. Must be a function of one argument (that varies from 0 to 1) that returns a 2-element list, tuple or array (x, y).
curve_derivative : function
If set, it should be the derivative of the curve function. Must be a function of one argument (that varies from 0 to 1) that returns a 2-element list, tuple or array (x,y). If None, the derivative will be calculated numerically.
number_of_evaluations : integer
Number of points where the curve function will be evaluated. The final segment will have twice this number of points.
max_points : integer
if 2 * number_of_evaluations > max_points, the element will be fractured in smaller polygons with at most max_points each.
final_width : number
If set, the paths of this segment will have their widths linearly changed from their current value to this one.
final_distance : number
If set, the distance between paths is linearly change from its current value to this one along this segment.
datatype : integer, list
The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.

Returns

out : Path
This object.

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(angle, center=(0, 0))

Rotate this object.

Parameters

angle : number
The angle of rotation (in radians).
center : array-like[2]
Center point for the rotation.

Returns

out : Path
This object.
segment(layer, length, direction=None, final_width=None, final_distance=None, axis_offset=0, datatype=None)

Add a straight section to the path.

Parameters

layer : integer, list
The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated.
length : number
Length of the section to add.
direction : {‘+x’, ‘-x’, ‘+y’, ‘-y’} or number
Direction or angle (in radians) of rotation of the segment.
final_width : number
If set, the paths of this segment will have their widths linearly changed from their current value to this one.
final_distance : number
If set, the distance between paths is linearly change from its current value to this one along this segment.
axis_offset : number
If set, the paths will be offset from their direction by this amount.
datatype : integer, list
The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.

Returns

out : Path
This object.
to_gds(multiplier)

Convert this object to a series of GDSII elements.

Parameters

multiplier : number
A number that multiplies all dimensions written in the GDSII elements.

Returns

out : string
The GDSII binary string that represents this object.
turn(layer, radius, angle, number_of_points=199, max_points=199, final_width=None, final_distance=None, datatype=None)

Add a curved section to the path.

Parameters

layer : integer, list
The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated.
radius : number
Central radius of the section.
angle : {‘r’, ‘l’, ‘rr’, ‘ll’} or number
Angle (in radians) of rotation of the path. The values ‘r’ and ‘l’ represent 90-degree turns cw and ccw, respectively; the values ‘rr’ and ‘ll’ represent analogous 180-degree turns.
number_of_points : integer
Number of vertices that form the object (polygonal approximation).
max_points : integer
if number_of_points > max_points, the element will be fractured in smaller polygons with at most max_points each.
final_width : number
If set, the paths of this segment will have their widths linearly changed from their current value to this one.
final_distance : number
If set, the distance between paths is linearly change from its current value to this one along this segment.
datatype : integer, list
The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.

Returns

out : Path
This object.

Notes

The GDSII specification supports only a maximum of 199 vertices per polygon.

PolyPath

class gdspy.PolyPath(layer, points, width, number_of_paths=1, distance=0, corners=0, max_points=199, datatype=None)

Bases: gdspy.PolygonSet

Series of geometric objects that form a polygonal path or a collection of parallel polygonal paths.

Parameters

layer : integer, list
The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated.
points : array-like[N][2]
Endpoints of each path segment.
width : number or array-like[N]
Width of the path. If an array is given, width at each endpoint.
number_of_paths : positive integer
Number of parallel paths to create simultaneously.
distance : number or array-like[N]
Distance between the centers of adjacent paths. If na array is given, distance at each endpoint.
corners : positive integer
Type of the joins: 0 - miter join, 1 - bevel join
max_points : integer
The paths will be fractured in polygons with at most max_points.
datatype : integer, list
The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.

Returns

out : PolyPath
This object.

Notes

The bevel joint will give strange results if the number of paths is greater than 1.

area(by_layer=False)

Calculate the total area of the path(s).

Parameters

by_layer : bool
If True, the return value is a dictionary C{{layer: area}}.

Returns

out : number, dictionary
Area of this object.
fillet(radius, points_per_2pi=128, max_points=199)

Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

Parameters

radius : number
Radius of the corners.
points_per_2pi : integer
Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi.
max_points : integer
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
fracture(max_points=199)

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
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
rotate(angle, center=(0, 0))

Rotate this object.

Parameters

angle : number
The angle of rotation (in radians).
center : array-like[2]
Center point for the rotation.

Returns

out : PolygonSet
This object.
to_gds(multiplier)

Convert this object to a series of GDSII elements.

Parameters

multiplier : number
A number that multiplies all dimensions written in the GDSII elements.

Returns

out : string
The GDSII binary string that represents this object.

L1Path

class gdspy.L1Path(layer, initial_point, direction, width, length, turn, number_of_paths=1, distance=0, max_points=199, datatype=None)

Bases: gdspy.PolygonSet

Series of geometric objects that form a path or a collection of parallel paths with Manhattan geometry.

Parameters

layer : integer, list
The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated.
initial_point : array-like[2]
Starting position of the path.
direction : {‘+x’, ‘+y’, ‘-x’, ‘-y’}
Starting direction of the path.
width : number
The initial width of each path.
length : array-like
Lengths of each section to add.
turn : array-like
Direction to turn before each section. The sign indicate the turn direction (ccw is positive), and the modulus is a multiplicative factor for the path width after each turn. Must have 1 element less then length.
number_of_paths : positive integer
Number of parallel paths to create simultaneously.
distance : number
Distance between the centers of adjacent paths.
datatype : integer, list
The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.

Returns

out : L1Path
This object.

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.

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)
area(by_layer=False)

Calculate the total area of the path(s).

Parameters

by_layer : bool
If True, the return value is a dictionary C{{layer: area}}.

Returns

out : number, dictionary
Area of this object.
fillet(radius, points_per_2pi=128, max_points=199)

Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

Parameters

radius : number
Radius of the corners.
points_per_2pi : integer
Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi.
max_points : integer
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
fracture(max_points=199)

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
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
rotate(angle, center=(0, 0))

Rotate this object.

Parameters

angle : number
The angle of rotation (in radians).
center : array-like[2]
Center point for the rotation.

Returns

out : L1Path
This object.
to_gds(multiplier)

Convert this object to a series of GDSII elements.

Parameters

multiplier : number
A number that multiplies all dimensions written in the GDSII elements.

Returns

out : string
The GDSII binary string that represents this object.

Text

class gdspy.Text(layer, text, size, position=(0, 0), horizontal=True, angle=0, datatype=None)

Bases: gdspy.PolygonSet

Polygonal text object.

Each letter is formed by a series of polygons.

Parameters

layer : integer
The GDSII layer number for these elements.
text : string
The text to be converted in geometric objects.
size : number
Base size of each character.
position : array-like[2]
Text position (lower left corner).
horizontal : bool
If True, the text is written from left to right; if False, from top to bottom.
angle : number
The angle of rotation of the text.
datatype : integer
The GDSII datatype for this element (between 0 and 255).

Examples

>>> text = gdspy.Text(8, 'Sample text', 20, (-10, -100))
>>> myCell.add(text)
area(by_layer=False)

Calculate the total area of the path(s).

Parameters

by_layer : bool
If True, the return value is a dictionary C{{layer: area}}.

Returns

out : number, dictionary
Area of this object.
fillet(radius, points_per_2pi=128, max_points=199)

Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

Parameters

radius : number
Radius of the corners.
points_per_2pi : integer
Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi.
max_points : integer
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
fracture(max_points=199)

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
Maximal number of points in each resulting polygon (must be greater than 4).

Returns

out : PolygonSet
This object.
rotate(angle, center=(0, 0))

Rotate this object.

Parameters

angle : number
The angle of rotation (in radians).
center : array-like[2]
Center point for the rotation.

Returns

out : PolygonSet
This object.
to_gds(multiplier)

Convert this object to a series of GDSII elements.

Parameters

multiplier : number
A number that multiplies all dimensions written in the GDSII elements.

Returns

out : string
The GDSII binary string that represents this object.

Functions

boolean

gdspy.boolean(layer, objects, operation, max_points=199, datatype=None, eps=1e-13)

Execute any boolean operation on polygons and polygon sets.

Parameters

layer : integer
The GDSII layer number for the resulting element.
objects : array-like
Operands of the boolean operation. Each element of this array must be a Polygon, PolygonSet, CellReference, CellArray, or an array-like[N][2] of vertices of a polygon.
operation : function
Function that accepts as input len(objects) integers. Each integer represents the incidence of the corresponding object. The function must return a bool or integer (interpreted as bool).
max_points : integer
If greater than 4, fracture the resulting polygons to ensure they have at most max_points vertices. This is not a tessellating function, so this number should be as high as possible. For example, it should be set to 199 for polygons being drawn in GDSII files.
datatype : integer
The GDSII datatype for the resulting element (between 0 and 255).
eps : positive number
Small number to be used as tolerance in intersection and overlap calculations.

Returns

out : PolygonSet
Result of the boolean operation.

Notes

Since operation receives a list of integers as input, it can be somewhat more general than boolean operations only. See the examples below.

Because of roundoff errors there are a few cases when this function can cause segmentation faults. If that happens, increasing the value of eps might help.

Examples

>>> circle = gdspy.Round(0, (0, 0), 10)
>>> triangle = gdspy.Round(0, (0, 0), 12, 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 cir, tri: cir or tri)
>>> intersection = gdspy.boolean(1, [circle, triangle],
                lambda cir, tri: cir and tri)
>>> subtraction = gdspy.boolean(1, [circle, triangle],
                lambda cir, tri: cir and not tri)
>>> multi_xor = gdspy.boolean(1, [badPath], lambda p: p % 2)

slice

gdspy.slice(layer, objects, position, axis, datatype=None)

Slice polygons and polygon sets at given positions along an axis.

Parameters

layer : integer, list
The GDSII layer numbers for the elements between each division. If the number of layers in the list is less than the number of divided regions, the list is repeated.
objects : Polygon, PolygonSet, or list
Operand of the slice operation. If this is a list, each element must be a Polygon, PolygonSet, CellReference, CellArray, or an array-like[N][2] of vertices of a polygon.
position : number or list of numbers
Positions to perform the slicing operation along the specified axis.
axis : 0 or 1
Axis along which the polygon will be sliced.
datatype : integer
The GDSII datatype for the resulting element (between 0 and 255).

Returns

out : list[N] of PolygonSet
Result of the slicing operation, with N = len(positions) + 1. Each PolygonSet comprises all polygons between 2 adjacent slicing positions, in crescent order.

Examples

>>> ring = gdspy.Round(1, (0, 0), 10, inner_radius = 5)
>>> result = gdspy.slice(1, ring, [-7, 7], 0)
>>> cell.add(result[1])

Variables

gdspy.current_default_datatype = 0

Default datatype for created structures.

This value is used as the datatype for structures created with a datatype None (default). It works as a state variable.

Table Of Contents

Previous topic

Sample File

Next topic

Import and Output

This Page