diff --git a/gplugins/utils/get_component_with_net_layers.py b/gplugins/utils/get_component_with_net_layers.py index a194df05..cdd9aac2 100644 --- a/gplugins/utils/get_component_with_net_layers.py +++ b/gplugins/utils/get_component_with_net_layers.py @@ -1,65 +1,65 @@ import copy import gdsfactory as gf -from gdsfactory.typings import Component, LayerStack +from gdsfactory.typings import Component, layer_stack -def remove_empty_layerstack_layers( +def remove_empty_layer_stack_layers( component: Component, - layerstack: LayerStack, -) -> LayerStack: - """Returns a new layerstack without layers that don't appear in the provided component. + layer_stack: layer_stack, +) -> layer_stack: + """Returns a new layer_stack without layers that don't appear in the provided component. Arguments: component: to process. - layerstack: to process. + layer_stack: to process. Returns: - new_layerstack: without layers that do not appear in component + new_layer_stack: without layers that do not appear in component """ - new_layerstack = layerstack.copy() + new_layer_stack = layer_stack.copy() layers_present = component.layers - layernames_dict = new_layerstack.get_layer_to_layername() + layernames_dict = new_layer_stack.get_layer_to_layername() layernames_present = [ name for sublist in [layernames_dict[layer] for layer in layers_present] for name in sublist ] - for key in list(new_layerstack.layers.keys()): + for key in list(new_layer_stack.layers.keys()): if key not in layernames_present: - del new_layerstack.layers[key] + del new_layer_stack.layers[key] - return new_layerstack + return new_layer_stack def get_component_with_net_layers( component: Component, - layerstack: LayerStack, + layer_stack: layer_stack, portnames: list[str], delimiter: str = "#", new_layers_init: tuple[int, int] = (10010, 0), - add_to_layerstack: bool = True, -) -> tuple[Component, LayerStack]: + add_to_layer_stack: bool = True, +) -> tuple[Component, layer_stack]: """Returns a component where polygons touching a port are put on new logical layers. Useful to quickly define boundary conditions from component ports in simulation. New layers are named "layername{delimiter}portname". Args: component: to process. - layerstack: to process. + layer_stack: to process. portnames: list of portnames to process into new layers. delimiter: the new layer created is called "layername{delimiter}portname". new_layers_init: initial layer number for the temporary new layers. - add_to_layerstack: if True, adds the new layers to net_layerstack. + add_to_layer_stack: if True, adds the new layers to net_layer_stack. Returns: net_component: new component with port_polygons tagged on new layers - net_layerstack: new layerstack with "layername{delimiter}portname" entries + net_layer_stack: new layer_stack with "layername{delimiter}portname" entries """ import gdstk - # Initialize returned component and layerstack + # Initialize returned component and layer_stack net_component = component.copy() - net_layerstack = layerstack.copy() + net_layer_stack = layer_stack.copy() # For each port to consider, convert relevant polygons for i, portname in enumerate(portnames): @@ -74,7 +74,7 @@ def get_component_with_net_layers( gdstk.offset(gdstk.Polygon(polygon), gf.get_active_pdk().grid_size), )[0]: try: - port_layernames = net_layerstack.get_layer_to_layername()[ + port_layernames = net_layer_stack.get_layer_to_layername()[ port.layer ] except KeyError as e: @@ -86,13 +86,13 @@ def get_component_with_net_layers( new_layers_init[0] + i, new_layers_init[1] + j, ) - if add_to_layerstack: - new_layer = copy.deepcopy(net_layerstack.layers[old_layername]) + if add_to_layer_stack: + new_layer = copy.deepcopy(net_layer_stack.layers[old_layername]) new_layer.layer = ( new_layers_init[0] + i, new_layers_init[1] + j, ) - net_layerstack.layers[ + net_layer_stack.layers[ f"{old_layername}{delimiter}{portname}" ] = new_layer net_component.add_polygon(polygon, layer=new_layer_number) @@ -102,4 +102,4 @@ def get_component_with_net_layers( net_component.name = f"{component.name}_net_layers" - return net_component, net_layerstack + return net_component, net_layer_stack