def btnPlotSteps_clicked(): scan = getScan() print 'range [%g, %g]' % (scan['angles'][0], scan['angles'][-1]) try: for mask in Plot1.masks: Plot1.remove_mask(mask) except: pass if Plot1.get_dataset() is None: scan_angleMin = builtin_min(scan['angles']) scan_angleMax = builtin_max(scan['angles']) dummy = zeros(2) dummy.axes[0] = [scan_angleMin, scan_angleMax] Plot1.add_dataset(dummy) inclusive = True angles = scan['angles'] for i in xrange(1, len(angles)): xL = angles[i - 1] xH = angles[i] Plot1.add_mask_1d(xL, xH, '', inclusive) inclusive = not inclusive groups = scan['groups'] for i in xrange(len(groups)): Plot1.add_mask_1d(groups[i], groups[i] + 1e-12, str(i + 1), True)
def slopeAt(list, i): L = 0 H = len(list) - 1 yL = list[builtin_max(L, i - 1)] yH = list[builtin_min(H, i + 1)] return yH - yL
def minmax(cp, size): _check_params(len(cp), size) max_sample, min_sample = 0, 0 for sample in _get_samples(cp, size): max_sample = builtin_max(sample, max_sample) min_sample = builtin_min(sample, min_sample) return min_sample, max_sample
def startScan(configModel): ''' setup ''' scanVariable = configModel.scanVariable crystal = configModel.crystal mode = configModel.mode MainDeadTime = 1.08E-6 TransDeadTime = 1.08E-6 if 'Si111' in crystal: empLevel = 0.3 bkgLevel = 0.277 dOmega = 2.3E-6 gDQv = 0.0586 gDQh = 0 wavelength = 4.74 TransmissionTube = 10 TransBackground = 0 # counts per second elif 'Si311' in crystal: empLevel = 0.34 bkgLevel = 0.333 dOmega = 4.6E-7 gDQv = 0.117 gDQh = 0 wavelength = 2.37 TransmissionTube = 9 TransBackground = 0 # counts per second else: print 'selected crystal is invalid' return ''' angles ''' scan = configModel.scan scan_angleMin = builtin_min(scan['angles']) scan_angleMax = builtin_max(scan['angles']) if ('m1om' in scanVariable) or ('m2om' in scanVariable): tolerance = 2 approved = False if 'Si111' in crystal: if (180 - tolerance <= scan_angleMin) and (scan_angleMax <= 180 + tolerance): approved = True elif 'Si311' in crystal: if (0 - tolerance <= scan_angleMin) and (scan_angleMax <= 0 + tolerance): approved = True if not approved: print 'angle out of range' return ''' execution ''' sics.execute('hset user/name ' + configModel.user_name) sics.execute('hset user/email ' + configModel.user_email) sics.execute('hset sample/name ' + configModel.sample_name) sics.execute('hset sample/description ' + configModel.sample_description) sics.execute('hset sample/thickness %g' % configModel.sample_thickness) sics.execute('hset experiment/bkgLevel %g' % bkgLevel) sics.execute('hset experiment/empLevel %g' % empLevel) sics.execute('hset instrument/detector/MainDeadTime %g' % MainDeadTime) sics.execute('hset instrument/detector/TransDeadTime %g' % TransDeadTime) sics.execute('hset instrument/detector/TransBackground %g' % TransBackground) sics.execute('hset instrument/detector/TransmissionTube %i' % TransmissionTube) sics.execute('hset instrument/crystal/dOmega %g' % dOmega) sics.execute('hset instrument/crystal/gDQv %g' % gDQv) sics.execute('hset instrument/crystal/gDQh %g' % gDQh) sics.execute('hset instrument/crystal/wavelength %g' % wavelength) sics.execute('hset instrument/crystal/scan_variable ' + scanVariable) sicsController = sics.getSicsController() # slits def getSlitValues(gap, offset, a0, b0, aOpen, bOpen): if gap == 'fully opened': return (aOpen, bOpen) if gap == 'fully closed': gap = -5.0 offset = 0.0 a = a0 + 0.5 * float(gap) + float(offset) b = b0 - 0.5 * float(gap) + float(offset) return (a, b) ss1vg = configModel.ss1vg ss1vo = configModel.ss1vo ss1hg = configModel.ss1hg ss1ho = configModel.ss1ho ss2vg = configModel.ss2vg ss2vo = configModel.ss2vo ss2hg = configModel.ss2hg ss2ho = configModel.ss2ho (ss1u, ss1d) = getSlitValues(ss1vg, ss1vo, ss1u0, ss1d0, 35.8, -38.8) (ss1r, ss1l) = getSlitValues(ss1hg, ss1ho, ss1r0, ss1l0, 57.0, -58.0) (ss2u, ss2d) = getSlitValues(ss2vg, ss2vo, ss2u0, ss2d0, 37.0, -39.5) (ss2r, ss2l) = getSlitValues(ss2hg, ss2ho, ss2r0, ss2l0, 35.0, -35.0) # apply slits run = {} run['ss1u'] = ss1u run['ss1d'] = ss1d run['ss1r'] = ss1r run['ss1l'] = ss1l run['ss2u'] = ss2u run['ss2d'] = ss2d run['ss2r'] = ss2r run['ss2l'] = ss2l sics.multiDrive(run) time.sleep(2) while not sicsController.getServerStatus().equals( ServerStatus.EAGER_TO_EXECUTE): time.sleep(0.1) ''' sics.execute('run ss1u %.2f' % ss1u) sics.execute('run ss1d %.2f' % ss1d) sics.execute('run ss1r %.2f' % ss1r) sics.execute('run ss1l %.2f' % ss1l) sics.execute('run ss2u %.2f' % ss2u) sics.execute('run ss2d %.2f' % ss2d) sics.execute('run ss2r %.2f' % ss2r) sics.execute('run ss2l %.2f' % ss2l) ''' # load sample positions sam_positions = str(configModel.sam_position) if (len(sam_positions) == 0) or (sam_positions == 'fixed'): samz_list = [None] else: samz_list = [] pos2samz = {} pos2samz['1'] = 33.5 pos2samz['2'] = 178.5 pos2samz['3'] = 323.5 pos2samz['4'] = 468.5 pos2samz['5'] = 613.5 pos2samz['1 top'] = 17.4 pos2samz['1 bottom'] = 77.7 pos2samz['2 top'] = 163.5 pos2samz['2 bottom'] = 223.1 pos2samz['3 top'] = 308.0 pos2samz['3 bottom'] = 368.1 pos2samz['4 top'] = 454.1 pos2samz['4 bottom'] = 513.6 pos2samz['5 top'] = 598.2 pos2samz['5 bottom'] = 658.0 samz_list.append(pos2samz[sam_positions]) ''' for range in filter(None, sam_positions.split(',')): rangeItems = range.split('-') if ('' in rangeItems) or (len(rangeItems) < 1) or (len(rangeItems) > 2): raise Exception('format in "Sample Position" is incorrect') if len(rangeItems) == 1: samz_list.append(pos2samz[int(rangeItems[0])]) else: for i in xrange(int(rangeItems[0]), int(rangeItems[1])+1): samz_list.append(pos2samz[i]) if len(samz_list) == 0: samz_list = [0.0] ''' for samz in samz_list: sics.execute('histmem stop') time.sleep(3) sics.execute('histmem mode time') if samz is not None: print 'run samz %.2f' % samz sics.execute('run samz %.2f' % samz) # sics.execute('prun samz 2' % samz) !!! time.sleep(1) while not sicsController.getServerStatus().equals( ServerStatus.EAGER_TO_EXECUTE): time.sleep(0.1) sics.execute('newfile HISTOGRAM_XYT') #sics.execute('autosave 60') # 60 seconds time.sleep(1) # start/stop hmm if mode == 'count_roi': sics.execute('histmem preset %i' % 1) time.sleep(1) sics.execute('histmem start') time.sleep(5) while not sicsController.getServerStatus().equals( ServerStatus.EAGER_TO_EXECUTE): time.sleep(0.1) sics.execute('histmem stop') print 'frames:', len(scan['angles']) for frame_index in xrange(len(scan['angles'])): angle = scan['angles'][frame_index] preset = scan['presets'][frame_index] maxTime = scan['maxTimes'][frame_index] print 'run %s %.6f' % (scanVariable, angle) sics.execute('run %s %.6f' % (scanVariable, angle)) time.sleep(10) while not sicsController.getServerStatus().equals( ServerStatus.EAGER_TO_EXECUTE): time.sleep(0.1) print 'run done' time.sleep(1) print 'histmem start' while True: if mode == 'count_roi': sics.execute('histmem preset %i' % maxTime) else: sics.execute('histmem preset %i' % preset) time.sleep(5) sics.execute('histmem start') time.sleep(5) if mode == 'count_roi': print 'count_roi' time.sleep(configModel.min_time) count_roi = 0 while not sicsController.getServerStatus().equals( ServerStatus.EAGER_TO_EXECUTE): try: count_roi = int( sicsext.runCommand( 'hmm configure num_events_filled_to_count_roi' )) print count_roi if count_roi > preset: print count_roi print 'reached desired count_roi' sics.execute('histmem pause') time.sleep(1) break except: pass time.sleep(0.5) break else: while not sicsController.getServerStatus().equals( ServerStatus.EAGER_TO_EXECUTE): time.sleep(0.1) valid = False for i in xrange(10): time.sleep(1) detector_time = sics.getValue( '/instrument/detector/time').getFloatData() valid = (detector_time >= preset - 1) or ( detector_time >= preset * 0.90) if valid: break print 'detector_time:', detector_time if valid: break else: print 'scan was invalid and needs to be repeated' #sics.execute('histmem stop') sics.execute('save %i' % frame_index) frame_index += 1 print 'histmem done' sics.execute('newfile clear') #sics.execute('autosave 0') # disable autosave # Get output filename filenameController = sicsController.findDeviceController( 'datafilename') savedFilename = filenameController.getValue().getStringData() print 'saved:', savedFilename print 'done' print