-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadjust_stim_frame.py
200 lines (161 loc) · 4.34 KB
/
adjust_stim_frame.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import getch
import os
import numpy as np
import matplotlib.pyplot as plt
import ALP
import Patterns
import time
keypress='1'
command='None'
LR_STEP=1
UD_STEP=1
WIDTH_STEP=1
HEIGHT_STEP=1
Width = 48
Height = 40
esc_char=chr(27).encode()
#===define ALP field of illumination===
Patterns.ImWidth = Width #60
Patterns.ImHeight = Height #50
DMDWidth=1024
DMDHeight=768
#===initialize image===
x1=271 #x is row, y is column
x2=x1+Height
y1=464
y2=y1+Width
'''
#(a,b,c,d)
x1,x2: right(-) left (+)
y1,y2: down(-) up (+)
("+str(x1)+", "+str(y1)+")" + " ("+str(x2)+", "+str(y2)+")"
'''
stimulated=np.zeros([DMDHeight,DMDWidth])
stimulated[x1:x2,y1:y2]=255
#create checkerboard for use as mask
checkerboard=Patterns.checkerboard(9)/255 #use as mask
ptn=Patterns.checkerboard(10)
new_seq=Patterns.ALPimg([ptn])
stimulated_foo=new_seq[0]
#===initalize ALP===
ALP.init()
bitnum = 8L
picnum = 1L
stimon_time = 100000L
stimoff_time = 0L
seq_id=ALP.seq_alloc(bitnum,picnum)
ALP.seq_timing(seq_id, stimon_time, stimoff_time)
ALP.seq_upload(seq_id, [stimulated])
update=True
checkerboard_mode=True
b=1
while keypress != esc_char:
keypress=getch.getch()
upload_alp=False
if keypress=='o':
LR_STEP=LR_STEP+1
elif keypress=='p':
LR_STEP=max(0,LR_STEP-1)
elif keypress=='k':
UD_STEP=UD_STEP+1
elif keypress=='l':
UD_STEP=max(0,UD_STEP-1)
elif keypress=='8':
Height=min(DMDHeight,Height+HEIGHT_STEP)
upload_alp=True
elif keypress=='2':
Height=max(1,Height-HEIGHT_STEP)
upload_alp=True
elif keypress=='4':
Width=Width+(WIDTH_STEP)
upload_alp=True
elif keypress=='6':
Width=max(1,Width-WIDTH_STEP)
upload_alp=True
elif keypress=='\r':
plt.imshow(stimulated)
plt.show()
elif keypress=='m':
update = not update
elif keypress=='i':
checkerboard=checkerboard[::-1] #invert checkerboard
upload_alp=True
elif keypress=='c':
b=1
checkerboard_mode=not checkerboard_mode
upload_alp=True
elif keypress=='b': #black
b=not b
upload_alp=True
elif keypress=='n':
#b=np.load('../Pattern/ALP_intensity.npy')
#b=np.zeros(b.shape)+100.0
upload_alp=True
#===update image===
# move images
if keypress == 'a':
y1=max(0,y1-LR_STEP)
upload_alp=True
elif keypress == 'd':
y1=min(DMDWidth,y1+LR_STEP)
upload_alp=True
elif keypress == 'w':
x1=max(0,x1-UD_STEP)
upload_alp=True
image_changed=1
elif keypress == 's':
x1=min(DMDHeight,x1+UD_STEP)
upload_alp=True
x2=min(DMDHeight,x1+Height)
y2=min(DMDWidth,y1+Width)
stimulated[:]=0 #clear
'''
#==frame==
stimulated[x1,y1:y2]=255.0*b
stimulated[x2,y1:y2]=255.0*b
stimulated[x1:x2,y1]=255.0*b
stimulated[x1:x2,y2]=255.0*b
'''
#==checkerboard==
stimulated[x1:x2,y1:y2]=255.0
#stimulated[x1:x2,y1:y2] = stimulated[x1:x2,y1:y2] * checkerboard
'''
#==grid of dots===
stimulated[:]=0
xs=range(x1,x2,20)
ys=range(y1,y2,20)
for x in xs:
for y in ys:
stimulated[x,y]=255
if checkerboard_mode:
pass
#stimulated[x1:x2,y1:y2] = stimulated[x1:x2,y1:y2] * checkerboard
'''
os.system('cls')
#past=now
#now=time.time()
if update == False:
upload_alp = False
else:
upload_alp = True
if upload_alp:
#===upload image===
ALP.stop()
ALP.seq_upload(seq_id, [stimulated])
ALP.seq_start_loop(seq_id)
print keypress
print "PRESS ESCAPE TO QUIT"
print "("+str(x1)+", "+str(y1)+")" + " ("+str(x2)+", "+str(y2)+")"
print "Move Left/CamBottom(a) or Right/CamTop(d) by " + str(LR_STEP) +" pixels"
print "Increase(o) or Decrease(p)\n"
print "Move Up/CamRight(w) or Down/CamLeft(s) by " + str(UD_STEP) +" pixels"
print "Increase(k) or Decrease(l)\n"
print "Height: " + str(Height) + " increase(8) or decrease(2)"
print "Width: " + str(Width)+ " increase(4) or decrease(6)"
print "Enter: display image"
print "(i)nvert checkerboard"
print "(b)lack"
print "(n)ormalize"
print "Update (M)ode update is: " + str(update)
ALP.stop()
ALP.shutdown()