From c6684936cf2b3025f481c367e18ef0ca33f1237b Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sat, 26 Sep 2020 17:33:46 -0700 Subject: [PATCH] Improve docs, error messages, and type annotations --- masque/file/gdsii.py | 23 ++++++++++------------- masque/file/oasis.py | 1 - masque/pattern.py | 2 +- masque/shapes/shape.py | 2 +- masque/shapes/text.py | 4 ++-- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/masque/file/gdsii.py b/masque/file/gdsii.py index 18fc9ff..3d97fe3 100644 --- a/masque/file/gdsii.py +++ b/masque/file/gdsii.py @@ -10,6 +10,12 @@ Note that GDSII references follow the same convention as `masque`, Scaling, rotation, and mirroring apply to individual instances, not grid vectors or offsets. + +Notes: + * absolute positioning is not supported + * PLEX is not supported + * ELFLAGS are not supported + * GDS does not support library- or structure-level annotations """ from typing import List, Any, Dict, Tuple, Callable, Union, Sequence, Iterable, Optional from typing import Sequence, Mapping @@ -35,8 +41,6 @@ from ..repetition import Grid from ..utils import rotation_matrix_2d, get_bit, set_bit, vector2, is_scalar, layer_t from ..utils import remove_colinear_vertices, normalize_mirror, annotations_t -#TODO absolute positioning - logger = logging.getLogger(__name__) @@ -127,8 +131,6 @@ def build(patterns: Union[Pattern, Sequence[Pattern]], structure = gdsii.structure.Structure(name=pat.name.encode('ASCII')) lib.append(structure) -# structure.properties = _annotations_to_properties(pat.annotations, 512) - structure += _shapes_to_elements(pat.shapes) structure += _labels_to_texts(pat.labels) structure += _subpatterns_to_refs(pat.subpatterns) @@ -243,9 +245,6 @@ def read(stream: io.BufferedIOBase, patterns = [] for structure in lib: pat = Pattern(name=structure.name.decode('ASCII')) - if pat.annotations: - logger.warning('Dropping Pattern-level annotations; they are not supported by python-gdsii') -# pat.annotations = {str(k): v for k, v in structure.properties} for element in structure: # Switch based on element type: if isinstance(element, gdsii.elements.Boundary): @@ -304,10 +303,8 @@ def _ref_to_subpat(element: Union[gdsii.elements.SRef, Helper function to create a SubPattern from an SREF or AREF. Sets subpat.pattern to None and sets the instance .identifier to (struct_name,). - BUG: - "Absolute" means not affected by parent elements. - That's not currently supported by masque at all, so need to either tag it and - undo the parent transformations, or implement it in masque. + NOTE: "Absolute" means not affected by parent elements. + That's not currently supported by masque at all (and not planned). """ rotation = 0.0 offset = numpy.array(element.xy[0], dtype=float) @@ -320,12 +317,12 @@ def _ref_to_subpat(element: Union[gdsii.elements.SRef, scale = element.mag # Bit 13 means absolute scale if get_bit(element.strans, 15 - 13): - raise PatternError('Absolute scale is not implemented yet!') + raise PatternError('Absolute scale is not implemented in masque!') if element.angle is not None: rotation = numpy.deg2rad(element.angle) # Bit 14 means absolute rotation if get_bit(element.strans, 15 - 14): - raise PatternError('Absolute rotation is not implemented yet!') + raise PatternError('Absolute rotation is not implemented in masque!') # Bit 0 means mirror x-axis if get_bit(element.strans, 15 - 0): mirror_across_x = True diff --git a/masque/file/oasis.py b/masque/file/oasis.py index 142b4a1..8d9e074 100644 --- a/masque/file/oasis.py +++ b/masque/file/oasis.py @@ -47,7 +47,6 @@ path_cap_map = { PathExtensionScheme.Arbitrary: Path.Cap.SquareCustom, } -#TODO implement properties #TODO implement more shape types? def build(patterns: Union[Pattern, Sequence[Pattern]], diff --git a/masque/pattern.py b/masque/pattern.py index adbef2b..2393a6f 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -18,7 +18,7 @@ from .shapes import Shape, Polygon from .label import Label from .utils import rotation_matrix_2d, vector2, normalize_mirror, AutoSlots, annotations_t from .error import PatternError, PatternLockedError -from .traits import LockableImpl, AnnotatableImpl +from .traits import LockableImpl, AnnotatableImpl, Scalable visitor_function_t = Callable[['Pattern', Tuple['Pattern'], Dict, numpy.ndarray], 'Pattern'] diff --git a/masque/shapes/shape.py b/masque/shapes/shape.py index 6c72263..8ffb1a4 100644 --- a/masque/shapes/shape.py +++ b/masque/shapes/shape.py @@ -246,7 +246,7 @@ class Shape(PositionableImpl, LayerableImpl, DoseableImpl, Rotatable, Mirrorable List of `Polygon` objects with grid-aligned edges. """ from . import Polygon - import skimage.measure + import skimage.measure # type: ignore import float_raster grid_x = numpy.unique(grid_x) diff --git a/masque/shapes/text.py b/masque/shapes/text.py index debd994..2384404 100644 --- a/masque/shapes/text.py +++ b/masque/shapes/text.py @@ -170,8 +170,8 @@ def get_char_as_polygons(font_path: str, char: str, resolution: float = 48*64, ) -> Tuple[List[List[List[float]]], float]: - from freetype import Face - from matplotlib.path import Path + from freetype import Face # type: ignore + from matplotlib.path import Path # type: ignore """ Get a list of polygons representing a single character.