Skip to content

Commit

Permalink
Merge pull request gdsfactory#1240 from gdsfactory/633c
Browse files Browse the repository at this point in the history
make Component.remap_layers safe

Former-commit-id: 63d25f6 [formerly 6c322ac]
Former-commit-id: a027e38683c91577714be747b1fa73a39f93e1f3
  • Loading branch information
joamatab committed Feb 5, 2023
2 parents 1e7a705 + f9c9e47 commit 8b5ac84
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 8 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
@@ -1,5 +1,9 @@
# [CHANGELOG](https://keepachangelog.com/en/1.0.0/)

## 6.33.0

- fix kweb and set log level to warning instead of debug [PR](https://github.com/gdsfactory/gdsfactory/pull/1237)

## 6.32.0

- add general JAX interpolator [PR](https://github.com/gdsfactory/gdsfactory/pull/1230)
Expand Down
9 changes: 5 additions & 4 deletions gdsfactory/component.py
Expand Up @@ -2071,17 +2071,18 @@ def get_info(self):
def remap_layers(
self, layermap, include_labels: bool = True, include_paths: bool = True
) -> Component:
"""Moves all polygons in the Component from one layer to another according to the layermap argument.
"""Returns a copy of the component with remapped layers.
Args:
layermap: Dictionary of values in format {layer_from : layer_to}.
include_labels: Selects whether to move Labels along with polygons.
include_paths: Selects whether to move Paths along with polygons.
"""
component = self.copy()
layermap = {_parse_layer(k): _parse_layer(v) for k, v in layermap.items()}

all_D = list(self.get_dependencies(True))
all_D.append(self)
all_D = list(component.get_dependencies(True))
all_D.append(component)
for D in all_D:
for p in D.polygons:
layer = (p.layer, p.datatype)
Expand Down Expand Up @@ -2112,7 +2113,7 @@ def remap_layers(
new_datatypes[layer_number] = new_layer[1]
path.set_layers(*new_layers)
path.set_datatypes(*new_datatypes)
return self
return component


def copy(
Expand Down
4 changes: 0 additions & 4 deletions gdsfactory/path.py
Expand Up @@ -943,10 +943,6 @@ def extrude(

if x.decorator:
c = x.decorator(c) or c

if x.add_pins:
c = x.add_pins(c) or c

return c


Expand Down
44 changes: 44 additions & 0 deletions tests/test_extract.py
@@ -0,0 +1,44 @@
from __future__ import annotations

import gdsfactory as gf
from gdsfactory.add_pins import add_pins_siepic


def test_extract():
c = gf.components.straight(
length=10,
width=0.5,
bbox_layers=[gf.LAYER.WGCLAD],
bbox_offsets=[3],
with_bbox=True,
cladding_layers=None,
add_pins=add_pins_siepic,
add_bbox=None,
)
c2 = c.extract(layers=[gf.LAYER.PORT])

assert len(c.polygons) == 2, len(c.polygons)
assert len(c2.polygons) == 0, len(c2.polygons)

assert len(c.paths) == 2, len(c.paths)
assert len(c2.paths) == 2, len(c2.paths)
assert gf.LAYER.WGCLAD in c.layers
assert gf.LAYER.PORT in c2.layers
return c2


if __name__ == "__main__":
c = test_extract()
c.show()

c = gf.components.straight(
length=10,
width=0.5,
bbox_layers=[gf.LAYER.WGCLAD],
bbox_offsets=[3],
with_bbox=True,
cladding_layers=None,
add_pins=add_pins_siepic,
add_bbox=None,
)
c2 = c.extract(layers=[gf.LAYER.PORT])
27 changes: 27 additions & 0 deletions tests/test_remap.py
@@ -0,0 +1,27 @@
from __future__ import annotations

import gdsfactory as gf
from gdsfactory.add_pins import add_pins_siepic


def test_remap_layers():
c = gf.components.straight(length=1, width=0.5, add_pins=add_pins_siepic)
c2 = c.remap_layers({gf.LAYER.WG: gf.LAYER.WGN, gf.LAYER.PORT: gf.LAYER.PORTE})

assert len(c.polygons) == 1, len(c.polygons)
assert len(c2.polygons) == 1, len(c2.polygons)
assert len(c.paths) == 2, len(c.paths)
assert len(c2.paths) == 2, len(c2.paths)
assert gf.LAYER.WG in c.layers
assert gf.LAYER.WGN in c2.layers
assert gf.LAYER.PORTE in c2.layers
return c2


if __name__ == "__main__":
c = test_remap_layers()
# c.show()

c = gf.components.straight(length=1, width=0.5, add_pins=add_pins_siepic)
c2 = c.remap_layers({gf.LAYER.WG: gf.LAYER.WGN, gf.LAYER.PORT: gf.LAYER.PORTE})
c2.show()

0 comments on commit 8b5ac84

Please sign in to comment.