def is_numerical(obj): if is_number(obj): return True if is_non_str_seq(obj) or isinstance(obj, numpy.ndarray): if is_number(obj[0]): return True elif is_non_str_seq(obj[0]) or isinstance(obj, numpy.ndarray): if is_number(obj[0][0]): return True return False
def is_numerical(obj): if is_number(obj): return True if is_non_str_seq(obj) or isinstance(obj, numpy.ndarray): if is_number(obj[0]): return True elif is_non_str_seq(obj[0]) or isinstance(obj, numpy.ndarray): if is_number(obj[0][0]): return True return False
def is_chunk(type_, value): if type_ == ElementType.CTExpChannel and is_non_str_seq(value): return True elif (type_ == ElementType.OneDExpChannel and is_non_str_seq(value)): # empty list is also considered as chunk if (len(value) == 0 or not is_number(value[0])): return True elif (type_ == ElementType.TwoDExpChannel and len(value) > 0 and not is_number(value[0][0])): return True return False
def _preprocessParameters(self, parameters): if is_pure_str(parameters): inside_str = False pars = [] par = '' for c in parameters: if c == '"': if inside_str: inside_str = False pars.append(par) par = '' else: inside_str = True elif c == ' ': if inside_str: par += c else: pars.append(par) par = '' else: par += c if par: pars.append(par) return pars elif is_non_str_seq(parameters): return parameters
def _runMacro(self, xml, **kwargs): #kwargs like 'synch' are ignored in this re-implementation if self._spock_state != RUNNING_STATE: print "Unable to run macro: No connection to door '%s'" % self.getSimpleName() raise Exception("Unable to run macro: No connection") if xml is None: xml = self.getRunningXML() kwargs['synch'] = True try: return BaseDoor._runMacro(self, xml, **kwargs) except KeyboardInterrupt: self.write('\nCtrl-C received: Stopping... ') self.block_lines = 0 self.command_inout("StopMacro") self.writeln("Done!") except PyTango.DevFailed, e: if is_non_str_seq(e.args) and \ not isinstance(e.args, (str, unicode)): reason, desc = e.args[0].reason, e.args[0].desc macro_obj = self.getRunningMacro() if reason == 'MissingParam': print "Missing parameter:", desc print macro_obj.getInfo().doc elif reason == 'WrongParam': print "Wrong parameter:", desc print macro_obj.getInfo().doc elif reason == 'UnkownParamObj': print "Unknown parameter:", desc elif reason == 'MissingEnv': print "Missing environment:", desc elif reason in ('API_CantConnectToDevice', 'API_DeviceNotExported'): self._updateState(self._old_sw_door_state, TaurusSWDevState.Shutdown, silent=True) print "Unable to run macro: No connection to door '%s'" % self.getSimpleName() else: print "Unable to run macro:", reason, desc
def _preprocessParameters(self, parameters): if is_pure_str(parameters): inside_str = False pars = [] par = '' for c in parameters: if c == '"': if inside_str: inside_str = False pars.append(par) par = '' else: inside_str = True elif c == ' ': if inside_str: par += c else: pars.append(par) par = '' else: par += c if par: pars.append(par) return pars elif is_non_str_seq(parameters): return parameters
def decodeRepeat(self, raw_param_repeat, param_repeat_def): """Decode and validate repeat parameter :param raw_param_repeat: (lxml.etree._Element or list) xml element representing param repeat with subelements representing repetitions or list representing repetitions :param param_repeat_def: (dict) repeat parameter definition :return: (list): list with decoded parameter repetitions """ name = param_repeat_def['name'] param_type = param_repeat_def['type'] min_rep = param_repeat_def['min'] max_rep = param_repeat_def['max'] param_repeat = [] if raw_param_repeat is None: raw_param_repeat = param_repeat_def['default_value'] if raw_param_repeat is None: raw_param_repeat = [] len_rep = len(raw_param_repeat) if min_rep and len_rep < min_rep: msg = 'Found %d repetitions of param %s, min is %d' % \ (len_rep, name, min_rep) raise MissingRepeat(msg) if max_rep and len_rep > max_rep: msg = 'Found %d repetitions of param %s, max is %d' % \ (len_rep, name, max_rep) raise SupernumeraryRepeat(msg) # repeat params with only one member and only one repetition value are # allowed - encapsulate it in list and try to decode anyway; # for the moment this only works for non XML decoding but could be # extended in the future to support XML as well if not is_non_str_seq(raw_param_repeat)\ and not isinstance(raw_param_repeat, etree._Element): raw_param_repeat = [raw_param_repeat] for raw_repeat in raw_param_repeat: if len(param_type) > 1: repeat = [] for i, member_type in enumerate(param_type): try: member_raw = raw_repeat[i] except IndexError: member_raw = None member = self.decodeNormal(member_raw, member_type) repeat.append(member) else: # if the repeat parameter is composed of just one member # do not encapsulate it in list and pass directly the item if isinstance(raw_repeat, etree._Element): raw_repeat = raw_repeat[0] # check if one tries to decode repeat parameter of just one # member encapsulated in a list, empty lists are still allowed # to indicate default value elif isinstance(raw_repeat, list) and len(raw_repeat) > 0: msg = 'Repetitions of just one member must not be lists' raise WrongParam(msg) repeat = self.decodeNormal(raw_repeat, param_type[0]) param_repeat.append(repeat) return param_repeat
def _get_h5_scan_files(macro): scan_dir = macro._getEnv("ScanDir") scan_files = macro._getEnv("ScanFile") if not is_non_str_seq(scan_files): scan_files = [scan_files] h5_scan_files = [] for scan_file in scan_files: file_name, file_ext = os.path.splitext(scan_file) if file_ext not in NXscanH5_FileRecorder.formats.values(): continue h5_scan_files.append(os.path.join(scan_dir, scan_file)) return h5_scan_files
def is_chunk(type_, obj): if not is_non_str_seq(obj): return False if type_ == ElementType.CTExpChannel: return True elif type_ == ElementType.OneDExpChannel: # empty list is also considered as chunk if len(obj) == 0 or not is_number(obj[0]): return True elif type_ == ElementType.TwoDExpChannel: # empty list is also considered as chunk if len(obj) == 0 or not is_number(obj[0][0]): return True return False
def __init__(self, file_, nb_of_columns=(20, 0, 0), nb_of_points=100, integ_time=.1, pandas=False): self.file = file_ if not is_non_str_seq(nb_of_columns): self.nb_of_scalars = nb_of_columns self.nb_of_spectrums = 0 self.nb_of_images = 0 else: self.nb_of_scalars = nb_of_columns[0] self.nb_of_spectrums = nb_of_columns[1] self.nb_of_images = nb_of_columns[2] self.nb_of_points = nb_of_points self.integ_time = integ_time self.record_list = None self.environ = dict() self._pandas = pandas
def _runMacro(self, xml, **kwargs): # kwargs like 'synch' are ignored in this re-implementation if self._spock_state != RUNNING_STATE: print("Unable to run macro: No connection to door '%s'" % self.getSimpleName()) raise Exception("Unable to run macro: No connection") if self.stateObj.read().rvalue == PyTango.DevState.RUNNING: print("Another macro is running. Wait until it finishes...") raise Exception("Unable to run macro: door in RUNNING state") if xml is None: xml = self.getRunningXML() kwargs['synch'] = True try: return BaseDoor._runMacro(self, xml, **kwargs) except KeyboardInterrupt: self._handle_stop() except PyTango.DevFailed as e: if is_non_str_seq(e.args) and \ not isinstance(e.args, str): reason, desc = e.args[0].reason, e.args[0].desc macro_obj = self.getRunningMacro() if reason == 'MissingParam': print("Missing parameter:", desc) print(macro_obj.getInfo().doc) elif reason == 'WrongParam': print("Wrong parameter:", desc) print(macro_obj.getInfo().doc) elif reason == 'UnkownParamObj': print("Unknown parameter:", desc) elif reason == 'MissingEnv': print("Missing environment:", desc) elif reason in ('API_CantConnectToDevice', 'API_DeviceNotExported'): self._updateState(self._old_sw_door_state, TaurusSWDevState.Shutdown, silent=True) print("Unable to run macro: No connection to door '%s'" % self.getSimpleName()) else: print("Unable to run macro:", reason, desc)
def is_chunk(obj): if is_non_str_seq(obj): return True return False