def _feed(self, time, activity): progress = self.progress step = progress // self.numshots % self.numsteps shot = progress % self.numshots readouts = self.control.sampler.readouts self.log(' -> shot {}', shot + 1) yaml.safe_dump([{ 'step': step, 'shot': shot, 'optics': self.optics[step], 'time': time, 'active': list(activity), 'readout': readouts, }], self.output_file, default_flow_style=False) self.shots.append([(readouts[mon]['posx'], readouts[mon]['posy']) for mon in self.monitors]) if len(self.readouts) >= 3: self.update_results() self._advance()
def export_params(filename, data, data_key=None): """Export parameters to .YAML/.STR file.""" _, ext = os.path.splitext(filename.lower()) if ext in ('.yml', '.yaml'): if data_key: data = {data_key: data} text = yaml.safe_dump(data, default_flow_style=False) elif ext == '.str': text = ''.join(['{} = {!r};\n'.format(k, v) for k, v in data.items()]) else: raise ValueError( "Unknown file format for export: {!r}".format(filename)) with open(filename, 'wt') as f: f.write(text)
def start(self): self.selected = self.get_quads() self.optics = self.get_optics() self.numsteps = len(self.optics) self.numshots = self.numUsedSpinBox.value() self.totalops = self.numsteps * self.numshots self.control.read_all() self.base_optics = { knob: self.model.read_param(knob) for knob in self.control.get_knobs() } self.progress = -1 self.backup = { p: self.base_optics[p.lower()] for q in self.selected for p in [self.quad_knobs[q]] } self.sectormaps = None self.output_file = open(self.filename, 'wt') yaml.safe_dump( { 'monitors': self.monitors, 'selected': self.selected, 'optics': self.optics, 'base_optics': self.base_optics, 'numsteps': self.numsteps, 'numshots': self.numshots, }, self.output_file, default_flow_style=False) self.output_file.write('records:\n') self.readouts = [] self.running = True self.tabWidget.setCurrentIndex(1) self.control.sampler.updated.connect(self._feed) self._advance() self.update_ui()
def export_params(filename, data, data_key=None): """Export parameters to .YAML/.STR file.""" _, ext = os.path.splitext(filename.lower()) if ext in ('.yml', '.yaml'): if data_key: data = {data_key: data} text = yaml.safe_dump(data, default_flow_style=False) elif ext == '.str': text = ''.join([ '{} = {!r};\n'.format(k, v) for k, v in data.items() ]) else: raise ValueError( "Unknown file format for export: {!r}".format(filename)) with open(filename, 'wt') as f: f.write(text)
def read_focus(self): focus_levels = parse_ints(self.focusEdit.text()) # TODO: this should be done with a more generic API # TODO: do this without beamoptikdll to decrease the waiting time plug = self.control.backend dll = self.control.backend.beamoptikdll values, channels = dll.GetMEFIValue() vacc = dll.GetSelectedVAcc() knobs = {self.quad_knobs[q] for q in self.get_quads()} optics = [] for focus in focus_levels: dll.SelectMEFI(vacc, *channels._replace(focus=focus)) optics.append({k: plug.read_param(k) for k in knobs}) dll.SelectMEFI(vacc, *channels) self.opticsEdit.setPlainText( yaml.safe_dump(optics, default_flow_style=False))
def write_data(self, data, indent="", **kwd): if self.file: self.file.write(textwrap.indent(yaml.safe_dump(data, **kwd), indent)) self.file.flush()