1 #pragma rtGlobals=3// Use modern global access method and strict wave access. 2 #pragma IgorVersion = 6.1 3 #pragma ModuleName = PearlScientaPreprocess 38 variable Lcrop = NumberByKey(
"Lcrop", param,
"=",
";")
39 variable Lsize = NumberByKey(
"Lsize", param,
"=",
";")
40 variable Hcrop = NumberByKey(
"Hcrop", param,
"=",
";")
41 variable Hsize = NumberByKey(
"Hsize", param,
"=",
";")
42 variable Cpos = NumberByKey(
"Cpos", param,
"=",
";")
43 variable Csize = NumberByKey(
"Csize", param,
"=",
";")
45 prompt Lcrop,
"Lower cropping region" 46 prompt Hcrop,
"Upper cropping region" 47 prompt Lsize,
"Lower background region" 48 prompt Hsize,
"Upper background region" 49 prompt Cpos,
"Center position" 50 prompt Csize,
"Center integration region" 52 doprompt
"int_linbg_reduction Parameters", lcrop, hcrop, lsize, hsize, cpos, csize
54 param = ReplaceNumberByKey(
"Lcrop", param, Lcrop,
"=",
";")
55 param = ReplaceNumberByKey(
"Lsize", param, Lsize,
"=",
";")
56 param = ReplaceNumberByKey(
"Hcrop", param, Hcrop,
"=",
";")
57 param = ReplaceNumberByKey(
"Hsize", param, Hsize,
"=",
";")
58 param = ReplaceNumberByKey(
"Cpos", param, Cpos,
"=",
";")
59 param = ReplaceNumberByKey(
"Csize", param, Csize,
"=",
";")
68 svar /z global_params = root:packages:pearl_explorer:s_reduction_params
69 if (svar_exists(global_params))
93 make /n=(nc) /free positions
100 for (ic = 0; ic < nc; ic += 1)
101 sc = num2char(char2num(
"A") + ic)
102 wave /z wc = CsrWaveRef($sc, win)
103 info = CsrInfo($sc, win)
104 tracename = StringByKey(
"TNAME", info,
":",
";")
105 if (waveexists(wc) && (wavedims(wc) == 2))
106 if (!waveexists(image))
108 imagename = tracename
110 if (cmpstr(tracename, imagename) == 0)
111 positions[np] = pcsr($sc, win)
117 np = floor(np / 2) * 2
118 redimension /n=(np) positions
119 sort positions, positions
121 positions = p >= np / 2 ? positions + 1 : positions
122 positions = positions / dimsize(image, 0)
125 variable ip2 = np / 2
126 variable ip1 = ip2 - 1
127 variable Cpos = (positions[ip1] + positions[ip2]) / 2
128 variable Csize = positions[ip2] - positions[ip1]
130 Cpos = (positions[ip1] + positions[ip2]) / 2
131 Csize = positions[ip2] - positions[ip1]
144 Lsize = positions[ip1]
145 Hsize = 1 - positions[ip2]
148 Lsize = Cpos - Csize / 2
149 Hsize = 1 - (Cpos + Csize / 2)
158 Lcrop = positions[ip1]
159 Hcrop = 1 - positions[ip2]
165 Lsize = max(Lsize - Lcrop, 0)
166 Hsize = max(Hsize - Hcrop, 0)
169 param = ReplaceNumberByKey(
"Lcrop", param, Lcrop,
"=",
";")
170 param = ReplaceNumberByKey(
"Lsize", param, Lsize,
"=",
";")
171 param = ReplaceNumberByKey(
"Hcrop", param, Hcrop,
"=",
";")
172 param = ReplaceNumberByKey(
"Hsize", param, Hsize,
"=",
";")
173 param = ReplaceNumberByKey(
"Cpos", param, Cpos,
"=",
";")
174 param = ReplaceNumberByKey(
"Csize", param, Csize,
"=",
";")
187 string data1_name =
"test_data1" 188 string data2_name =
"test_data2" 189 duplicate /o image, $data1_name, $data2_name
190 wave w_data1 = $data1_name
191 wave w_data2 = $data2_name
225 variable nx = dimsize(source, 0)
226 variable ny = dimsize(source, 1)
229 variable lcrop = NumberByKey(
"Lcrop", param,
"=",
";")
230 variable lsize = NumberByKey(
"Lsize", param,
"=",
";")
231 variable hcrop = NumberByKey(
"Hcrop", param,
"=",
";")
232 variable hsize = NumberByKey(
"Hsize", param,
"=",
";")
233 variable cpos = NumberByKey(
"Cpos", param,
"=",
";")
234 variable csize = NumberByKey(
"Csize", param,
"=",
";")
238 if (numtype(lcrop) != 0)
241 if (numtype(lsize) != 0)
244 if (numtype(hcrop) != 0)
247 if (numtype(hsize) != 0)
250 if (numtype(Cpos) != 0)
253 if (numtype(Csize) != 0)
257 variable lpos = lcrop + lsize / 2
258 variable hpos = 1 - (hcrop + hsize / 2)
266 duplicate /free dest1, lbg, hbg
268 p0 = round(lcrop * nx)
269 p1 = round((lcrop + lsize) * nx)
275 p0 = round((1 - hcrop - hsize) * nx)
276 p1 = round((1 - hcrop) * nx)
282 p0 = round((cpos - csize/2) * nx)
283 p1 = round((cpos + csize/2) * nx)
289 variable scale = (cpos - lpos) / (hpos - lpos)
291 dest1 -= scale * (hbg - lbg) + lbg
292 dest2 = sqrt(dest2 + scale^2 * (hbg + lbg))
304 param = ReplaceStringByKey(
"branch", param, num2str(branch),
"=",
";")
312 string pkpos_name =
"saf_pkpos_" + s_branch
313 string pkwid_name =
"saf_pkwid_" + s_branch
314 duplicate /o image, $pkpos_name, $pkwid_name
315 wave w_pkpos = $pkpos_name
316 wave w_pkwid = $pkwid_name
318 shockley_anglefit(image, w_pkpos, w_pkwid, param)
324 variable branch = NumberByKey(
"branch", param,
"=",
";")
326 prompt branch,
"Branch (-1 or +1)" 328 doprompt
"Shockley_anglefit_reduction Parameters", branch
330 param = ReplaceNumberByKey(
"branch", param, branch,
"=",
";")
351 variable nx = dimsize(source, 0)
352 variable ny = dimsize(source, 1)
355 variable branch = NumberByKey(
"branch", param,
"=",
";")
358 if (numtype(branch) != 0)
386 duplicate /free dest1, center
387 q0 = round((y0 - dimoffset(source, 1)) / dimdelta(source, 1))
388 q1 = round((y1 - dimoffset(source, 1)) / dimdelta(source, 1))
390 wavestats /q/m=1 center
391 p0 = round((v_maxloc - dimoffset(source, 0)) / dimdelta(source, 0))
392 p1 = round((v_maxloc + 0.4 - dimoffset(source, 0)) / dimdelta(source, 0))
395 make /n=(ny)/d/free profile
396 setscale /p x dimoffset(source,1), dimdelta(source,1), waveunits(source,1), profile
399 for (pp = p0; pp <= p1; pp += 1)
400 profile = source[pp][p]
401 curvefit /Q /NTHR=1 /W=2 gauss profile(y0,y1)
403 dest1[pp] = w_coef[2]
404 dest2[pp] = w_coef[3]
412 variable Lcrop = NumberByKey(
"Lcrop", param,
"=",
";")
413 variable Lsize = NumberByKey(
"Lsize", param,
"=",
";")
414 variable Hcrop = NumberByKey(
"Hcrop", param,
"=",
";")
415 variable Hsize = NumberByKey(
"Hsize", param,
"=",
";")
416 variable Cpos = NumberByKey(
"Cpos", param,
"=",
";")
417 variable Csize = NumberByKey(
"Csize", param,
"=",
";")
419 prompt Lcrop,
"Lower cropping region" 420 prompt Hcrop,
"Upper cropping region" 421 prompt Lsize,
"Lower background region" 422 prompt Hsize,
"Upper background region" 423 prompt Cpos,
"Center position" 424 prompt Csize,
"Center integration region" 426 doprompt
"int_quadbg_reduction Parameters", lcrop, hcrop, lsize, hsize, cpos, csize
428 param = ReplaceNumberByKey(
"Lcrop", param, Lcrop,
"=",
";")
429 param = ReplaceNumberByKey(
"Lsize", param, Lsize,
"=",
";")
430 param = ReplaceNumberByKey(
"Hcrop", param, Hcrop,
"=",
";")
431 param = ReplaceNumberByKey(
"Hsize", param, Hsize,
"=",
";")
432 param = ReplaceNumberByKey(
"Cpos", param, Cpos,
"=",
";")
433 param = ReplaceNumberByKey(
"Csize", param, Csize,
"=",
";")
447 string data1_name =
"test_data1" 448 string data2_name =
"test_data2" 449 duplicate /o image, $data1_name, $data2_name
450 wave w_data1 = $data1_name
451 wave w_data2 = $data2_name
474 variable nx = dimsize(source, 0)
475 variable ny = dimsize(source, 1)
478 variable lcrop = NumberByKey(
"Lcrop", param,
"=",
";")
479 variable lsize = NumberByKey(
"Lsize", param,
"=",
";")
480 variable hcrop = NumberByKey(
"Hcrop", param,
"=",
";")
481 variable hsize = NumberByKey(
"Hsize", param,
"=",
";")
482 variable cpos = NumberByKey(
"Cpos", param,
"=",
";")
483 variable csize = NumberByKey(
"Csize", param,
"=",
";")
487 if (numtype(lcrop) != 0)
490 if (numtype(lsize) != 0)
493 if (numtype(hcrop) != 0)
496 if (numtype(hsize) != 0)
499 if (numtype(Cpos) != 0)
502 if (numtype(Csize) != 0)
507 variable pcl = round(lcrop * nx)
508 variable pch = round((1 - hcrop) * nx)
510 variable pfl = round((lcrop + lsize) * nx)
511 variable pfh = round((1 - hcrop - hsize) * nx)
513 variable pil = round((cpos - csize/2) * nx)
514 variable pih = round((cpos + csize/2) * nx)
520 make /n=(nx) /d /free profile, mask, fit
521 setscale /p x dimoffset(source,0), dimdelta(source,0), waveunits(source,0), profile, mask, fit
522 mask = ((p >= pcl) && (p < pfl)) || ((p >= pfh) && (p < pch))
526 variable xil = x2pnt(profile, pil)
527 variable xih = x2pnt(profile, pih)
529 make /n=3 /free /d w_coef
530 for (qq = 0; qq < ny; qq += 1)
531 profile = source[p][qq]
532 curvefit /Q /NTHR=1 /W=2 poly 3, kwCWave=w_coef, profile /M=mask
533 fit = poly(w_coef, x)
534 sp = sum(profile, xil, xih)
535 sf = sum(fit, xil, xih)
547 return w[0] * (x^2 - w[1]^2)
554 if (!waveexists(params))
557 redimension /n=12/d params
559 variable h = wavemax(data) - wavemin(data)
594 make /free /n=4 /d w_int
597 variable pk1 = gauss1d(w_int, x)
599 variable pk2 = gauss1d(w_int, x)
601 variable pk3 = gauss1d(w_int, x)
602 w_int[0,2] = w[9 + p]
604 variable bg = poly(w_int, x)
606 return bg + pk1 + pk2 + pk3
614 if (!waveexists(params))
617 redimension /n=15 /d params
619 variable wmax = wavemax(data)
620 variable wmin = wavemin(data)
633 params[12] = (wmax - wmin) / dimdelta(data,1) / dimsize(data,1)
637 string h =
"0000000000000" 679 make /free /n=4 /d w_int
684 w_int[2,] = w[p0 + p - 2]
685 variable pk1 = gauss1d(w_int, a)
688 w_int[1,] = w[p0 + p - 1]
689 variable pk2 = gauss1d(w_int, a)
692 w_int[1,] = w[p0 + p - 1]
693 variable pk3 = gauss1d(w_int, a)
696 w_int[0,2] = w[p0 + p]
698 variable base = poly(w_int, a)
701 w_int[0,3] = w[p0 + p]
702 variable bg = poly(w_int, e)
704 return bg * (base + pk1 + pk2 + pk3)
718 variable Lcrop = NumberByKey(
"Lcrop", param,
"=",
";")
719 variable Lsize = NumberByKey(
"Lsize", param,
"=",
";")
720 variable Hcrop = NumberByKey(
"Hcrop", param,
"=",
";")
721 variable Hsize = NumberByKey(
"Hsize", param,
"=",
";")
722 variable Cpos = NumberByKey(
"Cpos", param,
"=",
";")
723 variable Csize = NumberByKey(
"Csize", param,
"=",
";")
725 prompt Lcrop,
"Lower cropping region" 726 prompt Hcrop,
"Upper cropping region" 727 prompt Lsize,
"Lower background region" 728 prompt Hsize,
"Upper background region" 729 prompt Cpos,
"Center position" 730 prompt Csize,
"Center integration region" 732 doprompt
"redim_linbg_reduction Parameters", lcrop, hcrop, lsize, hsize, cpos, csize
734 param = ReplaceNumberByKey(
"Lcrop", param, Lcrop,
"=",
";")
735 param = ReplaceNumberByKey(
"Lsize", param, Lsize,
"=",
";")
736 param = ReplaceNumberByKey(
"Hcrop", param, Hcrop,
"=",
";")
737 param = ReplaceNumberByKey(
"Hsize", param, Hsize,
"=",
";")
738 param = ReplaceNumberByKey(
"Cpos", param, Cpos,
"=",
";")
739 param = ReplaceNumberByKey(
"Csize", param, Csize,
"=",
";")
791 variable nx = dimsize(source, 0)
792 variable ny = dimsize(source, 1)
794 duplicate /free source, source_redim
795 redimension /n=(nx * ny) source_redim
797 redimension /n=(nx, ny) source_redim
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)
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)
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()