Ticket #9086: WrappedReduction-example.py

File WrappedReduction-example.py, 7.0 KB (added by Owen Arnold, 7 years ago)
Line 
1from WrappedReduction import *
2
3#####################        M2-0167 T=5K
4#( _ ,r1q , _)= ref('8169+8171+8173+8175+8177+8179+8181',theta=0.4)  #Test ref()
5#r1q= refl('8169+8171+8173+8175+8177+8179+8181',theta=0.4)  # Test refl
6r1q= refq('8169+8171+8173+8175+8177+8179+8181',theta=0.4)  # Test refq
7
8graph0=plotSpectrum(r1q,0); 
9graph0.activeLayer().setAxisScale(Layer.Left,1e-7,1,Layer.Log10); graph0.activeLayer().setAutoScale();
10
11#(_ ,r2q,  _)= ref('8197+8198+8199+8200', 0.615)
12#r2q= refl('8197+8198+8199+8200', 0.615)
13r2q= refq('8197+8198+8199+8200', 0.615)
14
15graph0=plotSpectrum(r2q,0); 
16graph0.activeLayer().setAxisScale(Layer.Left,1e-7,1,Layer.Log10); graph0.activeLayer().setAutoScale();
17
18#( _ ,r3q , _)= ref('8170+8172+8174+8176+8178+8180', theta=1.52)
19#r3q= refl('8170+8172+8174+8176+8178+8180', theta=1.52)
20r3q= refq('8170+8172+8174+8176+8178+8180', theta=1.52)
21
22graph0=plotSpectrum(r3q,0); 
23graph0.activeLayer().setAxisScale(Layer.Left,1e-7,1,Layer.Log10); graph0.activeLayer().setAutoScale();
24
25# Plot the data to check the results
26graph0=plotSpectrum([r1q,r2q,r3q],0); 
27graph0.activeLayer().setAxisScale(Layer.Left,1e-7,1,Layer.Log10); graph0.activeLayer().setAutoScale();
28
29# Rebin prior to stitching
30rr1q=Rebin(r1q,'0.009,-0.02,0.048')
31rr2q=Rebin(r2q,'0.014,-0.02,0.066')
32rr3q=Rebin(r3q,'0.026,-0.02,0.18')
33
34# Plot the data to check the results
35graph1=plotSpectrum([rr1q,rr2q,rr3q],0); 
36graph1.activeLayer().setAxisScale(Layer.Left,1e-7,1,Layer.Log10); graph1.activeLayer().setAutoScale();
37### Test Matplotlib graphics
38plt.plot(centerbins(rr1q[0].readX(0)),rr1q[0].readY(0), 'r.-',centerbins(rr1q[1].readX(0)),rr1q[1].readY(0), 'k.-' )
39plt.plot(centerbins(rr2q[0].readX(0)),rr2q[0].readY(0), 'b.-',centerbins(rr2q[1].readX(0)),rr2q[1].readY(0), 'g.-' )
40plt.plot(centerbins(rr3q[0].readX(0)),rr3q[0].readY(0), 'c.-',centerbins(rr3q[1].readX(0)),rr3q[1].readY(0), 'm.-' )
41#plt.show()   # Causes a full mantid crash.
42
43"""
44# Stitch three data sets together
45r5k = Stitch1DMany([rr1q,rr2q,rr3q], [0.014,0.026],[0.048,0.066],-0.05)
46
47# Plot the stitched data
48graph2=plotSpectrum(r5k,0);
49graph2.activeLayer().setAxisScale(Layer.Left,1e-7,1,Layer.Log10); graph2.activeLayer().setAutoScale();
50# Normalize the area of total reflection to 1
51y0=r5k[0].readY(0); y1=r5k[1].readY(0);
52avg=numpy.average( numpy.array( ( numpy.average(y0[0:10]), numpy.average(y1[0:10]) ) ) )
53r5k=r5k/avg
54
55# Write out textfiles
56#SaveAscii(r5k[0],'M2-167T=5KH=0p9T.001.dat', ScientificFormat=True,ColumnHeader=False)
57#SaveAscii(r5k[1],'M2-167T=5KH=0p9T.002.dat', ScientificFormat=True,ColumnHeader=False)
58
59#calculate the spin asymmetry and flipping ratio.  We rebin again to improve the error bar on the high q data
60rr=Rebin(r5k,'0.009,-0.05,0.02,0.07,0.2')
61asym=(rr[0]-rr[1])/(rr[0]+rr[1])
62ratio=rr[0]/rr[1]
63
64# Plot the stitched data
65graph3=plotSpectrum(asym,0);  graph3.activeLayer().setAxisTitle(0, "SA")
66graph4=plotSpectrum(Ratio,0);  graph4.activeLayer().setAxisTitle(0, "Ratio")
67g=mergePlots(graph3,graph4)
68
69# Write out textfiles
70#SaveAscii(asym,'M2-167T=5KH=0p9T.asy.dat', ScientificFormat=True,ColumnHeader=False)
71#SaveAscii(ratio,  'M2-167T=5KH=0p9T.rat.dat', ScientificFormat=True,ColumnHeader=False)
72
73"""
74'''
75#################################################################################################
76#####################        M2-0167 T=50K
77#################################################################################################
78r1q = refq('8187+8189+8191+8193', theta=0.401)
79r2q = refq('8196', theta=0.61)
80r3q = refq('8195', theta=0.9)
81r4q = refq('8188+8190+8192+8194', theta=1.501)
82# Rebin prior to stitching
83rr1q=Rebin(r1q,'0.009,-0.02,0.048')
84rr2q=Rebin(r2q,'0.0155,-0.02,0.06')
85rr3q=Rebin(r3q,'0.018,-0.02,0.1')
86rr4q=Rebin(r4q,'0.026,-0.02,0.2')
87
88# Plot the data to check the results
89graph1=plotSpectrum([rr1q,rr2q,rr3q,rr4q],0);
90graph1.activeLayer().setAxisScale(Layer.Left,1e-7,1,Layer.Log10); graph1.activeLayer().setAutoScale();
91
92# Stitch three data sets together
93r50k = Stitch1DMany([rr1q,rr2q,rr3q,rr4q], [0.0155,0.18,0.026],[0.048,0.06,0.1],'-0.05')
94
95# Plot the stitched data
96graph2=plotSpectrum(r50k,0);
97graph2.activeLayer().setAxisScale(Layer.Left,1e-7,1,Layer.Log10); graph2.activeLayer().setAutoScale();
98# Normalize the area of total reflection to 1
99y0=r50k[0].readY(0); y1=r50k[1].readY(0);
100avg=numpy.average( numpy.array( ( numpy.average(y0[0:10]), numpy.average(y1[0:10]) ) ) )
101r50k=r50k/avg
102
103# Write out textfiles
104#SaveAscii(r5k[0],'M2-167T=50KH=0p9T.001.dat', ScientificFormat=True,ColumnHeader=False)
105#SaveAscii(r5k[1],'M2-167T=50KH=0p9T.002.dat', ScientificFormat=True,ColumnHeader=False)
106
107 #calculate the spin asymmetry and flipping ratio.  We rebin again to improve the error bar on the high q data
108rr=Rebin(r50k,'0.009,-0.05,0.02,0.07,0.2')
109asym=(rr[0]-rr[1])/(rr[0]+rr[1])
110ratio=rr[0]/rr[1]
111
112# Plot the stitched data
113graph3=plotSpectrum(asym,0);  graph3.activeLayer().setAxisTitle(0, "SA")
114graph4=plotSpectrum(Ratio,0);  graph4.activeLayer().setAxisTitle(0, "Ratio")
115g=mergePlots(graph3,graph4)
116
117# Write out textfiles
118#SaveAscii(asym,'M2-167T=50KH=0p9T.asy.dat', ScientificFormat=True,ColumnHeader=False)
119#SaveAscii(ratio,  'M2-167T=50KH=0p9T.rat.dat', ScientificFormat=True,ColumnHeader=False)
120
121#################################################################################################
122#####################        M2-0167 T=300K
123#################################################################################################
124r1q=refq('8209+8210+8211', theta=0.618)
125r2q=refq('8212+8213+8214+8215+8216+8217+8218+8219+8220+8221+8222+8223+8224', theta=0.93)
126# Rebin prior to stitching
127rr1q=Rebin(r1q,'0.01,-0.03,0.048')
128rr2q=Rebin(r2q,'0.018,-0.03,0.15')
129
130# Plot the data to check the results
131graph1=plotSpectrum([rr1q,rr2q],0); graph1.activeLayer().setAxisScale(Layer.Left,1e-7,1,Layer.Log10); graph1.activeLayer().setAutoScale();
132
133# Stitch three data sets together
134r300k = Stitch1DMany([rr1q,rr2q], [0.018],[0.048],'-0.05')
135
136# Plot the stitched data
137graph2=plotSpectrum(r300k,0);  graph2.activeLayer().setAxisScale(Layer.Left,1e-7,1,Layer.Log10); graph2.activeLayer().setAutoScale();
138
139# Normalize the area of total reflection to 1
140y0=r300k[0].readY(0); y1=r300k[1].readY(0);
141avg=numpy.average( numpy.array( ( numpy.average(y0[0:10]), numpy.average(y1[0:10]) ) ) )
142r300k=r300k/avg
143
144# Write out textfiles
145#SaveAscii(r300k[0],'M2-167T=300KH=0p9T.001.dat', ScientificFormat=True,ColumnHeader=False)
146#SaveAscii(r300k[1],'M2-167T=300KH=0p9T.002.dat', ScientificFormat=True,ColumnHeader=False)
147
148#calculate the spin asymmetry and flipping ratio.  We rebin again to improve the error bar on the high q data
149rr=Rebin(r300k,'0.009,-0.05,0.02,0.07,0.2')
150asym=(rr[0]-rr[1])/(rr[0]+rr[1])
151ratio=rr[0]/rr[1]
152
153# Plot the stitched data
154graph3=plotSpectrum(asym,0);  graph3.activeLayer().setAxisTitle(0, "SA")
155graph4=plotSpectrum(Ratio,0);  graph4.activeLayer().setAxisTitle(0, "Ratio")
156g=mergePlots(graph3,graph4)
157
158# Write out textfiles
159#SaveAscii(asym,'M2-167T=300KH=0p9T.asy.dat', ScientificFormat=True,ColumnHeader=False)
160#SaveAscii(ratio,  'M2-167T=300KH=0p9T.rat.dat', ScientificFormat=True,ColumnHeader=False)
161
162'''