heitzmann / gdspy Goto Github PK
View Code? Open in Web Editor NEWPython module for creating GDSII stream files, usually CAD layouts.
License: Boost Software License 1.0
Python module for creating GDSII stream files, usually CAD layouts.
License: Boost Software License 1.0
I use conder python 3.6 and gdspy 1.3.1, I found if I set cells=[topcell], write_gds can't export the CellReference in the topcell, I must set cells=None, but the other cell will be exported too.
so I update the gdspy init code as below, for your reference.
I add one more function.
def CellList(cell,celllist=[],First=True):
if isinstance(cell,Cell):
if First==True:
celllist.append(cell)
for r in cell.elements:
if isinstance(r,CellReference):
celllist.append(r.ref_cell)
CellList(r.ref_cell,celllist=celllist,First=False)
return celllist
else:
return None
and also, I update def wirte_gds() as below:
def write_gds(outfile,
cells=None,
name='library',
unit=1.0e-6,
precision=1.0e-9):
current_library.name = name
current_library.unit = unit
current_library.precision = precision
totalcell=[]
if isinstance(cells,Cell):
totalcell=cellList(cells,celllist=[])
current_library.write_gds(outfile, totalcell)
elif isinstance(cells,list):
for cell in cells:
totalcell=totalcell+cellList(cell,celllist=[])
totalcell=set(totalcell)
current_library.write_gds(outfile, totalcell)
and then, if my code is gdspy.write_gds('a.gds',topcell), all the cellreference in the topcell can be exported successfully.
Following up on release 1.1 on Windows 7, python 3.5 64bit:
Installer (gdspy-1.1.win-amd64-py3.5.exe) doesn't work for me, error: Python 3.5-32 is required for this package.
When using pip I get the following error:
line 26, in with open('README.md') as fin: FileNotFoundError: [Errno 2] No such file or directory: 'README.md'
Using Setuptools v34 and ez-setup 0.9.
Note that Installing gdspy1.0 works flawlessly with pip on this setup.
Thanks for the new version, really appreciate your work!
I would like to propose some improvements to the description of Gdspy and clarifications to the installation instructions.
Gdspy is a Python module for creating/importing/merging of GDSII stream files. It includes key libraries for creating complex CAD layouts:
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.
Option 1: Download Gdspy and build from source using the following command:
python setup.py install
Option 2: Install Gdspy with pip:
pip install gdspy
Option 1: The preferred option is to install Gdspy using pre-compiled binaries that can be downloaded here for 32-bit or 64-bit systems. First, download a portable WinPython (tested with WinPython-64bit-3.5.2.2), run the executable to unpack the files to a directory. In the directory, run "WinPython Control Panel.exe" and click "Add packages". Select the downloaded Gdspy binary executable and click on "Install packages".
Option 2: Gdspy can also be built from source using a development environment to compile the boolean extension module using python setup.py install
command.
Having some issues installing gdspy v1.0 on Windows, my version is Python 3.5.2 :: Anaconda 4.0.0 (64-bit).
Tried pip install, and got a " Failed building wheel for gdspy" error.
Tried the pre-compiled binaries install option using gdspy-1.0.win-amd64-py3.5.exe, and get "Python version 3.5 -32 required, which was not found in the registry" error. Made sure I did execute the 64-bit version.
Any chance you can produce a new binary for Python 3.5 x64?
Thanks!
The present implementation seems to use current date and time for GDS cell and library timestamps. As a result, GDS files created from the same layout at different points in time will have different binary headers. While appropriate in most situations, this behaviour complicates some use cases that involve binary comparison of GDS files (e.g. regression testing).
I would like to propose to add an optional timestamp=None
argument to Cell.to_gds()
, GdsLibrary.write_gds()
, and GdsWriter()
constructor. If set to None
(the default), the functions would use the current date and time, otherwise the user-supplied timestamp would be used.
I created a new PolygonSet by applying
shape=gdspy.fast_boolean(Rectangle, Circle, 'not')
where Rectangle and Circle are partially overlapping. After that I merged all resulting polygons via merged=gdspy.fast_boolean(shape, None, 'or')
and applied the fillet method
merged.fillet(20, 100)
.
In the resulting shape, corners along the overlap path of the original shapes are not rounded accordingly or an erroneous shape is being generated.
When using gds_read
, I found that the polygons are represented as numpy.ndarray
of dtype('O')
, i.e. object
, not, say float
or 'float64'.
For feeding the polygons to programs downstream, sometimes this matters, sometimes not. For example matplotlib and FreeCAD recognize the coordinates as numbers but PyGmsh doesn't.
To demonstrate, take any gds, say tutorial.gds from here, and
gds = GdsLibrary()
gds.read_gds(argv[1])
for layer, v in gds.top_level()[0].get_polygons(True).iteritems():
print(layer, map(lambda p: (p.shape, p.dtype), v))
The workaround is trivial of course, just p.astype(float)
(as in Polygon.fillet
) or np.asarray(p, dtype=float)
if a function is preferred to a method, but I was curious as to why the coordinates weren't numeric in the first place.
gdspy.Cell.copy()
provides the ability to create a deep copy of a cell. It was noticed that when this is done for nested cells, any CellReferences
within the cell have a their _bb_valid
flags set to True
. Hence, if you perform a deep copy of a cell, and then try to get its bounding box using get_bounding_box()
, the algorithm fails, generating a KeyError
at the return statement of gdspy.Cell.get_bounding_box()
method.
I do not know all the implications of this, but at the very least, I believe the _bb_valid
flags for the dependencies have to be explicitly set to False
within cell.copy()
to allow recalculation of the bounding boxes:
for ref in new_cell.get_dependencies(True):
if ref._bb_valid:
print('Reference ' + str(ref) + ' bb_valid flag is True, set to False')
ref._bb_valid = False
Good day
I want to add every element in a GDS file to an array. Currently I am doing this:
file1 = gdspy.GdsImport('Dcsfq.gds')
cell = file1.extract(file1.top_level()[0])
//Found this at another issue topic
references = []
for element in cell.elements:
if isinstance(element, gdspy.CellReference):
print 'Cell ' + element.ref_cell.name + ' referenced at ' + str(element.origin)
references.append((element.ref_cell, element.origin))
elif isinstance(element, gdspy.CellArray):
print 'Array of cells ' + element.ref_cell.name + ' referenced at ' + str(element.origin)
references.append((element.ref_cell, element.origin))
This gives me the list of all the element references as it should, but I need to know the locations of the polys and other basic elements as well. I think the problem lies with the fact that I am only getting the top layer. Is there a way to loop through the file to obtain the location and type (polys, slices etc) and put it all on an array.
For instance if I basically want to replicate an entire gds file (I know I use simpler methods, this is just for explaining purposes) and i want to find the location of each element in the file and make a new cell containing all the elements and their original locations.
The reason I want to do this, is because I have multiple files that I want to merge, but they contain elements with the same names so i cant just use
ref_cell.add(gdspy.CellReference(cell2, (150,0)))
ref_cell.add(gdspy.CellReference(cell1,(0,0)))
ref_cell.add(gdspy.CellReference(cell3, (225,-150), rotation=90))
as then I get double naming. So if there is an easier way then I am proposing, I am open to try anything. Also let me know if I should post any of my files or more information.
Sorry for the long post and thanks for any feedback.
If tkinter is not present on the system then LayoutViewer fails to import at all:
>>> import gdspy
>>> gdspy.LayoutViewer()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'LayoutViewer'
Just thought I would let you know that it fails without indicating that a dependency is missing.
@heitzmann As we go between gdspy versions and our own software versions, we validate each transition by regenerating all .gds file masks and comparing if their content has changed compared to when they were originally created. This allows us to detect any software/packages bugs. In order to achieve this, .gds files are hashed using SHA-1 and then the hashes are compared. However, we have encountered the following challenge: .gds files appear to be always different even if they are generated by the same code. The difference was traced to the timestamp that is embedded by gdspy when .gds files are written. Our attempts to exclude timestamps within the binary files, and compare the rest of binary content, runs into difficulties because of structural differences of various files. Could you please advise on how best to tackle this issue?
FYI, I've started developing with this on Python 3.5 and I haven't had any trouble so far.
Had to get VS14 for pip to install (I'm on Win10), but it was fine after that. Probably could generate a wheel for it though, if you wanted?
Hi, based on class Round(), I add class Ellipse(), it is very usefule for me.
class Ellipse(PolygonSet):
__slots__ = 'layers', 'datatypes', 'polygons'
def __init__(self,
center,
radius_x,
radius_y,
inner_radius_x=0,
inner_radius_y=0,
initial_angle=0,
final_angle=0,
number_of_points=100,
max_points=199,
layer=0,
datatype=0):
radius=max(radius_x,radius_y)
if isinstance(number_of_points, float):
if inner_radius_x <= 0 and inner_radius_y<=0:
if final_angle == initial_angle:
number_of_points = int(
2 * radius * numpy.pi / number_of_points + 0.5)
else:
number_of_points = int(
abs(final_angle - initial_angle) * radius /
number_of_points + 0.5) + 2
else:
if final_angle == initial_angle:
number_of_points = 2 * int(
2 * radius * numpy.pi / number_of_points + 0.5) + 2
else:
number_of_points = 2 * int(
abs(final_angle - initial_angle) * radius /
number_of_points + 0.5) + 2
number_of_points = max(number_of_points, 3)
pieces = int(numpy.ceil(number_of_points / float(max_points)))
number_of_points = number_of_points // pieces
self.layers = [layer] * pieces
self.datatypes = [datatype] * pieces
self.polygons = [
numpy.zeros((number_of_points, 2)) for _ in range(pieces)
]
if final_angle == initial_angle and pieces > 1:
final_angle += 2 * numpy.pi
angles = numpy.linspace(initial_angle, final_angle, pieces + 1)
for ii in range(pieces):
if angles[ii + 1] == angles[ii]:
if inner_radius_x <= 0 and inner_radius_y<=0:
angle = numpy.arange(
number_of_points) * 2.0 * numpy.pi / number_of_points
self.polygons[ii][:, 0] = numpy.cos(angle)*radius_x
self.polygons[ii][:, 1] = numpy.sin(angle)*radius_y
self.polygons[ii] = (
self.polygons[ii] + numpy.array(center))
else:
n2 = number_of_points // 2
n1 = number_of_points - n2
angle = numpy.arange(n1) * 2.0 * numpy.pi / (n1 - 1.0)
self.polygons[ii][:n1, 0] = (
numpy.cos(angle) * radius_x + center[0])
self.polygons[ii][:n1, 1] = (
numpy.sin(angle) * radius_y + center[1])
angle = numpy.arange(n2) * -2.0 * numpy.pi / (n2 - 1.0)
self.polygons[ii][n1:, 0] = (
numpy.cos(angle) * inner_radius_x + center[0])
self.polygons[ii][n1:, 1] = (
numpy.sin(angle) * inner_radius_y + center[1])
else:
if inner_radius_x <= 0 and inner_radius_y<=0:
angle = numpy.linspace(angles[ii], angles[ii + 1],
number_of_points - 1)
self.polygons[ii][1:, 0] = numpy.cos(angle)* radius_x
self.polygons[ii][1:, 1] = numpy.sin(angle)* radius_y
self.polygons[ii] = (
self.polygons[ii] + numpy.array(center))
else:
n2 = number_of_points // 2
n1 = number_of_points - n2
angle = numpy.linspace(angles[ii], angles[ii + 1], n1)
self.polygons[ii][:n1, 0] = (
numpy.cos(angle) * radius_x + center[0])
self.polygons[ii][:n1, 1] = (
numpy.sin(angle) * radius_y + center[1])
angle = numpy.linspace(angles[ii + 1], angles[ii], n2)
self.polygons[ii][n1:, 0] = (
numpy.cos(angle) * inner_radius_x + center[0])
self.polygons[ii][n1:, 1] = (
numpy.sin(angle) * inner_radius_y + center[1])
def __str__(self):
return ("Round ({} polygons, {} vertices, layers {}, datatypes "
"{})").format(
len(self.polygons), sum([len(p) for p in self.polygons]),
list(set(self.layers)), list(set(self.datatypes)))
Value entered for precision doesn't seem to affect the result in any way. Expected result would be all points being on a grid of size precision but that doesn't seem to be the case.
I am trying to make rectangular shape array structure (all rectangular shape are same size), whose rotation angle is decided by formula. I am directly calculating the rotate value using a formula in radian. When the rotation angle is small, everything is ok, rectangular shaped fixed at particular location, but if theta values is large, it is making mistake to fixed the location of rectangular shape, more precisely the coordinate of each rectangular location changes with large theta values. I do not understand the reason, I am quite new in Python. Attaching both files for reference. I am not sure that it's my programming mistake or related to this package.
I will be happy if you could answer. personal mail Id [email protected]
`
import numpy
import gdspy
import math
print('Using gdspy module version ' + gdspy.version)
poly_cell = gdspy.Cell('POLYGONS')
trans_cell = gdspy.Cell('TRANS')
nm=1e-9;
um=1e-6;
#rect_1 = gdspy.Rectangle( (0.0, 0.0), (250nm, 95nm), 1 ).rotate(3.14/6) # Define horigontal rectangle
ncells = 5
P = 325nm
Lambda = 532nm
c = 3e8
f = 50*um
#A = 10
for iind in xrange (-ncells, ncells):
for jind in xrange(-ncells, ncells):
#print( jind)
rel_x1 = iindP # New location of the next polygons.
rel_y1 = jindP
print(rel_x1,rel_y1)
temp = (rel_x12) + (rel_y12)
print(temp)
temp1 = ((rel_x12) + (rel_y12) + (f2))(0.5)
print(temp1)
Theta = 100numpy.pi(f-temp1)/Lambda # When 100 times, the location of rect changes.
print(Theta)
rect_1 = gdspy.Rectangle( (0.0, 0.0), (250nm, 95nm), 1 ).rotate(Theta)
poly1 = gdspy.copy(rect_1, rel_x1,rel_y1) # Copy the first polygons into new location rel_x and rel_y.
trans_cell.add(poly1) # Adding them in layer. If you dont add them nothing will appear.
#text1 = gdspy.Text('BLUE 220 X 22 ' , 6, (15, -10), horizontal=True, angle=0, layer=1) # Horizontal is false meaning vertical text.
#trans_cell.add(text1)
#label1 = gdspy.Label('BLUE 220 X 22 ',(15, -15), 'nw', layer=1)
#trans_cell.add(label1)
gdspy.write_gds('lens.gds', unit=1.0, precision=1.0e-12)
gdspy.LayoutViewer()
`
@heitzmann I have installed the latest release (Patch 1.1.1) on Mac OSX, and am observing a different behaviour for the GDSII writing functionality compared to previous releases.
In the past (release 1.0), gds_print()
would accept a list of cells to be included in the output file, and then append any cell dependencies to the list of cells to be written. Here's the relevant code:
if cells == None:
cells = iter(Cell.cell_dict.values())
else:
cells = [Cell.cell_dict.get(c, c) for c in cells]
i = 0
while i < len(cells):
for cell in cells[i].get_dependencies():
if cell not in cells:
cells.append(cell)
i += 1
...
for cell in cells:
outfile.write(cell.to_gds(unit / precision))
This worked flawlessly for deeply hierarchical cell structures.
The implementation of this functionality in 1.1.1 (write_gds()
function), however, does not explicitly add the dependencies:
if cells is None:
cells = self.cell_dict.values()
else:
cells = [self.cell_dict.get(c, c) for c in cells]
for cell in cells:
outfile.write(cell.to_gds(unit / precision))
resulting in an empty GDSII file. If I add the while / for block (the part in bold above), the dependencies are indeed added, and the resulting file contains all intended hierarchy.
Should the dependencies be explicitly added here, as before? Or am I missing something in the new implementation of GdsLibrary
?
@heitzmann I am observing errors in the boolean subtraction algorithm in the latest gdspy 1.1.1.
Errors seem to occur with any structures that contain holes. An example below creates two polygon sets, in a shape of the digits 8 and 6. It then subtracts two identical cells. gdspy 1.0 produces an empty result, as expected. On the other hand, the boolean not
algorithm in gdspy 1.1.1 generates incorrect triangular structures.
import gdspy
coords8 = [[[-1.16635, -0.5 ], [-1.16635, 0.5 ], [-0.99945, 0.5 ], [-0.99945, -0.5 ]],
[[-0.99945, 0.3331 ], [-0.99945, 0.5 ], [-0.50005, 0.5 ], [-0.50005, -0.5 ],
[-0.99945, -0.5 ], [-0.99945, -0.3331 ], [-0.66695, -0.3331 ], [-0.66695, -0.08345],
[-0.99945, -0.08345], [-0.99945, 0.08345], [-0.66695, 0.08345], [-0.66695, 0.3331 ]]]
coords6 = [[[ 0.50005, -0.5 ], [ 0.50005, 0.5 ], [ 1.16635, 0.5 ], [ 1.16635, 0.3331 ], [ 0.66695, 0.3331 ], [ 0.66695, -0.5 ]],
[[ 0.66695, -0.5 ], [ 1.16635, -0.5 ], [ 1.16635, 0.08345], [ 0.66695, 0.08345], [ 0.66695, -0.08345], [ 0.99945, -0.08345], [ 0.99945, -0.3331 ], [ 0.66695, -0.3331 ]]]
poly8_layer1 = gdspy.PolygonSet(coords8, 1)
poly6_layer1 = gdspy.PolygonSet(coords6, 1)
poly8_layer2 = gdspy.PolygonSet(coords8, 2)
poly6_layer2 = gdspy.PolygonSet(coords6, 2)
cell1 = gdspy.Cell('CELL1')
cell2 = gdspy.Cell('CELL2')
cell1.add(poly8_layer1)
cell1.add(poly6_layer1)
cell2.add(poly8_layer2)
cell2.add(poly6_layer2)
cell_ref1 = gdspy.CellReference(cell1)
cell_ref2 = gdspy.CellReference(cell2)
result = gdspy.fast_boolean(cell_ref1, cell_ref2, 'not')
result_cell = gdspy.Cell('DIFF_CELL')
result_cell.add(result)
gdspy.write_gds('boolean_subtract_test_example.gds', cells=[cell1, cell2, result_cell]) # for gdspy 1.1.1
gdspy.print_gds('boolean_subtract_test_example.gds', cells=[result_cell]) # for gdspy 1.0
I've tried:
pip install gdspy
and also
git clone github:gdspy.git
followed by
pip install -e gdspy
The install goes fine, but the importing fails every time with the following message:
gdspy/clipper.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm
This works fine under Anaconda on OS X with python 3.6.
I tried installing the pyclipper
package from PyPI and it works fine (it is also a python wrapper for the C++ clipper library).
Hay there
I currently have 3 GDSII files that I am combining into one layout. I have managed to get all 3 cells into one cell and transposed and rotated them as necessary. Now I would only like to save one the one cell I have to a new GDS file.
import gdspy
file1 = gdspy.GdsImport('Dcsfq.gds')
file2 = gdspy.GdsImport('Conf2.gds')
file3 = gdspy.GdsImport('Tff4b.gds')
cell1 = file1.extract(file1.top_level()[0])
cell2 = file2.extract(file2.top_level()[0])
cell3 = file3.extract(file3.top_level()[0])
ref_cell = gdspy.Cell('TRANSLATED')
ref_cell.add(gdspy.CellReference(cell2, (150,0)))
ref_cell.add(gdspy.CellReference(cell1, (0,0)))
ref_cell.add(gdspy.CellReference(cell3, (225,-150), rotation=90))
newgds = gdspy.GdsPrint('new_gds.gds', unit=1.0e-6, precision=1.0e-9)
newgds.write_cell(ref_call)
newgds.close()
This however gives me an empty GDSII file. Am I doing the translations/rotation wrong, or is it the way I save the file that is not done properly? If someone could assist me with this I would be very greatful
Thanks
Hi Lucas,
Two questions:
Thanks,
Lawrence Tzuang
@heitzmann Hi, I use write_gds function, but all CellReference in the topcell are missing in the gds file.
Now, I use two method to solve this issue.
1: gdspy.wirte_gds('.gds',cells=None), this method, other topcell are wirted into the gds file too.
2: gdspy.write_gds('.gds',list(topcell.get_dependencies(True))+[topcell]), this method seems to work very well.
Do you have any other better suggestion?
thanks very much!
Hi
maybe not totally related to gdspy, but I just wonder if there is a common convention regarding the polygon vertices orientation in GDS file. The file I am opening has counter-clockwise but I read somewhere that GDS format does not dictate one way or the other. Is this true? How to express holes in a polygon then?
Thanks
enuinc
Trying to import a bunch of similar designs from externally made GDS files that have identical subcells.
I imagine the easy way to do this would be to add an overwrite_duplicate=False variable to extract and pass it directly to add.
Good day.
I seem to be spamming the forums a bit. Sorry for that. I am currently trying to compile my .py script to an exe. The script containt gdspy of course. I can't seem to find a way to do this properly and keep getting the following error when using pyinstaller (pyinstaller doesn't officially support gdspy, I believe).
Has anyone tried to compile gdspy dependent files? Please let me know if I need to provide any other details. My code is listed below and I have confirmed that pyinstaller is working and I have compile just a small "print("hallo world")" script and it worked 100%
import gdspy
print('Please enter file name:')
filename = raw_input()+ str('.gds')
file1 = gdspy.GdsImport('Dcsfq.gds')
file2 = gdspy.GdsImport('Conf2.gds')
file3 = gdspy.GdsImport('Tff4b.gds')
cell1 = file1.extract(file1.top_level()[0])
cell2 = file2.extract(file2.top_level()[0])
cell3 = file3.extract(file3.top_level()[0])
ref_cell = gdspy.Cell('TRANSLATED')
ref_cell.add(gdspy.CellReference(cell2, (150,0)))
ref_cell.add(gdspy.CellReference(cell1,(0,0)))
ref_cell.add(gdspy.CellReference(cell3, (225,-150), rotation=90))
gdspy.gds_print(filename, cells=[ref_cell], unit=1.0e-6, precision=1.0e-9)
gdspy.LayoutViewer(cells = ref_cell)
Any help will be greatly appreciated.
Thanks
I need to make fine slices of the polygons for my application and I wrote a script for the same. While the script itself doesn't throw any error, I see that polygons generated after slice operation are shifted from the original in a specific pattern. Here is original polygons superimposed.
The slices are aligned with the original in the left and right edges, but shifted down in the middle of the polygon. The deviation is more prominent when the slice is finer.
Here is the same output zoomed in with original polygon highlighted in white.
And here is one of the slices highlighted in white.
This is the code that generates this result.
`#!/usr/bin/python
import numpy
import gdspy
def frange(start, stop, step):
i = start
while i < stop:
yield i
i += step
poly_cell = gdspy.Cell('POLYGONS')
points = [(10.43631016, -35.44995495), (20.43478711, -35.27543088), (20.41733471, -34.27558319), (10.41885775, -34.45010725)]
polylist = []
poly2 = gdspy.Polygon(points, 0)
poly_cell.add(poly2)
polylist.append(poly2)
bbox = poly_cell.get_bounding_box()
print (bbox)
sl = []
for i in frange(bbox[0][0]+0.005, bbox[1][0]+0.005, .01):
sl.append(i)
result = gdspy.slice(polylist, (sl), 0)
poly_cell.add(result)
gdspy.LayoutViewer()
`
Hi!
I'm a new user of gdspy and I have some issues with the latest version. I'm using Anaconda with Python 3.5 and every time I try to run my script I have this error prompting :
File "C:\Users\Mathieu\Documents\Python\gdspy-1.0\gdspy__init__.py", line 44, in from gdspy import boolext
ImportError: cannot import name 'boolext'
And I have no idea why. Do you ?
The offset method for shapes that "close" upon themselves (i.e. enlarged such that the resulting polygon structure has overlapping portions) results in segmentation fault (SIGSEGV).
As a simple example -- letter C, drawn as a single polygon, and then enlarged using the offset method:
import gdspy
import numpy
cell = gdspy.Cell('CELL')
c_coords = numpy.array([ [ 0.6663 , 0.32629112],
[ 0.6663 , 0.1669 ],
[ 0.4994 , 0. ],
[ 0.1669 , 0. ],
[ 0. , 0.1669 ],
[ 0. , 0.8331 ],
[ 0.1669 , 1. ],
[ 0.4994 , 1. ],
[ 0.6663 , 0.8331 ],
[ 0.6663 , 0.67370888],
[ 0.4994 , 0.67370888],
[ 0.4994 , 0.76396776],
[ 0.43026776, 0.8331 ],
[ 0.23603224, 0.8331 ],
[ 0.1669 , 0.76396776],
[ 0.1669 , 0.23603224],
[ 0.23603224, 0.1669 ],
[ 0.43026776, 0.1669 ],
[ 0.4994 , 0.23603224],
[ 0.4994 , 0.32629112]])
poly = gdspy.Polygon(c_coords)
cell.add(poly)
offset_result = gdspy.offset(gdspy.CellReference(cell), distance=0.1)
offset_cell = gdspy.Cell('CELL_OFFSET')
offset_cell.add(offset_result)
gdspy.LayoutViewer(cells=[offset_cell])
For distance=0.1 (as above), the offset method returns the expected result. The moment the C-shape "closes" upon itself (distance >= 0.18), the call returns SIGSEGV.
Could you please suggest what can be done to avoid this? One workaround would be to break the shape into multiple polygons, but it is not a generic solution. Thank you.
Hi !
Is it possible to invert a complex gds file (to change resist toner) ?
Thanks.
Hello Lucas,
I am looking for a way to export to gds specific layers from a larger gds file. Alternatively, is there a way to import only a particular layer using gds_import?
Shreyas Shah
Using production layouts, we have observed wrong results using fast_boolean() using the "and" operation with gdspy 0.9. The error seems to be related to fracturing in such way that if the clipper results are to be fractured, the results may be wrong.
Is it possible that clipper results violate some condition implicit to gdspy?
Unfortunately, I cannot provide a test case by now. If I can spare some time in the coming weeks, I'll try to find a simple example useful for hunting down the bug.
Hi,
I have another question about the polygon coordinate precision extracted from GDS.
I am using the following code to get all polygons from a GDS file.
import gdspy
gdsii = gdspy.GdsLibrary()
gdsii.read_gds('out-file.gds')
main_cell = gdsii.top_level()[0]
pol_dict = main_cell.get_polygons(by_spec=True)
polygons = pol_dict[(41, 0)]
When I print out the values in polygons, I saw the following
[array([[2.16, 1.82],
[2.16, 0.98],
[1.82, 0.98],
[1.82, 0.54],
[2.26, 0.54],
[2.26, 0.76],
[2.34, 0.76],
[2.34, 1.82]]),
....
It seems I have to multiply 1000 to get the integer coordinates. Is this as expected?
I don't mind to multiply 1000 but I thought all numbers in GDS file is integer
Also, if I want to draw some polygons to output them to a GDS file, should I divide my coordinates by 1000?
Thanks
enuinc
gdspy doesn't seem to distinguish between relative vs absolute transform for AREF/SREF records. For example, CellReference.to_gds()
contains the following lines:
if self.x_reflection:
word += 0x8000
if not (self.magnification is None):
word += 0x0004
values += struct.pack('>2h', 12, 0x1B05) \
+ _eight_byte_real(self.magnification)
if not (self.rotation is None):
word += 0x0002
values += struct.pack('>2h', 12, 0x1C05) \
+ _eight_byte_real(self.rotation)
0x0004 (absolute magnification) and 0x0002 (absolute rotation) flags in STRANS are always set when there's magnification or rotation.
Unfortunately, absolute mag/rot should be avoided in hierarchical designs with many nested levels, where absolute transforms quickly get out of control. In most cases, we should only use relative magnify/rotate in designs. This is done by clearing these two flags, while still appending the MAG and/or ANGLE records.
In short, gdspy should support and distinguish between absolute and relative transforms, with relative transform being the default.
The following page documents this matter with great details:
http://boolean.klaasholwerda.nl/interface/bnf/gdsformat.html#rec_strans
get_layers only output layers number
get_datatypes only output datatype number
The real useful info is the pair of layer and datatype, or lpp.
get_lpp() should be a valuable function
In the definition of CellReference, polygons are (correctly) transformed according to
polygons[kk][ii] = polygons[kk][ii] * ct \
+ polygons[kk][ii][:, ::-1] * st
(e.g. x<- cos(theta) x - sin(theta) y, but labels are transformed according to:
lbl.position = lbl.position * ct + lbl.position * st
(e.g. x<- cos(theta) x - sin(theta) x), which is not consistent or unitary. The label formula should be corrected to follow the same formula as the polygons.
lbl.position = lbl.position * ct + lbl.position[::-1] * st
This correction fixed the disagreement I was seeing with a layout viewed in klayout.
I noticed that when I use a number_of_paths higher than 1 when I change the path distance between the paths this does not conserve the widths of the paths it draws. Only the widths of the paths at the beginning and the end of the tapered section. I would say that these two parameters could be simultaneously the width of the line and would strongly suggest this should be fixed, as for the effect can be difficult to observe but lead to errors none the less.
Hi
Great software and appear to have all the things I need. However, I can not figure out how to load a gds file (not very big, about 2MB), flatten its hierarchy, and extract all polygons in a given layer.
I am sorry for such an elementary question.
Thanks
enuinc
Hello. I am wondering if you could add Class: Ellipse support? Since Round is supported perfectly, I think this will not be a big problem. Thanks very much!
Path ends with custom size are not supported
Record type BGNEXTN (30) is not supported
Record type ENDTEXTN (31) is not supported
I'm referring to the following code segment.
def get_labels(self, depth=None):
labels = libCopy.deepcopy(self.labels)
if depth is None or depth >= 0:
for element in self.elements:
if isinstance(element, CellReference):
labels.extend(
element.get_labels(None if depth is None else depth -
1))
elif isinstance(element, CellArray):
labels.extend(
element.get_labels(None if depth is None else depth -
1))
return labels
Passing in depth=0, one gets labels from the top-level cell, plus labels from the first-level child elements.
In order to get labels from the top-level cell only, one has to pass in depth=-1.
This behavior was confusing to my colleagues. After reading the code, I think it's better to change one line:
if depth is None or depth > 0:
Im using Conda ipython with python version 3.6.3 on MacOS 10.13 to run code which opens a LayoutViewer. The code successfully opens a viewer. However when I try to close the viewer, either by clicking the red button at the upper left of the window or by selecting python>"quit python", I get a spinning beachball. The ipython command prompt returns (is no longer blocked) despite the spinning beachball.
I have the same problem in my python 2.7 conda environment.
Additionally, if I ignore the spinning beachball and hanging LayoutViewer, and continue working in the ipython shell, then the next time I call a layout viewer, the one that was hanging finally closes and a new layout viewer window opens.
I have noticed that if I open ipython, specifying tk backend i.e. "ipython --pylab=tk", then the viewer window will eventually close after first python>"quit python", followed by two (2) clicks of thew red button. This works both in the 3.6.3 main env and the 2.7 env. I say eventually because it usually fails (i.e. beachball) on the first invocation of "ipython --pylab=tk", but then starts to the work on the second or third. The default backend is 'MacOSX'.
Calling Cell.add() works fine with the LayoutViewer, but when the layout is then written to a GDS file, trying to open it up in Clewin 5 causes a "missing ENDSTR record" error. Trying to open it up in KLayout also causes an error.
Suggested fix is that trying to add a Cell directly to another Cell just inserts a CellReference at position (0,0), or something similar. Or maybe just throw an error? I'm sure trying to get the file to write correctly would take more time than either of these other two options.
@heitzmann : Our chip design workflow is based on gdspy 0.7 and is built on gdspy geometry objects and gdspy boolean operations. There is one feature, however, that requires us to use additional packages to complete the design cycle. In our mask layouts, it is critical to have the ability to introduce CD bias to account for the linewidth reduction during the fabrication process. In mathematical terms, one needs to have the ability to enlarge polygons by a predefined amount in the direction that is normal to the polygon surface... thus a request for this feature. Thank you.
Hi
I wanted to export a single layer from the gds file but I couldn't find the way for it so I have added a method using the flatten method to do it for me, but here is the problem when the file is slightly big(10MB) and I want to use my hand made method It becomes very time consuming so I wanted to ask how could I do Boolean operation with two cells from each other?
I am sure that what I have done could become more efficient using the appropriate library function but I don't know how.
Having a cell with different layers and references, is it possible to copy/translate one o multiple layers?
I have a "main cell" which is a set of multiple cells and cell references. These contain different elements in seven different layers. I wonder if it's possible to make a copy/translation of the whole "main cell", with the same set of cells and references, but just containing one of the layers.
Is it possible to nest cells using gdspy? I've poured over the documentation/examples but haven't found any explicit reference to nesting or cell hierarchy.
I'm building a library of function components that return cells. I would like more complex cells to call simpler cell routines. The GDS format obviously works really well with this recursive framework.
I'd like to add the DEPLOF font to gdspy.
It's a font used on other layout editors (e.g. LayoutEditor CleWin ), and is purpose-built for 2D layout/fab. I received permission from the creator of the MATLAB gdsii-toolbox (Ulf Griesmann) to adapt his implementation, and have it basically ready to go. My question is whether how I should write the commit--I was thinking of adding an additional argument font
to the init argument of the Text class. So that instead of
def __init__(self, text, size, position=(0, 0), horizontal=True, angle=0, layer=0, datatype=0)
it would now be
def __init__(self, text, size, position=(0, 0), horizontal=True, angle=0, font = 'block', layer=0, datatype=0)
where font
could be chosen to be either 'block' (the current font) or 'deplof' (the proposed font), so the change would be transparent and no one's layouts would be changed, but users would now have the option to select the DEPLOF font. (and perhaps down the road the default could be changed to DEPLOF)
Does sound reasonable?
I'm currently having an issue with properly writing hierarchical Cells (with references to other cells that have their own geometric objects) with write_gds()
. For example, see the minimum working example below:
import gdspy
top = gdspy.Cell("top")
top.add(gdspy.Rectangle((0,0), (15000, 15000), layer=10, datatype=0))
ex = gdspy.Cell("exclusion_region")
ex.add(gdspy.Rectangle((0, 13000), (15000, 15000), layer=7, datatype=0))
top.add(ex)
# gdspy.LayoutViewer()
gdspy.write_gds('test.gds', unit=1.0e-6, precision=1.0e-9)
with the following intended Cell hierarchy:
top (Cell)
|_ Rectangle
|_ ex (Cell)
|_ Rectangle
In the above, the gdspy.LayoutViewer() shows the correct hierarchy of Cells and objects. However, the GDSII file it creates (test.gds
), seems to be broken. When I try to open with Klayout, I get the error:
Invalid record or data type (position=194, record number=11, cell=top)
Any idea how I can properly write these Cells to GDS so it will show up correctly? Am I missing something pretty obvious?
Thanks!
Hi,
I am new to python and gdspy, I am writing a code to edit existing gds file, manipulate and dump new gds file, please help/guide me how can i achieve that.
thanks
vijay
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.