Converting OASIS file to PNG image file

Is there any way to programmatically convert an OASIS file to a PNG image file? I know that within the UI I can open OASIS and then do File>Screenshot, but I'd like a way to do if from within Python if possible. Thanks!!!

Comments

  • There is a related discussion ongoing: https://www.klayout.de/forum/discussion/1711/screenshot-with-all-the-layer-and-screenshot-only-one-layer#latest

    From there you can learn a lot about Python coded image generation scripts and it has a fancy version of a screenshot tool :)

    If by "Python" you mean the Python module on PyPI, it also has a LayoutView class and can bascially do the same.

    Matthias

  • Thank you for your response Matthias! I should have explained my issue better. We will be running on a system without graphics support so are unable to open the Klayout UI. I'd like to be able to make calls to KLayout from the command line to perform the oasis to image conversion. Does Klayout expose this functionality outside of the UI? Thank you!!!

  • edited August 2

    I'd advise to use the Python module. It provides a stripped-down version of the LayoutView class which can render OASIS to PNG without a graphics device.

    Just do

    pip install klayout
    

    There is a demo web component (https://pypi.org/project/kweb/) that uses this technique to render layout on a HTTP server interactively through a WebSockets connection.

    Matthias

  • edited August 7

    Hi chrisl,

    I hope the attached sample script from my toolbox will help you understand.

    -----------------------------------------------------------------------------------------------------
    oas2png-new.py
      << To convert OASIS file(s) to PNG file(s) with the help of KLayout Python Module>>
    
    $ [python3] oas2png-new.py                             (default)
        <-i|--input <OASIS file(s)>>                       ('')
        <-l|--lyp   <layer property file>>                 ('')
        [-t|--topcell <top cell name>]                     ('')
        [-p|--postfix <pfstr>] ex. ${_output_}${pfstr}.png ('')
        [-c|--conf  <KLayout's config file>]               (Linux & Mac: $HOME/.klayout/klayoutrc)
                                                           (Windows: %USERPROFILE%\klayout\klayoutrc)
        [-x|--sizex <image pixel size in X>]               (1000)
        [-y|--sizey <image pixel size in Y>]               (1000)
        [-b|--noborder] : without the image border         (disabled)
        [-d|--debug  <level>]                              (0)
        [-?|--?] : print this usage and exit               (disabled)
        You may use the -i option multiple times, including a wild card.
            ex. -i abc.oas  -i xzy.oas -i "*.oas" (-i '*.oas' in mac zsh)
    -----------------------------------------------------------------------------------------------------
    

    I have tested the code on Mac, Linux, and Windows 10.
    Note: the [-c|--conf <KLayout's config file>] option is now effective. Replaced the attachment.


    Sample Run

    MyHost{sekigawa}(1)$ ./oas2png-new.py -i "inv*.oas" -i ringo.oas -l invKazzzS.lyp
    ### <0001> Generating <inv2.png> from OASIS <inv2.oas> ...
    ### <0002> Generating <inv2a.png> from OASIS <inv2a.oas> ...
    ### <0003> Generating <inv2b.png> from OASIS <inv2b.oas> ...
    ### <0004> Generating <inv2c.png> from OASIS <inv2c.oas> ...
    ### <0005> Generating <inv2d.png> from OASIS <inv2d.oas> ...
    ### <0006> Generating <inv2e.png> from OASIS <inv2e.oas> ...
    ### <0007> Generating <inv2f.png> from OASIS <inv2f.oas> ...
    ### <0008> Generating <inv2g.png> from OASIS <inv2g.oas> ...
    ### <0009> Generating <ringo.png> from OASIS <ringo.oas> ...
    >>> Elapsed Time = 0.513 [sec] >>>
    
    MyHost{sekigawa}(2)$ ./oas2png-new.py -i ringo.oas -l invKazzzS.lyp -y 500
    ### <0001> Generating <ringo.png> from OASIS <ringo.oas> ...
    >>> Elapsed Time = 0.047 [sec] >>
    


    Kazzz-S

  • edited August 7

    Cont.

    Fixed a problem in Windows and re-attached the ZIP file (2024-08-06).
    Sorry about the inconvenience.

  • Cont.

    I found and fixed a fatal bug (cell hierarchy level is not checked), then re-attached the ZIP file (2024-08-07).
    Sorry about the inconvenience once again.

  • Hi @sekigawa,

    thank you very much for providing these scripts! It is very much appreciated :)

    Just for my understanding - the fatal bug is not something inside KLayout, isn't it?

    Thanks,

    Matthias

  • edited August 7

    Hi @Matthias,

    The bug was not inside KLayout; I misused an API function.

    Incorrect:

      :
      cellview.set_cell(topcellIdx)
      layoutview.max_hier_levels = layoutview.max_hier_levels + 1 <===
      # layoutview.max_hier_levels is not automatically set by layoutview.load_layout(); Hence, always, layoutview.max_hier_levels == 1
      layoutview.zoom_fit()
      :
    

    Correct:

      :
      cellview.set_cell(topcellIdx)
      layoutview.max_hier_levels = layout.cell(topcellIdx).hierarchy_levels() + 1 <===
      layoutview.zoom_fit()
      :
    

    Regards,
    Kazzz-S

  • Very good. Thanks for the explanation! :)

    Matthias

  • edited August 8

    I will check it out! thank you so much @sekigawa and @Matthias!!!

  • @sekigawa I made a small change to remove the requirement for the layer file as I only have OASIS to work with and the images convert with no issue! Thank you so much! The converted image looks the same as the one imported via KLayout as hoped for! :)

  • Traceback (most recent call last):
    File "D:\gds_to_image\oas2png-new.py", line 453, in
    main()
    File "D:\gds_to_image\oas2png-new.py", line 440, in main
    ProcessOneOASISFile( configdic, item, count )
    File "D:\gds_to_image\oas2png-new.py", line 278, in ProcessOneOASISFile
    layoutview.load_layer_props( LayerPorpFile )
    RuntimeError: Unable to open file: D:\gds_to_image\invKazzzS.lyp (errno=2) in LayoutViewBase.load_layer_props

    Hello, I got this error, where is invKazzzS.lyp file?

  • You need to provide your own *.lyp for OASIS files.
    If you want to trace the above sample run, please use the attached files.

Sign In or Register to comment.