Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

how to load a gds file, flatten it, and extract all polygons #42

Closed
enuinc opened this issue Mar 16, 2018 · 5 comments
Closed

how to load a gds file, flatten it, and extract all polygons #42

enuinc opened this issue Mar 16, 2018 · 5 comments

Comments

@enuinc
Copy link

enuinc commented Mar 16, 2018

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

@heitzmann
Copy link
Owner

Hello @enuinc,

Loading a GDSII file can be done with GdsLibrary.
If your file has a single top cell, then something like this should work:

import gdspy

lib = gdspy.GdsLibrary(infile='filename.gds')
main_cell = lib.top_cell()[0]
pol_dict = main_cell.get_polygons(by_spec=True)
polygons = pol_dict[(layer, datatype)]

Note that in the last line I assume you know the layer and datatype numbers you're after. If the polygons in the layer you want have different datatypes, you'll have to iterate over therm and append to the polygons list.

Also note there's no need to flatten the cell, because get_polygons already traverses the whole cell hierarchy.

@egholamy
Copy link

Hi
I guess it is
main_cell = lib.top_level()[0]

@heitzmann
Copy link
Owner

@egholami Yes, that's the correct command!

import gdspy

lib = gdspy.GdsLibrary(infile='filename.gds')
main_cell = lib.top_level()[0]
pol_dict = main_cell.get_polygons(by_spec=True)
polygons = pol_dict[(layer, datatype)]

@vandhanasiva
Copy link

vandhanasiva commented Jan 29, 2021

@heitzmann By any chance can we plot these polygons?

@heitzmann
Copy link
Owner

@vandhanasiva Each polygon in the list is simply an array of N vertices (a numpy.ndarray with shape (N, 2)), so any drawing library should be capable of drawing it. You can use, for example, matplotlib, or look for something more efficient if you have too many of them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants