-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
161 lines (112 loc) · 4.82 KB
/
Copy pathmain.py
File metadata and controls
161 lines (112 loc) · 4.82 KB
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
###############################################################################
# IMPORTANT: Don't forget to change the current working director at the top
# right part of the screen if using Spyder with IPython.
###############################################################################
from scanning_stage import Controller, Stage
from lightfield import Spectrometer
from time import sleep
def centerfrombottom(stage, diameter = 2):
# Used for moving to the center (roughly) of the disk electrode. Focus on
# the bottom edge of the disk and then run this
# Distance to move is the disk radius converted to microns
distance = 1000 * diameter/2
stage.move((0, distance))
while stage.busy:
pass
stage.set_home()
class Experiment():
def __init__(self, stage: Stage, spec: Spectrometer):
self.stage = stage
self.spec = spec
def run(self, name, t=60):
while self.stage.busy or self.spec.busy:
pass
self.spec.total_frames = t
self.spec.file_name = f'{name} pos = {self.stage.pos}'
print(f'Acquiring at {self.stage.pos}.')
self.spec.acquire()
def ec_scan(file_name, acq_time, exp, xsteps, ysteps, xsize, ysize, wait_time=0):
n = 0
for y in range(1, ysteps+1):
for x in range(1, xsteps+1):
n += 1
print(f'Step {n} out of {xsteps*ysteps}.')
# Wait until stage is no longer moving
while exp.stage.busy:
pass
# Wait extra time (optional)
if (x,y) != (1,1):
sleep(wait_time)
# At this point the potentiostat should be waiting for the trigger
# Acquire
print(f'Acquiring at {stage.pos}.')
exp.run(name=file_name, t=acq_time)
# Wait until spectrometer is no longer acquiring
while exp.spec.busy:
pass
# Move to new x position
exp.stage.move((xsize, 0))
# After all x positions were iterated over, reset x position and
# then move to the next y position
exp.stage.move((-xsteps*xsize, ysize))
while exp.stage.busy:
pass
# After all positions were iterated over, reset
# position to the original one
exp.stage.move((0, -ysteps*ysize))
# Wait for it to move and print final position
while exp.stage.busy:
pass
print(f'Finished. Position = {stage.pos}.')
def scan(name, stage, spec, xsteps, ysteps, xsize, ysize):
n = 0
for y in range(1, ysteps+1):
for x in range(1, xsteps+1):
n += 1
print(f'Step {n} out of {xsteps*ysteps}.')
# Wait until stage is not longer moving
while stage.busy:
pass
# Set file name to the current position
spec.file_name = f'{name} pos = {stage.pos}'
# Acquire at current position
print(f'Acquiring at {stage.pos}.')
spec.acquire()
# Wait until spectrometer is no longer acquiring
while spec.busy:
pass
# Move to new x position
stage.move((xsize, 0))
# After all x position were iterated over, reset
# x position and then move to the next y position
stage.move((-xsteps*xsize, ysize))
while stage.busy:
pass
# After all positions were iterated over, reset
# position to the original one
stage.move((0, -ysteps*ysize))
print(f'Finished. Position = {stage.pos}.')
# Instantiate Spectrometer class to controll LightField
spectrometer = Spectrometer()
spectrometer.connect()
# IMPORTANT: After LightField loads, don't forget to load the experiment!!
# Instantiate Controller to setup PriorScientific's API
controller = Controller()
# Instantiate Stage using the Controller instance
stage = Stage(controller)
# Connect the stage/controller with the computer through
# Port #6 (this will change if the USB is connected to
# another port on the computer)
stage.connect(6)
# Set the stage step size (default is 25/um), minimum value is 1. A step size
# of 1 will increase the accuracy of the position measurement 25-fold
stage.step_size = 1
# Set the stage speed
stage.speed = 10
### EXPERIMENT LOG BELOW ###
# P = 0.2 mW
# w = 636.75 nm
# 20x objective
exp = Experiment(stage, spectrometer)
stage.set_home()
ec_scan('Mapping 1uM NB 10x10', 120, exp, 10, 10, -5, -5, wait_time=300) # 10 by 10 GRID