gdshelpers.geometry package

Submodules

gdshelpers.geometry.chip module

class gdshelpers.geometry.chip.Cell(name: str)

Bases: object

add_cell(cell, origin=(0, 0), angle: Optional[float] = None, columns=1, rows=1, spacing=None)

Adds a Cell to this cell

Parameters:
  • cell – Cell to add
  • origin – position where to add the cell
  • angle – defines the rotation of the cell
  • columns – Number of columns
  • rows – Number of rows
  • spacing – Spacing between the cells, should be an array in the form [x_spacing, y_spacing]
add_dlw_data(dlw_type, dlw_id, data)

Adds data for 3D-hybrid-integration to the Cell. This is usually only done by using the Device

Parameters:
  • dlw_type – type of the represented object
  • dlw_id – id of the represented object
  • data – data of the object
add_dlw_marker(label: str, layer: int, origin, box_size=2.5)

Adds a marker for 3D-hybrid integration

Parameters:
  • label – Name of the marker, needs to be unique within the device
  • layer – Layer at which the marker and markers should be written
  • origin – Position of the marker
  • box_size – Size of the box of the marker
add_dlw_taper_at_port(label: str, layer: int, port: gdshelpers.parts.port.Port, taper_length: float, tip_width=0.01, with_markers=True, box_size=2.5)

Adds a taper for 3D-hybrid-integration at a certain port

Parameters:
  • label – Name of the port, needs to be unique within the device
  • layer – Layer at which the taper and markers should be written
  • port – Port to which the taper should be attached
  • taper_length – length of the taper
  • tip_width – final width of the tip
  • with_markers – for recognizing the taper markers near to the taper are necessary. In certain designs the standard positions are not appropriate and can therefore be disabled and manually added
  • box_size – Size of the box of the markers
add_ebl_frame(layer: int, frame_generator, bounds=None, **kwargs)

Adds global markers to the layout

Parameters:
  • layer – layer on which the markers should be positioned
  • frame_generator – either a method, which returns a list of the markers, which should be added or the name of a generator from the gdshelpers.geometry.ebl_frame_generators package
  • bounds – Optionally the bounds to use can be provided in the form (min_x, min_y, max_x, max_y). If None, the standard cell bounds will be used.
  • kwargs – Parameters which are directly passed to the frame generator (other than the bounds parameter)
add_ebl_marker(layer: int, marker)

Adds an Marker to the layout

Parameters:
  • layer – layer on which the marker should be positioned
  • marker – marker, that should be added (from gdshelpers.parts.markers)
add_frame(padding=30.0, line_width=1.0, frame_layer: int = 6, bounds=None)

Generates a rectangular frame around the contents of the cell.

Parameters:
  • padding – Add a padding of the given value around the contents of the cell
  • line_width – Width of the frame line
  • frame_layer – Layer to put the frame on.
  • bounds – Optionally, an explicit extent in the form (min_x, min_y, max_x, max_y) can be passed to the function. If None (default), the current extent of the cell will be chosen.
add_region_layer(region_layer: int = 5, layers: Optional[List[int]] = None)

Generate a region layer around all objects on layers and place it on layer region_layer. If layers is None, all layers are used.

add_to_desc(key, data)

Adds data to the .desc-file can be used for any data related to the cells, e.g. the swept parameters/…

Parameters:
  • key – name of the entry
  • data – data which are added to the .desc-file, the data have to be serializable by json
add_to_layer(layer: int, *geometry)

Adds a shapely geometry to a the layer

Parameters:
  • layer – id of the layer, a tuple (layer, datatype) can also be passed to define the datatype as well
  • geometry – shapely geometry
bounds

The outer bounding box of the cell. Returns None if it is empty.

export_mesh(filename: str, layer_defs)

Saves the current geometry as a mesh-file.

Parameters:
  • filename – Name of the file which will be created. The file ending determines the format.
  • layer_defs – Definition of the layers, should be a list like [(layer,(z_min,z_max)),…]
get_bounds(layers: Optional[List[int]] = None)

Calculates and returns the envelope for the given layers. Returns None if it is empty.

get_desc()
get_dlw_data()
get_fractured_layer_dict(max_points=4000, max_line_points=4000)
get_gdspy_cell(executor=None)
get_gdspy_lib()
get_oasis_cells(grid_steps_per_micron=1000, executor=None)
get_patches(origin=(0, 0), angle_sum=0, angle=0, layers: Optional[List[int]] = None)
get_reduced_layer(layer: int)

Returns a single shapely object containing the structures on a certain layer from this cell and all added cells.

Parameters:layer – the layer whose structures will be returned
Returns:a single shapely-geometry
save(name=None, library=None, grid_steps_per_micron=1000, parallel=False, max_workers=None)

Exports the layout and creates an DLW-file, if DLW-features are used.

