diff --git a/masque/file/gdsii.py b/masque/file/gdsii.py index 011afe4..c3a0719 100644 --- a/masque/file/gdsii.py +++ b/masque/file/gdsii.py @@ -151,7 +151,7 @@ def dose2dtype(patterns: List[Pattern], For each shape in each pattern, set shape.layer to the tuple (base_layer, datatype), where: layer is chosen to be equal to the original shape.layer if it is an int, - or shape.layer[0] if it is a tuple + or shape.layer[0] if it is a tuple. `str` layers raise a PatterError. datatype is chosen arbitrarily, based on calcualted dose for each shape. Shapes with equal calcualted dose will have the same datatype. A list of doses is retured, providing a mapping between datatype @@ -213,8 +213,10 @@ def dose2dtype(patterns: List[Pattern], data_type = dose_vals_list.index(shape.dose * pat_dose) if isinstance(shape.layer, int): shape.layer = (shape.layer, data_type) - else: + elif isinstance(shape.layer, tuple): shape.layer = (shape.layer[0], data_type) + else: + raise PatternError(f'Invalid layer for gdsii: {shape.layer}') new_pats[(pat_id, pat_dose)] = pat @@ -377,12 +379,14 @@ def _mlayer2gds(mlayer: layer_t) -> Tuple[int, int]: if isinstance(mlayer, int): layer = mlayer data_type = 0 - else: + elif isinstance(mlayer, tuple): layer = mlayer[0] if len(mlayer) > 1: data_type = mlayer[1] else: data_type = 0 + else: + raise PatternError(f'Invalid layer for gdsii: {layer}. Note that gdsii layers cannot be strings.') return layer, data_type diff --git a/masque/label.py b/masque/label.py index e09c60e..df7f3cf 100644 --- a/masque/label.py +++ b/masque/label.py @@ -55,7 +55,7 @@ class Label: @property def layer(self) -> layer_t: """ - Layer number (int or tuple of ints) + Layer number or name (int, tuple of ints, or string) """ return self._layer diff --git a/masque/shapes/shape.py b/masque/shapes/shape.py index 2f7db22..cfc4a54 100644 --- a/masque/shapes/shape.py +++ b/masque/shapes/shape.py @@ -174,7 +174,7 @@ class Shape(metaclass=ABCMeta): @property def layer(self) -> layer_t: """ - Layer number (int or tuple of ints) + Layer number or name (int, tuple of ints, or string) """ return self._layer diff --git a/masque/utils.py b/masque/utils.py index 22495d9..e71a0cd 100644 --- a/masque/utils.py +++ b/masque/utils.py @@ -8,7 +8,7 @@ import numpy # Type definitions vector2 = Union[numpy.ndarray, Tuple[float, float], Sequence[float]] -layer_t = Union[int, Tuple[int, int]] +layer_t = Union[int, Tuple[int, int], str] def is_scalar(var: Any) -> bool: