def check_facility(): """ Get the currently set facility and check if it is in the list of supported facilities, raising an AttributeError if not. """ current_facility = ConfigServiceImpl.Instance().getFacility().name() if current_facility not in SUPPORTED_FACILITIES: raise AttributeError( "Your facility {} is not supported by MuonAnalysis 2.0, so you" "will not be able to load any files. \n \n" "Supported facilities are :" + "\n - ".join(SUPPORTED_FACILITIES))
def get_default_grouping(instrument, main_field_direction): parameter_name = "Default grouping file" if instrument == "MUSR": parameter_name += " - " + main_field_direction try: grouping_file = ConfigService.getInstrument( instrument).getStringParameter(parameter_name)[0] except IndexError: return [], [] instrument_directory = ConfigServiceImpl.Instance().getInstrumentDirectory( ) filename = instrument_directory + grouping_file new_groups, new_pairs = load_utils.load_grouping_from_XML(filename) return new_groups, new_pairs
def PyExec(self): inst = self.getProperty('Instrument').value year = self.getProperty('Year').value num = self.getProperty('Numor').value self.log().information('Running LoadSINQ for ' + inst + " Y= " + str(year) + " N= " + str(num)) instmap = {} instmap['AMOR'] = 'amor' instmap['BOA'] = 'boa' instmap['DMC'] = 'dmc' instmap['FOCUS'] = 'focus' instmap['HRPT'] = 'hrpt' instmap['MARSI'] = 'mars' instmap['MARSE'] = 'mars' instmap['POLDI'] = 'poldi' instmap['RITA-2'] = 'rita2' instmap['SANS'] = 'sans' instmap['SANS2'] = 'sans2' instmap['TRICS'] = 'trics' hun = math.floor(num / 1000.) filename = '%03d/%s%04dn%06d.hdf' % (hun, instmap[inst], year, num) fullpath = '%s/%04d/%s/%s' % (datapath, year, instmap[inst], filename) wname = "__tmp" #hidden ws = None # Holds the workspace later if os.path.exists(fullpath): ws = mantid.simpleapi.LoadSINQFile(fullpath, inst, OutputWorkspace=wname) else: searchDirs = ConfigServiceImpl.Instance().getDataSearchDirs() filename = '%s%04dn%06d.hdf' % (instmap[inst], year, num) for entry in searchDirs: fullpath = '%s/%s' % (entry, filename) if os.path.exists(fullpath): ws = mantid.simpleapi.LoadSINQFile(fullpath, inst, OutputWorkspace=wname) break # If ws is still "None" at this point, the file was not found. if ws is None: raise Exception('File %s NOT found!' % filename) self.setProperty("OutputWorkspace", ws) mantid.simpleapi.DeleteWorkspace(wname)
def get_default_grouping(workspace, instrument, main_field_direction): parameter_name = "Default grouping file" if instrument == "MUSR": parameter_name += " - " + main_field_direction try: if isinstance(workspace, WorkspaceGroup): grouping_file = workspace[0].getInstrument().getStringParameter( parameter_name)[0] else: grouping_file = workspace.getInstrument().getStringParameter( parameter_name)[0] except IndexError: return [], [] instrument_directory = ConfigServiceImpl.Instance().getInstrumentDirectory( ) filename = instrument_directory + grouping_file new_groups, new_pairs, description = xml_utils.load_grouping_from_XML( filename) return new_groups, new_pairs
def get_default_grouping(workspace, instrument, main_field_direction): parameter_name = "Default grouping file" if instrument == "MUSR" or instrument == 'CHRONUS': parameter_name += " - " + main_field_direction if instrument != "PSI": try: if isinstance(workspace, WorkspaceGroup): grouping_file = workspace[0].getInstrument().getStringParameter(parameter_name)[0] else: grouping_file = workspace.getInstrument().getStringParameter(parameter_name)[0] except IndexError: return [], [], '' else: return get_grouping_psi(workspace) instrument_directory = ConfigServiceImpl.Instance().getInstrumentDirectory() filename = os.path.join(instrument_directory, grouping_file) new_groups, new_pairs, description, default = xml_utils.load_grouping_from_XML(filename) return new_groups, new_pairs, default
def get_default_instrument(): default_instrument = ConfigServiceImpl.Instance().getInstrument().name() if default_instrument not in file_utils.allowed_instruments: default_instrument = 'MUSR' return default_instrument
def PyExec(self): """ Mantid required """ self.log().debug('Poldi Data Analysis ---- start') sample_info_ws = self.getProperty("InputWorkspace").value load_data_at_the_end = False try: sample_ipp_ws_name = self.getProperty("OutputWorkspace").value if(sample_ipp_ws_name == ""): sample_ipp_ws_name = "PoldiIPPmanager" self.log().debug('Poldi IPP manager ---- %s'%(sample_info_ws_name)) sample_ipp_ws = mtd["PoldiIPPmanager"] self.log().debug(' ---- workspace ipp loaded') except: self.log().debug(' ---- workspace ipp created') sample_ipp_ws = WorkspaceFactory.createTable() sample_ipp_ws.addColumn("str","spl Name") sample_ipp_ws.addColumn("str","ipp version") load_data_at_the_end = True wlen_min = self.getProperty("wlenmin").value wlen_max = self.getProperty("wlenmax").value bad_wires_threshold = self.getProperty("BadWiresThreshold").value peak_detect_threshold = self.getProperty("PeakDetectionThreshold").value self.log().information('Poldi run with parameters') self.log().information(' - wlen_min : %s' %(wlen_min)) self.log().information(' - wlen_max : %s' %(wlen_max)) self.log().information(' - bad_wires_threshold : %s' %(bad_wires_threshold)) self.log().information(' - peak_detect_threshold : %s' %(peak_detect_threshold)) dictsearch=os.path.join(config['instrumentDefinition.directory'],"nexusdictionaries","poldi.dic") self.log().information('Poldi instr folder - %s' %(dictsearch)) firstOne="" self.log().debug('Poldi - load data') nb_of_sample = sample_info_ws.rowCount() self.log().information('Poldi - %d samples listed' %(nb_of_sample)) for sample in range(nb_of_sample): sampleName = sample_info_ws.column("spl Name")[sample] filePath = sample_info_ws.column("data file")[sample] sampleNameLog = sample_info_ws.column("spl log")[sample] sampleDeadWires = sample_info_ws.column("spl dead wires")[sample] self.log().information('Poldi - sample %s' %(sampleName)) LoadSINQFile(Instrument="POLDI", Filename=filePath, OutputWorkspace=sampleName) sample_output_ws = mtd[sampleName] PoldiLoadLog(InputWorkspace=sample_output_ws, Filename=filePath, Dictionary=dictsearch, PoldiLog=sampleNameLog) cfgService = ConfigServiceImpl.Instance() LoadInstrument(Workspace=sample_output_ws, Filename=cfgService.getInstrumentDirectory() + "POLDI_Definition_ipp13.xml", RewriteSpectraMap=True) self.log().debug('Poldi - set ipp') sample_instrument = sample_output_ws.getInstrument() ipp_version = sample_instrument.getStringParameter("ipp")[0] add_this_ipp = True for ipp in range(sample_ipp_ws.rowCount()): if(sample_ipp_ws.column("ipp version")[ipp] == ipp_version): add_this_ipp = False if(add_this_ipp): sample_ipp_ws.addRow([sampleName, ipp_version]) self.log().debug('Poldi - dead wires') PoldiRemoveDeadWires(InputWorkspace=sample_output_ws, RemoveExcludedWires=True, AutoRemoveBadWires=False, BadWiresThreshold=bad_wires_threshold, PoldiDeadWires=sampleDeadWires) nb_of_ipp = sample_ipp_ws.rowCount() self.log().information('Poldi - %d ipp listed' %(nb_of_ipp)) for ipp in range(nb_of_ipp): ex_of_sample = sample_ipp_ws.column("spl Name")[ipp] PoldiIPP = sample_ipp_ws.column("ipp version")[ipp] ipp_chopper_slits = "%s_Chopper" %PoldiIPP ipp_Poldi_spectra = "%s_Spectra" %PoldiIPP ipp_ipp_data = "%s_Data" %PoldiIPP ex_of_sample_ws = mtd[ex_of_sample] self.log().debug('Poldi - chopper slits') PoldiLoadChopperSlits(InputWorkspace=ex_of_sample_ws, PoldiChopperSlits=ipp_chopper_slits) self.log().debug('Poldi - spectra') PoldiLoadSpectra(InputWorkspace=ex_of_sample_ws, PoldiSpectra=ipp_Poldi_spectra) self.log().debug('Poldi - IPP') PoldiLoadIPP(InputWorkspace=ex_of_sample_ws, PoldiIPP=ipp_ipp_data) for sample in range(nb_of_sample): sampleName = sample_info_ws.column("spl Name" )[sample] filePath = sample_info_ws.column("data file")[sample] sampleNameLog = sample_info_ws.column("spl log" )[sample] sampleDeadWires= sample_info_ws.column("spl dead wires" )[sample] sampleNameCorr = sample_info_ws.column("spl corr" )[sample] groupedResults = GroupWorkspaces([mtd[sampleName].name(), sampleNameLog, sampleDeadWires]) RenameWorkspace(InputWorkspace=groupedResults, OutputWorkspace="%s_Metadata" % sampleName) if(load_data_at_the_end): self.setProperty("OutputWorkspace", sample_ipp_ws)