source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_BroadPeak_Pix_2D.ipf

Last change on this file was 1242, checked in by srkline, 3 years ago

updating the IgorVersion? pragma to v7.0 for all files to be consistent.

File size: 7.5 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2#pragma IgorVersion=6.1
3#pragma IgorVersion = 7.00
4
5
6// technically, I'm passing a coefficient wave that's TOO LONG to the XOP
7// BEWARE: see
8//ThreadSafe Function I_BroadPeak_Pix2D(w,x,y)
9
10// ALSO -- the pixels are not square in general, so this will add more complications...
11//      qval = sqrt((x-xCtr)^2+(y-yCtr)^2)                      // use if the pixels are square
12//      qval = sqrt((x-xCtr)^2+(y-yCtr)^2/4)                    // use for LR panels where the y pixels are half the size of x
13//      qval = sqrt((x-xCtr)^2/4+(y-yCtr)^2)                    // use for TB panels where the y pixels are twice the size of x
14
15//
16//
17// WaveStats/Q data_FL
18// coef_peakPix2d[2] = V_max
19// coef_peakPix2d[0] = 1
20// then set the xy center to something somewhat close (could do this based on FL, etc.)
21// then set the peak position somewhat close (how to do this??)
22//
23// FuncFitMD/H="11000111100"/NTHR=0 BroadPeak_Pix2D coef_PeakPix2D  data_FT /D
24//
25
26//
27// the calculation is done as for the QxQy data set:
28// three waves XYZ, then converted to a matrix
29//
30Proc V_PlotBroadPeak_Pix2D(xDim,yDim)                                           
31        Variable xDim=48, yDim=128
32        Prompt xDim "Enter X dimension: "
33        Prompt yDim "Enter Y dimension: "
34               
35        Make/O/D coef_PeakPix2D = {0, 3, 100, 0.5, 25, 2, 10, 8, 8, -10, 64}
36//      Make/O/D tmp_Pix2D =    {10, 3, 10, 0.3, 10, 2, 0.1}            //without the pixel ctrs                                       
37        make/o/t parameters_PeakPix2D = {"Porod Scale", "Porod Exponent","Lorentzian Scale","Lor Screening Length","Peak position","Lorentzian Exponent","Bgd [1/cm]", "xPix size (mm)","yPix size (mm)", "xCtr (pixels)", "yCtr (pixels)"}             
38        Edit parameters_PeakPix2D,coef_PeakPix2D                               
39       
40        // generate the triplet representation
41        Make/O/D/N=(xDim*yDim) xwave_PeakPix2D, ywave_PeakPix2D,zwave_PeakPix2D
42        V_FillPixTriplet(xwave_PeakPix2D, ywave_PeakPix2D,zwave_PeakPix2D,xDim,yDim)
43       
44       
45        Variable/G g_PeakPix2D=0
46        g_PeakPix2D := V_BroadPeak_Pix2D(coef_PeakPix2D,zwave_PeakPix2D,xwave_PeakPix2D,ywave_PeakPix2D)        //AAO 2D calculation
47       
48        Display ywave_PeakPix2D vs xwave_PeakPix2D
49        modifygraph log=0
50        ModifyGraph mode=3,marker=16,zColor(ywave_PeakPix2D)={zwave_PeakPix2D,*,*,YellowHot,0}
51        ModifyGraph standoff=0
52        ModifyGraph width={Plan,1,bottom,left}
53        ModifyGraph lowTrip=0.001
54        Label bottom "X pixels"
55        Label left "Y pixels"
56        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
57       
58        // generate the matrix representation
59        Make/O/D/N=(xDim,yDim) PeakPix2D_mat            // use the point scaling of the matrix (=pixels)
60        Duplicate/O $"PeakPix2D_mat",$"PeakPix2D_lin"           //keep a linear-scaled version of the data
61        // _mat is for display, _lin is the real calculation
62
63        // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation
64        Variable/G g_PeakPix2Dmat=0
65        g_PeakPix2Dmat := V_UpdatePix2Mat(xwave_PeakPix2D,ywave_PeakPix2D,zwave_PeakPix2D,PeakPix2D_lin,PeakPix2D_mat)
66       
67       
68        SetDataFolder root:
69//      AddModelToStrings("BroadPeak_Pix2D","coef_PeakPix2D","parameters_PeakPix2D","PeakPix2D")
70End
71
72
73//
74// this sets the x and y waves of the triplet to be the pixel numbers
75//
76//
77// -- this will need to be changed if I want to fit based on real-space mm
78//
79Function V_FillPixTriplet(xwave_PeakPix2D, ywave_PeakPix2D,zwave_PeakPix2D,xDim,yDim)
80        Wave xwave_PeakPix2D, ywave_PeakPix2D,zwave_PeakPix2D
81        Variable xDim,yDim
82               
83        Variable ii,jj 
84        ii=0
85        jj=0
86        do
87                do
88                        xwave_PeakPix2D[ii*yDim+ jj] = ii
89                        ywave_PeakPix2D[ii*yDim+ jj] = jj
90                        jj+=1
91                while(jj<yDim)
92                jj=0
93                ii+=1
94        while(ii<xDim)
95        return(0)
96End
97
98Function V_UpdatePix2Mat(Qx,Qy,inten,linMat,mat)
99        Wave Qx,Qy,inten,linMat,mat
100       
101        Variable xrows=DimSize(mat, 0 )                 
102        Variable yrows=DimSize(mat, 1 )                 
103               
104        String folderStr=GetWavesDataFolder(Qx,1)
105        NVAR/Z gIsLogScale=$(folderStr+"gIsLogScale")
106       
107//      linMat = inten[q*xrows+p]
108        linMat = inten[p*yrows+q]
109       
110        if(gIsLogScale)
111                mat = log(linMat)
112        else
113                mat = linMat
114        endif
115       
116        return(0)
117End
118
119//
120//  Fit function that is actually a wrapper to dispatch the calculation to N threads
121//
122// nthreads is 1 or an even number, typically 2
123// it doesn't matter if npt is odd. In this case, fractional point numbers are passed
124// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points
125// and the points "2.5" and "3.5" evaluate correctly as 2 and 3
126//
127Function V_BroadPeak_Pix2D(cw,zw,xw,yw) : FitFunc
128        Wave cw,zw,xw,yw
129       
130#if exists("BroadPeak_Pix2DX")                  //to hide the function if XOP not installed
131        MultiThread zw = BroadPeak_Pix2DX(cw,xw,yw)
132#else
133        MultiThread zw = V_I_BroadPeak_Pix2D(cw,xw,yw)
134#endif
135       
136        return(0)
137End
138
139//threaded version of the function
140ThreadSafe Function V_BroadPeak_Pix2D_T(cw,zw,xw,yw,p1,p2)
141        WAVE cw,zw,xw,yw
142        Variable p1,p2
143       
144#if exists("BroadPeak_Pix2DX")                  //to hide the function if XOP not installed
145        zw[p1,p2]= BroadPeak_Pix2DX(cw,xw,yw)
146#else
147        zw[p1,p2]= V_I_BroadPeak_Pix2D(cw,xw,yw)
148#endif
149
150        return 0
151End
152
153//// technically, I'm passing a coefficient wave that's TOO LONG to the XOP
154//// BEWARE
155//ThreadSafe Function I_BroadPeak_Pix2D(w,x,y)
156//      Wave w
157//      Variable x,y
158//     
159//      Variable retVal,qval
160////    WAVE tmp = root:tmp_Pix2D
161////    tmp = w[p]
162//     
163//      Variable xCtr,yCtr
164//      xCtr = w[7]
165//      yCtr = w[8]
166//     
167////    qval = sqrt((x-xCtr)^2+(y-yCtr)^2)                      // use if the pixels are square
168//      qval = sqrt((x-xCtr)^2+(y-yCtr)^2/4)                    // use for LR panels where the y pixels are half the size of x
169////    qval = sqrt((x-xCtr)^2/4+(y-yCtr)^2)                    // use for TB panels where the y pixels are twice the size of x
170//
171//      if(qval< 0.001)
172//              retval = w[6]                   //bgd
173//      else           
174//              retval = BroadPeakX(w,qval)             //pass only what BroadPeak needs
175////            retval = BroadPeakX(tmp,qval)           //pass only what BroadPeak needs
176//      endif
177//             
178//      return(retVal)
179//End
180
181
182
183//
184// This is not an XOP, but is correct in what it is passing and speed seems to be just fine.
185//
186ThreadSafe Function V_I_BroadPeak_Pix2D(w,xw,yw)
187//ThreadSafe Function fBroadPeak_Pix2D(w,xw,yw)
188        Wave w
189        Variable xw,yw
190
191        // variables are:                                                       
192        //[0] Porod term scaling
193        //[1] Porod exponent
194        //[2] Lorentzian term scaling
195        //[3] Lorentzian screening length [A]
196        //[4] peak location [1/A]
197        //[5] Lorentzian exponent
198        //[6] background
199       
200        //[7] xSize
201        //[8] ySize
202       
203        //[9] xCtr
204        //[10] yCtr
205       
206        Variable aa,nn,cc,LL,Qzero,mm,bgd,xctr,yctr,xSize,ySize
207        aa = w[0]
208        nn = w[1]
209        cc = w[2]
210        LL=w[3]
211        Qzero=w[4]
212        mm=w[5]
213        bgd=w[6]
214        xSize = w[7]
215        ySize = w[8]
216        xCtr = w[9]
217        yCtr = w[10]
218       
219//      local variables
220        Variable inten, qval,ratio
221
222//      x is the q-value for the calculation
223//      qval = sqrt(xw^2+yw^2)
224
225// ASSUMPTION
226//
227// base the scaling on the xSize
228
229// *** NOTE ***
230// "qval" here is NOT q
231// qval is a real space distance in the units of PIXELS. Not mm, not q, PIXELS
232// Don't put any meaning in the fitted values, it's simply a functional shape
233
234        ratio = (xSize/ySize)^2
235        if(ratio > 1)
236        //      qval = sqrt((xw-xCtr)^2+(yw-yCtr)^2)                    // use if the pixels are square
237                qval = sqrt((xw-xCtr)^2+((yw-yCtr)^2)/ratio)                    // use for LR panels where the y pixels are half the size of x 
238        else
239                qval = sqrt(((xw-xCtr)^2)*ratio+(yw-yCtr)^2)                    // use for TB panels where the y pixels are twice the size of x
240        endif
241
242        if(qval<.001)
243                return(bgd)
244        endif   
245       
246//      do the calculation and return the function value
247       
248        inten = aa/(qval)^nn + cc/(1 + (abs(qval-Qzero)*LL)^mm) + bgd
249
250        Return (inten)
251
252
253End
254
255
256
257//non-threaded version of the function, necessary for the smearing calculation
258// -- the smearing calculation can only calculate (nord) points at a time.
259//
260ThreadSafe Function V_BroadPeak_Pix2D_noThread(cw,zw,xw,yw)
261        WAVE cw,zw, xw,yw
262       
263#if exists("BroadPeak_Pix2DX")                  //to hide the function if XOP not installed
264        zw = BroadPeak_Pix2DX(cw,xw,yw)
265#else
266        zw = V_I_BroadPeak_Pix2D(cw,xw,yw)
267#endif
268
269        return 0
270End
271
272
273
274
275
276
277
278
279
280
281
282
283
Note: See TracBrowser for help on using the repository browser.