4 The FocusOps python module contains several scripts related to the focus stage..
17 Script to calibrate the focus stage step-ratio. Requires manual input of a micrometer measurement, in mm.
19 Moves to the front or back of the travel range, whichever is closer when invoked.
27 poss = 11500. - array(range(9))*2500.
29 poss = -9500. + array(range(9))*2500.
36 for i
in range(len(poss)):
37 print "************************"
38 print "Moving to %f microns." % poss[i]
40 resp = foc.pos(poss[i])
45 resp = foc.wait_move()
52 print "At %f microns." % pos
53 meas = float(raw_input(
"Enter measurement (in mm): "))
54 print "%f %f" % (pos, meas)
62 y = array(meas_pos)*1000.
63 A = numpy.vstack([x, ones(len(x))]).T
65 m,b = numpy.linalg.lstsq(A,y)[0]
69 print "\n\nCalibration Complete\n\n"
70 print "y = %f + %fx" % (b, m)
71 print "\nStd dev of residuals: %f microns\n" % numpy.std(resid)
72 print "Data:\nPosition\tMeasured\tResidual"
73 for i
in range(len(cal_pos)):
74 print "%f\t%f\t%f" %(cal_pos[i], meas_pos[i], resid[i])
80 def focus_old(start, end, stepsz, ims=5, settle_delay = 1.):
82 Peform a focus measurement.
84 First take darks, saving 5*ims images with gimbal in dark position. The moves from position start to end, in steps of size stepsz. At each position, the script pauses for settle_delay to allow vibrations to dissipate, and then take ims images. Images are saved in a sub-directory with the start time (standard VisAO filename) in the name. The visao_focuscurve.pro idl procedure is called to analyze the data, and the preset is updated.
86 start = the starting focus position (microns)
87 end = the ending focus position (microns)
88 stepsz = size of steps to take between focus positions (microns)
89 ims = number of images to save at each position
90 settle_delay = the time, in seconds, to pause after each move to settle vibrations
104 dist = abs( end - start)
107 print "Stepsize too small."
112 stepsz = stepsz * -1.
115 stepsz = stepsz * -1.
118 print "Number of images must be > 0."
122 sd = vis.get_visao_filename_now(
"focus_")
124 print "Moving focus stage to %f microns." % start
125 resp = foc.pos(start)
128 print "Focus motor error. "
133 print "************************"
134 print "Taking CCD 47 Darks"
136 darksd =
"%s/darks" % sd
139 gimbx = gimb.get_xpos()
140 gimby = gimb.get_ypos()
142 print "Gimbal start position: %f %f" % (gimbx, gimby)
148 print "Saving %i dark images" % (ims*5)
150 resp = ccd.save(ims*5)
152 print "CCD47 error. "
155 resp = ccd.wait_save()
157 print "CCD47 error. "
160 print "Saving complete."
162 print "Moving gimbal to %f %f" % (gimbx, gimby)
164 resp = gimb.move_xabs(gimbx)
166 print "Gimbal error. (moving x) "
169 resp = gimb.move_yabs(gimby)
171 print "Gimbal error. (moving y) "
174 resp = gimb.wait_move()
176 print "Gimbal error (wait_move()). "
179 print "Gimbal move complete"
181 resp = foc.wait_move()
184 print "Focus motor error. "
189 print "At %f microns.\n\nBeginning focus curve acquisition . . ." % pos
195 while abs(nextpos - start) < (dist + .1*abs(stepsz)):
196 print "************************"
197 print "Moving to %f microns . . ." % nextpos
199 resp = foc.pos(nextpos)
202 print "Focus motor error."
205 resp = foc.wait_move()
208 print "Focus motor error."
213 print "Move complete. Settling for %f seconds . . ." % settle_delay
215 t = time.mktime(time.localtime())
216 while(time.mktime(time.localtime()) - t < settle_delay):
217 time.sleep(settle_delay)
219 print "Saving %i images at %f microns." % (ims, pos)
223 print "CCD47 error. "
226 resp = ccd.wait_save()
228 print "CCD47 error. "
231 print "Saving complete."
233 nextpos = pos + stepsz
238 gimb.giveup_control()
240 print "\n\nFocus Curve acquistion complete.\n\n"
241 print "Analyzing . . .\n"
243 idlcmd =
"visao_focuscurve, /interact, subdir='" + os.getenv(
'VISAO_ROOT') +
"/data/ccd47/" + sd +
"/'"
247 print '******************\nSomething bad happened\n******************\n'
251 def focus(start, end, stepsz, ims=5, settle_delay = 1., ndarks=-1):
253 Peform a focus measurement.
255 First take darks, saving 5*ims images with gimbal in dark position. The moves from position start to end, in steps of size stepsz. At each position, the script pauses for settle_delay to allow vibrations to dissipate, and then take ims images. Images are saved in a sub-directory with the start time (standard VisAO filename) in the name. The visao_focuscurve.pro idl procedure is called to analyze the data, and the preset is updated.
257 start = the starting focus position (microns)
258 end = the ending focus position (microns)
259 stepsz = size of steps to take between focus positions (microns)
260 ims = number of images to save at each position
261 settle_delay = the time, in seconds, to pause after each move to settle vibrations
274 visao.visao_wait(.25)
276 dist = abs( end - start)
279 print "Stepsize too small."
284 stepsz = stepsz * -1.
287 stepsz = stepsz * -1.
290 print "Number of images must be > 0."
296 print "Moving focus stage to %f microns." % start
297 resp = vis.focus.pos(start)
300 print "Focus motor error. "
303 vis.take_darks(ndarks)
305 resp = vis.focus.wait_move()
308 print "Focus motor error. "
311 pos = vis.focus.get_pos()
313 print "At %f microns.\n\nBeginning focus curve acquisition . . ." % pos
317 while abs(nextpos - start) < (dist + .1*abs(stepsz)):
318 print "************************"
319 print "Moving to %f microns . . ." % nextpos
321 resp = vis.focus.pos(nextpos)
324 print "Focus motor error."
327 resp = vis.focus.wait_move()
330 print "Focus motor error."
333 pos = vis.focus.get_pos()
335 print "Move complete. Settling for %f seconds . . ." % settle_delay
337 visao.visao_wait(settle_delay)
340 print "Saving %i images at %f microns." % (ims, pos)
342 vis.take_science(ims)
344 print "Saving complete."
346 nextpos = pos + stepsz
348 vis.ccd47.subdir(
".")
353 print "\n\nFocus Curve acquistion complete.\n\n"
354 print "Analyzing . . .\n"
356 idlcmd =
"visao_focuscurve, /interact, subdir='" + os.getenv(
'VISAO_ROOT') +
"/data/ccd47/" + sd +
"/'"
360 print '******************\nSomething bad happened\n******************\n'
364 def visao_focus(stepsz = 1000., ims = 5, settle_delay=1.):
366 foc = vis.FocusCtrl()
372 if(fabs(d-9000) > fabs(d+9000)):
379 return focus(start, end, stepsz, ims, settle_delay)
382 def filter2_focus(filters=["SDSS r'", "SDSS i'", "SDSS z'", "950 Long Pass"], homefirst=0, stepsz=1000, ims=5, settle_delay = 1.):
384 Peform a focus measurement, in each of a sequence of filter wheel 2 positions.
386 The filters are specified as a python list, i.e. ["SDSS r'", "SDSS i'", "SDSS z'"]
388 If homefirst is true, the wheel is homed before beginning.
390 In each filter, the focus script is executed.
392 fw2 = vis.FilterWheel2()
397 print "Homing FilterWheel2. . ."
400 resp = fw2.wait_home()
402 print "Homing complete."
404 for i
in range(len(filters)):
406 print "Changing filter to %s . . ." % filters[i]
407 resp = fw2.set_filter(filters[i])
410 resp = fw2.wait_move()
412 filt = fw2.get_filter()
414 print "In filter %s . . ." % filt
416 if filt!= filters[i]:
417 print "Filter not correct."
420 visao_focus(stepsz, ims, settle_delay)
def get_visao_filename_now(prefix)