Parameters:
  • name – The filename of the saved file. The ending of the filename defines the format. Currently .gds, .oasis and .dxf are supported.
  • library – Name of the used library. Should stay None in order to select the library depending on the file-ending. The use of this parameter is deprecated and this parameter will be removed in a future release.
  • grid_steps_per_micron – Defines the resolution
  • parallel – Defines if parallelization is used (only supported in Python 3). Standard value will be changed to True in a future version. Deactivating can be useful for debugging reasons.
  • max_workers – If parallel is True, this can be used to limit the number of parallel processes. This can be useful if you run into out-of-memory errors otherwise.
save_desc(filename: str)

Saves a description file for the layout. The file format is not final yet and might change in a future release.

Parameters:filename – name of the file the description data will be written to
save_image(filename: str, layers: Optional[List[int]] = None, antialiased=True, resolution=1.0, ylim=(None, None), xlim=(None, None), scale=1.0)

Save cell object as an image.

You can either use a rasterized file format such as png but also formats such as SVG or PDF.

Parameters:
  • filename – Name of the image file.
  • layers – Layers to show im the image
  • resolution – Rasterization resolution in GDSII units.
  • antialiased – Whether to use a anti-aliasing or not.
  • ylim – Tuple of (min_x, max_x) to export.
  • xlim – Tuple of (min_y, max_y) to export.
  • scale – Defines the scale of the image
show(layers: Optional[List[int]] = None, padding=5)

Shows the current cell

Parameters:
  • layers – List of the layers to be shown, passing None shows all layers
  • padding – padding around the structure
size

Returns the size of the cell

start_viewer()

gdshelpers.geometry.ebl_frame_generators module

gdshelpers.geometry.ebl_frame_generators.raith_marker_frame(bounds, padding=100, pitch=200, size=20, n=5)

Generates a list of markers markers in each corner around the given bounding box. In each corner the markers are arranged in an L shape. This allows to have more markers (for exposure of many steps sometimes more than four markers are necessary) with larger distance between the markers (minimize risk of wrong markers being found by the EBL) without taking up too much space.

Parameters:
  • bounds – The bounds around which the markers will be arranged (the marker centers will be inside these bounds)
  • padding – Spacing between the given bounds and the markers. Can also be negative to place the markers inside the bounding box.
  • pitch – Pitch between two adjacent markers
  • size – The marker size
  • n – This determines the number of markers: There will be (2*n)+1 markers in each corner.

gdshelpers.geometry.shapely_adapter module

gdshelpers.geometry.shapely_adapter.bounds_union(bound_list)

Calculates the bounding box of all bounding boxes in the given list. Each bbox has to be given as (xmin, ymin, xmax, ymax) tuple.

Parameters:bound_list – List of tuples containing all bounding boxes to be merged
gdshelpers.geometry.shapely_adapter.convert_to_gdscad(objs, layer=1, datatype=None, path_width=1.0, path_pathtype=0, max_points=None, over_fracture_factor=1, max_points_line=None)

Convert any shapely or list of shapely objects to a list of gdsCAD objects.

Since Shapely objects do not contain layer information nor line width for Shapely lines, you have to specify these during conversion. Typically, you will only convert polygons and specify the layer.

Export options such as datatype and maximum number of points per Polygon/Line default to the current module default.

On special feature is the over_fracture_factor. The polygons will be fractured into max_points/over_fracture_factor points and then healed again - which results in better fragmentation of some geometries. An over_fracture_factor of 0 will suppress healing.

Parameters:
  • objs – Part or Shapely object or list of Parts and/or Shapely objects.
  • layer (int) – Layer on which to put the objects.
  • datatype (int) – GDS datatype of the converted objects. Defaults to module wide settings.
  • path_width (float) – With of GDS path, converted from Shapely lines.
  • path_pathtype (int) – GDS path end type.
  • max_points (int, None) – Maximum number of points. Defaults to module wide settings.
  • max_points_line (int, None) – Maximum number of points for lines. Defaults to module wide settings.
  • over_fracture_factor (int) –

    Break polygons in over_fracture_factor times smaller objects first. Then merge them again. May result in better fracturing but high numbers increase conversion time.

    When over_fracture_factor is set to 0, no additional healing is done.

gdshelpers.geometry.shapely_adapter.convert_to_layout_objs(objs, layer=1, datatype=None, path_width=1.0, path_pathtype=0, max_points=None, over_fracture_factor=1, max_points_line=None, library='gdscad', grid_steps_per_micron=1000)

Convert any shapely or list of shapely objects to a list of gdsCAD objects.

Since Shapely objects do not contain layer information nor line width for Shapely lines, you have to specify these during conversion. Typically, you will only convert polygons and specify the layer.

Export options such as datatype and maximum number of points per Polygon/Line default to the current module default.

On special feature is the over_fracture_factor. The polygons will be fractured into max_points/over_fracture_factor points and then healed again - which results in better fragmentation of some geometries. An over_fracture_factor of 0 will suppress healing.

