It looks like you're new here. If you want to get involved, click one of these buttons!
i write one script which give me layer name and there area of layer so i want to calculate density of every layer.
my script -
import pya
outputTxt = "out.txt"
filePaths = ["some path.gds"]
results = []
for filePath in filePaths:
layout = pya.Layout()
layerMap = layout.read(filePath)
topCells = [cell for cell in layout.top_cells()]
unit = layout.dbu
for cell in topCells:
for layer_id in layout.layer_indexes():
info = layout.get_info(layer_id)
region = pya.Region([rsi.shape().polygon.transformed(rsi.trans()) for rsi in cell.begin_shapes_rec(layer_id) if rsi.shape().polygon])
result = f"{filePath}, {cell.name}, L({info.layer}, {info.datatype}), {region.merged().area()*unit*unit : .3f} um-sq"
results.append(result)
resultsStr = "\n".join(results)
print(resultsStr)
f = open(outputTxt, "x")
with f : f.write(resultsStr)
Comments
Hello,
It's easier to make a DRC script using the area method (layer.area): https://www.klayout.de/doc-qt5/about/drc_ref_layer.html#h2-128
Here's an example:
You can use layers.each to go over all your layers...
Cheers,
Tomas