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

Add possibility of adding label when adding fiber array #2535

Merged
merged 1 commit into from Feb 15, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 46 additions & 1 deletion gdsfactory/routing/add_fiber_array.py
Expand Up @@ -3,6 +3,8 @@
from collections.abc import Callable
from functools import partial

import numpy as np

import gdsfactory as gf
from gdsfactory.component import Component
from gdsfactory.components.grating_coupler_elliptical_trenches import grating_coupler_te
Expand All @@ -12,10 +14,12 @@
from gdsfactory.routing.route_fiber_array import route_fiber_array
from gdsfactory.routing.sort_ports import sort_ports_x
from gdsfactory.typings import (
AnchorSubset,
ComponentSpec,
ComponentSpecOrList,
CrossSectionSpec,
LayerSpec,
Literal,
)


Expand All @@ -30,6 +34,9 @@
cross_section: CrossSectionSpec = "xs_sc",
get_input_labels_function: Callable | None = get_input_labels_dash,
layer_label: LayerSpec | None = None,
dev_id: str | None = None,
text: ComponentSpec | None = None,
id_placement: Literal[AnchorSubset] = "center",
**kwargs,
) -> Component:
"""Returns component with south routes and grating_couplers.
Expand All @@ -46,7 +53,13 @@
cross_section: cross_section function.
get_input_labels_function: function to get input labels. None skips labels.
layer_label: optional layer for grating coupler label.

dev_id: device if if we want to add a visible label for the device.
text: optional componentSpec to generate the text for the dev_id
id_placement: placement of the id.
"c" = center (in between the center grating couplers)
"r" = right of the right-most gc
"l" = left of the left-most gc
"s" = center and below the gc in y
Keyword Args:
bend: bend spec.
straight: straight spec.
Expand Down Expand Up @@ -178,6 +191,38 @@
component_new.add_port("loopback2", port=ports_loopback[1])

component_new.copy_child_info(component)

# Add a visible label to the structure if indicated
if dev_id and text:
if id_placement == "center":
lab = component_new << text(text=dev_id, justify="center")

Check warning on line 198 in gdsfactory/routing/add_fiber_array.py

View check run for this annotation

Codecov / codecov/patch

gdsfactory/routing/add_fiber_array.py#L198

Added line #L198 was not covered by tests
xs = [r.x for r in io_gratings_lines[0]]
ys = [r.y for r in io_gratings_lines[0]]
lab.center = (np.average(xs), ys[0])

Check warning on line 201 in gdsfactory/routing/add_fiber_array.py

View check run for this annotation

Codecov / codecov/patch

gdsfactory/routing/add_fiber_array.py#L201

Added line #L201 was not covered by tests
elif id_placement == "r":
lab = component_new << text(text=dev_id, justify="left")

Check warning on line 203 in gdsfactory/routing/add_fiber_array.py

View check run for this annotation

Codecov / codecov/patch

gdsfactory/routing/add_fiber_array.py#L203

Added line #L203 was not covered by tests
xmax = [r.xmax for r in io_gratings_lines[0]]
# Include the loopback ports for xmax, xmin calculation
if ports_loopback:
xmax += [r.xmax for r in io_gratings_lines[-1] + io_gratings_lines[-2]]
ys = [r.y for r in io_gratings_lines[0]]
lab.xmin = np.max(xmax) + 20
lab.y = ys[0]

Check warning on line 210 in gdsfactory/routing/add_fiber_array.py

View check run for this annotation

Codecov / codecov/patch

gdsfactory/routing/add_fiber_array.py#L209-L210

Added lines #L209 - L210 were not covered by tests
elif id_placement == "l":
lab = component_new << text(text=dev_id, justify="right")

Check warning on line 212 in gdsfactory/routing/add_fiber_array.py

View check run for this annotation

Codecov / codecov/patch

gdsfactory/routing/add_fiber_array.py#L212

Added line #L212 was not covered by tests
xmin = [r.xmin for r in io_gratings_lines[0]]
# Include the loopback ports for xmax, xmin calculation
if ports_loopback:
xmin += [r.xmin for r in io_gratings_lines[-1] + io_gratings_lines[-2]]
ys = [r.y for r in io_gratings_lines[0]]
lab.xmax = np.min(xmin) - 20
lab.y = ys[0]

Check warning on line 219 in gdsfactory/routing/add_fiber_array.py

View check run for this annotation

Codecov / codecov/patch

gdsfactory/routing/add_fiber_array.py#L218-L219

Added lines #L218 - L219 were not covered by tests
elif id_placement == "s":
lab = component_new << text(text=dev_id, justify="center")

Check warning on line 221 in gdsfactory/routing/add_fiber_array.py

View check run for this annotation

Codecov / codecov/patch

gdsfactory/routing/add_fiber_array.py#L221

Added line #L221 was not covered by tests
xs = [r.x for r in io_gratings_lines[0]]
ymins = [r.ymin for r in io_gratings_lines[0]]
lab.center = (np.average(xs), np.min(ymins) - 20)

Check warning on line 224 in gdsfactory/routing/add_fiber_array.py

View check run for this annotation

Codecov / codecov/patch

gdsfactory/routing/add_fiber_array.py#L224

Added line #L224 was not covered by tests

return component_new


Expand Down
6 changes: 6 additions & 0 deletions gdsfactory/typings.py
Expand Up @@ -124,6 +124,12 @@ class StepAllAngle:
"center",
"cc",
]
AnchorSubset = Literal[
"center",
"l",
"r",
"s",
]
Axis = Literal["x", "y"]
NSEW = Literal["N", "S", "E", "W"]

Expand Down