-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPatternGenerator.py
152 lines (131 loc) · 4.63 KB
/
PatternGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# -*- coding: utf-8 -*-
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
"""
Some basic functions for designing pattern.
"""
import numpy as np
def dotPattern(x,y,dose=1):
'''just dots and dose.'''
return np.array([[x,y,dose]])
def linPattern(x1,y1,x2,y2,ss,dose=1):
'''line start at (x1,y2), end at (x2,y2), step and dose at each step.'''
assert ss > 0
d=np.sqrt((x2-x1)**2+(y2-y1)**2)
a=np.arctan((y2-y1)/(x2-x1))
n=int(round(d/ss))
pattern=np.zeros((n, 3), dtype = np.float32)
for i in range(n):
pattern[i] = [x1+i*ss*np.cos(a),y1+i*ss*np.sin(a),dose]
return pattern
#l=linPattern(0,0,100,0,4)
def rectPattern(x1,y1,x2,y2,ss,dose=1):
'''rectangle = rows x lines.'''
assert ss > 0
nx=int(round(abs(x2-x1)/ss))
ny=int(round(abs(y2-y1)/ss))
pattern=np.zeros((nx*ny, 3), dtype = np.float32)
for i in range(ny):
pattern[i*nx:(i+1)*nx]=linPattern(x1,y1+i*ss,x2,y1+i*ss,ss,dose)
return pattern
#rect=rectPattern(0,0,20,10,3)
def ringPattern(x,y,r,ss,dose=1):
'''ring center (x,y), radius r, step size and dose.
'''
assert ss > 0
n=int(2*np.pi*r/ss)
pattern=np.zeros((n, 3), dtype = np.float32)
try:
a=2*np.pi/n
for i in range(n):
pattern[i]=[x+r*np.cos(a*i),y+r*np.sin(a*i),1]
except ZeroDivisionError:
pattern=dotPattern(x,y,dose)
return pattern
#ring=ringPattern(0,0,r,4)
def circPattern(x,y,r,ss,dose=1):
'''circle filled center at (x,y), radius, step size and dose.'''
assert ss > 0
pattern=np.zeros((0, 3), dtype = np.float32)
nr=int(r/ss)
for i in range(nr):
pattern=np.append(pattern,ringPattern(x,y,i*ss,ss,dose),axis=0)
return pattern
#circ=circPattern(0,0,r,ss)
def trianPattern(x,y,a,ss,dose=1):
'''todo!'''
return
def polyPattern(points,ss,dose=1):
'''todo!'''
return
def rot(alpha):
'''rotation angle alpha.
use case:
l=linPattern(0,0,36,0,4)
rota=rot(np.pi/3)
l2=l[:,:-1]*rota'''
return np.matrix( [[np.cos(alpha),-np.sin(alpha)],[np.sin(alpha),np.cos(alpha)]] )
def addPattern(pattern1,pattern2):
'''add pattern1 to pattern2.'''
pout=np.append(pattern2,pattern1,axis=0)
return pout
def mvPattern(x,y,pattern):
'''move pattern to (x,y).'''
pout=np.zeros_like(pattern)
for i in range(pattern.shape[0]):
pout[i,:-1]=[x,y]-pattern[i,:-1]
pout[i,-1]=pattern[i,-1]
return pout
def replacePointsByPattern(points, pattern):
'''map pattern to each site of points.'''
pout=mvPattern(points[0,0],points[0,1],pattern)
for point in points[1:]:
pout=np.append(pout,mvPattern(point[0],point[1],pattern),axis=0)
return pout
def PCsPattern(size,radius,a):
'''create sites for PhCs.'''
h=a*np.sin(np.pi/3) #space between 2 holes in y line
nx=int((size-2*radius)/a);Lx=a*nx+2*radius
ny=int((size-2*radius)/h);Ly=h*ny+2*radius
pattern = np.zeros((0, 2), dtype = np.float32)
for i in range(ny+1):
y = i*h - Ly/2 + radius
for j in range(nx+1-(i%2)):
x = (j + (i%2)*0.5)*a -Lx/2 + radius
pattern=np.append(pattern,[[x,y]],axis=0)
return np.array(pattern)
def PCsPattern2(a):
'''another PhCs sites.'''
cols=np.arange(-12,12,1)
rows=np.arange(-14,13,2)
site_points=np.zeros((0, 2), dtype = np.float32)
h=a*np.sin(np.pi/3)
for row in rows[::-1]:
for col in cols:
yd = row*h
xd = col*a
yu = yd + h
xu = xd + a/2
site_points=np.append(site_points,[[xu,yu]],axis=0)
site_points=np.append(site_points,[[xd,yd]],axis=0)
return site_points
def raithDots(p=1000,start_dose=1,dose_step=0.1,nx=30,ny=70):
'''Raith Demo dots dose test: pitch=1 (default) or 0.5 µm.'''
pattern = np.zeros_like(np.ndarray(((nx+1)*(ny+1),3)))
for i in range(pattern.shape[0]):
x = -nx*p/2 + (i%(nx+1))*p
stepy=int(i/(nx+1))
y = -ny*p/2 + stepy*p
dose = start_dose + stepy*dose_step
pattern[i]=[x,y,dose]
return pattern