i want to calculate density of every layer present in my gds.

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:

    # layer inputs
    
    layer_DIE_EXTENTS = input("1/0")
    
    layer_1 = input("2/0")
    
    # area calculation
    
    area_total = layer_DIE_EXTENTS.area.round(3)
    
    
    area_layer_1 = layer_1.area.round(3)
    tf_layer_1 = (area_layer_1/area_total*100.0).round(3)
    
    # output
    
    puts "Layer Areas and Transmission Factors"
    puts "------------------------------------------------\n\n"
    
    puts "Total Area\t=\t#{area_total}um^2\n\n"
    
    
    puts "layer_1 Area\t=\t#{area_layer_1}um^2"
    puts "layer_1 TF\t=\t#{tf_layer_1}%\n\n"
    

    You can use layers.each to go over all your layers...

    Cheers,

    Tomas

Sign In or Register to comment.