clip GDS to image

edited February 2023 in Python scripting

Hi all,

I am trying to use python (standalone) to get patch images from a drawing, but running into some issues. Ideally, I would be able to input a drawing and coordinates, and get a bitmap out. However, it would be fine to get a monochrome PNG out -- I could post-process from there.

Currently, I am able to get images out when I use coordinates of of a patch of about 10000x10000um, but when I go smaller (for features of about 100x100um), I get no output. Also, I would like to set it to show layers without fill (the diagonal lines) but unsure how to set this feature with python.

Here is my current code:

import klayout.lay as lay
import klayout.db as db

lv = lay.LayoutView()
ly = lay.CellView.active().layout()
lv.load_layout(in_file, 0)
lv.max_hier()

lv.save_image_with_options(out_file, w,h, 0, 0, 0, db.Box(x1, y1, x2, y2), True)

Any help would be greatly appreciated!

Edit: it seems like if I adjust the height and width, I am able to get smaller images. However, I now I would just like to get the stipple to be solid instead of hatched:

Comments

  • I guess the problem is with a specific detail of the standalone view. It still inherits concepts from it's UI times, specifically that is depends on some form of event loop. You need to call "lv.timer()" to establish a proper configuration. This could be included into "save_image" for convenience. If you like, drop me a ticket for this on GitHub: https://github.com/KLayout/klayout.

    Also in your code you are using "db.Box" for the drawing rectangle while it should be "db.DBox" with micrometer coordinates.

    Here is a working example:

    # taken from KLayout source tree, test data
    in_file = "testdata/lvs/ringo.gds"
    
    out_file = "out.png"
    
    w = 600
    h = 200
    x1 = 0
    y1 = 0
    x2 = 26
    y2 = 9
    
    import klayout.lay as lay
    import klayout.db as db
    
    lv = lay.LayoutView()
    lv.set_config("background-color", "#000000")
    lv.set_config("grid-visible", "false")
    lv.set_config("grid-show-ruler", "false")
    lv.set_config("text-visible", "false")
    lv.load_layout(in_file, 0)
    lv.clear_layers()
    
    # establish one layer, solid fill
    lp = lay.LayerProperties()
    lp.source = "9/0"
    lp.dither_pattern = 0
    lp.fill_color = 0xffffff
    lp.frame_color = 0xffffff
    lv.insert_layer(lv.begin_layers(), lp)
    
    lv.max_hier()
    
    # Important: event processing for delayed configuration events
    # Here: triggers refresh of the image properties
    lv.timer()
    
    lv.save_image_with_options(out_file, w, h, 0, 0, 0, db.DBox(x1, y1, x2, y2), False)
    

    This produces:

    Matthias

Sign In or Register to comment.