flake8-aided fixes
parent
db9b39dbc0
commit
6b01b43559
@ -0,0 +1,41 @@
|
|||||||
|
# pip install pillow scikit-image
|
||||||
|
# or
|
||||||
|
# sudo apt install python3-pil python3-skimage
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
from skimage.measure import find_contours
|
||||||
|
from matplotlib import pyplot
|
||||||
|
import numpy
|
||||||
|
|
||||||
|
from masque import Pattern, Library, Polygon
|
||||||
|
from masque.file.gdsii import writefile
|
||||||
|
|
||||||
|
#
|
||||||
|
# Read the image into a numpy array
|
||||||
|
#
|
||||||
|
im = Image.open('./Desktop/Camera/IMG_20220626_091101.jpg')
|
||||||
|
|
||||||
|
aa = numpy.array(im.convert(mode='L').getdata()).reshape(im.height, im.width)
|
||||||
|
|
||||||
|
threshold = (aa.max() - aa.min()) / 2
|
||||||
|
|
||||||
|
#
|
||||||
|
# Find edge contours and plot them
|
||||||
|
#
|
||||||
|
contours = find_contours(aa, threshold)
|
||||||
|
|
||||||
|
pyplot.imshow(aa)
|
||||||
|
for contour in contours:
|
||||||
|
pyplot.plot(contour[:, 1], contour[:, 0], linewidth=2)
|
||||||
|
pyplot.show(block=False)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create the layout from the contours
|
||||||
|
#
|
||||||
|
pat = Pattern()
|
||||||
|
pat.shapes = [Polygon(vertices=vv) for vv in contours if len(vv) < 1_000]
|
||||||
|
|
||||||
|
lib = {}
|
||||||
|
lib['my_mask_name'] = pat
|
||||||
|
|
||||||
|
writefile(lib, 'test_contours.gds', meters_per_unit=1e-9)
|
@ -1,103 +0,0 @@
|
|||||||
from typing import TypeVar, Dict, Tuple, Any
|
|
||||||
from abc import ABCMeta, abstractmethod
|
|
||||||
|
|
||||||
#from ..error import PatternLockedError
|
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar('T', bound='Lockable')
|
|
||||||
I = TypeVar('I', bound='LockableImpl')
|
|
||||||
|
|
||||||
|
|
||||||
class Lockable(metaclass=ABCMeta):
|
|
||||||
"""
|
|
||||||
Abstract class for all lockable entities
|
|
||||||
"""
|
|
||||||
__slots__ = () # type: Tuple[str, ...]
|
|
||||||
|
|
||||||
'''
|
|
||||||
---- Methods
|
|
||||||
'''
|
|
||||||
@abstractmethod
|
|
||||||
def lock(self: T) -> T:
|
|
||||||
"""
|
|
||||||
Lock the object, disallowing further changes
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
self
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def unlock(self: T) -> T:
|
|
||||||
"""
|
|
||||||
Unlock the object, reallowing changes
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
self
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def is_locked(self) -> bool:
|
|
||||||
"""
|
|
||||||
Returns:
|
|
||||||
True if the object is locked
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def set_locked(self: T, locked: bool) -> T:
|
|
||||||
"""
|
|
||||||
Locks or unlocks based on the argument.
|
|
||||||
No action if already in the requested state.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
locked: State to set.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
self
|
|
||||||
"""
|
|
||||||
if locked != self.is_locked():
|
|
||||||
if locked:
|
|
||||||
self.lock()
|
|
||||||
else:
|
|
||||||
self.unlock()
|
|
||||||
return self
|
|
||||||
|
|
||||||
|
|
||||||
class LockableImpl(Lockable, metaclass=ABCMeta):
|
|
||||||
"""
|
|
||||||
Simple implementation of Lockable
|
|
||||||
"""
|
|
||||||
__slots__ = () # type: Tuple[str, ...]
|
|
||||||
|
|
||||||
locked: bool
|
|
||||||
""" If `True`, disallows changes to the object """
|
|
||||||
|
|
||||||
'''
|
|
||||||
---- Non-abstract methods
|
|
||||||
'''
|
|
||||||
def __setattr__(self, name, value):
|
|
||||||
if self.locked and name != 'locked':
|
|
||||||
raise PatternLockedError()
|
|
||||||
object.__setattr__(self, name, value)
|
|
||||||
|
|
||||||
def __getstate__(self) -> Dict[str, Any]:
|
|
||||||
if hasattr(self, '__slots__'):
|
|
||||||
return {key: getattr(self, key) for key in self.__slots__}
|
|
||||||
else:
|
|
||||||
return self.__dict__
|
|
||||||
|
|
||||||
def __setstate__(self, state: Dict[str, Any]) -> None:
|
|
||||||
for k, v in state.items():
|
|
||||||
object.__setattr__(self, k, v)
|
|
||||||
|
|
||||||
def lock(self: I) -> I:
|
|
||||||
object.__setattr__(self, 'locked', True)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def unlock(self: I) -> I:
|
|
||||||
object.__setattr__(self, 'locked', False)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def is_locked(self) -> bool:
|
|
||||||
return self.locked
|
|
Loading…
Reference in New Issue