1 | # Transmission main |
---|
2 | # |
---|
3 | from mantidsimple import * |
---|
4 | from mantidplotpy import * |
---|
5 | import numpy |
---|
6 | |
---|
7 | def UnwrapMon(inWS): |
---|
8 | # Unwrap monitor - inWS contains M1,M2,S1 - outWS contains unwrapped Mon |
---|
9 | outWS = 'Mon' |
---|
10 | #Unwrap s1>2 to L of S2 (M2) ie 38.76 Ouput is in wavelength |
---|
11 | alg = UnwrapMonitor(InputWorkspace=inWS,OutputWorkspace=outWS,LRef='37.86') |
---|
12 | join = float(alg.getPropertyValue("JoinWavelength")) |
---|
13 | #Fill bad (dip) in spectrum |
---|
14 | RemoveBins(outWS,outWS,join-0.001,join+0.001,Interpolation="Linear") |
---|
15 | FFTSmooth(outWS,outWS,0) # Smooth - FFT |
---|
16 | mtd.deleteWorkspace(inWS) # delete monWS |
---|
17 | return outWS |
---|
18 | |
---|
19 | def TransMon(type,file,verbose): |
---|
20 | if verbose: |
---|
21 | mtd.sendLogMessage('Raw file : '+file) |
---|
22 | LoadRaw(Filename=file,OutputWorkspace='__m1',SpectrumMin=1,SpectrumMax=1) |
---|
23 | LoadRaw(Filename=file,OutputWorkspace='__m2',SpectrumMin=2,SpectrumMax=2) |
---|
24 | LoadRaw(Filename=file,OutputWorkspace='__det',SpectrumMin=3,SpectrumMax=3) |
---|
25 | # Check for single or multiple time regimes |
---|
26 | MonTCBstart = mtd['__m1'].readX(0)[0] |
---|
27 | SpecTCBstart = mtd['__det'].readX(0)[0] |
---|
28 | mtd.deleteWorkspace('__det') # delete monWS |
---|
29 | monWS = '__Mon' |
---|
30 | if (SpecTCBstart == MonTCBstart): |
---|
31 | monWS = UnwrapMon('__m1') # unwrap the monitor spectrum and convert to wavelength |
---|
32 | RenameWorkspace(monWS,'__Mon1') |
---|
33 | else: |
---|
34 | ConvertUnits('__m1','__Mon1',"Wavelength") |
---|
35 | ConvertUnits('__m2','__Mon2',"Wavelength") |
---|
36 | mtd.deleteWorkspace('__m2') # delete monWS |
---|
37 | Xin = mtd['__Mon1'].readX(0) |
---|
38 | xmin1 = mtd['__Mon1'].readX(0)[0] |
---|
39 | xmax1 = mtd['__Mon1'].readX(0)[len(Xin)-1] |
---|
40 | Xin = mtd['__Mon2'].readX(0) |
---|
41 | xmin2 = mtd['__Mon2'].readX(0)[0] |
---|
42 | xmax2 = mtd['__Mon2'].readX(0)[len(Xin)-1] |
---|
43 | wmin = max(xmin1,xmin2) |
---|
44 | wmax = min(xmax1,xmax2) |
---|
45 | CropWorkspace('__Mon1','__Mon1',wmin,wmax) |
---|
46 | RebinToWorkspace('__Mon2','__Mon1','__Mon2') |
---|
47 | monWS = file[0:8] +'_'+ type |
---|
48 | Divide('__Mon2','__Mon1',monWS) |
---|
49 | mtd.deleteWorkspace('__Mon1') # delete monWS |
---|
50 | mtd.deleteWorkspace('__Mon2') # delete monWS |
---|
51 | |
---|
52 | def IDATransStart(sfile,cfile,verbose=False): |
---|
53 | TransMon('Sam',sfile,verbose) |
---|
54 | TransMon('Can',cfile,verbose) |
---|
55 | samWS = sfile[0:8] + '_Sam' |
---|
56 | canWS =cfile[0:8] + '_Can' |
---|
57 | trWS = sfile[0:8] + '_Trans' |
---|
58 | Divide(samWS,canWS,trWS) |
---|
59 | trans = numpy.average(mtd[trWS].readY(0)) |
---|
60 | transWS = sfile[0:8] + '_Transmission' |
---|
61 | workdir = mantid.getConfigProperty('defaultsave.directory') |
---|
62 | group = samWS +','+ canWS +','+ trWS |
---|
63 | GroupWorkspaces(InputWorkspaces=group,OutputWorkspace=transWS) |
---|
64 | path = os.path.join(workdir,transWS+'.nxs') |
---|
65 | SaveNexusProcessed(transWS,path) |
---|
66 | if verbose: |
---|
67 | mtd.sendLogMessage('Transmission : '+str(trans)) |
---|
68 | mtd.sendLogMessage('Output file created : '+path) |
---|
69 | |
---|
70 | IDATransStart("IRS26176.RAW", "IRS26174.RAW") |
---|
71 | |
---|