예제 #1
0
def test_remove_layers():
    D = Device()
    D.add_polygon([(8, 6, 7, 9, 7), (6, 8, 9, 5, 7)], layer=13)
    D.add_polygon([(18, 16, 17, 19, 17), (16, 18, 19, 15, 17)], layer=14)
    xpts = list(range(1000))
    ypts = [x % 73 for x in xpts]
    p = D.add_polygon([xpts, ypts], layer=15)
    p.fracture(max_points=13, precision=1e-4)
    # Switch part of the polygons to layer (14,0)
    p.layers[13:17] = [14] * 4
    # Switch part of the polygons to layer (14,1)
    p.layers[23:27] = [14] * 4
    p.datatypes[23:27] = [1] * 4
    h = D.hash_geometry(precision=1e-4)
    assert (h == '7a7aa6a22b3d0b852a0e465398018dd19a1be305')
    D.remove_layers(layers=[13, (14, 0)])
    h = D.hash_geometry(precision=1e-4)
    assert (h == 'bb81ec3b3a6be2372a7ffc32f57121a9f1a97b34')
# We can even save the LayerSet as a KLayout .lyp file ("layer properties" file)
# useful for getting the color scheme in KLayout to match quickplot
import phidl.utilities as pu
pu.write_lyp('MyLayerSetPreview.lyp', layerset=ls)

#==============================================================================
# Removing  layers
#==============================================================================
# Now say we only wanted to get layers 4 and 5 from an imported.  We can remove
# the unwanted layers using the remove_layers() function
D = pg.import_gds(filename='MyLayerSetPreview.gds')

# We set "invert_selection" to True so that all layers EXCEPT 4 and 5
# are removed
D.remove_layers(layers=[4, 5], invert_selection=True)
qp(D)

# If we later decide that we actually don't want layer 4, as well, we
# can leave the `invert_selection` argument blank
D.remove_layers(layers=[4])
qp(D)

#==============================================================================
# Remapping layers
#==============================================================================
# Let's import our layerset preview again
D = pg.import_gds(filename='MyLayerSetPreview.gds')

# We can use the remap_layers() function to map layers arbitrarily. Say we
# wanted to move shapes on layer 5 to layer 99, and layer 6 to layer 77