Skip to content

Repository files navigation

layerops - GDS layer remap / filter / merge for gdsfactory

tests license

layerops applies layer-level edits to a GDS layout (or a gdsfactory Component): remap layers, keep or drop a set of layers, and union overlapping polygons within a layer. These are the everyday cleanup steps in PDK migration and layout prep. gdstk provides the boolean primitives; layerops drives them from a small JSON spec and writes the result back to GDS.

Operations

Operation What it does
map rewrite each layer through a map, e.g. {"1/0": "5/0"} (unmapped layers pass through)
keep / drop keep only, or drop, a set of layers (use one, not both)
merge union overlapping polygons within a layer (fewer shapes, same covered area)

Install

pip install -r requirements.txt

numpy and gdstk are the dependencies. gdsfactory is optional and used only to read a Component; a GDS file works without it.

Use

From the command line, with a JSON spec:

python cli.py in.gds --spec spec.json -o out.gds
{"map": {"1/0": "5/0"}, "drop": ["2/0"], "merge": true}

Layers are written as "layer/datatype" (or just "layer" for datatype 0). merge is true for every layer, or a list of layers. The operations are applied in order: map, then keep/drop, then merge.

From Python:

import load, cli, write

layout = load.from_gds("in.gds")
result = cli.apply_spec(layout, {"map": {"1/0": "5/0"}, "merge": True})
write.write_gds(result, "out.gds")

# from a gdsfactory Component:
# cli.apply_spec(load.from_component(component), spec)

A runnable example is in examples/quickstart.py:

before (layer: polygons, area): {'1/0': (2, 8.0), '2/0': (1, 4.0)}
after  (layer: polygons, area): {'2/0': (1, 4.0), '5/0': (1, 7.0)}

Layer 1 (two overlapping rectangles, summed area 8) is remapped to layer 5 and unioned into one shape with the true covered area of 7.

Modules

Module What it does
load.py flatten a GDS / Component into polygons by layer plus labels
remap.py rewrite layers through a map
sieve.py keep or drop a set of layers
merge.py union polygons within a layer
write.py write the result back to a single-cell GDS
cli.py python cli.py in.gds --spec spec.json end to end

Test

python run_checks.py validate <name>   # one module's self-check
python run_checks.py validate-all      # every module's self-check
python run_checks.py suite             # pytest tests/

Each operation is validated against a constructed layout with a known answer: a remapped layer keeps its area on the new layer, dropping a layer removes exactly it, two overlapping 2x2 rectangles merge to one shape of area 7, and writing then reloading reproduces the same layers and areas.

Scope

layerops works on a flattened layout, so the output is a single-cell GDS. That keeps the layer operations simple and exact; if you need to preserve hierarchy, run it on the cells you want to keep separate. It is a geometry transform, not a DRC.

About

Spec-driven GDS layer remap, filter, and merge

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages