Skip to content

Commit

Permalink
Merge pull request #2680 from gdsfactory/better_import_ports
Browse files Browse the repository at this point in the history
better import gds and ports
  • Loading branch information
joamatab committed Apr 16, 2024
2 parents 315a6c0 + 74d74a1 commit 993c2b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 6 additions & 6 deletions gdsfactory/add_ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def add_ports_from_markers_center(
tol: float = 0.1,
pin_extra_width: float = 0.0,
min_pin_area_um2: float | None = None,
max_pin_area_um2: float = 150.0 * 150.0,
max_pin_area_um2: float | None = 150.0 * 150.0,
skip_square_ports: bool = False,
xcenter: float | None = None,
ycenter: float | None = None,
Expand All @@ -100,8 +100,8 @@ def add_ports_from_markers_center(
ycenter: for guessing orientation of rectangular ports.
port_name_prefix: defaults to 'o' for optical and 'e' for electrical ports.
port_type: type of port (optical, electrical ...).
short_ports: if the port is on the short side rather than the long side
auto_rename_ports:
short_ports: if the port is on the short side rather than the long side.
auto_rename_ports: if True renames ports to avoid duplicates.
debug: if True prints ports that are skipped.
For inside=False the port location is at the middle of the PIN
Expand Down Expand Up @@ -189,7 +189,7 @@ def add_ports_from_markers_center(
orientation = 0
width = dy
x = pxmax if inside else x
elif x < xc: # west
else: # west
orientation = 180
width = dy
x = pxmin if inside else x
Expand All @@ -198,7 +198,7 @@ def add_ports_from_markers_center(
orientation = 90
width = dx
y = pymax if inside else y
elif y < yc: # south
else: # south
orientation = 270
width = dx
y = pymin if inside else y
Expand Down Expand Up @@ -232,7 +232,7 @@ def add_ports_from_markers_center(
x = pxmin if inside else x

if orientation == -1:
raise ValueError(f"Unable to detector port at ({x}, {y})")
raise ValueError(f"Unable to detect port orientation at ({x}, {y})")

x = snap_to_grid(x)
y = snap_to_grid(y)
Expand Down
5 changes: 5 additions & 0 deletions gdsfactory/read/import_gds.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from collections.abc import Callable
from pathlib import Path

import gdstk
Expand All @@ -23,6 +24,7 @@ def import_gds(
keep_name_short: bool = False,
unique_names: bool = True,
max_name_length: int = 250,
post_process: Callable[..., None] | None = None,
**kwargs,
) -> Component:
"""Returns a Component from a GDS file.
Expand All @@ -39,6 +41,7 @@ def import_gds(
unique_names: appends $ with a number to the name if the cell name is on CACHE. \
This avoids name collisions when importing multiple times the same cell name.
max_name_length: maximum length of the name.
post_process: function to post process the component after importing.
kwargs: extra to add to component.info (polarization, wavelength ...).
"""
gdspath = Path(gdsdir) / Path(gdspath) if gdsdir else Path(gdspath)
Expand Down Expand Up @@ -173,6 +176,8 @@ def import_gds(
for k, v in kwargs.items():
component.info[k] = v
component.imported_gds = True
if post_process:
post_process(component)
return component


Expand Down

0 comments on commit 993c2b4

Please sign in to comment.