Skip to content

Commit

Permalink
default read_metadata=False in import_gds, fix write_labels_klayout
Browse files Browse the repository at this point in the history
  • Loading branch information
joamatab committed Jan 2, 2023
1 parent d3bdb50 commit b5725b7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gdsfactory/component.py
Expand Up @@ -2146,7 +2146,7 @@ def test_import_gds_settings():

c = gf.components.mzi()
gdspath = c.write_gds_with_metadata()
c2 = gf.import_gds(gdspath, name="mzi_sample")
c2 = gf.import_gds(gdspath, name="mzi_sample", read_metadata=True)
c3 = gf.routing.add_fiber_single(c2)
assert c3

Expand Down
6 changes: 4 additions & 2 deletions gdsfactory/labels/merge_test_metadata.py
Expand Up @@ -79,12 +79,14 @@ def merge_test_metadata(

test_metadata = DictConfig({})

for label, x, y in labels_list:
for label, x, y, angle in labels_list:
cell = get_cell_from_string(label)

if cell in cells_metadata:
test_metadata[cell] = cells_metadata[cell]
test_metadata[cell].label = dict(x=float(x), y=float(y), text=label)
test_metadata[cell].label = dict(
x=float(x), y=float(y), text=label, angle=angle
)
else:
logger.error(f"missing cell metadata for {cell!r}")
warnings.warn(f"missing cell metadata for {cell!r}")
Expand Down
15 changes: 12 additions & 3 deletions gdsfactory/labels/write_labels.py
Expand Up @@ -32,6 +32,7 @@ def find_labels(
string: for the label.
x: x position (um).
y: y position (um).
angle: in degrees.
"""
import klayout.db as pya
Expand All @@ -57,7 +58,7 @@ def find_labels(
text = shape.text
if text.string.startswith(prefix):
transformed = text.transformed(trans)
yield text.string, transformed.x * dbu, transformed.y * dbu
yield text.string, transformed.x * dbu, transformed.y * dbu, trans.angle


def write_labels_klayout(
Expand All @@ -68,7 +69,11 @@ def write_labels_klayout(
) -> Path:
"""Load GDS and extracts labels in KLayout text and coordinates.
Returns CSV filepath.
Returns CSV filepath with each row:
- Text
- x
- y
- rotation (degrees)
Args:
gdspath: for the mask.
Expand Down Expand Up @@ -98,7 +103,11 @@ def write_labels_gdstk(
) -> Path:
"""Load GDS and extracts label text and coordinates.
Returns CSV filepath. Text, x, y, rotation (degrees)
Returns CSV filepath with each row:
- Text
- x
- y
- rotation (degrees)
Args:
gdspath: for the mask.
Expand Down
4 changes: 2 additions & 2 deletions gdsfactory/read/import_gds.py
Expand Up @@ -18,7 +18,7 @@ def import_gds(
gdspath: Union[str, Path],
cellname: Optional[str] = None,
gdsdir: Optional[Union[str, Path]] = None,
read_metadata: bool = True,
read_metadata: bool = False,
hashed_name: bool = True,
**kwargs,
) -> Component:
Expand All @@ -30,7 +30,7 @@ def import_gds(
gdspath: path of GDS file.
cellname: cell of the name to import. None imports top cell.
gdsdir: optional GDS directory.
read_metadata: loads metadata if it exists.
read_metadata: loads metadata (ports, settings) if it exists in YAML format.
hashed_name: appends a hash to a shortened component name.
kwargs: extra to add to component.info (polarization, wavelength ...).
"""
Expand Down
2 changes: 1 addition & 1 deletion gdsfactory/tests/test_import_gds2.py
Expand Up @@ -26,7 +26,7 @@ def test_read_gds_equivalent() -> None:
c1 = gf.components.straight(length=1.234)
gdspath = gf.PATH.gdsdir / "straight.gds"

c2 = gf.import_gds(gdspath)
c2 = gf.import_gds(gdspath, read_metadata=True)
d1 = c1.to_dict()
d2 = c2.to_dict()
d = jsondiff.diff(d1, d2)
Expand Down
4 changes: 2 additions & 2 deletions gdsfactory/tests/test_import_gds_with_hierarchy.py
Expand Up @@ -20,7 +20,7 @@ def test_read_gds_hash2() -> gf.Component:


def test_read_gds_with_settings2(data_regression: DataRegressionFixture) -> None:
c = gf.import_gds(gdspath)
c = gf.import_gds(gdspath, read_metadata=True)
data_regression.check(c.to_dict())


Expand All @@ -29,7 +29,7 @@ def test_read_gds_equivalent2() -> None:
settings."""
splitter = gf.components.mmi1x2(cross_section=cross_section)
c1 = gf.components.mzi(splitter=splitter, cross_section=cross_section)
c2 = gf.import_gds(gdspath)
c2 = gf.import_gds(gdspath, read_metadata=True)

d1 = c1.to_dict()
d2 = c2.to_dict()
Expand Down

0 comments on commit b5725b7

Please sign in to comment.