def _analyser_reflection(self, workspace): if workspace == '': return '' ws = mtd[workspace] inst = ws.getInstrument().getName() short_name = '' try: short_name = config.getFacility().instrument(inst).shortName().lower() except RuntimeError: for facility in config.getFacilities(): try: short_name = facility.instrument(inst).shortName().lower() except RuntimeError: pass if short_name == '': raise RuntimeError('Cannot find instrument "%s" in any facility' % str(inst)) run = ws.getRun().getLogData('run_number').value if self._multi_run: run += '_multi' try: analyser = ws.getInstrument().getStringParameter('analyser')[0] reflection = ws.getInstrument().getStringParameter('reflection')[0] except IndexError: analyser = '' reflection = '' prefix = short_name + run + '_' + analyser + reflection + '_red' return prefix
def _get_temperature(self, ws_name): """ Gets the sample temperature for a given workspace. @param ws_name Name of workspace @returns Temperature in Kelvin or None if not found """ instr, run_number = self._get_InstrRun(ws_name) facility = config.getFacility() pad_num = facility.instrument(instr).zeroPadding(int(run_number)) zero_padding = '0' * (pad_num - len(run_number)) run_name = instr + zero_padding + run_number log_filename = run_name.upper() + '.log' run = mtd[ws_name].getRun() if self._sample_log_name in run: # Look for temperature in logs in workspace tmp = run[self._sample_log_name].value value_action = { 'last_value': lambda x: x[len(x) - 1], 'average': lambda x: x.mean() } temp = value_action[self._sample_log_value](tmp) logger.debug('Temperature %d K found for run: %s' % (temp, run_name)) return temp else: # Logs not in workspace, try loading from file logger.information( 'Log parameter not found in workspace. Searching for log file.' ) log_path = FileFinder.getFullPath(log_filename) if log_path != '': # Get temperature from log file LoadLog(Workspace=ws_name, Filename=log_path) run_logs = mtd[ws_name].getRun() if self._sample_log_name in run_logs: tmp = run_logs[self._sample_log_name].value temp = tmp[len(tmp) - 1] logger.debug('Temperature %d K found for run: %s' % (temp, run_name)) return temp else: logger.warning('Log entry %s for run %s not found' % (self._sample_log_name, run_name)) else: logger.warning('Log file for run %s not found' % run_name) # Can't find log file logger.warning('No temperature found for run: %s' % run_name) return None
def _run_title(self, workspace): ws = mtd[workspace] title = ws.getRun()['run_title'].value.strip() runNo = ws.getRun()['run_number'].value inst = ws.getInstrument().getName() isn = config.getFacility().instrument(inst).shortName().upper() valid = "-_.() %s%s" % (string.ascii_letters, string.digits) title = ''.join(ch for ch in title if ch in valid) title = isn + runNo + '-' + title return title
def check_instrument_name(old_name,new_name): """ function checks if new instrument name is acceptable instrument name""" if new_name is None: if not old_name is None: return (None,None,str(config.getFacility())) else: raise KeyError("No instrument name is defined") if old_name == new_name: return # Instrument name might be a prefix, query Mantid for the full name short_name='' full_name='' try : instrument = config.getFacility().instrument(new_name) short_name = instrument.shortName() full_name = instrument.name() except RuntimeError: # it is possible to have wrong facility: facilities = config.getFacilities() old_facility = str(config.getFacility()) for facility in facilities: config.setString('default.facility',facility.name()) try : instrument = facility.instrument(new_name) short_name = instrument.shortName() full_name = instrument.name() if len(short_name)>0 : break except: pass if len(short_name)==0 : config.setString('default.facility',old_facility) raise KeyError(" Can not find/set-up the instrument: "+new_name+' in any supported facility') new_name = short_name facility = str(config.getFacility()) config['default.instrument'] = full_name return (new_name,full_name,facility)
def check_instrument_name(old_name, new_name): """ function checks if new instrument name is acceptable instrument name""" if new_name is None: if not (old_name is None): return (None, None, str(config.getFacility())) else: raise KeyError("No instrument name is defined") if old_name == new_name: return # Instrument name might be a prefix, query Mantid for the full name short_name = '' full_name = '' try: instrument = config.getFacility().instrument(new_name) short_name = instrument.shortName() full_name = instrument.name() except RuntimeError: # it is possible to have wrong facility: facilities = config.getFacilities() old_facility = str(config.getFacility()) for facility in facilities: config.setString('default.facility', facility.name()) try: instrument = facility.instrument(new_name) short_name = instrument.shortName() full_name = instrument.name() if len(short_name) > 0: break except: pass if len(short_name) == 0: config.setString('default.facility', old_facility) raise KeyError(" Can not find/set-up the instrument: " + new_name + ' in any supported facility') new_name = short_name facility = str(config.getFacility()) config['default.instrument'] = full_name return (new_name, full_name, facility)
def _get_temperature(self, ws_name): """ Gets the sample temperature for a given workspace. @param ws_name Name of workspace @returns Temperature in Kelvin or None if not found """ instr, run_number = self._get_InstrRun(ws_name) facility = config.getFacility() pad_num = facility.instrument(instr).zeroPadding(int(run_number)) zero_padding = '0' * (pad_num - len(run_number)) run_name = instr + zero_padding + run_number log_filename = run_name.upper() + '.log' run = mtd[ws_name].getRun() if self._sample_log_name in run: # Look for temperature in logs in workspace tmp = run[self._sample_log_name].value value_action = {'last_value': lambda x: x[len(x) - 1], 'average': lambda x: x.mean() } temp = value_action[self._sample_log_value](tmp) logger.debug('Temperature %d K found for run: %s' % (temp, run_name)) return temp else: # Logs not in workspace, try loading from file logger.information('Log parameter not found in workspace. Searching for log file.') log_path = FileFinder.getFullPath(log_filename) if log_path != '': # Get temperature from log file LoadLog(Workspace=ws_name, Filename=log_path) run_logs = mtd[ws_name].getRun() if self._sample_log_name in run_logs: tmp = run_logs[self._sample_log_name].value temp = tmp[len(tmp) - 1] logger.debug('Temperature %d K found for run: %s' % (temp, run_name)) return temp else: logger.warning('Log entry %s for run %s not found' % (self._sample_log_name, run_name)) else: logger.warning('Log file for run %s not found' % run_name) # Can't find log file logger.warning('No temperature found for run: %s' % run_name) return None
def _analyser_reflection(self, workspace): if workspace == '': return '' ws = mtd[workspace] ins = ws.getInstrument().getName() ins = config.getFacility().instrument(ins).shortName().lower() run = ws.getRun().getLogData('run_number').value try: analyser = ws.getInstrument().getStringParameter('analyser')[0] reflection = ws.getInstrument().getStringParameter('reflection')[0] except IndexError: analyser = '' reflection = '' prefix = ins + run + '_' + analyser + reflection + '_red' return prefix
def _analyser_reflection(self, workspace): if workspace == "": return "" ws = mtd[workspace] ins = ws.getInstrument().getName() ins = config.getFacility().instrument(ins).shortName().lower() run = ws.getRun().getLogData("run_number").value try: analyser = ws.getInstrument().getStringParameter("analyser")[0] reflection = ws.getInstrument().getStringParameter("reflection")[0] except IndexError: analyser = "" reflection = "" prefix = ins + run + "_" + analyser + reflection + "_red" return prefix
def getInstrRun(ws_name): """ Get the instrument name and run number from a workspace. @param ws_name - name of the workspace @return tuple of form (instrument, run number) """ run_number = get_run_number(ws_name) instrument = mtd[ws_name].getInstrument().getName() if instrument != '': facility = config.getFacility() instrument = facility.instrument(instrument).filePrefix(int(run_number)) instrument = instrument.lower() return instrument, run_number
def getInstrRun(ws_name): ''' Get the instrument name and run number from a workspace. @param ws_name - name of the workspace @return tuple of form (instrument, run number) ''' ws = mtd[ws_name] run_number = str(ws.getRunNumber()) if run_number == '0': #attempt to parse run number off of name match = re.match(r'([a-zA-Z]+)([0-9]+)', ws_name) if match: run_number = match.group(2) else: raise RuntimeError("Could not find run number associated with workspace.") instrument = ws.getInstrument().getName() facility = config.getFacility() instrument = facility.instrument(instrument).filePrefix(int(run_number)) instrument = instrument.lower() return instrument, run_number