-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSummaryPXP.ipf
More file actions
313 lines (277 loc) · 8.7 KB
/
SummaryPXP.ipf
File metadata and controls
313 lines (277 loc) · 8.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#pragma TextEncoding = "MacRoman"
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
// Menu item for easy execution
Menu "Macros"
"All Analysis"
End
Function AllAnalysis()
AngleLoader()
ProcessWaves()
End
//This function loads all the the waves from different Igor pxps in a directory
Function AngleLoader()
NewDataFolder/O/S root:data
String expDiskFolderName,expDataFolderName
String FileList, ThisFile, wList, ExcList, wName
Variable FileLoop, nWaves, i
NewPath/O/Q/M="Please find disk folder" ExpDiskFolder
if (V_flag!=0)
DoAlert 0, "Disk folder error"
Return -1
endif
PathInfo /S ExpDiskFolder
ExpDiskFolderName=S_path
FileList=IndexedFile(expDiskFolder,-1,".pxp")
Variable nFiles=ItemsInList(FileList)
for (FileLoop = 0; FileLoop < nFiles; FileLoop += 1)
ThisFile=StringFromList(FileLoop, FileList)
expDataFolderName=ReplaceString(".pxp",ThisFile,"") //get rid of .pxp
LoadData /L=1/O/P=expDiskFolder/T=$expDataFolderName ThisFile
SetDataFolder $expDataFolderName
wList = WaveList("*",";","")
excList = WaveList("pol*",";","") + WaveList("seg*",";","") + WaveList("e_*",";","")
wList = RemoveFromList(excList,wList)
nWaves = ItemsInList(wList)
for (i = 0; i < nWaves; i += 1)
wName = StringFromList(i,wList)
KillWaves $wName
endfor
SetDataFolder root:data:
endfor
End
Function ProcessWaves()
SetDataFolder root:data:
DFREF dfr = GetDataFolderDFR()
String folderName, wName, graphName
Variable numDataFolders = CountObjectsDFR(dfr, 4)
Make/O/T/N=(numDataFolders) fileNameWave
Make/O/N=(numDataFolders) medianWave,meanWave,sdWave
DoWindow /K histSLayout
NewLayout /N=histSLayout
DoWindow /K histELayout
NewLayout /N=histELayout
Variable i
for(i = 0; i < numDataFolders; i += 1)
folderName = GetIndexedObjNameDFR(dfr, 4, i)
fileNameWave[i] = folderName
wName = ":" + folderName + ":e_AngleWave"
Wave w0 = $wName
medianWave[i] = median(w0)
Wavestats/Q w0
meanWave[i] = V_avg
sdWave[i] = V_sdev
wName = ":" + folderName + ":seg_angle_pos_hist"
graphName = folderName + "_S_plot"
DoWindow/K $graphName
Display/N=$graphName $wName
Label bottom "Angle (¡)"
Label left "Frequency"
TextBox/C/N=text0/F=0/X=0.00/Y=0.00 folderName
SetAxis bottom 0,180
ModifyGraph mode=7
ModifyGraph hbFill=4
ModifyGraph rgb=(32768,32770,65535)
AppendLayoutObject /W=histSLayout graph $graphName
wName = ":" + folderName + ":e_angleWave_Hist"
graphName = folderName + "_E_plot"
DoWindow/K $graphName
Display/N=$graphName $wName
Label bottom "Angle (¡)"
Label left "Frequency"
TextBox/C/N=text0/F=0/X=0.00/Y=0.00 folderName
SetAxis bottom 0,180
ModifyGraph mode=7
ModifyGraph hbFill=4
ModifyGraph rgb=(65535,43688,32768)
AppendLayoutObject /W=histELayout graph $graphName
endfor
//There are 4 windows so...
Variable nRow = 2
Variable nCol = 2
Variable lIndent = 50
Variable tIndent = 50
Variable winWidth = 395
Variable winHeight = 208
Variable lArea = lIndent
Variable tArea = tIndent
Variable rArea = lIndent + winWidth
Variable bArea = tIndent + winHeight
DoWindow/K summaryTable
Edit/N=summaryTable/W=(lArea,tArea,rArea,bArea) fileNameWave,medianWave,meanWave,sdWave
lArea = lIndent
tArea = tIndent + winHeight + 23
rArea = lArea + winWidth
bArea = tArea + winHeight
DoWindow/K meanPlot
Display/N=meanPlot/W=(lArea,tArea,rArea,bArea) meanWave vs fileNameWave
ModifyGraph swapXY=1
SetAxis/A/N=1/E=1 bottom
SetAxis/A/R left
ModifyGraph rgb=(65535,43688,32768)
Label bottom "Mean Angle (¡)"
lArea = lIndent + winWidth + 1
tArea = tIndent
rArea = lArea + winWidth
bArea = tArea + winHeight
DoWindow/K sdPlot
Display/N=sdPlot/W=(lArea,tArea,rArea,bArea) sdWave vs fileNameWave
ModifyGraph swapXY=1
SetAxis/A/N=1/E=1 bottom
SetAxis/A/R left
ModifyGraph rgb=(65535,43688,32768)
Label bottom "Standard deviation (¡)"
lArea = lArea
tArea = tIndent + winHeight + 23
rArea = lArea + winWidth
bArea = tArea + winHeight
DoWindow/K medianPlot
Display/N=medianPlot/W=(lArea,tArea,rArea,bArea) medianWave vs fileNameWave
ModifyGraph swapXY=1
SetAxis/A/N=1/E=1 bottom
SetAxis/A/R left
ModifyGraph rgb=(65535,43688,32768)
Label bottom "Median Angle (¡)"
//Default Igor Window is 395 x 208 and sits at 35,45,430,253, title bar is 22
DoWindow /K summaryLayout
NewLayout /N=summaryLayout
AppendLayoutObject /W=summaryLayout graph meanPlot
AppendLayoutObject /W=summaryLayout graph sdPlot
AppendLayoutObject /W=summaryLayout graph medianPlot
// Tidy report
DoWindow /F summaryLayout
// in case these are not captured as prefs
#if igorversion()>=7
LayoutPageAction size(-1)=(595, 842), margins(-1)=(18, 18, 18, 18)
#endif
ModifyLayout units=0
ModifyLayout frame=0,trans=1
Execute /Q "Tile/A=(4,2) meanPlot,sdPlot,medianPlot"
SavePICT/E=-2 as "report.pdf"
// Tidy other report
DoWindow /F histSLayout
// in case these are not captured as prefs
#if igorversion()>=7
LayoutPageAction size(-1)=(595, 842), margins(-1)=(18, 18, 18, 18)
#endif
ModifyLayout units=0
ModifyLayout frame=0,trans=1
Execute /Q "Tile"
SavePICT/E=-2 as "histS.pdf"
// Tidy other report
DoWindow /F histELayout
// in case these are not captured as prefs
#if igorversion()>=7
LayoutPageAction size(-1)=(595, 842), margins(-1)=(18, 18, 18, 18)
#endif
ModifyLayout units=0
ModifyLayout frame=0,trans=1
Execute /Q "Tile"
SavePICT/E=-2 as "histE.pdf"
SetDataFolder root:
End
// To run this, designate which folders belong to which condition
// make desigWave with the same number of points as fileNameWave
// assign a value to each condition
// make condWave where the row number equals the condition name
Function MakeComparison()
SetDataFolder root:data
WAVE/T/Z fileNameWave
if(!WaveExists(fileNameWave))
abort "You need to run AllAnalysis() first"
endif
WAVE/Z desigWave
WAVE/Z/T condWave
if(!WaveExists(desigWave))
abort "Make desigWave and/or condWave"
endif
Variable nFolders = numpnts(fileNameWave)
Variable desigMax = wavemax(desigWave) + 1 // desigWave is 0-based
String containerName, wName, condName
Variable i,j
for(i = 0; i < desigMax; i += 1)
containerName = condWave[i] + "_angleWave"
Make/O $containerName
Wave w1 = $containerName
for(j = 0; j < nFolders; j += 1)
if(desigwave[j] == i)
wName = ":" + fileNameWave[j] + ":e_angleWave"
Wave w0 = $wName
Concatenate/NP=0 {w0}, w1
endif
endfor
endfor
CompareAlphaAll()
SetDataFolder root:
End
Function CompareAlphaAll()
String wList = WaveList("*angleWave",";","")
Variable nWaves = ItemsInList(wList)
String w0Name,w1Name
Make/O/N=(nWaves,nWaves) resultMat
Make/O/N=(nWaves) labelPos=p
Make/O/N=(nWaves)/T labelWave
Variable i,j
for(i = 0; i < nWaves; i += 1)
w0Name = StringFromList(i,wList)
Wave w0 = $w0Name
labelWave[i] = ReplaceString("_AngleWave",w0Name,"")
for(j = 0; j < nWaves; j += 1)
if(i == j)
resultMat[i][j] = 0
else
w1Name = StringFromList(j,wList)
Wave w1 = $w1Name
resultMat[i][j] = CompareAlpha(w0,w1)
endif
endfor
endfor
KillWindow/Z result
NewImage/N=result resultMat
ModifyImage/W=result resultMat ctab= {0.0001,1,RedWhiteBlue,0},minRGB=(52428,52428,52428),maxRGB=0
ModifyGraph/W=result userticks(left)={labelpos,labelWave}
ModifyGraph/W=result userticks(top)={labelpos,labelWave}
ModifyGraph/W=result tick=3,tkLblRot(left)=0,tkLblRot(top)=90,tlOffset=0
ModifyGraph/W=result margin(left)=42,margin(top)=42
String textName,labelValStr
Duplicate/O resultMat,labelVal
Variable matsize = numpnts(resultMat)
Redimension/N=(matsize) labelVal
DoWindow/F result
for(i = 0; i < matsize; i += 1)
if(labelVal[i] != 0)
textName = "text" + num2str(i)
labelValStr = num2str(Rounder(labelVal[i],2))
Tag/C/N=$textName/F=0/B=1/X=0.00/Y=0.00/L=0 resultMat, i, labelValStr
endif
endfor
End
/// @param w0c wave containing angle differences from ideal distribution (may have NaNs)
/// @param w1c wave containing angle differences from ideal distribution (may have NaNs)
Function CompareAlpha(w0c,w1c)
Wave w0c,w1c
Duplicate/O w0c, w0
Duplicate/O w1c, w1
WaveTransform zapnans w0
WaveTransform zapnans w1
Variable tempvar = 0
FindDuplicates/RN=w0ue/TOL=0.0001 w0
Variable nAngles = numpnts(w0ue)
Variable i
for(i = 0; i < nAngles; i += 1)
Extract/FREE/O w0,w2,w0 > (w0ue[i] - 0.0001) && w0 < (w0ue[i] + 0.0001)
Extract/FREE/O w1,w3,w1 > (w0ue[i] + 0.0001)
tempvar += numpnts(w2) * numpnts(w3)
endfor
tempvar /= (numpnts(w0) * numpnts(w1))
// Print tempvar
KillWaves w0ue,w0,w1
return tempvar
End
/// @param value this is the input value that requires rounding
/// @param numSigDigits number of significant digits for the rounding procedure
Function Rounder(value, numSigDigits)
Variable value, numSigDigits
String str
Sprintf str, "%.*g\r", numSigDigits, value
return str2num(str)
End