MaskSpec

class photonforge.MaskSpec(operand1=None, operand2=None, operation='+', dilation=0, translation=(0, 0))

Mask specification.

This class is mainly used when creating an ExtrusionSpec for a Technology.

Parameters:
  • operand1 (str | tuple[int, int] | MaskSpec | Iterable[str | tuple[int, int] | MaskSpec]) – Layers or sub-masks that compose this maks specification that are joined to create this specification.

  • operand2 (str | tuple[int, int] | MaskSpec | Iterable[str | tuple[int, int] | MaskSpec]) – Layers or sub-masks that can be combined with operand1 through a boolean operation.

  • operation (Literal["+", "*", "-", "^"]) – One of “+” (union), “*” (intersection), “-” (difference), or “^” (symmetric difference).

  • dilation – Dilation (erosion, if negative) applied to the mask.

  • translation – Translation applied to the mask.

Examples

Masks specifications can be combined using arithmetic operations:

>>> layer_1_0 = MaskSpec((1, 0))
>>> layer_2_0 = MaskSpec((2, 0), dilation=0.1)
>>> difference = layer_1_0 - layer_2_0
>>> eroded_diff = difference ** -0.1
>>> eroded_diff
MaskSpec(operand0=[MaskSpec((1, 0))], operand1=[MaskSpec((2, 0), dilation=0.1)], operation='-', dilation=-0.1)

Note

An empty list of operands indicates the full component bounds. The inversion of a layer is indicated by subtracting it from the component bounds.

Methods

copy()

Create a copy of this mask specification.

format([layer_names, technology])

Create a string expression for this mask using names instead of layers.

from_json(json_str)

Import object data from json.

parse(expression[, technology])

Parse a string expression into a mask specification.

uses_translation

uses_translation(self)

Attributes

dilation

Mask dilation.

json

(DEPRECATED) Json representation of this layer specification.

layer

Mask layer (read only).

operand1

First operand for this mask.

operand2

Second operand for this mask.

operation

Mask generation operation.

properties

Object properties.

translation

Mask translation.

copy()

Create a copy of this mask specification.

Returns:

New copy.

Return type:

MaskSpec

dilation

Mask dilation.

Type:

float

format(layer_names=None, technology=None)

Create a string expression for this mask using names instead of layers.

Parameters:
  • layer_names (dict[tuple[int, int], str] | None) – Dictionary mapping layer tuples to names, that will replace the layer tuples in the resulting expression. If not set, the technology layer names are used instead.

  • technology (Technology | None) – Technology whose layers will be used to extract the layer names. Not used if layer_names is defined. If not specified, the current default technology is used.

Returns:

Mask specification string.

Return type:

str

Example

>>> mask = MaskSpec.parse("(0, 0) * (1, 0)")
>>> mask.format({(0, 0): "A", (1, 0): "B"})
"('A' * 'B')"
static from_json(json_str)

Import object data from json.

Warning

This method is DEPRECATED and will be removed in the next release.

Parameters:

json_str (str) – String containing the json data.

Returns:

PhotonForge object.

Return type:

Any

json

(DEPRECATED) Json representation of this layer specification.

Type:

str

layer

Mask layer (read only).

Type:

tuple[int, int] | None

operand1

First operand for this mask.

Type:

list[MaskSpec]

operand2

Second operand for this mask.

Type:

list[MaskSpec]

operation

Mask generation operation.

Type:

Literal[“+”, “*”, “-”, “^”]

static parse(expression, technology=None)

Parse a string expression into a mask specification.

Parameters:
  • expression (str) – String expression to parse.

  • technology (Technology | None) – Technology to be used for layer names in the expression.

Returns:

Resulting mask specification.

Return type:

MaskSpec

Example

Invert layer (0, 0) and intersect the result with layer (10, 0):

>>> MaskSpec.parse("-(0, 0) * (10, 0)")
MaskSpec(operand0=[MaskSpec(operand0=[MaskSpec(operand0=[], operand1=[], operation='+')], operand1=[MaskSpec((0, 0))], operation='-')], operand1=[MaskSpec((10, 0))], operation='*')

Difference between layers ‘SLAB’ and ‘WG_CORE’ intersected with (9, 10):

>>> MaskSpec.parse("('SLAB' - 'WG_CORE') * (9, 10)")
MaskSpec(operand0=[MaskSpec(operand0=[MaskSpec((3, 0))], operand1=[MaskSpec((2, 0))], operation='-')], operand1=[MaskSpec((9, 10))], operation='*')

Union of ‘WG_CORE’ and ‘WG_CLAD’ eroded by 100 nm:

>>> MaskSpec.parse("('WG_CORE' + 'WG_CLAD') ** -0.1")
MaskSpec(operand0=[MaskSpec((2, 0)), MaskSpec((1, 0))], operand1=[], operation='+', dilation=-0.1)
properties

Object properties.

Type:

Properties

translation

Mask translation.

Type:

ndarray

uses_translation()

uses_translation(self) –

Check whether this mask or sub-masks use any translation.

Returns:

Mask translation indication.

Return type:

bool