source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/Sphere_2D_v40.ipf @ 515

Last change on this file since 515 was 515, checked in by srkline, 13 years ago

A bunch of random changes:
-SASCALC - added the 2.5 cm aperture NG3/7g/polarizer back in, but made the 5 cm the default
-Some fiddling with 2D functionality to enable 2D resolution smearing. Still a work in progress
-Added two new model functions, and added them to the list.
-Changes to the wrapper for the new release to generate kw=val strings as needed for each function
and its coefficients and parameters. This behavior has been changed in the new release, so this
fix should keep old analysis experiments compatible with the new version.

File size: 6.1 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 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 PlotSphere2D(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        Make/O/D coef_sf2D = {1.,60,1e-6,6.3e-6,0.01}                                           
27        make/o/t parameters_sf2D = {"scale","Radius (A)","SLD sphere (A-2)","SLD solvent","bkgd (cm-1)"}               
28        Edit parameters_sf2D,coef_sf2D                         
29       
30        // generate the triplet representation
31        Duplicate/O $(str+"_qx") xwave_sf2D
32        Duplicate/O $(str+"_qy") ywave_sf2D,zwave_sf2D                 
33               
34        Variable/G g_sf2D=0
35        g_sf2D := Sphere2D(coef_sf2D,zwave_sf2D,xwave_sf2D,ywave_sf2D)  //AAO 2D calculation
36       
37        Display ywave_sf2D vs xwave_sf2D
38        modifygraph log=0
39        ModifyGraph mode=3,marker=16,zColor(ywave_sf2D)={zwave_sf2D,*,*,YellowHot,0}
40        ModifyGraph standoff=0
41        ModifyGraph width={Aspect,1}
42        ModifyGraph lowTrip=0.001
43        Label bottom "qx (A\\S-1\\M)"
44        Label left "qy (A\\S-1\\M)"
45        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
46       
47        // generate the matrix representation
48        ConvertQxQy2Mat(xwave_sf2D,ywave_sf2D,zwave_sf2D,"sf2D_mat")
49        Duplicate/O $"sf2D_mat",$"sf2D_lin"             //keep a linear-scaled version of the data
50        // _mat is for display, _lin is the real calculation
51
52        // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation
53        Variable/G g_sf2Dmat=0
54        g_sf2Dmat := UpdateQxQy2Mat(xwave_sf2D,ywave_sf2D,zwave_sf2D,sf2D_lin,sf2D_mat)
55       
56       
57        SetDataFolder root:
58        AddModelToStrings("Sphere2D","coef_sf2D","parameters_sf2D","sf2D")
59End
60
61// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
62Proc PlotSmearedSphere2D(str)                                                           
63        String str
64        Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4)
65       
66        // if any of the resolution waves are missing => abort
67//      if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
68//              Abort
69//      endif
70       
71        SetDataFolder $("root:"+str)
72       
73        // Setup parameter table for model function
74        Make/O/D smear_coef_sf2D = {1.,60,1e-6,6.3e-6,0.01}                                     
75        make/o/t smear_parameters_sf2D = {"scale","Radius (A)","SLD sphere (A-2)","SLD solvent (A-2)","bkgd (cm-1)"}
76        Edit smear_parameters_sf2D,smear_coef_sf2D                                     
77       
78        Duplicate/O $(str+"_qx") smeared_sf2D   //1d place for the smeared model
79        SetScale d,0,0,"1/cm",smeared_sf2D                                     
80               
81        Variable/G gs_sf2D=0
82        gs_sf2D := fSmearedSphere2D(smear_coef_sf2D,smeared_sf2D)       //this wrapper fills the STRUCT
83
84        Display $(str+"_qy") vs $(str+"_qx")
85        modifygraph log=0
86        ModifyGraph mode=3,marker=16,zColor($(str+"_qy"))={smeared_sf2D,*,*,YellowHot,0}
87        ModifyGraph standoff=0
88        ModifyGraph width={Aspect,1}
89        ModifyGraph lowTrip=0.001
90        Label bottom "qx (A\\S-1\\M)"
91        Label left "qy (A\\S-1\\M)"
92        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
93       
94        // generate the matrix representation
95        Duplicate/O $(str+"_qx"), sm_qx
96        Duplicate/O $(str+"_qy"), sm_qy         // I can't use local variables in dependencies, so I need the name (that I can't get)
97       
98        ConvertQxQy2Mat(sm_qx,sm_qy,smeared_sf2D,"sm_sf2D_mat")
99        Duplicate/O $"sm_sf2D_mat",$"sm_sf2D_lin"               //keep a linear-scaled version of the data
100        // _mat is for display, _lin is the real calculation
101
102        // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation
103        Variable/G gs_sf2Dmat=0
104        gs_sf2Dmat := UpdateQxQy2Mat(sm_qx,sm_qy,smeared_sf2D,sm_sf2D_lin,sm_sf2D_mat)
105       
106        SetDataFolder root:
107        AddModelToStrings("SmearedSphere2D","smear_coef_sf2D","smear_parameters_sf2D","sf2D")
108End
109
110
111//threaded version of the function
112ThreadSafe Function Sphere2D_T(cw,zw,xw,yw,p1,p2)
113        WAVE cw,zw,xw,yw
114        Variable p1,p2
115       
116#if exists("Sphere_2DX")                        //to hide the function if XOP not installed
117       
118        zw[p1,p2]= Sphere_2DX(cw,xw,yw)
119
120#endif
121
122        return 0
123End
124
125//
126//  Fit function that is actually a wrapper to dispatch the calculation to N threads
127//
128// nthreads is 1 or an even number, typically 2
129// it doesn't matter if npt is odd. In this case, fractional point numbers are passed
130// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points
131// and the points "2.5" and "3.5" evaluate correctly as 2 and 3
132//
133Function Sphere2D(cw,zw,xw,yw) : FitFunc
134        Wave cw,zw,xw,yw
135       
136        Variable npt=numpnts(yw)
137        Variable i,nthreads= ThreadProcessorCount
138        variable mt= ThreadGroupCreate(nthreads)
139
140//      Variable t1=StopMSTimer(-2)
141       
142        for(i=0;i<nthreads;i+=1)
143        //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1)
144                ThreadStart mt,i,Sphere2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1))
145        endfor
146
147        do
148                variable tgs= ThreadGroupWait(mt,100)
149        while( tgs != 0 )
150
151        variable dummy= ThreadGroupRelease(mt)
152       
153//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6
154       
155        return(0)
156End
157
158
159//non-threaded version of the function
160Function Sphere2D_noThread(cw,zw,xw,yw)
161        WAVE cw,zw, xw,yw
162       
163#if exists("Sphere_2DX")                        //to hide the function if XOP not installed
164       
165        zw= Sphere_2DX(cw,xw,yw)
166
167#endif
168
169        return 0
170End
171
172// I think I did this because when I do the quadrature loops I'm calling the AAO with 1-pt waves, so threading
173// would just be a slowdown
174Function SmearedSphere2D(s)
175        Struct ResSmear_2D_AAOStruct &s
176       
177        Smear_2DModel_5(Sphere2D_noThread,s)
178        return(0)
179end
180
181
182Function fSmearedSphere2D(coefW,resultW)
183        Wave coefW,resultW
184       
185        String str = getWavesDataFolder(resultW,0)
186        String DF="root:"+str+":"
187       
188        WAVE qx = $(DF+str+"_qx")
189        WAVE qy = $(DF+str+"_qy")
190        WAVE qz = $(DF+str+"_qz")
191        WAVE sigQx = $(DF+str+"_sigQx")
192        WAVE sigQy = $(DF+str+"_sigQy")
193        WAVE shad = $(DF+str+"_fs")
194       
195        STRUCT ResSmear_2D_AAOStruct s
196        WAVE s.coefW = coefW   
197        WAVE s.zw = resultW     
198        WAVE s.qx = qx
199        WAVE s.qy = qy
200        WAVE s.qz = qz
201        WAVE s.sigQx = sigQx
202        WAVE s.sigQy = sigQy
203        WAVE s.fs = shad
204       
205        Variable err
206        err = SmearedSphere2D(s)
207       
208        return (0)
209End
Note: See TracBrowser for help on using the repository browser.