示例#1
0
 def publish_start(self, state, scan_def):
     vary_dict = OrderedDict(scan_def['vary'])
     full_filename = os.path.join(state['project_path'], scan_def['filename'])
     if scan_def['comment'] == 'Find_Peak':
         self.broadcaster.new_findpeak(scan_def['iterations'], full_filename, vary_dict.keys(), scan_def['namestr'])
     else:
         self.broadcaster.new_data(scan_def['iterations'], full_filename, vary_dict.keys(), scan_def['comment'], scan_def['namestr'])
示例#2
0
 def GenerateHeader(self, state = None, scan_def = None):
     params = deepcopy(state)
     start_params = deepcopy(state)
     start_params.update(dict(scan_def['init_state']))
     scan_expr = OrderedDict(scan_def['vary'])
     scan_state0 = {'i': 0}
     context = deepcopy(start_params)
     context.update(math.__dict__) # load up the standard context
     
     for d in scan_expr:
         scan_state0[d] = eval(str(scan_expr[d]), context, scan_state0)
     scan_state1 = {'i': 1}
     for d in scan_expr:
         scan_state1[d] = eval(str(scan_expr[d]), context, scan_state1)
     diff = {}
     for d in scan_expr:
         diff[d] = scan_state1[d] - scan_state0[d]
         
     start_params.update(scan_state0) # get the start positions of moving objects...
     #ibuf_data = scan_def['ibuf_data']
     description = scan_def['comment']
     description = '%-50s' % description[:50]  # chop it off at 50, but also pad the right to 50 if too short
     file_prefix = description[:5]
     filename = scan_def['filename']
     tstring = "'I'   " # this is an i-buffer, after all
     ttype  = 'RAW' # dunno why
     numpoints = scan_def['iterations']
     count_type = start_params.get('scaler_gating_mode', 'TIME') #default to time, if not specified
     if count_type == 'TIME':
         monitor = start_params.get('scaler_time_preset', 1.0)
     elif count_type == 'NEUT':
         monitor = start_params.get('scaler_monitor_preset', 1)
     else:
         monitor = 1
     prefactor = start_params.get('scaler_prefactor', 1)
     tstart = float(start_params.get('t1', 0.0))
     tincr = float(diff.get('t1', 0.0))
     hfield = float(start_params.get('h1', 0.0))
     num_detectors = int(start_params['num_detectors'])
     polarized_beam = scan_def.get('polarization_enabled', False)
     timestr =  time.strftime('%b %d %Y %H:%M')
     #timestr = params['timestr']
     collim = start_params['collimation']
     mosaic = start_params['mosaic']
     wavelength = start_params['wavelength']
     
     header = "'%12s' '%17s' %6s%8.f.%5i  '%4s'%5i  '%3s'\n" % (filename, timestr, tstring, monitor, prefactor, count_type, numpoints, ttype)
     header += '  Filename         Date            Scan       Mon    Prf  Base   #pts  Type    \n'
     header += '%50s ' % (description,)
     flipper_state_string = {True: 'ON ', False: 'OFF'}
     if polarized_beam: 
         header += 'F1: %3s  F2: %3s  \n' % (flipper_state_string[start_params['flipper1']], flipper_state_string[start_params['flipper2']])
     else: 
         header += '\n'
     header += '%4i %4i %4i %4i %3i %3i %3i ' % (collim[0], collim[1], collim[2], collim[3], mosaic[0], mosaic[1], mosaic[2])
     header += ' %7.4f    %8.5f %7.5f %9.5f %4i ' % (wavelength, tstart, tincr, hfield, num_detectors)
     if params['magnets_defined'] > 0: # looks back into the calling parent, ic.  Make explicit?
         Hinc = float(diff.get('h0', 0.0))
         Hconv = 1.000 # need to look up in MOTORS.BUF?
         header += '%7.4f %7.4f' % (Hinc, Hconv)
     header += '\n'
     header += ' Collimation      Mosaic    Wavelength   T-Start   Incr.   H-field #Det    '
     if params['magnets_defined'] > 0: # looks back into the calling parent, ic.  Make explicit?
         header += '  H-conv   H-Inc'
     header += '\n'
     
     motnames = []
     for motnum in range(1,7):
         motname = 'a%d' % motnum
         start = float(start_params.get(motname, 0.0))
         step = float(diff.get(motname, 0.0))
         stop = start + ((numpoints - 1) * step)
         header += '%3d   %11.5f%11.5f%11.5f\n' % (motnum, start, step, stop)
         motnames.append(motname)
     header += ' Mot:    Start       Step      End\n'
     
     data_keys = []
     motors_to_move = [m for m in motnames if m in scan_expr.keys()]
     for movable in OrderedDict(scan_def['vary']):
         if not movable.lower().startswith('t') and not movable.lower().startswith('h'):
             # leave off temp and h-devices for now
             data_keys.append('     %s   ' % movable.upper()) 
     #for motname in motors_to_move:
     #    data_keys.append('     %s   ' % motname.upper()) 
     
     data_keys.append('  MIN  ')
     if not count_type == 'NEUT': 
         data_keys.append('    MONITOR ')
     data_keys.append('     COUNTS ')
     if num_detectors > 1: 
         data_keys.append('     EXTRA  ')
     
     for i in range(params['temp_controllers_defined']):
         tc = params['t%d' % (i+1)]
         print tc
         if hasattr(tc, 'keys'):
             for key in tc.keys():
                 data_keys.append(' TEMP%d_%s ' % (i+1, key))
         else: # just a number
             data_keys.append(' TEMP%d ' % (i+1))
         # this mimics the ICP behaviour in which the temperature is only looked at if a T device is defined
     for i in range(params['magnets_defined']):
         hc = params['h%d' % (i+1)]
         if hasattr(hc, 'keys'):
             for key in hc.keys():
                 data_keys.append(' H-Field%d_%s ' % (i+1, key))
         else: # just a number
             data_keys.append(' H-Field%d ' % (i+1))
         # this mimics the ICP behaviour in which the H-field is only looked at if a magnet device is defined
     # now generate the data header from the keys
     for key in data_keys:
         header += key
     header += '\n'
     
     return header