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

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

Adding three new 2D functions, the easy ones that use a Gaussian distribution of parameters.

Changed the parsing of constraints to only build a constraint wave for those parameters that are not being held. failing to do so results in an "unknown error" from curve fitting. This fix was done in both the 1D and 2D wrappers.

Changed the default mask that was two pixels all around to now mask out the beamstop for 2D data sets. 8 pixel radius is currently hard-wired in PlotUtils2D - and is generated as the fit is dispatched, automatically determining the beam center from the data set.

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