def acquire(tuning, rc, filename=None, action_name='', bin_name=None): # File defaults if filename is None: filename, acq_id = tuning.filename(rc=rc, action=action_name) else: try: acq_id = str(int(filename.split('_')[0])) except ValueError: acq_id = str(time.time()) cmd = [os.path.join(tuning.bin_path, bin_name), '-p', 50, rc, filename] status = tuning.run(cmd) if status != 0: return False, {'error': 'command failed: %s' % str(cmd)} # Register this acquisition, taking nframes from runfile. fullname = os.path.join(tuning.base_dir, filename) rf = MCERunfile(fullname + ".run") n_frames = rf.Item('par_ramp', 'par_step loop1 par1', type='int')[2] * \ rf.Item('par_ramp', 'par_step loop2 par1', type='int')[2] tuning.register(acq_id, 'tune_servo', fullname, n_frames) return True, {'basename': acq_id, 'filename': fullname }
def acquire(tuning, rc, filename=None, fb=None, bias=None, gain=None, old_servo=False): # File defaults if filename is None: filename, acq_id = tuning.filename(rc=rc, action='sq2servo') else: try: acq_id = str(int(filename.split('_')[0])) except ValueError: acq_id = str(time.time()) if old_servo: # Biasing semantics are complicated, fix me. if bias is None: bias = tuning.get_exp_param('sq2_servo_bias_ramp') change_bias = not (bias == False) if (bias == True): bias = {} for k in ['start','count','step']: bias[k] = tuning.get_exp_param('sq2_servo_bias_%s'%k) elif (bias == False): bias = {'start': 0, 'count': 1, 'step': 0 } # FB if fb is None: fb = {} for k in ['start','count','step']: fb[k] = tuning.get_exp_param('sq2_servo_flux_%s'%k) if gain is None: if rc == 's': rci = 0 else: rci = int(rc) - 1 gain = tuning.get_exp_param('sq2_servo_gain')[rci*8] # Execute C servo program cmd = [os.path.join(tuning.bin_path, 'sq2servo'), '-E0', filename, bias['start'], bias['step'], bias['count'], fb['start'], fb['step'], fb['count'], rc, int(change_bias), gain, int(not change_bias)] else: cmd = [os.path.join(tuning.bin_path, 'sq2servo'), '-p', 50, '-E1', rc, filename] status = tuning.run(cmd) if status != 0: return False, {'error': 'command failed: %s' % str(cmd)} # Register this acquisition, taking nframes from runfile. fullname = os.path.join(tuning.base_dir, filename) rf = MCERunfile(fullname + ".run") n_frames = rf.Item('par_ramp', 'par_step loop1 par1', type='int')[2] * \ rf.Item('par_ramp', 'par_step loop2 par1', type='int')[2] tuning.register(acq_id, 'tune_sq2_servo', fullname, n_frames) return True, {'basename': acq_id, 'filename': fullname }
def acquire(tuning, rc, filename=None, fb=None, gain=None, super_servo=False, old_servo=False): # File defaults if filename is None: filename, acq_id = tuning.filename(rc=rc, action='sq1servo') else: try: acq_id = str(int(filename.split('_')[0])) except ValueError: acq_id = str(time.time()) if super_servo: cmd = [os.path.join(tuning.bin_path, 'sq1servo_all'), '-p', 50] else: cmd = [os.path.join(tuning.bin_path, 'sq1servo')] if old_servo: # FB if fb is None: fb = {} for k in ['start', 'count', 'step']: fb[k] = tuning.get_exp_param('sq1_servo_flux_%s' % k) if gain is None: if rc == 's': rci = 0 else: rci = int(rc) - 1 gain = tuning.get_exp_param('sq1_servo_gain')[rci * 8] # This syntax is for pre-2010 servo programs that only do one gain. cmd += [ '-E0', filename, 0, 0, 0, fb['start'], fb['step'], fb['count'], rc, 0, tuning.get_exp_param("default_num_rows"), gain, 1 ] else: cmd += ['-p', 50, '-E1', rc, filename] status = tuning.run(cmd) if status != 0: return False, {'error': 'command failed: %s' % str(cmd)} # Register this acquisition, taking nframes from runfile. fullname = os.path.join(tuning.base_dir, filename) rf = MCERunfile(fullname + ".run") n_frames = rf.Item('par_ramp', 'par_step loop1 par1', type='int')[2] * \ rf.Item('par_ramp', 'par_step loop2 par1', type='int')[2] tuning.register(acq_id, 'tune_sq1_servo', fullname, n_frames) return True, {'basename': acq_id, 'filename': fullname}
def from_runfile(self, filename): rf = MCERunfile(filename) acq_cards = rf.Item('FRAMEACQ', 'RC', type='int') rc = 'rc%i' % acq_cards[0] for k, (c, p) in self.mce_params: if k == 'barrier': continue if c == 'rca': c = rc item = rf.Item('HEADER', 'RB %s %s' % (c, p), type='int') if item is None: raise RuntimeError, "Failed to find key for %s %s" % (c, p) self.params[k] = item[0] self.derive()
def acquire(tuning, rc=None, filename=None, data_mode=4): if rc is None: rc = 'rcs' # File defaults if filename is None: action = 'lock' filename, acq_id = tuning.get_filename(rc=rc, action=action) else: try: acq_id = str(int(filename.split('_')[0])) except ValueError: acq_id = str(time.time()) # Set data mode and acquire cmd = ('mce_cmd -x wb %s data_mode %i' % (rc, data_mode)).split() if tuning.run(cmd) != 0: return False, {'error': 'command failed: %s' % str(cmd)} cmd = ['mce_run', file_name, npts, rc[-1]] if tuning.run(cmd) != 0: return False, {'error': 'command failed: %s' % str(cmd)} # Register this acquisition, taking nframes from runfile. fullname = os.path.join(tuning.data_dir, filename) rf = MCERunfile(fullname) n_frames = rf.Item('FRAMEACQ','DATA_FRAMECOUNT',type='int',array=False) util.register(acq_id, 'tune_ramp', fullname, n_frames) return True, {'basename': acq_id, 'filename':fullname, 'rc': rc, }
def acquire_tes_ramp(tuning, rc, filename=None): # File defaults if filename is None: action = 'sq1ramptes' filename, acq_id = tuning.filename(rc=rc, action=action) else: try: acq_id = str(int(filename.split('_')[0])) except ValueError: acq_id = str(time.time()) # Execute ramp cmd = ['ramp_sq1_tes_bias', filename, rc] status = tuning.run(cmd) if status != 0: return False, {'error': 'command failed: %s' % str(cmd)} # Register this acquisition, taking nframes from runfile. fullname = os.path.join(tuning.base_dir, filename) rf = MCERunfile(fullname + '.run') n_frames = rf.Item('FRAMEACQ','DATA_FRAMECOUNT',type='int',array=False) tuning.register(acq_id, 'tune_ramp', fullname, n_frames) return True, {'basename': acq_id, 'filename':fullname, 'rc': rc, }
def acquire(tuning, rc, filename=None, do_bias=None): # File defaults if filename is None: filename, acq_id = tuning.filename(rc=rc, action='ssa') else: try: acq_id = str(int(filename.split('_')[0])) except ValueError: acq_id = str(time.time()) # Bias ramp default if do_bias is None: do_bias = tuning.get_exp_param('sa_ramp_bias') # Execute ramp cmd = ['ramp_sa_fb', filename, rc, int(do_bias)] status = tuning.run(cmd) if status: return False, { 'error': 'command failed: %s with status %i' % (str(cmd), status) } # Register this acquisition, taking nframes from runfile. fullname = os.path.join(tuning.base_dir, filename) rf = MCERunfile(fullname + ".run") n_frames = rf.Item('FRAMEACQ', 'DATA_FRAMECOUNT', type='int', array=False) tuning.register(acq_id, 'tune_ramp', fullname, n_frames) return True, { 'basename': acq_id, 'filename': fullname, 'rc': rc, 'do_bias': do_bias, }
def read_data(self, filename): """ Loads an sq1servo data set. Can probably figure out if there is multi-row data present and do The Right Thing. """ rf = MCERunfile(filename + '.run') self.rf = rf self.data_origin = { 'filename': filename, 'basename': filename.split('/')[-1] } # Record the columns rcs = rf.Item('FRAMEACQ', 'RC', type='int') self.cols = array([i + (rc - 1) * 8 for rc in rcs for i in range(8)]) # Fix me: runfile always indicates bias was ramped, even though it usually wasn't bias_ramp = (rf.Item('par_ramp', 'par_title loop1 par1', \ array=False).strip() == 'sq1bias') if bias_ramp: bias0, d_bias, n_bias = rf.Item('par_ramp', 'par_step loop1 par1', type='int') fb0, d_fb, n_fb = rf.Item('par_ramp', 'par_step loop2 par1', type='int') self.bias_style = 'ramp' self.bias = bias0 + d_bias * arange(n_bias) else: fb0, d_fb, n_fb = rf.Item('par_ramp', 'par_step loop1 par1', type='int') n_bias = 1 # This should just extend the else; the second clause is a bug work-around if not bias_ramp or (bias_ramp and n_bias == 1): self.bias_style = 'select' row_order = np.array( rf.Item('HEADER', 'RB ac row_order', type='int')) # Delay setting self.bias until we know what rows are involved... self.d_fb = d_fb self.fb = fb0 + arange(n_fb) * d_fb # Prime self.data_shape = (n_bias, 1, len(self.cols), n_fb) # Attempt load after counting bias/fb steps if len(glob.glob(filename + '.bias')): self._read_single(filename) else: self._read_super(filename) if not bias_ramp or (bias_ramp and n_bias == 1): idx = row_order[self.rows] self.bias = array(rf.Item('HEADER', 'RB sq1 bias', type='int'))[idx]
def read_data(self, filename, reduce_rows=False): self.mcefile = None rf = MCERunfile(filename+'.run') self.rf = rf self.error, self.data = util.load_bias_file(filename+'.bias') self.data_origin = {'filename': filename, 'basename': filename.split('/')[-1]} self.gridded = True self.data_shape = self.data.shape # Ravel. self.data.shape = (-1, self.data.shape[-1]) # Record the rows and columns, roughly rcs = rf.Item('FRAMEACQ', 'RC', type='int') self.cols = array([i+(rc-1)*8 for rc in rcs for i in range(8)]).ravel() self.rows = array([-1]) # Fix me: runfile always indicates bias was ramped, even though it usually wasn't bias_ramp = (rf.Item('par_ramp', 'par_title loop1 par1', \ array=False).strip() == 'sq2bias') if bias_ramp: bias0, d_bias, n_bias = rf.Item('par_ramp', 'par_step loop1 par1', type='int') fb0, d_fb, n_fb = rf.Item('par_ramp', 'par_step loop2 par1', type='int') self.bias_style = 'ramp' self.bias = bias0 + d_bias*arange(n_bias) else: fb0, d_fb, n_fb = rf.Item('par_ramp', 'par_step loop1 par1', type='int') n_bias = 1 # This should just extend the else; the second clause is a bug work-around if not bias_ramp or (bias_ramp and n_bias == 1): self.bias_style = 'select' self.bias = array(rf.Item('HEADER', 'RB sq2 bias', type='int'))[self.cols] self.d_fb = d_fb self.fb = fb0 + arange(n_fb) * d_fb # Natural order if bias_ramp: self.data.shape = (len(self.rows), len(self.cols), n_bias, n_fb) self.error.shape = (len(self.rows), len(self.cols), n_bias, n_fb) self.data = self.data.transpose([2, 0, 1, 3]) self.error = self.error.transpose([2, 0, 1, 3]) self.data_shape = self.data.shape self.data = self.data.reshape(-1, n_fb) self.error = self.error.reshape(-1, n_fb)
src = args[0] if len(args) > 1: fout = open(args[1]) else: fout = sys.stdout fin = MCERunfile(src) pairs = [ ('default_sa_bias', 'RB sa bias'), ('default_sq2_bias', 'RB sq2 bias'), ('default_sq1_bias', 'RB ac on_bias'), ('default_sq1_bias_off', 'RB ac off_bias'), ] for k1, k2 in pairs: d = fin.Item('HEADER', k2, type='int', array=True) if opts.mas_param: fout.write('mas_param set %s '%k1) fout.write(' '.join(['%i'%x for x in d]) + '\n') else: fout.write('%s = [\n' % k1) nr = (len(d)+7)/8 for i in range(nr): fout.write(' ' * 10 + ', '.join(['%6i'%x for x in d[i*8:i*8+8]])) if i != nr-1: fout.write(',\n') else: fout.write('];\n')