Changeset 5367
- Timestamp:
- 27/07/10 11:17:22 (6 weeks ago)
- Location:
- trunk/Code
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/Code/Mantid/PythonAPI/scripts/Excitations/IndirectEnergyConversion.py
r5358 r5367 17 17 tmp_ws = outWS + str(i) 18 18 LoadRaw(rawfiles[i], tmp_ws) 19 Plus(outWS, tmp_ws, outWS) 19 try: 20 Plus(outWS, tmp_ws, outWS) 21 except: 22 print 'Rawfiles do not match, not suitable for summing.' 23 sys.exit('Rawfiles not suitable for summing.') 20 24 mantid.deleteWorkspace(tmp_ws) 21 25 workspace = mtd.getMatrixWorkspace(outWS) … … 168 172 return outWS_n 169 173 170 def convert_to_energy(rawfiles, mapfile, first, last, efixed, SumFiles=False, bgremove = [0, 0], tempK=-1, calib='', rebinParam='', cleanUp = True):174 def convert_to_energy(rawfiles, mapfile, first, last, efixed, SumFiles=False, bgremove = [0, 0], tempK=-1, calib='', rebinParam='', CleanUp = True, instrument='', savesuffix='', saveFormats = [], savedir=''): 171 175 ''' 172 176 This function, when passed the proper arguments, will run through the steps of convert to energy … … 177 181 or with the createMappingFile function. 178 182 ''' 179 output_workspaces = [] 183 output_workspace_names = [] 184 runNos = [] 180 185 workspace, ws_name = loadData(rawfiles, Sum=SumFiles) 181 186 for i in range(0, len(workspace)): … … 183 188 MonWS_n = monitorEfficiency() 184 189 runNo = workspace[i].getRun().getLogData("run_number").value() 190 runNos.append(runNo) 185 191 CropWorkspace(ws_name[i], 'Time', StartWorkspaceIndex= (first - 1), EndWorkspaceIndex=( last - 1)) 186 192 mantid.deleteWorkspace(ws_name[i]) … … 192 198 cte = conToEnergy(efixed, outWS_n='EnergyRebinned' + str(i)) 193 199 if ( rebinParam != ''): 194 rebin = rebinData(rebinParam, inWS_n='EnergyRebinned' + str(i)) 200 rebin = rebinData(rebinParam, inWS_n=cte) 201 else: 202 if CleanUp: 203 RenameWorkspace(cte, 'Energy') 204 else: 205 CloneWorkspace(cte, 'Energy') 195 206 if ( tempK != -1 ): 196 207 db = detailedBalance(tempK) 197 208 scale = scaleAndGroup(mapfile, outWS_n='IconComplete' + str(i) + '_' + runNo) 198 output_workspaces.append(scale) 199 return output_workspaces 209 output_workspace_names.append(scale) 210 if ( saveFormats != [] ): 211 saveItems(output_workspace_names, runNos, saveFormats, instrument, savesuffix, directory = savedir) 200 212 201 213 … … 231 243 SaveNexusProcessed(outWS_n, savefile, 'Vanadium') 232 244 return outWS_n 245 246 def saveItems(workspaces, runNos, fileFormats, ins, suffix, directory = ''): 247 for i in range(0, len(workspaces)): 248 filename = ins + runNos[i] + '_' + suffix 249 if directory != '': 250 filename = os.path.join(directory, filename) 251 for j in fileFormats: 252 if j == 'spe': 253 SaveSPE(workspaces[i], filename + '.spe') 254 elif j == 'nxs': 255 SaveNexusProcessed(workspaces[i], filename + '.nxs') 256 else: 257 print 'Save: unknown file type.' 258 system.exit('Save: unknown file type.') -
trunk/Code/qtiplot/MantidQt/CustomInterfaces/inc/Indirect.h
r5358 r5367 67 67 void clearReflectionInfo(); ///< clear various line edit boxes 68 68 QString createMapFile(const QString& groupType); ///< create the mapping file with which to group results 69 QString savePyCode( QString filePrefix); ///< create python code as string to save files69 QString savePyCode(); ///< create python code as string to save files 70 70 bool isDirty(); ///< state whether interface has had any changes 71 71 void isDirty(bool state); ///< signify changes to interface -
trunk/Code/qtiplot/MantidQt/CustomInterfaces/src/Indirect.cpp
r5358 r5367 101 101 QString groupFile = createMapFile(m_uiForm.cbMappingOptions->currentText()); 102 102 if ( groupFile == "" ) 103 {104 103 return; 105 }106 104 107 105 QString filePrefix = m_uiForm.cbInst->itemData(m_uiForm.cbInst->currentIndex()).toString().toLower(); … … 142 140 143 141 if ( m_uiForm.ckUseCalib->isChecked() ) 144 { 145 QString calibFile = m_uiForm.leCalibrationFile->text(); 146 pyInput += "calib = r'"+calibFile+"'\n"; 147 } 142 pyInput += "calib = r'"+m_uiForm.leCalibrationFile->text()+"'\n"; 148 143 else 149 {150 144 pyInput += "calib = ''\n"; 151 }152 145 153 146 pyInput += "efixed = "+m_uiForm.leEfixed->text()+"\n"; … … 169 162 170 163 if ( m_uiForm.ckDetailedBalance->isChecked() ) 171 {172 164 pyInput += "tempK = "+m_uiForm.leDetailedBalance->text()+"\n"; 173 }174 165 else 175 {176 166 pyInput += "tempK = -1\n"; 177 }178 167 179 168 pyInput += "mapfile = r'"+groupFile+"'\n"; 180 169 181 182 pyInput += "icon_workspaces = ind.convert_to_energy(rawfiles, mapfile, first, last, efixed, SumFiles=Sum, bgremove = bgRemove, tempK = tempK, calib = calib, rebinParam = rebinParam)\n";183 170 } 184 171 185 172 if (tryToSave) 186 173 { 187 // pyInput += "iconWS = scale\n"; 188 // pyInput += savePyCode(filePrefix); 189 } 174 pyInput += savePyCode(); 175 } 176 else 177 { 178 pyInput += 179 "fileFormats = []\n" 180 "ins = ''\n" 181 "directory = ''\n" 182 "suffix = ''\n"; 183 } 184 185 pyInput += "ind.convert_to_energy(rawfiles, mapfile, " 186 "first, last, efixed, SumFiles=Sum, bgremove = bgRemove, tempK = tempK, calib = calib, " 187 "rebinParam = rebinParam, instrument = ins, savesuffix = suffix, saveFormats = fileFormats," 188 "savedir = directory)\n"; 190 189 191 190 QString pyOutput = runPythonCode(pyInput).trimmed(); … … 195 194 showInformationBox("The following error occurred:\n" + pyOutput 196 195 + "\n\nAnalysis did not complete."); 196 return; 197 197 } 198 198 … … 464 464 465 465 /** 466 * This function creates the Python script necessary to s ave the workspacedata467 * in the formats requested.466 * This function creates the Python script necessary to set the variables used for saving data 467 * in the main convert_to_energy script. 468 468 * @return python code as a string 469 469 */ 470 QString Indirect::savePyCode(QString filePrefix) 471 { 472 QString pyInput = "\n# Save Files\n"; 473 if ( m_uiForm.leNameSPE->text() != "" ) 474 { 475 pyInput += "savefile = r'" +m_uiForm.leNameSPE->text()+ "'\n"; 476 } 477 else { 478 pyInput += 479 "savefile = mtd.getConfigProperty('defaultsave.directory')\n" 480 "savefile += '" +filePrefix+ "'\n"; 481 if ( m_uiForm.cbAnalyser->currentText() == "graphite" ) 482 { 483 pyInput += "savefile += 'ipg'\n"; 484 } 485 else if ( m_uiForm.cbAnalyser->currentText() == "mica" || m_uiForm.cbAnalyser->currentText() == "fmica" ) 486 { 487 pyInput += "savefile += 'imi'\n"; 488 } 489 } 470 QString Indirect::savePyCode() 471 { 472 QString analyser = m_uiForm.cbAnalyser->currentText(); 473 474 QString ins = m_uiForm.cbInst->itemData(m_uiForm.cbInst->currentIndex()).toString().toLower(); 475 QString suffix = analyser + m_uiForm.cbReflection->currentText() + "_"; 476 QString directory = m_uiForm.leNameSPE->text(); 477 478 if ( analyser == "graphite" ) 479 suffix += "ipg"; 480 else if ( analyser == "mica" || analyser == "fmica" ) 481 suffix += "imi"; 482 483 QStringList fileFormats; 484 QString fileFormatList; 490 485 491 486 if ( m_uiForm.save_ckNexus->isChecked() ) 492 { 493 pyInput += "SaveNexusProcessed(iconWS, savefile + '.nxs')\n"; 494 } 487 fileFormats << "nxs"; 495 488 if ( m_uiForm.save_ckSPE->isChecked() ) 496 { 497 pyInput += "SaveSPE(iconWS, savefile + '.spe')\n"; 498 } 489 fileFormats << "spe"; 490 491 if ( fileFormats.size() != 0 ) 492 fileFormatList = "[ '" + fileFormats.join("', '") + "']"; 493 else 494 fileFormatList = "[]"; 495 496 QString pyInput = 497 "# Save File Parameters\n" 498 "ins = '" + ins + "'\n" 499 "suffix = '" + suffix + "'\n" 500 "fileFormats = " + fileFormatList + "\n" 501 "directory = r'" + directory + "'\n"; 499 502 500 503 return pyInput; … … 695 698 void Indirect::browseSave() 696 699 { 697 QString Analyser = m_uiForm.cbAnalyser->currentText(); 698 QString filePrefix = m_uiForm.cbInst->itemData(m_uiForm.cbInst->currentIndex()).toString().toLower(); 699 filePrefix += "_" + Analyser + m_uiForm.cbReflection->currentText() + "_"; 700 701 QString defSave = m_saveDir + filePrefix; 702 if ( Analyser == "graphite" ) 703 defSave += "ipg"; 704 else 705 defSave += "imi"; 706 QString savFile = QFileDialog::getSaveFileName(this, "Save File Name", 707 defSave, "File Stem (*)"); 708 709 if ( savFile != "" ) 710 { 711 m_uiForm.leNameSPE->setText(savFile); 700 QString savDir = QFileDialog::getExistingDirectory(this, "Save Directory", 701 m_saveDir, QFileDialog::ShowDirsOnly); 702 703 if ( savDir != "" ) 704 { 705 m_uiForm.leNameSPE->setText(savDir); 712 706 isDirty(true); 713 707 }
