PEARL Procedures rev-distro-2.1.1-1-gf419e92-dirty Igor procedures for the analysis of PEARL data

pearl-area-profiles.ipf
Go to the documentation of this file.
1 #pragma rtGlobals=3 // Use modern global access method and strict wave access.
2 #pragma IgorVersion = 6.1
3 #pragma ModuleName = PearlAreaProfiles
4 #pragma version = 1.05
5
19
25
54 threadsafe function /wave ad_extract_rod(dataset, x1, x2, y1, y2, z1, z2, destname, [noavg, sdev, pscale])
55 wave dataset
56 variable x1, x2, y1, y2, z1, z2
57 string destname
58 variable noavg
59 variable sdev
60 variable pscale
61
62 if (wavedims(dataset) != 3)
63 return $""
64 endif
65 if (ParamIsDefault(noavg))
66 noavg = 0
67 endif
68 if (ParamIsDefault(sdev))
69 sdev = 0
70 endif
71 if (ParamIsDefault(pscale))
72 pscale = 0
73 endif
74
75 variable p1, p2, q1, q2, r1, r2
76 if (pscale)
77 p1 = x1
78 p2 = x2
79 q1 = y1
80 q2 = y2
81 r1 = z1
82 r2 = z2
83 else
84 p1 = round((x1 - DimOffset(dataset, 0)) / DimDelta(dataset, 0))
85 p2 = round((x2 - DimOffset(dataset, 0)) / DimDelta(dataset, 0))
86 q1 = round((y1 - DimOffset(dataset, 1)) / DimDelta(dataset, 1))
87 q2 = round((y2 - DimOffset(dataset, 1)) / DimDelta(dataset, 1))
88 r1 = round((z1 - DimOffset(dataset, 2)) / DimDelta(dataset, 2))
89 r2 = round((z2 - DimOffset(dataset, 2)) / DimDelta(dataset, 2))
90 endif
91
92 if ((numtype(p1) == 2) || (numtype(p2) == 2))
93 return ad_extract_rod_x(dataset, min(q1, q2), max(q1, q2), min(r1, r2), max(r1, r2), destname, noavg=noavg, sdev=sdev)
94 elseif ((numtype(q1) == 2) || (numtype(q2) == 2))
95 return ad_extract_rod_y(dataset, min(p1, p2), max(p1, p2), min(r1, r2), max(r1, r2), destname, noavg=noavg, sdev=sdev)
96 elseif ((numtype(r1) == 2) || (numtype(r2) == 2))
97 return ad_extract_rod_z(dataset, min(p1, p2), max(p1, p2), min(q1, q2), max(q1, q2), destname, noavg=noavg, sdev=sdev)
98 else
99 return $""
100 endif
101 end
102
106 threadsafe function /wave ad_extract_rod_x(dataset, q1, q2, r1, r2, destname, [noavg, sdev])
107 wave dataset
108 variable q1, q2, r1, r2
109 // -inf < q1 < q2 < +inf, -inf < r1 < r2 < +inf
110 string destname
111 variable noavg
112 variable sdev
113
114 if (ParamIsDefault(noavg))
115 noavg = 0
116 endif
117 if (ParamIsDefault(sdev))
118 sdev = 0
119 endif
120 variable avg = !noavg && !sdev
121
122 q1 = max(q1, 0)
123 q2 = min(q2, dimsize(dataset, 1) - 1)
124 r1 = max(r1, 0)
125 r2 = min(r2, dimsize(dataset, 2) - 1)
126
127 if (strlen(destname) > 0)
128 duplicate /r=[][q1,q1][r1,r1]/o dataset, $destname
129 wave w_dest = $destname
130 else
131 duplicate /r=[][q1,q1][r1,r1] /free dataset, w_dest
132 endif
133 redimension /n=(dimsize(w_dest, 0)) w_dest
134 setscale /p x dimoffset(dataset, 0), dimdelta(dataset, 0), waveunits(dataset, 0), w_dest
135
136 w_dest = 0
137 variable qq, rr
138 variable nn = 0
139 for (qq = q1; qq <= q2; qq += 1)
140 for (rr = r1; rr <= r2; rr += 1)
141 w_dest += dataset[p][qq][rr]
142 nn += 1
143 endfor
144 endfor
145
146 if (sdev)
147 duplicate /free w_dest, w_squares
148 w_squares = 0
149 for (qq = q1; qq <= q2; qq += 1)
150 for (rr = r1; rr <= r2; rr += 1)
151 w_squares += dataset[p][qq][rr]^2
152 endfor
153 endfor
154 endif
155
156 if (avg)
157 w_dest /= nn
158 elseif (sdev)
159 w_dest = sqrt( (w_squares - w_dest^2 / nn) / (nn - 1) )
160 endif
161
162 return w_dest
163 end
164
168 threadsafe function /wave ad_extract_rod_y(dataset, p1, p2, r1, r2, destname, [noavg, sdev])
169 wave dataset
170 variable p1, p2, r1, r2
171 // 0 <= p1 < p2 < dimsize(0), 0 <= r1 < r2 < dimsize(2)
172 string destname
173 variable noavg
174 variable sdev
175
176 if (ParamIsDefault(noavg))
177 noavg = 0
178 endif
179 if (ParamIsDefault(sdev))
180 sdev = 0
181 endif
182 variable avg = !noavg && !sdev
183
184 p1 = max(p1, 0)
185 p2 = min(p2, dimsize(dataset, 0) - 1)
186 r1 = max(r1, 0)
187 r2 = min(r2, dimsize(dataset, 2) - 1)
188
189 if (strlen(destname) > 0)
190 duplicate /r=[p1,p1][][r1,r1]/o dataset, $destname
191 wave w_dest = $destname
192 else
193 duplicate /r=[p1,p1][][r1,r1] /free dataset, w_dest
194 endif
195 redimension /n=(dimsize(w_dest, 1)) w_dest
196 setscale /p x dimoffset(dataset, 1), dimdelta(dataset, 1), waveunits(dataset, 1), w_dest
197
198 w_dest = 0
199 variable pp, rr
200 variable nn = 0
201 for (pp = p1; pp <= p2; pp += 1)
202 for (rr = r1; rr <= r2; rr += 1)
203 w_dest += dataset[pp][p][rr]
204 nn += 1
205 endfor
206 endfor
207
208 if (sdev)
209 duplicate /free w_dest, w_squares
210 w_squares = 0
211 for (pp = p1; pp <= p2; pp += 1)
212 for (rr = r1; rr <= r2; rr += 1)
213 w_squares += dataset[pp][p][rr]^2
214 nn += 1
215 endfor
216 endfor
217 endif
218
219 if (avg)
220 w_dest /= nn
221 elseif (sdev)
222 w_dest = sqrt( (w_squares - w_dest^2 / nn) / (nn - 1) )
223 endif
224
225 return w_dest
226 end
227
231 threadsafe function /wave ad_extract_rod_z(dataset, p1, p2, q1, q2, destname, [noavg, sdev])
232 wave dataset
233 variable p1, p2, q1, q2
234 // 0 <= p1 < p2 < dimsize(0), 0 <= q1 < q2 < dimsize(1)
235 string destname
236 variable noavg
237 variable sdev
238
239 if (ParamIsDefault(noavg))
240 noavg = 0
241 endif
242 if (ParamIsDefault(sdev))
243 sdev = 0
244 endif
245 variable avg = !noavg && !sdev
246
247 p1 = max(p1, 0)
248 p2 = min(p2, dimsize(dataset, 0) - 1)
249 q1 = max(q1, 0)
250 q2 = min(q2, dimsize(dataset, 1) - 1)
251
252 if (strlen(destname) > 0)
253 duplicate /r=[p1,p1][q1,q1][]/o dataset, $destname
254 wave w_dest = $destname
255 else
256 duplicate /r=[p1,p1][q1,q1][] /free dataset, w_dest
257 endif
258 redimension /n=(dimsize(w_dest, 2)) w_dest
259 setscale /p x dimoffset(dataset, 2), dimdelta(dataset, 2), waveunits(dataset, 2), w_dest
260
261 w_dest = 0
262 variable pp, qq
263 variable nn = 0
264 for (pp = p1; pp <= p2; pp += 1)
265 for (qq = q1; qq <= q2; qq += 1)
266 w_dest += dataset[pp][qq][p]
267 nn += 1
268 endfor
269 endfor
270
271 if (sdev)
272 duplicate /free w_dest, w_squares
273 w_squares = 0
274 for (pp = p1; pp <= p2; pp += 1)
275 for (qq = q1; qq <= q2; qq += 1)
276 w_squares += dataset[pp][qq][p]^2
277 nn += 1
278 endfor
279 endfor
280 endif
281
282 if (avg)
283 w_dest /= nn
284 elseif (sdev)
285 w_dest = sqrt( (w_squares - w_dest^2 / nn) / (nn - 1) )
286 endif
287
288 return w_dest
289 end
290
313 threadsafe function /wave ad_extract_slab(dataset, x1, x2, y1, y2, z1, z2, destname, [noavg, pscale])
314 wave dataset
315 variable x1, x2, y1, y2, z1, z2
316 string destname
317 variable noavg
318 variable pscale
319
320 if (wavedims(dataset) != 3)
321 return $""
322 endif
323 if (ParamIsDefault(noavg))
324 noavg = 0
325 endif
326 if (ParamIsDefault(pscale))
327 pscale = 0
328 endif
329
330 variable p1, p2, q1, q2, r1, r2
331 if (pscale)
332 p1 = x1
333 p2 = x2
334 q1 = y1
335 q2 = y2
336 r1 = z1
337 r2 = z2
338 else
339 p1 = round((x1 - DimOffset(dataset, 0)) / DimDelta(dataset, 0))
340 p2 = round((x2 - DimOffset(dataset, 0)) / DimDelta(dataset, 0))
341 q1 = round((y1 - DimOffset(dataset, 1)) / DimDelta(dataset, 1))
342 q2 = round((y2 - DimOffset(dataset, 1)) / DimDelta(dataset, 1))
343 r1 = round((z1 - DimOffset(dataset, 2)) / DimDelta(dataset, 2))
344 r2 = round((z2 - DimOffset(dataset, 2)) / DimDelta(dataset, 2))
345 endif
346
347 if ((numtype(p1) < 2) && (numtype(p2) < 2))
348 return ad_extract_slab_x(dataset, min(p1, p2), max(p1, p2), destname, noavg=noavg)
349 elseif ((numtype(q1) < 2) && (numtype(q2) < 2))
350 return ad_extract_slab_y(dataset, min(q1, q2), max(q1, q2), destname, noavg=noavg)
351 elseif ((numtype(r1) < 2) && (numtype(r2) < 2))
352 return ad_extract_slab_z(dataset, min(r1, r2), max(r1, r2), destname, noavg=noavg)
353 else
354 return $""
355 endif
356 end
357
358 threadsafe function /wave ad_extract_slab_x(dataset, p1, p2, destname, [noavg])
359 wave dataset
360 variable p1, p2
361 // x coordinate range (point scaling) to be integrated
362 // -inf <= p1 < p2 <= +inf
363 string destname // name of destination wave. to be created in current data folder. overrides existing.
364 // if empty, the function returns a free wave
365 variable noavg // zero or default = average, non-zero = sum
366
367 if (ParamIsDefault(noavg))
368 noavg = 0
369 endif
370 p1 = max(p1, 0)
371 p2 = min(p2, dimsize(dataset, 0) - 1)
372
373 if (strlen(destname) > 0)
374 duplicate /r=[p1,p1][][]/o dataset, $destname
375 wave w_dest = $destname
376 else
377 duplicate /r=[p1,p1][][] /free dataset, w_dest
378 endif
379 redimension /n=(dimsize(w_dest, 1), dimsize(w_dest, 2)) w_dest
380 setscale /p x dimoffset(dataset, 1), dimdelta(dataset, 1), waveunits(dataset, 1), w_dest
381 setscale /p y dimoffset(dataset, 2), dimdelta(dataset, 2), waveunits(dataset, 2), w_dest
382
383 w_dest = 0
384 variable pp
385 variable nn = 0
386 for (pp = p1; pp <= p2; pp += 1)
387 w_dest += dataset[pp][p][q]
388 nn += 1
389 endfor
390
391 if (noavg == 0)
392 w_dest /= nn
393 endif
394
395 return w_dest
396 end
397
398 threadsafe function /wave ad_extract_slab_y(dataset, q1, q2, destname, [noavg])
399 wave dataset
400 variable q1, q2
401 // y coordinate range (point scaling) to be integrated
402 // -inf <= q1 < q2 <= +inf
403 string destname // name of destination wave. to be created in current data folder. overrides existing.
404 // if empty, the function returns a free wave
405 variable noavg // zero or default = average, non-zero = sum
406
407 if (ParamIsDefault(noavg))
408 noavg = 0
409 endif
410 q1 = max(q1, 0)
411 q2 = min(q2, dimsize(dataset, 1) - 1)
412
413 if (strlen(destname) > 0)
414 duplicate /r=[][q1,q1][]/o dataset, $destname
415 wave w_dest = $destname
416 else
417 duplicate /r=[][q1,q1][] /free dataset, w_dest
418 endif
419 redimension /n=(dimsize(w_dest, 0), dimsize(w_dest, 2)) w_dest
420 setscale /p x dimoffset(dataset, 0), dimdelta(dataset, 0), waveunits(dataset, 0), w_dest
421 setscale /p y dimoffset(dataset, 2), dimdelta(dataset, 2), waveunits(dataset, 2), w_dest
422
423 w_dest = 0
424 variable qq
425 variable nn = 0
426 for (qq = q1; qq <= q2; qq += 1)
427 w_dest += dataset[p][qq][q]
428 nn += 1
429 endfor
430
431 if (noavg == 0)
432 w_dest /= nn
433 endif
434
435 return w_dest
436 end
437
438 threadsafe function /wave ad_extract_slab_z(dataset, r1, r2, destname, [noavg])
439 wave dataset
440 variable r1, r2
441 // z coordinate range (point scaling) to be integrated
442 // -inf <= r1 < r2 <= +inf
443 string destname // name of destination wave. to be created in current data folder. overrides existing.
444 // if empty, the function returns a free wave
445 variable noavg // zero or default = average, non-zero = sum
446
447 if (ParamIsDefault(noavg))
448 noavg = 0
449 endif
450 r1 = max(r1, 0)
451 r2 = min(r2, dimsize(dataset, 2) - 1)
452
453 if (strlen(destname) > 0)
454 duplicate /r=[][][r1,r1]/o dataset, $destname
455 wave w_dest = $destname
456 else
457 duplicate /r=[][][r1,r1] /free dataset, w_dest
458 endif
459 redimension /n=(dimsize(w_dest, 0), dimsize(w_dest, 1)) w_dest
460 setscale /p x dimoffset(dataset, 0), dimdelta(dataset, 0), waveunits(dataset, 0), w_dest
461 setscale /p y dimoffset(dataset, 1), dimdelta(dataset, 1), waveunits(dataset, 1), w_dest
462
463 w_dest = 0
464 variable rr
465 variable nn = 0
466 for (rr = r1; rr <= r2; rr += 1)
467 w_dest += dataset[p][q][rr]
468 nn += 1
469 endfor
470
471 if (noavg == 0)
472 w_dest /= nn
473 endif
474
475 return w_dest
476 end
477
480 threadsafe function /wave ad_profile_x(dataset, q1, q2, destname, [noavg])
481 wave dataset
482 variable q1, q2 // -inf <= q1 < q2 <= +inf
483 // deprecated: q2 = -1 stands for dimsize(0) - 1
484 string destname // name of destination wave. to be created in current data folder. overrides existing.
485 // if empty, the function returns a free wave
486 variable noavg // zero or default = average, non-zero = sum
487
488 if (ParamIsDefault(noavg))
489 noavg = 0
490 endif
491
492 if (strlen(destname) > 0)
493 duplicate /r=[0,0][] /o dataset, $destname
494 wave w_dest = $destname
495 else
496 duplicate /r=[0,0][] /free dataset, w_dest
497 endif
498
499 return ad_profile_x_w(dataset, q1, q2, w_dest, noavg=noavg)
500 end
501
504 threadsafe function /wave ad_profile_x_w(dataset, q1, q2, destwave, [noavg])
505 wave dataset
506 variable q1, q2 // -inf <= q1 < q2 <= +inf
507 // deprecated: q2 = -1 stands for dimsize(0) - 1
508 wave destwave // existing destination wave
509 variable noavg // zero or default = average, non-zero = sum
510
511 if (ParamIsDefault(noavg))
512 noavg = 0
513 endif
514
515 redimension /n=(dimsize(dataset, 0)) destwave
516 setscale /p x dimoffset(dataset, 0), dimdelta(dataset, 0), waveunits(dataset, 0), destwave
517 setscale d 0, 0, waveunits(dataset, -1), destwave
518
519 q1 = max(q1, 0)
520 if (q2 < 0)
521 q2 = inf
522 endif
523 q2 = min(q2, dimsize(dataset, 1) - 1)
524
525 destwave = 0
526 variable qq
527 variable nn = 0
528 for (qq = q1; qq <= q2; qq += 1)
529 destwave += dataset[p][qq]
530 nn += 1
531 endfor
532
533 if (noavg == 0)
534 destwave /= nn
535 endif
536
537 return destwave
538 end
539
542 threadsafe function /wave ad_profile_y(dataset, p1, p2, destname, [noavg])
543 wave dataset
544 variable p1, p2 // -inf <= p1 < p2 < inf
545 // deprecated: p2 = -1 stands for dimsize(0) - 1
546 string destname // name of destination wave. to be created in current data folder. overrides existing.
547 // if empty, the function returns a free wave
548 variable noavg // zero or default = average, non-zero = sum
549
550 if (ParamIsDefault(noavg))
551 noavg = 0
552 endif
553
554 if (strlen(destname) > 0)
555 duplicate /r=[][0,0] /o dataset, $destname
556 wave w_dest = $destname
557 else
558 duplicate /r=[][0,0] /free dataset, w_dest
559 endif
560 MatrixTranspose w_dest
561
562 return ad_profile_y_w(dataset, p1, p2, w_dest, noavg=noavg)
563 end
564
567 threadsafe function /wave ad_profile_y_w(dataset, p1, p2, destwave, [noavg])
568 wave dataset
569 variable p1, p2 // -inf <= p1 < p2 < inf
570 // deprecated: p2 = -1 stands for dimsize(0) - 1
571 wave destwave // existing destination wave
572 variable noavg // zero or default = average, non-zero = sum
573
574 if (ParamIsDefault(noavg))
575 noavg = 0
576 endif
577
578 redimension /n=(dimsize(dataset, 1)) destwave
579 setscale /p x dimoffset(dataset, 1), dimdelta(dataset, 1), waveunits(dataset, 1), destwave
580 setscale d 0, 0, waveunits(dataset, -1), destwave
581
582 p1 = max(p1, 0)
583 if (p2 < 0)
584 p2 = inf
585 endif
586 p2 = min(p2, dimsize(dataset, 0) - 1)
587
588 destwave = 0
589 variable pp
590 variable nn = 0
591 for (pp = p1; pp <= p2; pp += 1)
592 destwave += dataset[pp][p]
593 nn += 1
594 endfor
595
596 if (noavg == 0)
597 destwave /= nn
598 endif
599
600 return destwave
601 end
602
603 threadsafe function calc_y_profile_mins(image)
604 // experimental
605 wave image
606
607 wave yminlocs = ad_profile_x(image, 0, 0, "ymins", noavg=1)
608 variable nx = dimsize(image, 0)
609 variable ix
610 for (ix = 0; ix < nx; ix += 1)
611 wave profile = ad_profile_y(image, ix, ix, "", noavg=1)
612 wavestats /q/m=1 profile
613 yminlocs[ix] = v_minloc
614 endfor
615 end
616
621 function ad_collect_multiscan_y(dataset, positions, destwave, [noavg])
622 wave dataset
623 wave positions
624 wave destwave
625 variable noavg
626
627 variable tol = (wavemax(positions) - wavemin(positions)) / numpnts(positions) / 100
628
629 duplicate /free positions, positions_sorted
630 sort positions_sorted, positions_sorted
631 duplicate /free positions_sorted, positions_diff
632 differentiate /p /meth=2 positions_sorted /d=positions_diff
633 positions_diff[0] = 1
634 extract /free positions_sorted, positions_unique, positions_diff > tol
635 variable n_unique = numpnts(positions_unique)
636 redimension /n=(dimsize(dataset, 0), n_unique) destwave
637
638 variable i
639 variable nx, ny
640 for (i = 0; i < n_unique; i += 1)
641 extract /free dataset, data_extract, abs(positions[q] - positions_unique[i]) < tol
642 nx = dimsize(dataset, 0)
643 ny = dimsize(data_extract, 0) / nx
644 redimension /n=(nx, ny) data_extract
645 wave profile = ad_profile_x(data_extract, -inf, inf, "", noavg=noavg)
646 destwave[][i] = profile[p]
647 endfor
648 end
ad_extract_slab_x
threadsafe wave ad_extract_slab_x(wave dataset, variable p1, variable p2, string destname, variable noavg=defaultValue)
Definition: pearl-area-profiles.ipf:358
ad_extract_rod_x
threadsafe wave ad_extract_rod_x(wave dataset, variable q1, variable q2, variable r1, variable r2, string destname, variable noavg=defaultValue, variable sdev=defaultValue)
1D cut through 3D dataset along X dimension.
Definition: pearl-area-profiles.ipf:106
ad_profile_y
threadsafe wave ad_profile_y(wave dataset, variable p1, variable p2, string destname, variable noavg=defaultValue)
1D cut through 2D dataset along Y dimension, new destination wave.
Definition: pearl-area-profiles.ipf:542
ad_profile_x_w
threadsafe wave ad_profile_x_w(wave dataset, variable q1, variable q2, wave destwave, variable noavg=defaultValue)
1D cut through 2D dataset along X dimension, existing destination wave.
Definition: pearl-area-profiles.ipf:504
ad_extract_slab_z
threadsafe wave ad_extract_slab_z(wave dataset, variable r1, variable r2, string destname, variable noavg=defaultValue)
Definition: pearl-area-profiles.ipf:438
ad_collect_multiscan_y
variable ad_collect_multiscan_y(wave dataset, wave positions, wave destwave, variable noavg=defaultValue)
collect profiles from a multi-scan.
Definition: pearl-area-profiles.ipf:621
ad_extract_slab_y
threadsafe wave ad_extract_slab_y(wave dataset, variable q1, variable q2, string destname, variable noavg=defaultValue)
Definition: pearl-area-profiles.ipf:398
ad_extract_rod_z
threadsafe wave ad_extract_rod_z(wave dataset, variable p1, variable p2, variable q1, variable q2, string destname, variable noavg=defaultValue, variable sdev=defaultValue)
1D cut through 3D dataset along Z dimension.
Definition: pearl-area-profiles.ipf:231
ad_profile_y_w
threadsafe wave ad_profile_y_w(wave dataset, variable p1, variable p2, wave destwave, variable noavg=defaultValue)
1D cut through 2D dataset along X dimension, existing destination wave.
Definition: pearl-area-profiles.ipf:567
ad_extract_rod_y
threadsafe wave ad_extract_rod_y(wave dataset, variable p1, variable p2, variable r1, variable r2, string destname, variable noavg=defaultValue, variable sdev=defaultValue)
1D cut through 3D dataset along Y dimension.
Definition: pearl-area-profiles.ipf:168
calc_y_profile_mins
threadsafe variable calc_y_profile_mins(wave image)
Definition: pearl-area-profiles.ipf:603
ad_profile_x
threadsafe wave ad_profile_x(wave dataset, variable q1, variable q2, string destname, variable noavg=defaultValue)
1D cut through 2D dataset along X dimension, new destination wave.
Definition: pearl-area-profiles.ipf:480
ad_extract_rod
threadsafe wave ad_extract_rod(wave dataset, variable x1, variable x2, variable y1, variable y2, variable z1, variable z2, string destname, variable noavg=defaultValue, variable sdev=defaultValue, variable pscale=defaultValue)
1D cut through 3D dataset, integrate in normal dimensions
Definition: pearl-area-profiles.ipf:54
ad_extract_slab
threadsafe wave ad_extract_slab(wave dataset, variable x1, variable x2, variable y1, variable y2, variable z1, variable z2, string destname, variable noavg=defaultValue, variable pscale=defaultValue)
2D cut through 3D dataset, integrate in normal dimension
Definition: pearl-area-profiles.ipf:313