Map layer and datatype before writing a GDS

Hi everyone,

I am asking some help, because there is something that I can do using the GUI of klayout but I want to do it using a python script.
Using the GUI in edit mode, I read a GDS, I go to Edit/Layer/Edit Layer Specification and I update the layer number and datatype of some layer before writing down a new GDS.

However I did not success to do it using a script in batch mode.
The first thing I tried was to use a 'layer_map' from 'LoadLayoutOptions' but I do not retrieve the new layer in the written GDS.
Then I thought I need to copy the layer content in a newly created layer and then remove the old layer. It could works but the thing is I would like to map many datatype layers into the same datatype (for example layer 4.0, 4.1 and 4.2 became 16.0). In that case, does that mean I should perform a boolean operation to get that unique layer ?

Should I dig in the 'layer_map' solution ? Should I switch to OR operation solution ? Or is there another wy to do it ?
Thank you for your help

Note : Here is a trial with layer map

import pya as kl

ly = kl.Layout()
option = kl.LoadLayoutOptions()
option.layer_map.map("*/* : *+12/0", 0)
ly.read("my_file.gds", option)
## Display layer and datatype
for layer_idx in ly.layer_indexes():
  info = ly.get_info(layer_idx)
  print("Layer "+info.name+" : ",info.layer, info.datatype)

ly.write("my_new_file.gds.gz")

Comments

  • Hi @klayanoob,

    I tried the script and it seems to do what it is supposed to. I had three layers, 1/0, 1/5 and 2/0. With the map instruction you give, they get mapped to 13/0 (=1/0 and 1/5) and 14/0 (=2/0). So what do you mean by "you do not retrieve the new layer in the written GDS"?

    Another and more accessible solution is maybe to change the layer specification before saving:

    # save layer 1/0 as 12/0
    l = ly.layer(1, 0)
    ly.set_info(l, kl.LayerInfo(12, 0))
    ly.write(...)
    

    You can also change multiple layers to the same specification, like this:

    # save layer 1/0 and 1/5 as 12/0
    l = ly.layer(1, 0)
    ly.set_info(l, kl.LayerInfo(12, 0))
    l = ly.layer(1, 5)
    ly.set_info(l, kl.LayerInfo(12, 0))
    ly.write(...)
    

    so you can form a loop translating the layers you find in your file.

    I'd not implement a boolean operation. That is too heavy. If you need to join layers, you can use "Layout#move_layer" which adds the shapes of one layer to another one and empties the original layer.

    Matthias

Sign In or Register to comment.