Toolkit Documentation

Set of helper functions that make it easier to manipulate and work with subclasses defined in components module

class picwriter.toolkit.Component(name, *args)

Super class for all objects created in PICwriter. This class handles rotations, naming, etc. for all components, so that writing python code for new cells requires less overhead. Component is a wrapper around gdspy Cell objects.

Args:
  • name (string): The name prefix to be used for these
Keyword Args:
  • angle (float): Angle in radians (between 0 and pi/2) at which the waveguide bends towards the coupling region. Default=pi/6.
add(element, origin=(0, 0), rotation=0.0, x_reflection=False)

Add a reference to an element or list of elements to the cell associated with this component

picwriter.toolkit.add(top_cell, component_cell, center=(0, 0), x_reflection=False)

First creates a CellReference to subcell, then adds this to topcell at location center.

Args:
  • top_cell (gdspy.Cell): Cell being added to
  • component_cell (gdspy.Cell): Cell of the component being added
Keyword Args:
  • port (tuple): location for the subcell to be added
  • direction (string): Direction that the component will point towards, can be of type ‘NORTH’, ‘WEST’, ‘SOUTH’, ‘EAST’, OR an angle (float, in radians). Defaults to ‘EAST’ (zero degrees of rotation).
Returns:
None
picwriter.toolkit.build_mask(cell, wgt, final_layer=None, final_datatype=None)

Builds the appropriate mask according to the resist specifications and fabrication type. Does this by applying a boolean ‘XOR’ or ‘AND’ operation on the waveguide and clad masks.

Args:
  • cell (gdspy.Cell): Cell with components. Final mask is placed in this cell.
  • wgt (WaveguideTemplate): Waveguide template containing the resist information, and layers/datatypes for the waveguides and cladding.
Keyword Args:
  • final_layer (int): layer to place the mask on (defaults to wgt.clad_layer + 1)
  • final_datatype (int): datatype to place the mask on (defaults to 0)
Returns:
None
picwriter.toolkit.build_waveguide_polygon(func, wg_width, start_direction, end_direction, start_val=0, end_val=1, grid=0.001)
Args:
  • func (function): Function that takes a single (floating point) argument, and returns a (x,y) tuple.
  • wg_width (float): Waveguide width
  • num_pts (int): Number of points that make up the waveguide path
  • start_direction (float): Starting direction of the path, in radians.
  • end_direction (float): End direction of the path, in radians.
Keyword Args:
  • start_val (float): Starting value (argument passed to func). Defaults to 0.
  • end_val (float): Ending value (argument passed to func). Defaults to 1.
  • grid (float): Grid resolution used to determine when curve length has converged. Guarantees that polygon formed by the points results in no more than a grid/2.0 error from the true position. Defaults to 0.001
Returns:
Two lists, one for each edge of the waveguide.
picwriter.toolkit.dist(pt1, pt2)

Given two cardinal points, returns the distance between the two.

Args:
  • pt1 (tuple): Point 1
  • pt2 (tuple): Point 2
Returns:
float Distance

Example:

import picwriter.toolkit as tk
print(tk.dist((0, 0), (100, 100)))

The above prints 141.42135623730951

picwriter.toolkit.flip_direction(direction)

Returns the opposite of direction, where each direction is either 'NORTH', 'WEST', 'SOUTH', or 'EAST'

Args:
  • direction (direction): Direction to be flipped
  • pt2 (tuple): Point 2
Returns:
direction ('NORTH', 'WEST', 'SOUTH', or 'EAST')
picwriter.toolkit.get_angle(pt1, pt2)

Given two cardinal points, returns the corresponding angle in radians. Must be an integer multiple of pi/2.

Args:
  • pt1 (tuple): Point 1
  • pt2 (tuple): Point 2
Returns:
float Angle (integer multiple of pi/2)

Example:

import picwriter.toolkit as tk
print(tk.get_angle((0, 0), (0, 100)))

The above prints 1.5707963267948966

picwriter.toolkit.get_curve_length(func, start, end, grid=0.001)

Returns the length (in microns) of a curve defined by the function func on the interval [start, end]

Args:
  • func (function): Function that takes a single (floating point) argument, and returns a (x,y) tuple.
  • start (float): Starting value (argument passed to func).
  • end (float): Ending value (argument passed to func).
Keyword Args:
  • grid (float): Grid resolution used to determine when curve length has converged. Defaults to 0.001.
Returns:
float Length
picwriter.toolkit.get_direction(pt1, pt2)

Returns a cardinal direction ('NORTH', 'WEST', 'SOUTH', and 'EAST') that corresponds to a cartesian point pt1 (tuple), pointing TOWARDS a second point `pt2

Args:
  • pt1 (tuple): Point 1
  • pt2 (tuple): Point 2
Returns:
string ('NORTH', 'WEST', 'SOUTH', and 'EAST')

Example:

import picwriter.toolkit as tk
tk.get_direction((0,0), (-100,0))

The above prints ‘WEST’

picwriter.toolkit.get_exact_angle(pt1, pt2)

Given two cardinal points, returns the corresponding angle in radians.

Args:
  • pt1 (tuple): Point 1
  • pt2 (tuple): Point 2
Returns:
float Angle (in radians)

Example:

import picwriter.toolkit as tk
print(tk.get_angle((0, 0), (100, 100)))

The above prints 0.785398163

picwriter.toolkit.get_keys(cell)

Returns a list of the keys available in a portlist, such as ‘input’, ‘output’, ‘top_output’, etc. Only works for picwriter components.

Args:
  • cell (gdspy.Cell): Cell from which to get get the portlist
Returns:
List of portlist keys corresponding to ‘cell’.
picwriter.toolkit.get_trace_length(trace, wgt)

Returns the total length of a curved waveguide trace.

Args:
  • trace (list): tracelist of (x,y) points all specifying 90 degree angles. Assumes there are no bends on the first and last point.
  • wgt (WaveguideTemplate): template for the waveguide, the bend_radius of which is used to compute the length of the curved section.
Returns:
float corresponding to the length of the waveguide trace
picwriter.toolkit.get_turn(dir1, dir2)

Returns an angle (+pi/2 or -pi/2) corresponding to the CW or CCW turns that takes you from direction dir1 to dir2, where each direction is either 'NORTH', 'WEST', 'SOUTH', or 'EAST'

Args:
  • dir1 (direction): Point 1
  • pt2 (tuple): Point 2
Returns:
float (+pi/2 or -pi/2)
picwriter.toolkit.normalize_angle(angle)

Returns the angle (in radians) between -pi and +pi that corresponds to the input angle

Args:
  • angle (float): Angle to normalize
Returns:
float Angle
picwriter.toolkit.reset_database()

Resets the gdspy library, and resets the CURRENT_CELLS and CURRENT_CELL_NAMES dicts

picwriter.toolkit.translate_point(pt, length, direction, height=0.0)

Returns the point (tuple) corresponding to pt translated by distance length in direction direction where each direction is either 'NORTH', 'WEST', 'SOUTH', or 'EAST'

Args:
  • pt (tuple): Starting point
  • length (float): Distance to move in direction
  • direction (direction): Direction to move in
Keyword Args:
  • height (float): Distance to move perpendicular to direction. Defaults to 0.
Returns:
point, tuple (x, y)