source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/Models_2D/Ellipsoid2D.ipf @ 202

Last change on this file since 202 was 202, checked in by srkline, 15 years ago

Re-wrapped the DANSE XOP calls to pass a zero background so that all of the averages are correct. The background value is added in after the XOP call. Ideally the XOP should be changed to do this internally, but rather than waiting, we'll proceed this path.

File size: 4.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.0
3
4//
5// !!! FOR THE ELLIPSOID, THE ANGLE THETA IS DEFINED FROM ????
6//
7// The plotting macro sets up TWO dependencies
8// - one for the triplet calculation
9// - one for a matrix to display, a copy of the triplet
10//
11// For display, there are two copies of the matrix. One matrix is linear, and is a copy of the
12// triplet (which is ALWAYS linear). The other matrix is toggled log/lin for display
13// in the same way the 2D SANS data matrix is handled.
14//
15
16///  REQUIRES DANSE XOP for 2D FUNCTIONS
17
18//
19// the calculation is done as for the QxQy data set:
20// three waves XYZ, then converted to a matrix
21//
22Proc PlotEllipsoid2D(str)                                               
23        String str
24        Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4)
25       
26        SetDataFolder $("root:"+str)
27       
28        // Setup parameter table for model function
29//      make/O/T/N=12 parameters_Ellip2D
30//      Make/O/D/N=12 coef_Ellip2D
31        make/O/T/N=11 parameters_Ellip2D
32        Make/O/D/N=11 coef_Ellip2D
33       
34        coef_Ellip2D[0] = 1.0
35        coef_Ellip2D[1] = 20.0
36        coef_Ellip2D[2] = 60.0
37        coef_Ellip2D[3] = 1.0e-6
38        coef_Ellip2D[4] = 0.0
39        coef_Ellip2D[5] = 1.57
40        coef_Ellip2D[6] = 0.0
41        coef_Ellip2D[7] = 0.0
42        coef_Ellip2D[8] = 0.0
43        coef_Ellip2D[9] = 0.0
44        coef_Ellip2D[10] = 0.0
45        // hard-wire the number of integration points
46//      coef_Ellip2D[11] = 10
47       
48        parameters_Ellip2D[0] = "Scale"
49        parameters_Ellip2D[1] = "Radius_a"
50        parameters_Ellip2D[2] = "Radius_b (rotation axis)"
51        parameters_Ellip2D[3] = "Contrast"
52        parameters_Ellip2D[4] = "Background"
53        parameters_Ellip2D[5] = "Axis Theta"
54        parameters_Ellip2D[6] = "Axis Phi"
55        parameters_Ellip2D[7] = "Sigma of polydisp in R_a [Angstrom]"
56        parameters_Ellip2D[8] = "Sigma of polydisp in R_b [Angstrom]"
57        parameters_Ellip2D[9] = "Sigma of polydisp in Theta [rad]"
58        parameters_Ellip2D[10] = "Sigma of polydisp in Phi [rad]"
59       
60//      parameters_Ellip2D[11] = "Num of polydisp points"
61
62       
63        Edit parameters_Ellip2D,coef_Ellip2D                                   
64       
65        // generate the triplet representation
66        Duplicate/O $(str+"_qx") xwave_Ellip2D
67        Duplicate/O $(str+"_qy") ywave_Ellip2D,zwave_Ellip2D                   
68               
69        Variable/G gs_Ellip2D=0
70        gs_Ellip2D := Ellipsoid2D(coef_Ellip2D,zwave_Ellip2D,xwave_Ellip2D,ywave_Ellip2D)       //AAO 2D calculation
71       
72        Display ywave_Ellip2D vs xwave_Ellip2D
73        modifygraph log=0
74        ModifyGraph mode=3,marker=16,zColor(ywave_Ellip2D)={zwave_Ellip2D,*,*,YellowHot,0}
75        ModifyGraph standoff=0
76        ModifyGraph width={Aspect,1}
77        ModifyGraph lowTrip=0.001
78        Label bottom "qx (A\\S-1\\M)"
79        Label left "qy (A\\S-1\\M)"
80        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
81       
82        // generate the matrix representation
83        ConvertQxQy2Mat(xwave_Ellip2D,ywave_Ellip2D,zwave_Ellip2D,"Ellip2D_mat")
84        Duplicate/O $"Ellip2D_mat",$"Ellip2D_lin"               //keep a linear-scaled version of the data
85        // _mat is for display, _lin is the real calculation
86
87        // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation
88        Variable/G gs_Ellip2Dmat=0
89        gs_Ellip2Dmat := UpdateQxQy2Mat(xwave_Ellip2D,ywave_Ellip2D,zwave_Ellip2D,Ellip2D_lin,Ellip2D_mat)
90       
91       
92        SetDataFolder root:
93        AddModelToStrings("Ellipsoid2D","coef_Ellip2D","Ellip2D")
94End
95
96//AAO version, uses XOP if available
97// simply calls the original single point calculation with
98// a wave assignment (this will behave nicely if given point ranges)
99//
100// NON-THREADED IMPLEMENTATION
101//
102//Function Ellipsoid2D(cw,zw,xw,yw) : FitFunc
103//      Wave cw,zw,xw,yw
104//     
105//#if exists("EllipsoidModel_D")
106//
107//      Make/O/D/N=12 Ellip2D_tmp
108//      Ellip2D_tmp = cw
109//      Ellip2D_tmp[11] = 25
110//     
111//      zw = EllipsoidModel_D(Ellip2D_tmp,xw,yw)
112//     
113////    zw = EllipsoidModel_D(cw,xw,yw)
114//#else
115//      Abort "You do not have the SANS Analysis XOP installed"
116//#endif
117//      return(0)
118//End
119//
120
121//threaded version of the function
122ThreadSafe Function Ellipsoid2D_T(cw,zw,xw,yw,p1,p2)
123        WAVE cw,zw,xw,yw
124        Variable p1,p2
125       
126#if exists("EllipsoidModel_D")                  //to hide the function if XOP not installed
127
128        Make/O/D/N=12 Ellip2D_tmp
129        Ellip2D_tmp = cw
130        Ellip2D_tmp[11] = 25
131        Ellip2D_tmp[4] = 0              //pass in a zero background and add it in later
132       
133        zw[p1,p2]= EllipsoidModel_D(Ellip2D_tmp,xw,yw) + cw[4]
134       
135#endif
136
137        return 0
138End
139
140//
141//  Fit function that is actually a wrapper to dispatch the calculation to N threads
142//
143// nthreads is 1 or an even number, typically 2
144// it doesn't matter if npt is odd. In this case, fractional point numbers are passed
145// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points
146// and the points "2.5" and "3.5" evaluate correctly as 2 and 3
147//
148Function Ellipsoid2D(cw,zw,xw,yw) : FitFunc
149        Wave cw,zw,xw,yw
150       
151        Variable npt=numpnts(yw)
152        Variable i,nthreads= ThreadProcessorCount
153        variable mt= ThreadGroupCreate(nthreads)
154
155        for(i=0;i<nthreads;i+=1)
156        //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1)
157                ThreadStart mt,i,Ellipsoid2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1))
158        endfor
159
160        do
161                variable tgs= ThreadGroupWait(mt,100)
162        while( tgs != 0 )
163
164        variable dummy= ThreadGroupRelease(mt)
165       
166        return(0)
167End
Note: See TracBrowser for help on using the repository browser.