1 #pragma rtGlobals=3// Use modern global access method and strict wave access. 2 #pragma IgorVersion = 6.1 3 #pragma ModuleName = PearlScientaPreprocess 39 variable Lcrop = NumberByKey(
"Lcrop", param,
"=",
";")
40 variable Lsize = NumberByKey(
"Lsize", param,
"=",
";")
41 variable Hcrop = NumberByKey(
"Hcrop", param,
"=",
";")
42 variable Hsize = NumberByKey(
"Hsize", param,
"=",
";")
43 variable Cpos = NumberByKey(
"Cpos", param,
"=",
";")
44 variable Csize = NumberByKey(
"Csize", param,
"=",
";")
46 prompt Lcrop,
"Lower cropping region" 47 prompt Hcrop,
"Upper cropping region" 48 prompt Lsize,
"Lower background region" 49 prompt Hsize,
"Upper background region" 50 prompt Cpos,
"Center position" 51 prompt Csize,
"Center integration region" 53 doprompt
"int_linbg_reduction Parameters", lcrop, hcrop, lsize, hsize, cpos, csize
55 param = ReplaceNumberByKey(
"Lcrop", param, Lcrop,
"=",
";")
56 param = ReplaceNumberByKey(
"Lsize", param, Lsize,
"=",
";")
57 param = ReplaceNumberByKey(
"Hcrop", param, Hcrop,
"=",
";")
58 param = ReplaceNumberByKey(
"Hsize", param, Hsize,
"=",
";")
59 param = ReplaceNumberByKey(
"Cpos", param, Cpos,
"=",
";")
60 param = ReplaceNumberByKey(
"Csize", param, Csize,
"=",
";")
69 svar /z global_params = root:packages:pearl_explorer:s_reduction_params
70 if (svar_exists(global_params))
94 make /n=(nc) /free positions
101 for (ic = 0; ic < nc; ic += 1)
102 sc = num2char(char2num(
"A") + ic)
103 wave /z wc = CsrWaveRef($sc, win)
104 info = CsrInfo($sc, win)
105 tracename = StringByKey(
"TNAME", info,
":",
";")
106 if (waveexists(wc) && (wavedims(wc) == 2))
107 if (!waveexists(image))
109 imagename = tracename
111 if (cmpstr(tracename, imagename) == 0)
112 positions[np] = pcsr($sc, win)
118 np = floor(np / 2) * 2
119 redimension /n=(np) positions
120 sort positions, positions
122 positions = p >= np / 2 ? positions + 1 : positions
123 positions = positions / dimsize(image, 0)
126 variable ip2 = np / 2
127 variable ip1 = ip2 - 1
128 variable Cpos = (positions[ip1] + positions[ip2]) / 2
129 variable Csize = positions[ip2] - positions[ip1]
131 Cpos = (positions[ip1] + positions[ip2]) / 2
132 Csize = positions[ip2] - positions[ip1]
145 Lsize = positions[ip1]
146 Hsize = 1 - positions[ip2]
149 Lsize = Cpos - Csize / 2
150 Hsize = 1 - (Cpos + Csize / 2)
159 Lcrop = positions[ip1]
160 Hcrop = 1 - positions[ip2]
166 Lsize = max(Lsize - Lcrop, 0)
167 Hsize = max(Hsize - Hcrop, 0)
170 param = ReplaceNumberByKey(
"Lcrop", param, Lcrop,
"=",
";")
171 param = ReplaceNumberByKey(
"Lsize", param, Lsize,
"=",
";")
172 param = ReplaceNumberByKey(
"Hcrop", param, Hcrop,
"=",
";")
173 param = ReplaceNumberByKey(
"Hsize", param, Hsize,
"=",
";")
174 param = ReplaceNumberByKey(
"Cpos", param, Cpos,
"=",
";")
175 param = ReplaceNumberByKey(
"Csize", param, Csize,
"=",
";")
188 string data1_name =
"test_data1" 189 string data2_name =
"test_data2" 190 duplicate /o image, $data1_name, $data2_name
191 wave w_data1 = $data1_name
192 wave w_data2 = $data2_name
226 variable nx = dimsize(source, 0)
227 variable ny = dimsize(source, 1)
230 variable lcrop = NumberByKey(
"Lcrop", param,
"=",
";")
231 variable lsize = NumberByKey(
"Lsize", param,
"=",
";")
232 variable hcrop = NumberByKey(
"Hcrop", param,
"=",
";")
233 variable hsize = NumberByKey(
"Hsize", param,
"=",
";")
234 variable cpos = NumberByKey(
"Cpos", param,
"=",
";")
235 variable csize = NumberByKey(
"Csize", param,
"=",
";")
239 if (numtype(lcrop) != 0)
242 if (numtype(lsize) != 0)
245 if (numtype(hcrop) != 0)
248 if (numtype(hsize) != 0)
251 if (numtype(Cpos) != 0)
254 if (numtype(Csize) != 0)
258 variable lpos = lcrop + lsize / 2
259 variable hpos = 1 - (hcrop + hsize / 2)
267 duplicate /free dest1, lbg, hbg
269 p0 = round(lcrop * nx)
270 p1 = round((lcrop + lsize) * nx)
276 p0 = round((1 - hcrop - hsize) * nx)
277 p1 = round((1 - hcrop) * nx)
283 p0 = round((cpos - csize/2) * nx)
284 p1 = round((cpos + csize/2) * nx)
290 variable scale = (cpos - lpos) / (hpos - lpos)
292 dest1 -= scale * (hbg - lbg) + lbg
293 dest2 = sqrt(dest2 + scale^2 * (hbg + lbg))
305 param = ReplaceStringByKey(
"branch", param, num2str(branch),
"=",
";")
313 string pkpos_name =
"saf_pkpos_" + s_branch
314 string pkwid_name =
"saf_pkwid_" + s_branch
315 duplicate /o image, $pkpos_name, $pkwid_name
316 wave w_pkpos = $pkpos_name
317 wave w_pkwid = $pkwid_name
319 shockley_anglefit(image, w_pkpos, w_pkwid, param)
325 variable branch = NumberByKey(
"branch", param,
"=",
";")
327 prompt branch,
"Branch (-1 or +1)" 329 doprompt
"Shockley_anglefit_reduction Parameters", branch
331 param = ReplaceNumberByKey(
"branch", param, branch,
"=",
";")
352 variable nx = dimsize(source, 0)
353 variable ny = dimsize(source, 1)
356 variable branch = NumberByKey(
"branch", param,
"=",
";")
359 if (numtype(branch) != 0)
387 duplicate /free dest1, center
388 q0 = round((y0 - dimoffset(source, 1)) / dimdelta(source, 1))
389 q1 = round((y1 - dimoffset(source, 1)) / dimdelta(source, 1))
391 wavestats /q/m=1 center
392 p0 = round((v_maxloc - dimoffset(source, 0)) / dimdelta(source, 0))
393 p1 = round((v_maxloc + 0.4 - dimoffset(source, 0)) / dimdelta(source, 0))
396 make /n=(ny)/d/free profile
397 setscale /p x dimoffset(source,1), dimdelta(source,1), waveunits(source,1), profile
400 for (pp = p0; pp <= p1; pp += 1)
401 profile = source[pp][p]
402 curvefit /Q /NTHR=1 /W=2 gauss profile(y0,y1)
404 dest1[pp] = w_coef[2]
405 dest2[pp] = w_coef[3]
413 variable Lcrop = NumberByKey(
"Lcrop", param,
"=",
";")
414 variable Lsize = NumberByKey(
"Lsize", param,
"=",
";")
415 variable Hcrop = NumberByKey(
"Hcrop", param,
"=",
";")
416 variable Hsize = NumberByKey(
"Hsize", param,
"=",
";")
417 variable Cpos = NumberByKey(
"Cpos", param,
"=",
";")
418 variable Csize = NumberByKey(
"Csize", param,
"=",
";")
420 prompt Lcrop,
"Lower cropping region" 421 prompt Hcrop,
"Upper cropping region" 422 prompt Lsize,
"Lower background region" 423 prompt Hsize,
"Upper background region" 424 prompt Cpos,
"Center position" 425 prompt Csize,
"Center integration region" 427 doprompt
"int_quadbg_reduction Parameters", lcrop, hcrop, lsize, hsize, cpos, csize
429 param = ReplaceNumberByKey(
"Lcrop", param, Lcrop,
"=",
";")
430 param = ReplaceNumberByKey(
"Lsize", param, Lsize,
"=",
";")
431 param = ReplaceNumberByKey(
"Hcrop", param, Hcrop,
"=",
";")
432 param = ReplaceNumberByKey(
"Hsize", param, Hsize,
"=",
";")
433 param = ReplaceNumberByKey(
"Cpos", param, Cpos,
"=",
";")
434 param = ReplaceNumberByKey(
"Csize", param, Csize,
"=",
";")
448 string data1_name =
"test_data1" 449 string data2_name =
"test_data2" 450 duplicate /o image, $data1_name, $data2_name
451 wave w_data1 = $data1_name
452 wave w_data2 = $data2_name
475 variable nx = dimsize(source, 0)
476 variable ny = dimsize(source, 1)
479 variable lcrop = NumberByKey(
"Lcrop", param,
"=",
";")
480 variable lsize = NumberByKey(
"Lsize", param,
"=",
";")
481 variable hcrop = NumberByKey(
"Hcrop", param,
"=",
";")
482 variable hsize = NumberByKey(
"Hsize", param,
"=",
";")
483 variable cpos = NumberByKey(
"Cpos", param,
"=",
";")
484 variable csize = NumberByKey(
"Csize", param,
"=",
";")
488 if (numtype(lcrop) != 0)
491 if (numtype(lsize) != 0)
494 if (numtype(hcrop) != 0)
497 if (numtype(hsize) != 0)
500 if (numtype(Cpos) != 0)
503 if (numtype(Csize) != 0)
508 variable pcl = round(lcrop * nx)
509 variable pch = round((1 - hcrop) * nx)
511 variable pfl = round((lcrop + lsize) * nx)
512 variable pfh = round((1 - hcrop - hsize) * nx)
514 variable pil = round((cpos - csize/2) * nx)
515 variable pih = round((cpos + csize/2) * nx)
521 make /n=(nx) /d /free profile, mask, fit
522 setscale /p x dimoffset(source,0), dimdelta(source,0), waveunits(source,0), profile, mask, fit
523 mask = ((p >= pcl) && (p < pfl)) || ((p >= pfh) && (p < pch))
527 variable xil = x2pnt(profile, pil)
528 variable xih = x2pnt(profile, pih)
530 make /n=3 /free /d w_coef
531 for (qq = 0; qq < ny; qq += 1)
532 profile = source[p][qq]
533 curvefit /Q /NTHR=1 /W=2 poly 3, kwCWave=w_coef, profile /M=mask
534 fit = poly(w_coef, x)
535 sp = sum(profile, xil, xih)
536 sf = sum(fit, xil, xih)
548 return w[0] * (x^2 - w[1]^2)
555 if (!waveexists(params))
558 redimension /n=12/d params
560 variable h = wavemax(data) - wavemin(data)
595 make /free /n=4 /d w_int
598 variable pk1 = gauss1d(w_int, x)
600 variable pk2 = gauss1d(w_int, x)
602 variable pk3 = gauss1d(w_int, x)
603 w_int[0,2] = w[9 + p]
605 variable bg = poly(w_int, x)
607 return bg + pk1 + pk2 + pk3
615 if (!waveexists(params))
618 redimension /n=15 /d params
620 variable wmax = wavemax(data)
621 variable wmin = wavemin(data)
634 params[12] = (wmax - wmin) / dimdelta(data,1) / dimsize(data,1)
638 string h =
"0000000000000" 680 make /free /n=4 /d w_int
685 w_int[2,] = w[p0 + p - 2]
686 variable pk1 = gauss1d(w_int, a)
689 w_int[1,] = w[p0 + p - 1]
690 variable pk2 = gauss1d(w_int, a)
693 w_int[1,] = w[p0 + p - 1]
694 variable pk3 = gauss1d(w_int, a)
697 w_int[0,2] = w[p0 + p]
699 variable base = poly(w_int, a)
702 w_int[0,3] = w[p0 + p]
703 variable bg = poly(w_int, e)
705 return bg * (base + pk1 + pk2 + pk3)
719 variable Lcrop = NumberByKey(
"Lcrop", param,
"=",
";")
720 variable Lsize = NumberByKey(
"Lsize", param,
"=",
";")
721 variable Hcrop = NumberByKey(
"Hcrop", param,
"=",
";")
722 variable Hsize = NumberByKey(
"Hsize", param,
"=",
";")
723 variable Cpos = NumberByKey(
"Cpos", param,
"=",
";")
724 variable Csize = NumberByKey(
"Csize", param,
"=",
";")
726 prompt Lcrop,
"Lower cropping region" 727 prompt Hcrop,
"Upper cropping region" 728 prompt Lsize,
"Lower background region" 729 prompt Hsize,
"Upper background region" 730 prompt Cpos,
"Center position" 731 prompt Csize,
"Center integration region" 733 doprompt
"redim_linbg_reduction Parameters", lcrop, hcrop, lsize, hsize, cpos, csize
735 param = ReplaceNumberByKey(
"Lcrop", param, Lcrop,
"=",
";")
736 param = ReplaceNumberByKey(
"Lsize", param, Lsize,
"=",
";")
737 param = ReplaceNumberByKey(
"Hcrop", param, Hcrop,
"=",
";")
738 param = ReplaceNumberByKey(
"Hsize", param, Hsize,
"=",
";")
739 param = ReplaceNumberByKey(
"Cpos", param, Cpos,
"=",
";")
740 param = ReplaceNumberByKey(
"Csize", param, Csize,
"=",
";")
792 variable nx = dimsize(source, 0)
793 variable ny = dimsize(source, 1)
795 duplicate /free source, source_redim
796 redimension /n=(nx * ny) source_redim
798 redimension /n=(nx, ny) source_redim
814 param = ReplaceNumberByKey(
"rngl", param, -inf,
"=",
";")
815 param = ReplaceNumberByKey(
"rngh", param, inf,
"=",
";")
816 param = ReplaceNumberByKey(
"pos1", param, 113.70,
"=",
";")
817 param = ReplaceNumberByKey(
"wid1", param, 1.46,
"=",
";")
818 param = ReplaceNumberByKey(
"pos2", param, 126.53,
"=",
";")
819 param = ReplaceNumberByKey(
"wid2", param, 1.63,
"=",
";")
820 param = ReplaceNumberByKey(
"ybox", param, 1,
"=",
";")
821 param = ReplaceStringByKey(
"return", param,
"amp1",
"=",
";")
837 variable rngl = NumberByKey(
"rngl", param,
"=",
";")
838 variable rngh = NumberByKey(
"rngh", param,
"=",
";")
839 variable pos1 = NumberByKey(
"pos1", param,
"=",
";")
840 variable wid1 = NumberByKey(
"wid1", param,
"=",
";")
841 variable pos2 = NumberByKey(
"pos2", param,
"=",
";")
842 variable wid2 = NumberByKey(
"wid2", param,
"=",
";")
843 variable ybox = NumberByKey(
"ybox", param,
"=",
";")
844 string retpar = StringByKey(
"return", param,
"=",
";")
846 prompt rngl,
"range low" 847 prompt rngh,
"range high" 848 prompt pos1,
"position 1" 849 prompt wid1,
"width 1" 850 prompt pos2,
"position 2" 851 prompt wid2,
"width 2" 852 prompt ybox,
"ybox (1 or 3)" 853 prompt retpar,
"return", popup
"amp1;amp2;" 855 doprompt
"gauss2_reduction reduction parameters", rngl, rngh, pos1, wid1, pos2, wid2, ybox, retpar
857 param = ReplaceNumberByKey(
"rngl", param, rngl,
"=",
";")
858 param = ReplaceNumberByKey(
"rngh", param, rngh,
"=",
";")
859 param = ReplaceNumberByKey(
"pos1", param, pos1,
"=",
";")
860 param = ReplaceNumberByKey(
"wid1", param, wid1,
"=",
";")
861 param = ReplaceNumberByKey(
"pos2", param, pos2,
"=",
";")
862 param = ReplaceNumberByKey(
"wid2", param, wid2,
"=",
";")
863 param = ReplaceStringByKey(
"return", param, retpar,
"=",
";")
864 param = ReplaceNumberByKey(
"ybox", param, ybox,
"=",
";")
908 variable nx = dimsize(source, 0)
909 variable ny = dimsize(source, 1)
918 variable rngl = NumberByKey(
"rngl", param,
"=",
";")
919 variable rngh = NumberByKey(
"rngh", param,
"=",
";")
920 variable pos1 = NumberByKey(
"pos1", param,
"=",
";")
921 variable wid1 = NumberByKey(
"wid1", param,
"=",
";")
922 variable pos2 = NumberByKey(
"pos2", param,
"=",
";")
923 variable wid2 = NumberByKey(
"wid2", param,
"=",
";")
924 variable ybox = NumberByKey(
"ybox", param,
"=",
";")
925 string retpar = StringByKey(
"return", param,
"=",
";")
928 if (cmpstr(retpar,
"amp2") == 0)
937 duplicate /free xprof, xprof_sig
938 make /free /d /n=8 w_coef, W_sigma
939 w_coef[0] = {1, pos1, wid1, 1, pos2, wid2, 0, 0}
941 variable pl = max(x2pnt(xprof, rngl), 0)
942 variable ph = min(x2pnt(xprof, rngh), numpnts(xprof) - 1)
948 make /free /n=(4,8) cmat
959 variable p1 = numpnts(dest1) - 1
964 p0 += ceil((ybox - 1) / 2)
965 p1 -= ceil((ybox - 1) / 2)
967 variable V_FitNumIters
969 for (pp = p0; pp <= p1; pp += 1)
970 xprof = source[p][pp]
972 xprof += source[p][pp-1] + source[p][pp+1]
974 xprof_sig = max(sqrt(xprof), 1)
978 wmin = wavemin(xprof)
979 wmax = wavemax(xprof)
980 w_coef[0] = wmax - wmin
981 w_coef[3] = w_coef[0]
984 FuncFit /H=
"01101100" /Q /NTHR=1 /N /W=2 DblGaussLinBG w_coef xprof[pl,ph] /C={cmat, cvec} /I=1 /W=xprof_sig[pl,ph]
987 if (V_FitNumIters < 40)
988 dest1[pp] = max(w_coef[idestcoef], 0)
989 dest2[pp] = max(w_sigma[idestcoef], 0)
993 dest1 *= w_coef[idestcoef+2] * sqrt(pi)
994 dest2 *= w_coef[idestcoef+2] * sqrt(pi)
wave fit_scienta_ang_transm(wave data, wave params)
variable test_int_linbg(wave image)
threadsafe variable Shockley_anglefit(wave source, wave dest1, wave dest2, string *param)
variable prompt_gauss2_reduction(string *param)
prompt for the gauss2_reduction parameters
threadsafe variable redim_linbg_reduction(wave source, wave dest1, wave dest2, string *param)
linear background reduction function for incorrectly dimensioned scienta image
variable scienta_poly_bg(wave w, variable e, variable a)
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.
wave fit_scienta_poly_bg(wave data, wave params, variable bgterms)
variable prompt_Shockley_anglefit(string *param)
threadsafe variable adh5_setup_profile(wave image, wave profile, variable dim)
set up a one-dimensional wave for a line profile based on a 2D original wave.
variable prompt_int_quadbg_reduction(string *param)
threadsafe variable scienta_ang_transm(wave w, variable x)
threadsafe variable int_quadbg_reduction(wave source, wave dest1, wave dest2, string *param)
threadsafe variable gauss2_reduction(wave source, wave dest1, wave dest2, string *param)
fit horizontal cuts of an image with two gaussian peaks on a linear background
variable test_shockley_anglefit(wave image, variable branch)
threadsafe variable int_linbg_reduction(wave source, wave dest1, wave dest2, string *param)
variable scienta_norm(wave w, variable x)
variable prompt_redim_linbg_reduction(string *param)
parameter dialog for the redim_linbg_reduction() function
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.
variable prompt_int_linbg_reduction(string *param)
variable test_int_quadbg(wave image)
string csr_int_linbg_reduction(string win)
string capture_int_linbg_cursors()
variable test_gauss2_reduction(wave image)
apply the gauss2_reduction function to a single image