From 9d18c3340b24aae19549a21f54181783cca845a6 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Mon, 20 Oct 2014 15:47:47 +0100 Subject: [PATCH] Remove old file, fiting sort of working Refs #10391 --- .../algorithms/WorkflowAlgorithms/MolDyn.py | 40 +-- .../scripts/Inelastic/IndirectMolDyn.py | 328 ------------------ 2 files changed, 20 insertions(+), 348 deletions(-) delete mode 100644 Code/Mantid/scripts/Inelastic/IndirectMolDyn.py diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/MolDyn.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/MolDyn.py index 1a4ac1e632c2..a8f7e4947c0e 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/MolDyn.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/MolDyn.py @@ -142,7 +142,7 @@ def PyExec(self): workdir = config['defaultsave.directory'] out_filename = os.path.join(workdir, self._out_ws + '.nxs') if self._verbose: - logger.notice('Creating file: %s' % out_filename) + logger.information('Creating file: %s' % out_filename) SaveNexus(InputWorkspace=self._out_ws, Filename=out_filename) # Set the output workspace @@ -232,9 +232,9 @@ def _find_dimensions(self, data): num_f = int(f_el[2]) if self._verbose: - logger.notice(data[2][1:-1]) - logger.notice(data[3][1:-1]) - logger.notice(data[6][1:-1]) + logger.debug(data[2][1:-1]) + logger.debug(data[3][1:-1]) + logger.debug(data[6][1:-1]) return num_q, num_t, num_f @@ -264,7 +264,7 @@ def _cdl_import(self, data, name): Q.append(float(Qlist[nQ - 1][:-1]) / 10.0) if self._verbose: - logger.notice('Q values = ' + str(Q)) + logger.information('Q values = ' + str(Q)) lt1 = _find_starts(data, ' time =', lq2) # start T values lt2 = _find_ends(data, ';', lt1) @@ -280,7 +280,7 @@ def _cdl_import(self, data, name): T.append(float(Tlist[nT - 1][:-1])) T.append(2 * T[nT - 1] - T[nT - 2]) if self._verbose: - logger.notice('T values = ' + str(T[:2]) + ' to ' + str(T[-3:])) + logger.information('T values = ' + str(T[:2]) + ' to ' + str(T[-3:])) lf1 = _find_starts(data, ' frequency =', lq2) # start F values lf2 = _find_ends(data, ';', lf1) @@ -296,7 +296,7 @@ def _cdl_import(self, data, name): F.append(float(Flist[nF - 1][:-1])) F.append(2 * F[nF - 1] - T[nF - 2]) if self._verbose: - logger.notice('F values = ' + str(F[:2]) + ' to ' + str(F[-3:])) + logger.information('F values = ' + str(F[:2]) + ' to ' + str(F[-3:])) # Function output_ws_list = list() @@ -333,7 +333,7 @@ def _cdl_import(self, data, name): for n in range(0, nQ): if self._verbose: logger.information(str(start)) - logger.notice('Reading : ' + data[start[n]]) + logger.information('Reading : ' + data[start[n]]) Slist = _make_list(data, start[n] + 1, start[n + 1] - 1) if n == nQ - 1: @@ -345,7 +345,7 @@ def _cdl_import(self, data, name): raise RuntimeError('Error reading S values') else: if self._verbose: - logger.notice('S values = ' + str(S[:2]) + ' to ' + str(S[-2:])) + logger.information('S values = ' + str(S[:2]) + ' to ' + str(S[-2:])) if n == 0: Qaxis += str(Q[n]) xDat = xEn @@ -388,15 +388,15 @@ def _ascii_import(self, data, name): nX = len(x) if self._verbose: - logger.notice('nQ = ' + str(nQ)) - logger.notice('nT = ' + str(nX)) + logger.information('nQ = ' + str(nQ)) + logger.information('nT = ' + str(nX)) xT = np.array(x) eZero = np.zeros(nX) Qaxis = '' for m in range(0, nQ): if self._verbose: - logger.notice('Q[' + str(m + 1) + '] : ' + str(Q[m])) + logger.information('Q[' + str(m + 1) + '] : ' + str(Q[m])) S = [] for n in range(0, nX): @@ -426,7 +426,7 @@ def _ascii_import(self, data, name): InstrParas(self._out_ws, instr, ana, refl) efixed = RunParas(self._out_ws, instr, name, name, self._verbose) if self._verbose: - logger.notice('Qmax = ' + str(Qmax) + ' ; efixed = ' + str(efixed)) + logger.information('Qmax = ' + str(Qmax) + ' ; efixed = ' + str(efixed)) pi4 = 4.0 * math.pi wave = 1.8 * math.sqrt(25.2429 / efixed) theta = [] @@ -443,20 +443,20 @@ def _convolve_with_res(self): Performs collvolution with an instrument resolution workspace. """ - base = os.path.basename(self._sam_path) - self._sam_ws = os.path.splitext(base)[0] - self._sam_ws += '_' + str(self._functions[0]) + # TODO + + function_ws_name = mtd[self._out_ws].getItem(0).getName() f1 = 'composite=Convolution;' f2 = 'name=TabulatedFunction,Workspace=' + self._res_ws + ',WorkspaceIndex=0;' - f3 = 'name=TabulatedFunction,Workspace=' + self._sam_ws + ',WorkspaceIndex=0' + f3 = 'name=TabulatedFunction,Workspace=' + function_ws_name + ',WorkspaceIndex=0' function = f1 + f2 + f3 - Fit(Function=function, InputWorkspace=self._sam_ws, MaxIterations=0, CreateOutput=True, + Fit(Function=function, InputWorkspace=function_ws_name, MaxIterations=0, CreateOutput=True, ConvolveMembers=True) - conv_ws = self._sam_ws + '_conv' - Symmetrise(Sample=self._sam_ws, XMin=0, XMax=self._emax, + conv_ws = self._out_ws + '_conv' + Symmetrise(Sample=function_ws_name, XMin=0, XMax=self._emax, Verbose=self._verbose, Plot=False, Save=False, OutputWorkspace=conv_ws) diff --git a/Code/Mantid/scripts/Inelastic/IndirectMolDyn.py b/Code/Mantid/scripts/Inelastic/IndirectMolDyn.py deleted file mode 100644 index 3b9485f8dea2..000000000000 --- a/Code/Mantid/scripts/Inelastic/IndirectMolDyn.py +++ /dev/null @@ -1,328 +0,0 @@ -#Force for ILL backscattering raw -# -from IndirectImport import * -from mantid.simpleapi import * -from mantid import config, logger, mtd -from mantid.kernel import V3D -import sys, math, os.path, numpy as np -from IndirectCommon import StartTime, EndTime, ExtractFloat, ExtractInt -from IndirectNeutron import ChangeAngles, InstrParas, RunParas -mp = import_mantidplot() - -# Routines for Ascii file of MolDyn data - -def SplitLine(a): - elements = a.split() #split line on character - extracted = [] - for n in elements: - extracted.append(float(n)) - return extracted #values as list - -def FindDimensions(a,Verbose): - ldim = FindStarts(a,'dimensions',0) - lQ = FindTabStarts(a,'NQVALUES',0) - lT = FindTabStarts(a,'NTIMES',0) - lF = FindTabStarts(a,'NFREQUENCIES',0) - Qel = a[lQ].split() - nQ = int(Qel[2]) - Tel = a[lT].split() - nT = int(Tel[2]) - Fel = a[lF].split() - nF = int(Tel[2]) - if Verbose: - logger.notice(a[2][1:-1]) - logger.notice(a[3][1:-1]) - logger.notice(a[6][1:-1]) - return nQ,nT,nF - -def FindStarts(asc,c,l1): - for l in range(l1,len(asc)): - char = asc[l] - if char.startswith(c): - line = l - break - return line - -def FindTabStarts(asc,c,l1): - for l in range(l1,len(asc)): - char = asc[l][1:] - if char.startswith(c): - line = l - break - return line - -def FindEnds(asc,c,l1): - for l in range(l1,len(asc)): - char = asc[l] - if char.endswith(c): - line = l - break - return line - -def FindChar(asc,c,l1): - for l in range(l1,len(asc)): - char = asc[l] - if char.find(c): - line = l - break - return line - -def MakeList(a,l1,l2): - asc = '' - for m in range(l1,l2+1): - asc += a[m] - alist = asc.split(',') - return alist - -# Load an dat/cdl file -def loadFile(path): - try: - handle = open(path, 'r') - asc = [] - for line in handle: - line = line.rstrip() - asc.append(line) - handle.close() - - return asc - except: - error = 'ERROR *** Could not load ' + path - sys.exit(error) - -def MolDynImport(fname,functions,Verbose,Plot,Save): #Ascii start routine - StartTime('MolDynImport') - workdir = config['defaultsave.directory'] - - #seperate functions string and strip whitespace - functions = [x.strip() for x in functions.split(',')] - - path = fname - base = os.path.basename(path) - fname = os.path.splitext(base)[0] - - if(not os.path.isfile(path)): - path = FileFinder.getFullPath(path) - - if Verbose: - logger.notice('Functions : '+str(functions)) - logger.notice('Reading file : ' + path) - - asc = loadFile(path) - lasc = len(asc) - -# raw head - nQ,nT,nF = FindDimensions(asc,Verbose) - ldata = FindStarts(asc,'data:',0) - lq1 = FindStarts(asc,' q =',ldata) #start Q values - lq2 = FindStarts(asc,' q =',lq1-1) - Qlist = MakeList(asc,lq1,lq2) - if nQ != len(Qlist): - error = 'ERROR *** reading Q values' - logger.notice(error) - sys.exit(error) - Qf = Qlist[0].split() - Q = [float(Qf[2])/10.0] - for m in range(1,nQ-1): - Q.append(float(Qlist[m])/10.0) - Q.append(float(Qlist[nQ-1][:-1])/10.0) - if Verbose: - logger.notice('Q values = '+str(Q)) - lt1 = FindStarts(asc,' time =',lq2) #start T values - lt2 = FindEnds(asc,';',lt1) - Tlist = MakeList(asc,lt1,lt2) - if nT != len(Tlist): - error = 'ERROR *** reading Time values' - logger.notice(error) - sys.exit(error) - Tf = Tlist[0].split() - T = [float(Tf[2])] - for m in range(1,nT-1): - T.append(float(Tlist[m])) - T.append(float(Tlist[nT-1][:-1])) - T.append(2*T[nT-1]-T[nT-2]) - if Verbose: - logger.notice('T values = '+str(T[:2])+' to '+str(T[-3:])) - lf1 = FindStarts(asc,' frequency =',lq2) #start F values - lf2 = FindEnds(asc,';',lf1) - Flist = MakeList(asc,lf1,lf2) - if nF != len(Flist): - error = 'ERROR *** reading Freq values' - logger.notice(error) - sys.exit(error) - Ff = Flist[0].split() - F = [float(Ff[2])] - for m in range(1,nF-1): - F.append(float(Flist[m])) - F.append(float(Flist[nF-1][:-1])) - F.append(2*F[nF-1]-T[nF-2]) - if Verbose: - logger.notice('F values = '+str(F[:2])+' to '+str(F[-3:])) -# Function - for func in functions: - start = [] - lstart = lt2 - if func[:3] == 'Fqt': - nP = nT - xEn = np.array(T) - eZero = np.zeros(nT) - xUnit = 'TOF' - elif func[:3] == 'Sqw': - nP = nF - xEn = np.array(F) - eZero = np.zeros(nF) - xUnit = 'Energy' - else: - error = "ERROR *** Failed to parse function string " + func - sys.exit(error) - - for n in range(0,nQ): - for m in range(lstart,lasc): - char = asc[m] - if char.startswith(' // '+func): - start.append(m) - lstart = m+1 - lend = FindEnds(asc,';',lstart) - start.append(lend+1) - - #Throw error if we couldn't find the function - if(len(start) < 2): - error = "ERROR *** Failed to parse function string " + func - sys.exit(error) - -# logger.notice('Start lines : '+str(start)) - Qaxis = '' - for n in range(0,nQ): - if Verbose: - print start - logger.notice('Reading : '+asc[start[n]]) - Slist = MakeList(asc,start[n]+1,start[n+1]-1) - if n == nQ-1: - Slist[nP-1] = Slist[nP-1][:-1] - S = [] - for m in range(0,nP): - S.append(float(Slist[m])) - if nP != len(S): - error = 'ERROR *** reading S values' - logger.notice(error) - sys.exit(error) - else: - if Verbose: - logger.notice('S values = '+str(S[:2])+' to '+str(S[-2:])) - if n == 0: - Qaxis += str(Q[n]) - xDat = xEn - yDat = np.array(S) - eDat = eZero - else: - Qaxis += ','+str(Q[n]) - xDat = np.append(xDat,xEn) - yDat = np.append(yDat,np.array(S)) - eDat = np.append(eDat,eZero) - outWS = fname+'_'+func - CreateWorkspace(OutputWorkspace=outWS, DataX=xDat, DataY=yDat, DataE=eDat, - Nspec=nQ, UnitX=xUnit, VerticalAxisUnit='MomentumTransfer', VerticalAxisValues=Qaxis) - if Save: - opath = os.path.join(workdir,outWS+'.nxs') - SaveNexusProcessed(InputWorkspace=outWS, Filename=opath) - if Verbose: - logger.notice('Output file : ' + opath) - if (Plot != 'None'): - plotMolDyn(outWS,Plot) - EndTime('MolDynImport') - -def plotMolDyn(inWS,Plot): - if (Plot == 'Spectrum' or Plot == 'Both'): - nHist = mtd[inWS].getNumberHistograms() - if nHist > 10 : - nHist = 10 - plot_list = [] - for i in range(0, nHist): - plot_list.append(i) - res_plot=mp.plotSpectrum(inWS,plot_list) - if (Plot == 'Contour' or Plot == 'Both'): - cont_plot=mp.importMatrixWorkspace(inWS).plotGraph2D() - -def MolDynText(fname,Verbose,Plot,Save): #Ascii start routine - StartTime('MolDynAscii') - workdir = config['defaultsave.directory'] - - path = fname - base = os.path.basename(path) - fname = os.path.splitext(base)[0] - - if(not os.path.isfile(path)): - path = FileFinder.getFullPath(path) - - if Verbose: - logger.notice('Reading file : ' + path) - - asc = loadFile(path) - lasc = len(asc) - - val = SplitLine(asc[3]) - Q = [] - for n in range(1,len(val)): - Q.append(val[n]) - nQ = len(Q) - x = [] - y = [] - for n in range(4,lasc): - val = SplitLine(asc[n]) - x.append(val[0]) - yval = val[1:] - y.append(yval) - nX = len(x) - if Verbose: - logger.notice('nQ = '+str(nQ)) - logger.notice('nT = '+str(nX)) - xT = np.array(x) - eZero = np.zeros(nX) - Qaxis = '' - for m in range(0,nQ): - if Verbose: - logger.notice('Q['+str(m+1)+'] : '+str(Q[m])) - S = [] - for n in range(0,nX): - S.append(y[n][m]) - if m == 0: - Qaxis += str(Q[m]) - xDat = xT - yDat = np.array(S) - eDat = eZero - else: - Qaxis += ','+str(Q[m]) - xDat = np.append(xDat,xT) - yDat = np.append(yDat,np.array(S)) - eDat = np.append(eDat,eZero) - outWS = fname + '_iqt' - CreateWorkspace(OutputWorkspace=outWS, DataX=xDat, DataY=yDat, DataE=eDat, - Nspec=nQ, UnitX='TOF') -# Nspec=nQ, UnitX='TOF', VerticalAxisUnit='MomentumTransfer', VerticalAxisValues=Qaxis) - Qmax = Q[nQ-1] - instr = 'MolDyn' - ana = 'qmax' - if Qmax <= 2.0: - refl = '2' - else: - refl = '4' - InstrParas(outWS,instr,ana,refl) - efixed = RunParas(outWS,instr,fname,fname,Verbose) - if Verbose: - logger.notice('Qmax = '+str(Qmax)+' ; efixed = '+str(efixed)) - pi4 = 4.0*math.pi - wave=1.8*math.sqrt(25.2429/efixed) - theta = [] - for n in range(0,nQ): - qw = wave*Q[n]/pi4 - ang = 2.0*math.degrees(math.asin(qw)) - theta.append(ang) - ChangeAngles(outWS,instr,theta,Verbose) - if Save: - opath = os.path.join(workdir,outWS+'.nxs') - SaveNexusProcessed(InputWorkspace=outWS, Filename=opath) - if Verbose: - logger.notice('Output file : ' + opath) - if (Plot != 'None'): - plotMolDyn(outWS,Plot) - EndTime('MolDynAscii') -