def writeScanInit(self, mode, smpinfo, scandic): next_sc = self.nextScanName() self.logger('%s Initiating scan %s %s\n' % ('#' * 20, next_sc, '#' * 20)) self.logger('Sample info: %s\n' % smpinfo) self.logger('%s: Setting up scan using %s mode.\n' % (getCurrentTime(), mode)) self.logger('%s: %s' % (getCurrentTime(), scandic)) self.logger('\n\n')
def motorReady(self, l, mt): self.logger('%s: Checking whether motors are ready.\n' % (getCurrentTime())) actpv = self.pvs['%s_Act' % l].pv rqspv = self.pvs['%s_Rqs' % l].pv self.pvs['%s_Act' % l].motorReady(rqspv, mt) if self.pvs['%s_Act' % l].motor_ready: self.logger('%s: %s motor is in position with value'\ '%.2f\n'%(getCurrentTime(), l, actpv.value)) return 1 else: self.logger('%s: %s motor not in position, current: %.2f,'\ ' request: %.2f\n'%(getCurrentTime(), l, actpv.value, rqspv.value)) return 0
def changeTomoRotate(self, theta): curr_angle = self.pvs['tomo_rot_Act'].pv.value t = getCurrentTime() self.logger.write( '%s; Changing tomo rotation angle from to %.2f to %.2f\n' % (t, curr_angle, theta)) self.pvs['tomo_rot_Act'].pv.put_callback(theta)
def changeSMRotate(self, theta): curr_angle = np.round(self.pvs['sm_rot_Act'].curr_value, 2) t = getCurrentTime() self.logger( '%s; Changing sample rotation angle from to %.2f to %.2f\n' % (t, curr_angle, theta)) self.pvs['sm_rot_Act'].put_callback(theta)
def logProgress(self, scname, scidx=0, n_scns=1, pbarval=None, pbarmsg=None, logTemp=False): nlines = caget(self.pvs['tot_lines']) tic = time.perf_counter() tic1 = tic scmonitor_tic = tic with tqdm(total=nlines, desc='%s (%d/%d)' % (scname, scidx, n_scns)) as pbar: pbar.update(caget(self.pvs['cur_lines'])) while caget(self.pvs['run']): toc = time.perf_counter() if logTemp & ((toc - tic1) >= 1): self.logTemp() tic1 = toc # if (toc - scmonitor_tic) < (caget(self.pvs['det_time']) / 10): # print('in scan monitor') # print(toc - scmonitor_tic) # self.detPauseStart() # scmonitor_tic = toc elif (toc - tic) >= 10: # time.sleep(10) cline = caget(self.pvs['cur_lines']) self.updatePbar(pbar, scname, pbarval=pbarval, pbarmsg=pbarmsg, cline=cline, nlines=nlines) pbar.update(cline - pbar.n) # sys.stdout.write('Scanning %s (batch %d/%d): line %d/%d is done\n'\ # %(scname, scidx+1, n_scns, cline, nlines)) tic = toc self.updatePbar(pbar, scname, pbarval=pbarval, pbarmsg=pbarmsg, done=1) pbar.update(nlines) self.logger('%s: Finish scan: %s%s' % (getCurrentTime(), scname, '\n' * 3)) self.blockBeamBDA() self.changeXYcombinedMode
def motorReady(self, label, mtolerance): self.logger.write('%s: Checking whether motors are ready.\n' % (getCurrentTime())) rules = [0] * len(label) for i, (l, t) in enumerate(zip(label, mtolerance)): actpv = self.pvs['%s_Act' % l].pv rqspv = self.pvs['%s_Rqs' % l].pv self.pvs['%s_Act' % l].motorReady(rqspv.pv, t**2) if self.pvs['%s_Act' % l].motor_ready: self.logger.write('%s: %s motor is in position with value'\ '%.2f\n'%(getCurrentTime(), l, actpv.value)) rules[i] = 1 else: self.logger.write('%s: %s motor not in position, current: %.2f,'\ ' request: %.2f\n'%(getCurrentTime(), l, actpv.value, rqspv.value)) if all(rules): self.logger.write('%s: Motors ready\n' % getCurrentTime()) return 1 else: return 0
def execScan(self, scname, scidx, n_scns, pbar): self.setXYcenter() self.changeXtoPiezolMode() self.centerPiezoXY() self.openBeamBDA() # Execute Scan caput(self.pvs['run'], 1) self.logger('%s: Scanning \n' % (getCurrentTime())) if pbar is None: self.logProgress(scname, scidx=scidx, n_scns=n_scns)
def logTemp(self): logpvs = [ 'CryoCon1:In_3', 'CryoCon1:In_2', 'CryoCon3:In_2', 'CryoCon3:Loop_2', 'CryoCon1:In_1' ] msg = getCurrentTime() + ': ' cline = caget(self.pvs['cur_lines']) msg += '%d, ' % (cline) for lpv in logpvs: msg += '%.3f, ' % (caget(self.pvs[lpv])) msg += '\n' self.logger_logbook_only(msg)
def angleSweepScanInit(self, params_label, params, scname, scidx, n_scns, pbar): self.blockBeamBDA() self.changeXYcombinedMode() self.logger('%s: Putting Tomo angle rotation back to 0 deg\n' % (getCurrentTime())) self.changeTomoRotate(0) # initialize angle at 0 deg time.sleep(1) self.assignPosValToPVs(params_label[:-1], params[:-1]) self.motorReady(['x_center', 'y_center', 'z_value'], [0.1, 0.1, 0.5]) self.changeTomoRotate(params[-1]) # change to desired angle self.motorReady(['x_center', 'z_value'], [0.1, 0.5]) self.execScan(scname, scidx, n_scns, pbar)
def openBeamBDA(self, BDA): self.logger('%s: Move BDA to open position at: %.3f\n' % (getCurrentTime(), BDA)) self.pvs['BDA_pos'].put_callback(BDA)
def blockBeamBDA(self, BDA): bda_pos = BDA - 500 t = getCurrentTime() self.logger('%s: Move BDA to block position at: %.3f\n' % (t, bda_pos)) self.pvs['BDA_pos'].put_callback(bda_pos)
def blockBeamBDA(self): bda_pos = self.scandic['BDAin'] - 500 t = getCurrentTime() self.logger.write('%s: Move BDA to block position at: %.3f\n' % (t, bda_pos)) self.pvs['BDA_pos'].pv.put_callback(bda_pos)
def openBeamBDA(self): bda_pos = self.scandic['BDAin'] self.logger.write('%s: Move BDA to open position at: %.3f\n' % (getCurrentTime(), bda_pos)) self.pvs['BDA_pos'].pv.put_callback(bda_pos)
def assignSinglePV(self, pvstr, pvval): self.pvs[pvstr].pv.put(pvval) self.logger('%s: Change %s to %.3f\n' % (getCurrentTime(), pvstr, pvval))
def setXYcenter(self): self.logger('%s: Update the current position as the center of'\ 'the scan.\n'%(getCurrentTime())) self.pvs['x_setcenter'].pv.put(1) self.pvs['y_setcenter'].pv.put(1)
def changeXYcombinedMode(self): self.logger('%s; Changing XY scan mode to combined motion\n' % (getCurrentTime())) self.pvs['x_motorMode'].pv.put(0) self.pvs['y_motorMode'].pv.put(0)
def centerPiezoXY(self): self.logger.write('%s: Centering piezoX and piezoY.\n' % (getCurrentTime())) self.pvs['piezo_xCenter'].pv.put_callback(1) self.pvs['piezo_ycenter'].pv.put_callback(1)
def changeXtoPiezolMode(self): self.logger.write('%s: Changing X scan mode to Piezo only\n' % (getCurrentTime())) self.pvs['x_motorMode'].pv.put_callback(2) time.sleep(1.)
def changeXtoPiezolMode(self): self.logger('%s: Changing X scan mode to Piezo only\n' % (getCurrentTime())) self.pvs['x_motorMode'].pv.put(2)
def onPutComplete(self, pvname=None, **kws): sys.stdout.write('%s: Finish updating PV %s with value of %s\n'\ %(getCurrentTime(), self.pvname, str(self.putvalue))) self.put_complete = 1
def centerPiezoXY(self): self.logger('%s: Centering piezoX and piezoY.\n' % (getCurrentTime())) self.pvs['piezo_xCenter'].pv.put(1) self.pvs['piezo_yCenter'].pv.put(1)
def assignPosValToPVs(self, pvstr, pvval): for s_, v_ in zip(pvstr, pvval): self.pvs[s_].pv.put(v_) self.logger('%s: Change %s to %.3f\n' % (getCurrentTime(), s_, v_))