Improve docs, error messages, and type annotations
This commit is contained in:
parent
84f811e9d1
commit
c6684936cf
@ -10,6 +10,12 @@ Note that GDSII references follow the same convention as `masque`,
|
|||||||
|
|
||||||
Scaling, rotation, and mirroring apply to individual instances, not grid
|
Scaling, rotation, and mirroring apply to individual instances, not grid
|
||||||
vectors or offsets.
|
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 List, Any, Dict, Tuple, Callable, Union, Sequence, Iterable, Optional
|
||||||
from typing import Sequence, Mapping
|
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 rotation_matrix_2d, get_bit, set_bit, vector2, is_scalar, layer_t
|
||||||
from ..utils import remove_colinear_vertices, normalize_mirror, annotations_t
|
from ..utils import remove_colinear_vertices, normalize_mirror, annotations_t
|
||||||
|
|
||||||
#TODO absolute positioning
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -127,8 +131,6 @@ def build(patterns: Union[Pattern, Sequence[Pattern]],
|
|||||||
structure = gdsii.structure.Structure(name=pat.name.encode('ASCII'))
|
structure = gdsii.structure.Structure(name=pat.name.encode('ASCII'))
|
||||||
lib.append(structure)
|
lib.append(structure)
|
||||||
|
|
||||||
# structure.properties = _annotations_to_properties(pat.annotations, 512)
|
|
||||||
|
|
||||||
structure += _shapes_to_elements(pat.shapes)
|
structure += _shapes_to_elements(pat.shapes)
|
||||||
structure += _labels_to_texts(pat.labels)
|
structure += _labels_to_texts(pat.labels)
|
||||||
structure += _subpatterns_to_refs(pat.subpatterns)
|
structure += _subpatterns_to_refs(pat.subpatterns)
|
||||||
@ -243,9 +245,6 @@ def read(stream: io.BufferedIOBase,
|
|||||||
patterns = []
|
patterns = []
|
||||||
for structure in lib:
|
for structure in lib:
|
||||||
pat = Pattern(name=structure.name.decode('ASCII'))
|
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:
|
for element in structure:
|
||||||
# Switch based on element type:
|
# Switch based on element type:
|
||||||
if isinstance(element, gdsii.elements.Boundary):
|
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
|
Helper function to create a SubPattern from an SREF or AREF. Sets subpat.pattern to None
|
||||||
and sets the instance .identifier to (struct_name,).
|
and sets the instance .identifier to (struct_name,).
|
||||||
|
|
||||||
BUG:
|
NOTE: "Absolute" means not affected by parent elements.
|
||||||
"Absolute" means not affected by parent elements.
|
That's not currently supported by masque at all (and not planned).
|
||||||
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.
|
|
||||||
"""
|
"""
|
||||||
rotation = 0.0
|
rotation = 0.0
|
||||||
offset = numpy.array(element.xy[0], dtype=float)
|
offset = numpy.array(element.xy[0], dtype=float)
|
||||||
@ -320,12 +317,12 @@ def _ref_to_subpat(element: Union[gdsii.elements.SRef,
|
|||||||
scale = element.mag
|
scale = element.mag
|
||||||
# Bit 13 means absolute scale
|
# Bit 13 means absolute scale
|
||||||
if get_bit(element.strans, 15 - 13):
|
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:
|
if element.angle is not None:
|
||||||
rotation = numpy.deg2rad(element.angle)
|
rotation = numpy.deg2rad(element.angle)
|
||||||
# Bit 14 means absolute rotation
|
# Bit 14 means absolute rotation
|
||||||
if get_bit(element.strans, 15 - 14):
|
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
|
# Bit 0 means mirror x-axis
|
||||||
if get_bit(element.strans, 15 - 0):
|
if get_bit(element.strans, 15 - 0):
|
||||||
mirror_across_x = True
|
mirror_across_x = True
|
||||||
|
@ -47,7 +47,6 @@ path_cap_map = {
|
|||||||
PathExtensionScheme.Arbitrary: Path.Cap.SquareCustom,
|
PathExtensionScheme.Arbitrary: Path.Cap.SquareCustom,
|
||||||
}
|
}
|
||||||
|
|
||||||
#TODO implement properties
|
|
||||||
#TODO implement more shape types?
|
#TODO implement more shape types?
|
||||||
|
|
||||||
def build(patterns: Union[Pattern, Sequence[Pattern]],
|
def build(patterns: Union[Pattern, Sequence[Pattern]],
|
||||||
|
@ -18,7 +18,7 @@ from .shapes import Shape, Polygon
|
|||||||
from .label import Label
|
from .label import Label
|
||||||
from .utils import rotation_matrix_2d, vector2, normalize_mirror, AutoSlots, annotations_t
|
from .utils import rotation_matrix_2d, vector2, normalize_mirror, AutoSlots, annotations_t
|
||||||
from .error import PatternError, PatternLockedError
|
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']
|
visitor_function_t = Callable[['Pattern', Tuple['Pattern'], Dict, numpy.ndarray], 'Pattern']
|
||||||
|
@ -246,7 +246,7 @@ class Shape(PositionableImpl, LayerableImpl, DoseableImpl, Rotatable, Mirrorable
|
|||||||
List of `Polygon` objects with grid-aligned edges.
|
List of `Polygon` objects with grid-aligned edges.
|
||||||
"""
|
"""
|
||||||
from . import Polygon
|
from . import Polygon
|
||||||
import skimage.measure
|
import skimage.measure # type: ignore
|
||||||
import float_raster
|
import float_raster
|
||||||
|
|
||||||
grid_x = numpy.unique(grid_x)
|
grid_x = numpy.unique(grid_x)
|
||||||
|
@ -170,8 +170,8 @@ def get_char_as_polygons(font_path: str,
|
|||||||
char: str,
|
char: str,
|
||||||
resolution: float = 48*64,
|
resolution: float = 48*64,
|
||||||
) -> Tuple[List[List[List[float]]], float]:
|
) -> Tuple[List[List[List[float]]], float]:
|
||||||
from freetype import Face
|
from freetype import Face # type: ignore
|
||||||
from matplotlib.path import Path
|
from matplotlib.path import Path # type: ignore
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Get a list of polygons representing a single character.
|
Get a list of polygons representing a single character.
|
||||||
|
Loading…
Reference in New Issue
Block a user