Parameters:
  • objs – Part or Shapely object or list of Parts and/or Shapely objects.
  • layer (int) – Layer on which to put the objects.
  • datatype (int) – GDS datatype of the converted objects. Defaults to module wide settings.
  • path_width (float) – With of GDS path, converted from Shapely lines.
  • path_pathtype (int) – GDS path end type.
  • max_points (int, None) – Maximum number of points. Defaults to module wide settings.
  • max_points_line (int, None) – Maximum number of points for lines. Defaults to module wide settings.
  • over_fracture_factor (int) –

    Break polygons in over_fracture_factor times smaller objects first. Then merge them again. May result in better fracturing but high numbers increase conversion time.

    When over_fracture_factor is set to 0, no additional healing is done.

  • library (str) – Defines the used library, either gdscad or gdspy
  • grid_steps_per_micron (int) – Number of steps of the grid per micron, defaults to 1000 steps per micron
gdshelpers.geometry.shapely_adapter.cut_shapely_object(obj, x_axis=None, y_axis=None, other_side=False)

Cut a shapely object into two halves.

If both x_axis and y_axis are None, they are assumed to be the center of the bounding box.

If only one of the axis is given, and the other axis is None, the object is cut at the given axis.

If both values are given, or inferred to be the center of the bounding box due to being both None, the object is cut along its longer side.

Parameters:
  • obj (shapely.base.BaseGeometry) – Basically any shapely object
  • x_axis (float, None) – x-axis cut value.
  • y_axis – y-axis cut value.
  • other_side – If the cut axis is determined automatically, use the other direction.
Returns:

A tuple of two shapely objects.

Return type:

list

gdshelpers.geometry.shapely_adapter.fracture(obj, max_points_poly, max_points_line, max_interior=0)
gdshelpers.geometry.shapely_adapter.fracture_intelligently(obj, max_points, max_points_line, over_fracture_factor=1)
gdshelpers.geometry.shapely_adapter.geometric_union(objs)

Join a list of Parts and/or Shapely objects to one big Shapely object.

Parameters:objs – List of Parts and Shapely objects.
Returns:Merged Shapely geometry.
Return type:shapely.base.BaseGeometry
gdshelpers.geometry.shapely_adapter.heal(objs, max_points, max_interior=0)

Heal a list of Shapely geometries.

All elements touching each other will be merged as long as the number of points remains below max_points.

Parameters:
  • objs (list, tuple) – List Shapely geometries.
  • max_points (int) – Maximum number of points.
Returns:

List of healed Shapely geometries.

Return type:

list

gdshelpers.geometry.shapely_adapter.shapely_collection_to_basic_objs(collection)

Convert the object or the collection to a list of basic shapely objects.

Parameters:collection
Returns:
rtype:
gdshelpers.geometry.shapely_adapter.transform_bounds(bounds, origin, rotation=0, scale=1.0)

Transform a bounds tuple (xmin, ymin, xmax, ymax) by the given offset, rotation and scale.

Module contents

gdshelpers.geometry.convert_to_gdscad(objs, layer=1, datatype=None, path_width=1.0, path_pathtype=0, max_points=None, over_fracture_factor=1, max_points_line=None)

Convert any shapely or list of shapely objects to a list of gdsCAD objects.

Since Shapely objects do not contain layer information nor line width for Shapely lines, you have to specify these during conversion. Typically, you will only convert polygons and specify the layer.

Export options such as datatype and maximum number of points per Polygon/Line default to the current module default.

On special feature is the over_fracture_factor. The polygons will be fractured into max_points/over_fracture_factor points and then healed again - which results in better fragmentation of some geometries. An over_fracture_factor of 0 will suppress healing.

Parameters:
  • objs – Part or Shapely object or list of Parts and/or Shapely objects.
  • layer (int) – Layer on which to put the objects.
  • datatype (int) – GDS datatype of the converted objects. Defaults to module wide settings.
  • path_width (float) – With of GDS path, converted from Shapely lines.
  • path_pathtype (int) – GDS path end type.
  • max_points (int, None) – Maximum number of points. Defaults to module wide settings.
  • max_points_line (int, None) – Maximum number of points for lines. Defaults to module wide settings.
  • over_fracture_factor (int) –

    Break polygons in over_fracture_factor times smaller objects first. Then merge them again. May result in better fracturing but high numbers increase conversion time.

    When over_fracture_factor is set to 0, no additional healing is done.

gdshelpers.geometry.geometric_union(objs)

Join a list of Parts and/or Shapely objects to one big Shapely object.

Parameters:objs – List of Parts and Shapely objects.
Returns:Merged Shapely geometry.
Return type:shapely.base.BaseGeometry
gdshelpers.geometry.cut_shapely_object(obj, x_axis=None, y_axis=None, other_side=False)

Cut a shapely object into two halves.

If both x_axis and y_axis are None, they are assumed to be the center of the bounding box.

If only one of the axis is given, and the other axis is None, the object is cut at the given axis.

If both values are given, or inferred to be the center of the bounding box due to being both None, the object is cut along its longer side.

Parameters:
  • obj (shapely.base.BaseGeometry) – Basically any shapely object
  • x_axis (float, None) – x-axis cut value.
  • y_axis – y-axis cut value.
  • other_side – If the cut axis is determined automatically, use the other direction.
Returns:

A tuple of two shapely objects.

Return type:

list

gdshelpers.geometry.fracture(obj, max_points_poly, max_points_line, max_interior=0)