PEARL Procedures  rev-distro-1.4.0-0-g80a01f2
Igor procedures for the analysis of PEARL data
pearl-scienta-preprocess.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 = PearlScientaPreprocess
4 #pragma version = 1.02
5 
6 // $Id$
7 // author: matthias.muntwiler@psi.ch
8 // Copyright (c) 2013-14 Paul Scherrer Institut
9 
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 // http://www.apache.org/licenses/LICENSE-2.0
14 
29 
34 
35 variable prompt_int_linbg_reduction(string* param){
36  string &param
37 
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, "=", ";")
44 
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"
51 
52  doprompt "int_linbg_reduction Parameters", lcrop, hcrop, lsize, hsize, cpos, csize
53  if (v_flag == 0)
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, "=", ";")
60  endif
61 
62  return v_flag
63 };
64 
66  // this function is for testing only, until we implement a proper interface
67  string param = csr_int_linbg_reduction("")
68  svar /z global_params = root:packages:pearl_explorer:s_reduction_params
69  if (svar_exists(global_params))
70  global_params = param
71  endif
72  return param
73 };
74 
75 string csr_int_linbg_reduction(string win){
76  // PRELIMINARY - function arguments may change
77 
78  // sets reduction parameters from cursors in a graph.
79  // an even number of cursors (2 or more) must be set on the image.
80  // cursor names and order do not matter,
81  // except that the alphabetically first cursor which is attached to an image selects the image.
82  // the cursors mark the following positions, from innermost to outermost pair:
83  // 1) low and high limits of peak region.
84  // 2) peak-side boundary of lower and upper background region.
85  // 3) lower and upper cropping region.
86 
87  string win
88 
89  // read all cursor positions
90  variable ic
91  string sc
92  variable nc = 10
93  make /n=(nc) /free positions
94  variable np = 0
95  wave /z image = $""
96  string imagename = ""
97  string tracename = ""
98  string info
99 
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))
107  wave image = wc
108  imagename = tracename
109  endif
110  if (cmpstr(tracename, imagename) == 0)
111  positions[np] = pcsr($sc, win)
112  np += 1
113  endif
114  endif
115  endfor
116 
117  np = floor(np / 2) * 2// ignore odd cursor
118  redimension /n=(np) positions
119  sort positions, positions
120  // shift upper positions by one so that the rightmost pixel becomes 1.0
121  positions = p >= np / 2 ? positions + 1 : positions
122  positions = positions / dimsize(image, 0)
123 
124  // map innermost cursor pair to peak center and size
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]
129  if (ip1 >= 0)
130  Cpos = (positions[ip1] + positions[ip2]) / 2
131  Csize = positions[ip2] - positions[ip1]
132  else
133  // default: a small region in the center
134  Cpos = 0.5
135  Csize = 0.2
136  endif
137 
138  // background region
139  ip1 -= 1
140  ip2 += 1
141  variable Lsize
142  variable Hsize
143  if (ip1 >= 0)
144  Lsize = positions[ip1]
145  Hsize = 1 - positions[ip2]
146  else
147  // default: everything outside the peak region
148  Lsize = Cpos - Csize / 2
149  Hsize = 1 - (Cpos + Csize / 2)
150  endif
151 
152  // crop region
153  ip1 -= 1
154  ip2 += 1
155  variable Lcrop
156  variable Hcrop
157  if (ip1 >= 0)
158  Lcrop = positions[ip1]
159  Hcrop = 1 - positions[ip2]
160  else
161  // default: dead corners of the EW4000 at PEARL
162  Lcrop = 0.11
163  Hcrop = 0.11
164  endif
165  Lsize = max(Lsize - Lcrop, 0)
166  Hsize = max(Hsize - Hcrop, 0)
167 
168  string param = ""
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, "=", ";")
175 
176  return param
177 };
178 
179 variable test_int_linbg(wave image){
180  // useful for testing or manual processing
181  // since the int_linbg_reduction function cannot be called from the command line directly.
182  wave image
183 
184  string param = ""
186 
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
192 
193  int_linbg_reduction(image, w_data1, w_data2, param)
194 };
195 
196 threadsafe variable int_linbg_reduction(wave source, wave dest1, wave dest2, string* param){
197  // data reduction function for adh5_load_reduced_detector
198  // calculates the average pixel value of each angular slice
199  // in one center and two background intervals.
200  // a background value is calculated at the center position
201  // by linear interpolation from the two background values.
202  // returns the center minus linear background in dest1.
203  // returns the Poisson one-sigma error in dest2.
204  wave source// source wave
205  // Scienta detector image, energy axis along X, angle axis along Y
206  wave dest1, dest2// destination waves
207  // each wave is a one-dimensional intensity distribution
208  // the function may redimension these waves to one of the image dimensions
209  // (it must be clear to the user which dimension this is).
210  // the meaning of dest1 and dest2 is up to the particular function,
211  // e.g. dest1 could hold the mean value and dest2 the one-sigma error,
212  // or dest1 could hold the X-profile, and dest2 the Y-profile.
213  string &param// parameters in a key1=value1;key2=value2;... list
214  // all region parameters are relative to the image size (0...1)
215  // Lcrop = size of the lower cropping region
216  // Hcrop = size of the upper cropping region
217  // Lsize = size of the lower background integration region
218  // Hsize = size of the upper background integration region
219  // Cpos = center position of the of the peak integration region
220  // Csize = size of the peak integration region
221 
222  // typical values (peak centered on detector, FWHM ~ 20 % of image)
223  // Lcrop=0.11;Hcrop=0.11;Lsize=0.2;Hsize=0.2;Cpos=0.5;Csize=0.2
224 
225  variable nx = dimsize(source, 0)
226  variable ny = dimsize(source, 1)
227 
228  // read parameters
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, "=", ";")
235 
236  // validate parameters
237  // background parameters are optional, center parameter is required.
238  if (numtype(lcrop) != 0)
239  lcrop = 0
240  endif
241  if (numtype(lsize) != 0)
242  lsize = 0
243  endif
244  if (numtype(hcrop) != 0)
245  hcrop = 0
246  endif
247  if (numtype(hsize) != 0)
248  hsize = 0
249  endif
250  if (numtype(Cpos) != 0)
251  return 1// Cpos parameter missing
252  endif
253  if (numtype(Csize) != 0)
254  return 2// Csize parameter missing
255  endif
256 
257  variable lpos = lcrop + lsize / 2
258  variable hpos = 1 - (hcrop + hsize / 2)
259 
260  variable p0
261  variable p1
262 
263  adh5_setup_profile(source, dest1, 1)
264  adh5_setup_profile(source, dest2, 1)
265 
266  duplicate /free dest1, lbg, hbg
267  if (lsize > 0)
268  p0 = round(lcrop * nx)
269  p1 = round((lcrop + lsize) * nx)
270  ad_profile_y_w(source, p0, p1, lbg)
271  else
272  lbg = 0
273  endif
274  if (hsize > 0)
275  p0 = round((1 - hcrop - hsize) * nx)
276  p1 = round((1 - hcrop) * nx)
277  ad_profile_y_w(source, p0, p1, hbg)
278  else
279  hbg = 0
280  endif
281  if (csize > 0)
282  p0 = round((cpos - csize/2) * nx)
283  p1 = round((cpos + csize/2) * nx)
284  ad_profile_y_w(source, p0, p1, dest1)
285  else
286  dest1 = 0
287  endif
288 
289  variable scale = (cpos - lpos) / (hpos - lpos)
290  dest2 = dest1
291  dest1 -= scale * (hbg - lbg) + lbg
292  dest2 = sqrt(dest2 + scale^2 * (hbg + lbg))
293  return 0// return zero if successful, non-zero if an error occurs
294 };
295 
296 variable test_shockley_anglefit(wave image, variable branch){
297  // apply the Shockley_anglefit function to a single image
298  // useful for testing or manual processing
299  // since the Shockley_anglefit function cannot be called from the command line directly.
300  wave image
301  variable branch// +1 or -1
302 
303  string param = ""
304  param = ReplaceStringByKey("branch", param, num2str(branch), "=", ";")
305 
306  string s_branch
307  if (branch >= 0)
308  s_branch = "p"
309  else
310  s_branch = "n"
311  endif
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
317 
318  shockley_anglefit(image, w_pkpos, w_pkwid, param)
319 };
320 
321 variable prompt_Shockley_anglefit(string* param){
322  string &param
323 
324  variable branch = NumberByKey("branch", param, "=", ";")
325 
326  prompt branch, "Branch (-1 or +1)"
327 
328  doprompt "Shockley_anglefit_reduction Parameters", branch
329  if (v_flag == 0)
330  param = ReplaceNumberByKey("branch", param, branch, "=", ";")
331  endif
332 
333  return v_flag
334 };
335 
336 threadsafe variable Shockley_anglefit(wave source, wave dest1, wave dest2, string* param){
337  // data reduction function for adh5_load_reduced_detector
338  // specialized for analysing the Cu(111) Shockley surface state
339  // do curve fitting of one branch of the surface state
340  // the result is peak position versus energy
341  // TODO: this function contains hard-coded parameters. please generalize as necessary.
342  wave source// source wave
343  // Scienta detector image, energy axis along X, angle axis along Y
344  // the apex of the surface state must be at angle 0
345  wave dest1, dest2// destination waves
346  // dest1: peak position
347  // dest2: peak width (sigma)
348  string &param// parameters in a key1=value1;key2=value2;... list
349  // branch=-1 or +1: select negative (positive) angles for the fit interval, respectively
350 
351  variable nx = dimsize(source, 0)
352  variable ny = dimsize(source, 1)
353 
354  // read parameters
355  variable branch = NumberByKey("branch", param, "=", ";")
356 
357  // validate parameters
358  if (numtype(branch) != 0)
359  branch = +1
360  endif
361 
362  // prepare output
363  adh5_setup_profile(source, dest1, 0)
364  adh5_setup_profile(source, dest2, 0)
365  dest1 = nan
366  dest2 = nan
367 
368  // select angle range
369  // hard-coded for a particular measurement series
370  variable y0
371  variable y1
372  if (branch < 0)
373  y0 = -5
374  y1 = 0
375  else
376  y0 = 0
377  y1 = 5
378  endif
379 
380  // select energy range
381  // start at the point of highest intensity and go up 0.45 eV
382  variable p0
383  variable p1
384  variable q0
385  variable q1
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))
389  ad_profile_x_w(source, q0, q1, center)
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))
393 
394  // prepare intermediate data buffer
395  make /n=(ny)/d/free profile
396  setscale /p x dimoffset(source,1), dimdelta(source,1), waveunits(source,1), profile
397 
398  variable pp
399  for (pp = p0; pp <= p1; pp += 1)
400  profile = source[pp][p]
401  curvefit /Q /NTHR=1 /W=2 gauss profile(y0,y1)
402  wave w_coef
403  dest1[pp] = w_coef[2]
404  dest2[pp] = w_coef[3]
405  endfor
406  return 0// return zero if successful, non-zero if an error occurs
407 };
408 
409 variable prompt_int_quadbg_reduction(string* param){
410  string &param
411 
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, "=", ";")
418 
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"
425 
426  doprompt "int_quadbg_reduction Parameters", lcrop, hcrop, lsize, hsize, cpos, csize
427  if (v_flag == 0)
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, "=", ";")
434  endif
435 
436  return v_flag
437 };
438 
439 variable test_int_quadbg(wave image){
440  // useful for testing or manual processing
441  // since the int_quadbg_reduction function cannot be called from the command line directly.
442  wave image
443 
444  string param = ""
446 
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
452 
453  int_quadbg_reduction(image, w_data1, w_data2, param)
454 };
455 
456 threadsafe variable int_quadbg_reduction(wave source, wave dest1, wave dest2, string* param){
457  // data reduction function for adh5_load_reduced_detector
458  // integrates peak area minus a quadratic backgrouind
459  wave source// source wave
460  // Scienta detector image, energy axis along X, angle axis along Y
461  wave dest1, dest2// destination waves
462  string &param// parameters in a key1=value1;key2=value2;... list
463  // all region parameters are relative to the image size (0...1)
464  // Lcrop = size of the lower cropping region
465  // Hcrop = size of the upper cropping region
466  // Lsize = size of the lower background integration region
467  // Hsize = size of the upper background integration region
468  // Cpos = center position of the of the peak integration region
469  // Csize = size of the peak integration region
470 
471  // typical values (peak centered on detector, FWHM ~ 20 % of image)
472  // Lcrop=0.11;Hcrop=0.11;Lsize=0.2;Hsize=0.2;Cpos=0.5;Csize=0.2
473 
474  variable nx = dimsize(source, 0)
475  variable ny = dimsize(source, 1)
476 
477  // read parameters
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, "=", ";")
484 
485  // validate parameters
486  // background parameters are optional, center parameter is required.
487  if (numtype(lcrop) != 0)
488  lcrop = 0
489  endif
490  if (numtype(lsize) != 0)
491  lsize = 0
492  endif
493  if (numtype(hcrop) != 0)
494  hcrop = 0
495  endif
496  if (numtype(hsize) != 0)
497  hsize = 0
498  endif
499  if (numtype(Cpos) != 0)
500  return 1// Cpos parameter missing
501  endif
502  if (numtype(Csize) != 0)
503  return 2// Csize parameter missing
504  endif
505 
506  // crop boundaries
507  variable pcl = round(lcrop * nx)
508  variable pch = round((1 - hcrop) * nx)
509  // fit boundaries
510  variable pfl = round((lcrop + lsize) * nx)
511  variable pfh = round((1 - hcrop - hsize) * nx)
512  // integration boundaries
513  variable pil = round((cpos - csize/2) * nx)
514  variable pih = round((cpos + csize/2) * nx)
515 
516  adh5_setup_profile(source, dest1, 0)
517  adh5_setup_profile(source, dest2, 0)
518 
519  // prepare intermediate data buffer
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))
523 
524  variable qq
525  variable sp, sf
526  variable xil = x2pnt(profile, pil)
527  variable xih = x2pnt(profile, pih)
528 
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)
536  dest1[qq] = sp - sf
537  dest2[qq] = sqrt(sp)
538  endfor
539 
540  return 0// return zero if successful, non-zero if an error occurs
541 };
542 
543 variable scienta_norm(wave w, variable x){
544  wave w
545  variable x
546 
547  return w[0] * (x^2 - w[1]^2)
548 };
549 
550 wave fit_scienta_ang_transm(wave data, wave params){
551  wave data// measured angular distribution (1D)
552  wave /z params
553 
554  if (!waveexists(params))
555  make /n=12 /o params
556  endif
557  redimension /n=12/d params
558 
559  variable h = wavemax(data) - wavemin(data)
560  params[0] = h / 2
561  params[1] = 0
562  params[2] = 7
563  params[3] = h / 4
564  params[4] = -23
565  params[5] = 4
566  params[6] = h / 4
567  params[7] = +23
568  params[8] = 4
569  params[9] = h / 2
570  params[10] = 0
571  params[11] = -0.001
572  FuncFit /NTHR=0 /q scienta_ang_transm params data
573 
574  return params
575 };
576 
577 threadsafe variable scienta_ang_transm(wave w, variable x){
578  // parameterized angular transmission function of the analyser
579  wave w// coefficients
580  // w[0] = amplitude gauss 1
581  // w[1] = position gauss 1
582  // w[2] = width gauss 1
583  // w[3] = amplitude gauss 2
584  // w[4] = position gauss 2
585  // w[5] = width gauss 2
586  // w[6] = amplitude gauss 3
587  // w[7] = position gauss 3
588  // w[8] = width gauss 3
589  // w[9] = constant background
590  // w[10] = linear background
591  // w[11] = quadratic background
592  variable x
593 
594  make /free /n=4 /d w_int
595  w_int[0] = 0
596  w_int[1,] = w[p - 1]
597  variable pk1 = gauss1d(w_int, x)
598  w_int[1,] = w[p + 2]
599  variable pk2 = gauss1d(w_int, x)
600  w_int[1,] = w[p + 5]
601  variable pk3 = gauss1d(w_int, x)
602  w_int[0,2] = w[9 + p]
603  w_int[3] = 0
604  variable bg = poly(w_int, x)
605 
606  return bg + pk1 + pk2 + pk3
607 };
608 
609 wave fit_scienta_poly_bg(wave data, wave params, variable bgterms){
610  wave data// measured distribution (2D)
611  wave /z params// wave, will be redimensioned for the correct size
612  variable bgterms// number of terms in the polynomial background: 2, 3, or 4
613 
614  if (!waveexists(params))
615  make /n=15 /o params
616  endif
617  redimension /n=15 /d params
618 
619  variable wmax = wavemax(data)
620  variable wmin = wavemin(data)
621  params[0] = 0
622  params[1] = 7
623  params[2] = 1 / 2
624  params[3] = -23
625  params[4] = 4
626  params[5] = 1 / 2
627  params[6] = +23
628  params[7] = 4
629  params[8] = 1
630  params[9] = 0
631  params[10] = -0.001
632  params[11] = wmin
633  params[12] = (wmax - wmin) / dimdelta(data,1) / dimsize(data,1)
634  params[13] = 0
635  params[14] = 0
636 
637  string h = "0000000000000"
638  if (bgterms < 3)
639  h = h + "1"
640  else
641  h = h + "0"
642  endif
643  if (bgterms < 4)
644  h = h + "1"
645  else
646  h = h + "0"
647  endif
648  FuncFitMD /NTHR=1 /q /h=h scienta_poly_bg params data
649 
650  return params
651 };
652 
653 variable scienta_poly_bg(wave w, variable e, variable a){
654  // polynomial background with
655  // parameterized angular transmission function of the analyser
656  wave w// coefficients
657  // angular transmission, varies with a
658  // amplitude of gauss 1 = 1 constant
659  // other peak amplitudes and linear terms are relative to gauss 1
660  // w[0] = position gauss 1
661  // w[1] = width gauss 1
662  // w[2] = amplitude gauss 2, relative to gauss 1
663  // w[3] = position gauss 2
664  // w[4] = width gauss 2
665  // w[5] = amplitude gauss 3, relative to gauss 1
666  // w[6] = position gauss 3
667  // w[7] = width gauss 3
668  // w[8] = constant term
669  // w[9] = linear term
670  // w[10] = quadratic term
671  // spectral background, varies with e
672  // w[11] = constant term
673  // w[12] = linear term
674  // w[13] = quadratic term
675  // w[14] = cubic term
676  variable a// detection angle
677  variable e// electron energy
678 
679  make /free /n=4 /d w_int
680  variable p0 = 0
681 
682  w_int[0] = 0
683  w_int[1] = 1
684  w_int[2,] = w[p0 + p - 2]
685  variable pk1 = gauss1d(w_int, a)
686  p0 += 2
687 
688  w_int[1,] = w[p0 + p - 1]
689  variable pk2 = gauss1d(w_int, a)
690  p0 += 3
691 
692  w_int[1,] = w[p0 + p - 1]
693  variable pk3 = gauss1d(w_int, a)
694  p0 += 3
695 
696  w_int[0,2] = w[p0 + p]
697  w_int[3] = 0
698  variable base = poly(w_int, a)
699  p0 += 3
700 
701  w_int[0,3] = w[p0 + p]
702  variable bg = poly(w_int, e)
703 
704  return bg * (base + pk1 + pk2 + pk3)
705 };
706 
715 variable prompt_redim_linbg_reduction(string* param){
716  string &param
717 
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, "=", ";")
724 
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"
731 
732  doprompt "redim_linbg_reduction Parameters", lcrop, hcrop, lsize, hsize, cpos, csize
733  if (v_flag == 0)
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, "=", ";")
740  endif
741 
742  return v_flag
743 };
744 
786 threadsafe variable redim_linbg_reduction(wave source, wave dest1, wave dest2, string* param){
787  wave source
788  wave dest1, dest2
789  string &param
790 
791  variable nx = dimsize(source, 0)
792  variable ny = dimsize(source, 1)
793 
794  duplicate /free source, source_redim
795  redimension /n=(nx * ny) source_redim
796  nx += 1
797  redimension /n=(nx, ny) source_redim
798 
799  return int_linbg_reduction(source_redim, dest1, dest2, param)
800 };
801 
802 
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()