def run(self, motor_list): show_dial = self.getViewOption(ViewOption.ShowDial) motor_width = 9 motor_names = [] motor_pos = [] motor_list = list(motor_list) motor_list.sort() for motor in motor_list: name = motor.getName() motor_names.append([name]) pos = motor.getPosition(force=True) if pos is None: pos = float('NAN') motor_pos.append((pos, )) motor_width = max(motor_width, len(name)) fmt = '%c*.%df' % ('%', motor_width - 5) table = Table(motor_pos, elem_fmt=[fmt], col_head_str=motor_names, col_head_width=motor_width, **self.table_opts) for line in table.genOutput(): self.output(line)
def run(self, integ_time): if self.mnt_grp is None: self.error('ActiveMntGrp is not defined or has invalid value') return # integration time has to be accessible from with in the hooks # so declare it also instance attribute self.integ_time = integ_time self.debug("Counting for %s sec", integ_time) self.outputDate() self.output('') self.flushOutput() for preAcqHook in self.getHooks('pre-acq'): preAcqHook() state, data = self.mnt_grp.count(integ_time) for postAcqHook in self.getHooks('post-acq'): postAcqHook() names, counts = [], [] for ch_info in self.mnt_grp.getChannelsEnabledInfo(): names.append(' %s' % ch_info.label) ch_data = data.get(ch_info.full_name) if ch_data is None: counts.append("<nodata>") elif ch_info.shape > [1]: counts.append(list(ch_data.shape)) else: counts.append(ch_data) self.setData(Record(data)) table = Table([counts], row_head_str=names, row_head_fmt='%*s', col_sep=' = ') for line in table.genOutput(): self.output(line)
def run(self, integ_time): if self.mnt_grp is None: self.error('ActiveMntGrp is not defined or has invalid value') return self.debug("Counting for %s sec", integ_time) self.outputDate() self.output('') self.flushOutput() state, data = self.mnt_grp.count(integ_time) names, counts = [], [] for ch_info in self.mnt_grp.getChannelsEnabledInfo(): names.append(' %s' % ch_info.label) ch_data = data.get(ch_info.full_name) if ch_info.shape > [1]: counts.append(list(ch_data.shape)) else: counts.append(ch_data) table = Table([counts], row_head_str=names, row_head_fmt='%*s', col_sep=' = ') for line in table.genOutput(): self.output(line)
def run(self, motor_list): motor_width = 10 motor_names = [] motor_pos = [] for motor in motor_list: name = motor.getName() motor_names.append([name]) posObj = motor.getPositionObj() upos = map(str, [ posObj.getMaxValue(), motor.getPosition(force=True), posObj.getMinValue() ]) pos_data = [''] + upos motor_pos.append(pos_data) elem_fmt = (['%*s'] + ['%*s'] * 3) * 2 row_head_str = [ 'User', ' High', ' Current', ' Low', ] table = Table(motor_pos, elem_fmt=elem_fmt, row_head_str=row_head_str, col_head_str=motor_names, col_head_width=motor_width, **self.table_opts) for line in table.genOutput(): self.output(line)
def run(self, pseudo): conf = DiscretePseudoMotorConfiguration(pseudo, self) col_head_str = [['pos'], ['set'], ['min'], ['max']] row_head_str = [] value_list = [] for k, v in conf.items(): row_head_str.append(k) _row_values = [k] for i in col_head_str: _row_values.append(v[i[0]]) value_list.append(_row_values) if len(value_list): # Sort by position column value_list = sorted(value_list, key=lambda x: x[1]) # Transpose matrix value_list = map(list, zip(*value_list)) # Extract sorted row headers row_head_str = value_list[0] # Extract sorted values value_list = value_list[1:] table = Table(value_list, row_head_str=row_head_str, col_head_str=col_head_str, col_head_width=15) for line in table.genOutput(): self.output(line) else: self.output('No configuration available')
def run(self, pseudo): conf = DiscretePseudoMotorConfiguration(pseudo, self) col_head_str = [['pos'], ['set'], ['min'], ['max']] row_head_str = [] value_list = [] for k, v in list(conf.items()): row_head_str.append(k) _row_values = [k] for i in col_head_str: _row_values.append(v[i[0]]) value_list.append(_row_values) if len(value_list): # Sort by position column value_list = sorted(value_list, key=lambda x: x[1]) # Transpose matrix value_list = list(map(list, list(zip(*value_list)))) # Extract sorted row headers row_head_str = value_list[0] # Extract sorted values value_list = value_list[1:] table = Table(value_list, row_head_str=row_head_str, col_head_str=col_head_str, col_head_width=15) for line in table.genOutput(): self.output(line) else: self.output('No configuration available')
def printAllPos(self): motor_width = 10 table = Table(self.all_pos, elem_fmt=['%*.4f'], col_head_str=self.all_names, col_head_width=motor_width) self.outputBlock(table.genOutput()) self.flushOutput()
def printAllValues(self): ch_width = 10 table = Table(self.values, elem_fmt=['%*.4f'], col_head_str=self.names, col_head_width=ch_width) self.outputBlock(table.genOutput()) self.flushOutput()
def run(self, integ_time, countable_elem): if self.countable_elem is None: msg = ('Unknown countable {0} element. Use macro parameter or' 'ActiveMntGrp environment variable'.format( self.countable_elem_name)) self.error(msg) return # integration time has to be accessible from with in the hooks # so declare it also instance attribute self.integ_time = integ_time self.debug("Counting for %s sec", integ_time) self.outputDate() self.output('') self.flushOutput() for preAcqHook in self.getHooks('pre-acq'): preAcqHook() try: state, data = self.countable_elem.count(integ_time) except Exception: if self.countable_elem.type == Type.MeasurementGroup: names = self.countable_elem.ElementList elements = [self.getObj(name) for name in names] self.dump_information(elements) raise if state != DevState.ON: if self.countable_elem.type == Type.MeasurementGroup: names = self.countable_elem.ElementList elements = [self.getObj(name) for name in names] self.dump_information(elements) raise ValueError("Acquisition ended with {}".format( state.name.capitalize())) for postAcqHook in self.getHooks('post-acq'): postAcqHook() names, counts = [], [] if self.countable_elem.type == Type.MeasurementGroup: meas_grp = self.countable_elem for ch_info in meas_grp.getChannelsEnabledInfo(): names.append(' %s' % ch_info.label) ch_data = data.get(ch_info.full_name) counts.append(_value_to_repr(ch_data)) else: channel = self.countable_elem names.append(" %s" % channel.name) counts.append(_value_to_repr(data)) # to be compatible with measurement group count data = {channel.full_name: data} self.setData(Record(data)) table = Table([counts], row_head_str=names, row_head_fmt='%*s', col_sep=' = ') for line in table.genOutput(): self.output(line)
def printAllPos(self): motor_width = 10 pos_format = self.getViewOption(ViewOption.PosFormat) fmt = '%*.4f' if pos_format > -1: fmt = '%c*.%df' % ('%', int(pos_format)) table = Table(self.all_pos, elem_fmt=[fmt], col_head_str=self.all_names, col_head_width=motor_width) self.outputBlock(table.genOutput()) self.flushOutput()
def run(self, motor_list): motor_width = 10 motor_names = [] motor_pos = [] for motor in motor_list: name = motor.getName() motor_names.append([name]) posObj = motor.getPositionObj() upos = map(str, [posObj.getMaxValue(), motor.getPosition(force=True), posObj.getMinValue()]) pos_data = [''] + upos motor_pos.append(pos_data) elem_fmt = (['%*s'] + ['%*s'] * 3) * 2 row_head_str = ['User', ' High', ' Current', ' Low',] table = Table(motor_pos, elem_fmt=elem_fmt, row_head_str=row_head_str, col_head_str=motor_names, col_head_width=motor_width, **self.table_opts) for line in table.genOutput(): self.output(line)
def run(self, motor_list): show_dial = self.getViewOption(ViewOption.ShowDial) motor_width = 9 motor_names = [] motor_pos = [] motor_list = list(motor_list) motor_list.sort() for motor in motor_list: name = motor.getName() motor_names.append([name]) pos = motor.getPosition(force=True) if pos is None: pos = float('NAN') motor_pos.append((pos,)) motor_width = max(motor_width,len(name)) fmt = '%c*.%df' % ('%',motor_width - 5) table = Table(motor_pos, elem_fmt=[fmt], col_head_str=motor_names, col_head_width=motor_width, **self.table_opts) for line in table.genOutput(): self.output(line)
def run(self, integ_time, mnt_grp): if self.mnt_grp is None: self.error('The MntGrp {} is not defined or has invalid ' 'value'.format(self.mnt_grp_name)) return # integration time has to be accessible from with in the hooks # so declare it also instance attribute self.integ_time = integ_time self.debug("Counting for %s sec", integ_time) self.outputDate() self.output('') self.flushOutput() for preAcqHook in self.getHooks('pre-acq'): preAcqHook() state, data = self.mnt_grp.count(integ_time) for postAcqHook in self.getHooks('post-acq'): postAcqHook() names, counts = [], [] for ch_info in self.mnt_grp.getChannelsEnabledInfo(): names.append(' %s' % ch_info.label) ch_data = data.get(ch_info.full_name) if ch_data is None: counts.append("<nodata>") elif ch_info.shape > [1]: counts.append(list(ch_data.shape)) else: counts.append(ch_data) self.setData(Record(data)) table = Table([counts], row_head_str=names, row_head_fmt='%*s', col_sep=' = ') for line in table.genOutput(): self.output(line)
row_headers.append('User') t_format.append(fmt) if show_dial: row_headers.append('Dial') t_format.append(fmt) # sort the data dict by keys col_headers = [] values = [] for mot_name, mot_values in sorted(data.items()): col_headers.append([mot_name]) # convert name to list values.append(mot_values) # create and print table table = Table(values, elem_fmt=t_format, col_head_str=col_headers, col_head_width=motor_width, row_head_str=row_headers) for line in table.genOutput(): self.output(line) class _wum(Macro): """Show user motor positions""" param_def = [ ['motor_list', ParamRepeat(['motor', Type.Moveable, None, 'Motor to move']), None, 'List of motor to show'], ] def prepare(self, motor_list, **opts): self.table_opts = {} def run(self, motor_list):
def run(self, motor_list): motor_width = 10 motor_names = [] motor_pos = [] show_dial = self.getViewOption(ViewOption.ShowDial) show_ctrlaxis = self.getViewOption(ViewOption.ShowCtrlAxis) pos_format = self.getViewOption(ViewOption.PosFormat) for motor in motor_list: max_len = 0 if show_ctrlaxis: axis_nb = getattr(motor, "axis") ctrl_name = self.getController(motor.controller).name max_len = max(max_len, len(ctrl_name), len(str(axis_nb))) name = motor.getName() max_len = max(max_len, len(name)) max_len = max_len + 5 if max_len < 14: max_len = 14 # Length of 'Not specified' str_fmt = "%c%ds" % ('%', int(max_len)) name = str_fmt % name motor_names.append([name]) posObj = motor.getPositionObj() if pos_format > -1: fmt = '%c.%df' % ('%', int(pos_format)) try: val1 = fmt % motor.getPosition(force=True) val1 = str_fmt % val1 except: val1 = str_fmt % motor.getPosition(force=True) val2 = str_fmt % posObj.getMaxValue() val3 = str_fmt % posObj.getMinValue() if show_ctrlaxis: valctrl = str_fmt % (ctrl_name) valaxis = str_fmt % str(axis_nb) upos = map(str, [valctrl, valaxis, ' ', val2, val1, val3]) else: upos = map(str, ['', val2, val1, val3]) pos_data = upos if show_dial: try: val1 = fmt % motor.getDialPosition(force=True) val1 = str_fmt % val1 except: val1 = str_fmt % motor.getDialPosition(force=True) dPosObj = motor.getDialPositionObj() val2 = str_fmt % dPosObj.getMaxValue() val3 = str_fmt % dPosObj.getMinValue() dpos = map(str, [val2, val1, val3]) pos_data += [''] + dpos motor_pos.append(pos_data) elem_fmt = (['%*s'] + ['%*s'] * 5) * 2 row_head_str = [] if show_ctrlaxis: row_head_str += ['Ctrl', 'Axis'] row_head_str += ['User', ' High', ' Current', ' Low'] if show_dial: row_head_str += ['Dial', ' High', ' Current', ' Low'] table = Table(motor_pos, elem_fmt=elem_fmt, row_head_str=row_head_str, col_head_str=motor_names, col_head_width=motor_width, **self.table_opts) for line in table.genOutput(): self.output(line)
def run(self, motor_list): show_dial = self.getViewOption(ViewOption.ShowDial) show_ctrlaxis = self.getViewOption(ViewOption.ShowCtrlAxis) pos_format = self.getViewOption(ViewOption.PosFormat) motor_width = 9 motors = {} # dict(motor name: motor obj) requests = {} # dict(motor name: request id) data = {} # dict(motor name: list of motor data) # sending asynchronous requests: neither Taurus nor Sardana extensions # allow asynchronous requests - use PyTango asynchronous request model for motor in motor_list: name = motor.getName() motors[name] = motor args = ('position',) if show_dial: args += ('dialposition',) _id = motor.read_attributes_asynch(args) requests[name] = _id motor_width = max(motor_width, len(name)) data[name] = [] # get additional motor information (ctrl name & axis) if show_ctrlaxis: for name, motor in motors.iteritems(): ctrl_name = self.getController(motor.controller).name axis_nb = str(getattr(motor, "axis")) data[name].extend((ctrl_name, axis_nb)) motor_width = max(motor_width, len(ctrl_name), len(axis_nb)) # collect asynchronous replies while len(requests) > 0: req2delete = [] for name, _id in requests.iteritems(): motor = motors[name] try: attrs = motor.read_attributes_reply(_id) for attr in attrs: value = attr.value if value is None: value = float('NaN') data[name].append(value) req2delete.append(name) except PyTango.AsynReplyNotArrived: continue except PyTango.DevFailed: data[name].append(float('NaN')) if show_dial: data[name].append(float('NaN')) req2delete.append(name) self.debug('Error when reading %s position(s)' % name) self.debug('Details:', exc_info=1) continue # removing motors which alredy replied for name in req2delete: requests.pop(name) # define format for numerical values fmt = '%c*.%df' % ('%', motor_width - 5) if pos_format > -1: fmt = '%c*.%df' % ('%', int(pos_format)) # prepare row headers and formats row_headers = [] t_format = [] if show_ctrlaxis: row_headers += ['Ctrl', 'Axis'] t_format += ['%*s', '%*s'] row_headers.append('User') t_format.append(fmt) if show_dial: row_headers.append('Dial') t_format.append(fmt) # sort the data dict by keys col_headers = [] values = [] for mot_name, mot_values in sorted(data.items()): col_headers.append([mot_name]) # convert name to list values.append(mot_values) # create and print table table = Table(values, elem_fmt=t_format, col_head_str=col_headers, col_head_width=motor_width, row_head_str=row_headers) for line in table.genOutput(): self.output(line)
if show_dial: row_headers.append('Dial') t_format.append(fmt) # sort the data dict by keys col_headers = [] values = [] for mot_name, mot_values in sorted(data.items()): col_headers.append([mot_name]) # convert name to list values.append(mot_values) # create and print table table = Table(values, elem_fmt=t_format, col_head_str=col_headers, col_head_width=motor_width, row_head_str=row_headers) for line in table.genOutput(): self.output(line) class _wum(Macro): """Show user motor positions""" param_def = [ [ 'motor_list', ParamRepeat(['motor', Type.Moveable, None, 'Motor to move']), None, 'List of motor to show' ], ] def prepare(self, motor_list, **opts):