Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend pya.Cell().image #231

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion klayout_dot_config/grain.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<salt-grain>
<name>siepic_tools</name>
<version>0.5.16</version>
<version>0.5.17</version>
<api-version>0.27</api-version>
<title>SiEPIC Tools</title>
<doc>Tools for designing Silicon Photonic Integrated Circuits, including waveguides, component simulations, functional verification, DRC verification, Functional verification, netlist extraction, circuit simulations. Layout can be implemented graphically or by programming in Python using the SiEPIC functions and KLayout Python API. Framework and examples for creating layouts using scripts. Includes a generic PDK (GSiP). Other PDKs are installed separately, and depend on SiEPIC-Tools.</doc>
Expand Down
2 changes: 1 addition & 1 deletion klayout_dot_config/python/SiEPIC/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SiEPIC-Tools package for KLayout
'''

__version__ = "0.5.16"
__version__ = "0.5.17"

print("KLayout SiEPIC-Tools version %s" %__version__)

Expand Down
140 changes: 87 additions & 53 deletions klayout_dot_config/python/SiEPIC/extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,69 +1753,102 @@ def pinPoint(self, pin_name, verbose=False):
return matched_pins[0].center


def show(self):
'''Show the cell in KLayout using klive'''
def show(self, file_path = None, lyrdb_filename=None):
'''
Show the cell in KLayout using klive

args
file_path: os.path folder location to save
'''

# Save the cell in a temporary file
from ._globals import TEMP_FOLDER
import os
file_out = os.path.join(TEMP_FOLDER, self.name+'.gds')

if not file_path:
# Save the cell in a temporary file
from ._globals import TEMP_FOLDER
file_path = TEMP_FOLDER

file_out = os.path.join(file_path, self.name+'.gds')
self.write(file_out)

# Display in KLayout
from SiEPIC._globals import Python_Env
if Python_Env == 'Script':
from SiEPIC.utils import klive
klive.show(file_out, technology=self.layout().technology().name, keep_position=True)
klive.show(file_out, lyrdb_filename=lyrdb_filename, technology=self.layout().technology().name, keep_position=True)


def plot(self, width = 800, show_labels = True, show_ruler = True, retina = True):
'''
Generate an image of the layout cell, and display. Useful for Jupyter notebooks

Args:
self: pya.Cell
width: number of pixels
show_labels: KLayout display config to show text = True, https://www.klayout.de/doc-qt5/code/class_LayoutView.html#method101
show_ruler: KLayout display config to show ruler = True
retina: IPython.display.Image configuration for retina display, True
'''

from io import BytesIO
from IPython.display import Image, display

# Create a LayoutView, and populate it with the current cell & layout
cell = self
layout_view = pya.LayoutView()
cell_view_index = layout_view.create_layout(True)
layout_view.active_cellview_index = cell_view_index
cell_view = layout_view.cellview(cell_view_index)
layout = cell_view.layout()
layout.assign(cell.layout())
cell_view.cell = layout.cell(cell.name)

# Load layer properties from the technology
lyp_path=layout.technology().eff_layer_properties_file()
if not lyp_path:
raise Exception ('SiEPIC.extend.plot: technology not specified.')
layout_view.load_layer_props(lyp_path)

# Configure the layout view settings
# print(layout_view.get_config_names())
layout_view.set_config("text-font",3)
layout_view.set_config("background-color", "#ffffff")
layout_view.set_config("text-visible", "true" if show_labels else "false")
layout_view.set_config("grid-show-ruler", "true" if show_ruler else "false")

# Zoom out and show all layout details
layout_view.max_hier()
layout_view.zoom_fit()

# Display as a PNG
width = width * (2 if retina else 1)
pixel_buffer = layout_view.get_pixels(width, cell.bbox().height()/cell.bbox().width()*width)
png_data = pixel_buffer.to_png_data()
im = Image(png_data, retina=retina)
display(im)
'''
Generate an image of the layout cell, and display. Useful for Jupyter notebooks

Args:
self: pya.Cell
width: number of pixels
show_labels: KLayout display config to show text = True, https://www.klayout.de/doc-qt5/code/class_LayoutView.html#method101
show_ruler: KLayout display config to show ruler = True
retina: IPython.display.Image configuration for retina display, True
'''

from io import BytesIO
from IPython.display import Image, display

# Create a LayoutView, and populate it with the current cell & layout
cell = self
layout_view = pya.LayoutView()
cell_view_index = layout_view.create_layout(True)
layout_view.active_cellview_index = cell_view_index
cell_view = layout_view.cellview(cell_view_index)
layout = cell_view.layout()
layout.assign(cell.layout())
cell_view.cell = layout.cell(cell.name)

# Load layer properties from the technology
lyp_path=layout.technology().eff_layer_properties_file()
if not lyp_path:
raise Exception ('SiEPIC.extend.plot: technology not specified.')
layout_view.load_layer_props(lyp_path)

# Configure the layout view settings
# print(layout_view.get_config_names())
layout_view.set_config("text-font",3)
layout_view.set_config("background-color", "#ffffff")
layout_view.set_config("text-visible", "true" if show_labels else "false")
layout_view.set_config("grid-show-ruler", "true" if show_ruler else "false")

# Zoom out and show all layout details
layout_view.max_hier()
layout_view.zoom_fit()

# Display as a PNG
width = width * (2 if retina else 1)
pixel_buffer = layout_view.get_pixels(width, cell.bbox().height()/cell.bbox().width()*width)
png_data = pixel_buffer.to_png_data()
im = Image(png_data, retina=retina)
display(im)
return im


def image(self, file_out = None, file_format = 'PNG', width = 800, show_labels = True, show_ruler = True, retina = True):
'''
Generate an image of the layout cell, and save

Args:
self: pya.Cell
file_out: os.path to save the image
file_format: 'PNG'
width: number of pixels
show_labels: KLayout display config to show text = True, https://www.klayout.de/doc-qt5/code/class_LayoutView.html#method101
show_ruler: KLayout display config to show ruler = True
retina: IPython.display.Image configuration for retina display, True
'''

# Create an image of the layout
im = self.plot(width=width, show_labels=show_labels, show_ruler=show_ruler, retina=retina)
# save
with open(file_out, "wb") as f:
f.write(im.data)


#################################################################################

Expand All @@ -1831,6 +1864,7 @@ def plot(self, width = 800, show_labels = True, show_ruler = True, retina = True
pya.Cell.pinPoint = pinPoint
pya.Cell.show = show
pya.Cell.plot = plot
pya.Cell.image = image


#################################################################################
Expand Down
2 changes: 1 addition & 1 deletion klayout_dot_config/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "SiEPIC"
version = "0.5.16"
version = "0.5.17"
authors = [
{ name="Lukas Chrostowski", email="[email protected]" },
]
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions klayout_dot_config/tech/GSiP/pymacros/tests/test_FaML.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,18 @@ def test_FaML_two(show_klive=False):
num_errors = layout_check(cell = cell, verbose=False, GUI=True, file_rdb=file_lyrdb)
print('Number of errors: %s' % num_errors)


cell.image(os.path.join(path,'test_FaML_two.png'))

# Display the layout in KLayout, using KLayout Package "klive", which needs to be installed in the KLayout Application
cell.show(file_path = path, lyrdb_filename=file_lyrdb)

'''
if show_klive:
if Python_Env == 'Script':
from SiEPIC.utils import klive
klive.show(file_out, lyrdb_filename=file_lyrdb, technology=tech_name)
'''
os.remove(file_out)

if num_errors > 0:
Expand Down
Loading