1 #pragma TextEncoding = "UTF-8"
2 #pragma rtGlobals=3 // Use modern global access method and strict wave access.
4 #pragma IgorVersion = 6.2
5 #pragma ModuleName = PearlAnglescanProcess
6 #include "pearl-vector-operations"
7 #include "pearl-polar-coordinates"
8 #include <New Polar Graphs>
110 dfref df1 = GetWavesDataFolderDFR(strip1)
111 dfref df2 = GetWavesDataFolderDFR(strip2)
112 variable ny1 = dimsize(strip1, 1)
113 variable ny2 = dimsize(strip2, 1)
115 concatenate /np=1 {strip2}, strip1
116 string modified = AddListItem(NameOfWave(strip1),
"")
122 wave /z w1 = WaveRefIndexedDFR(df1, iw)
127 wave /z w2 = df2:$(NameOfWave(w1))
128 if (WaveExists(w1) && WaveExists(w2))
129 if ((DimSize(w1, 0) == ny1) && (DimSize(w1, 1) == 0) && (DimSize(w2, 0) == ny2) && (DimSize(w2, 1) == 0))
130 concatenate /np=0 {w2}, w1
131 modified = AddListItem(NameOfWave(w1), modified,
"", Inf)
139 if ((DataFolderRefStatus(df1) != 1) || (DataFolderRefStatus(df2) != 1))
183 variable snx = dimsize(strip, 0)
184 variable sny = dimsize(strip, 1)
186 variable sq1hi = max(qlo-1, 0)
187 variable sq2lo = min(qhi+1, sny - 1)
188 variable sq2hi = dimsize(strip, 1) - 1
192 variable dny = sny - (sq2lo - sq1hi + 1)
194 variable dq1hi = sq1hi
195 variable dq2lo = dq1hi + 1
196 variable dq2hi = dny - 1
197 variable q1ofs = sq1lo - dq1lo
198 variable q2ofs = sq2lo - dq2lo
200 duplicate /free strip, strip_copy
201 redimension /n=(dnx,dny) strip
202 strip[][dq1lo,dq1hi] = strip_copy[p][q + q1ofs]
203 strip[][dq2lo,dq2hi] = strip_copy[p][q + q2ofs]
205 duplicate /free theta, theta_copy
206 redimension /n=(dny) theta
207 theta[dq1lo,dq1hi] = theta_copy[p + q1ofs]
208 theta[dq2lo,dq2hi] = theta_copy[p + q2ofs]
210 duplicate /free tilt, tilt_copy
211 redimension /n=(dny) tilt
212 tilt[dq1lo,dq1hi] = tilt_copy[p + q1ofs]
213 tilt[dq2lo,dq2hi] = tilt_copy[p + q2ofs]
215 duplicate /free phi, phi_copy
216 redimension /n=(dny) phi
217 phi[dq1lo,dq1hi] = phi_copy[p + q1ofs]
218 phi[dq2lo,dq2hi] = phi_copy[p + q2ofs]
254 variable smooth_method
255 variable smooth_factor
258 if (ParamIsDefault(smooth_method))
261 if (ParamIsDefault(smooth_factor))
262 switch(smooth_method)
270 if (ParamIsDefault(check))
278 extract /free /indx raw_dist, clean_index, numtype(raw_dist) == 0
279 duplicate /free raw_dist, dist, dist_x
280 redimension /n=(numpnts(clean_index)) dist, dist_x
281 dist = raw_dist[clean_index[p]]
282 dist_x = pnt2x(raw_dist, clean_index[p])
283 variable div = mean(dist)
287 duplicate /o raw_dist, check_dist
288 check_dist = numtype(raw_dist) == 0 ? interp(x, dist_x, dist) : nan
292 switch(smooth_method)
294 Smooth /B /E=3 smooth_factor, dist
297 Smooth /E=3 smooth_factor, dist
300 make /n=1 /d /free fit_params
301 fit_scienta_ang_transm(raw_dist, fit_params)
302 duplicate /free raw_dist, dist, dist_x
304 dist = scienta_ang_transm(fit_params, x)
307 loess /smth=(smooth_factor) srcWave=dist, factors={dist_x}
312 duplicate /o raw_dist, check_smoo
313 check_smoo = interp(x, dist_x, dist)
318 strip /= interp(x, dist_x, dist)
352 variable theta_offset
356 if (ParamIsDefault(check))
359 if (ParamIsDefault(theta_offset))
362 if (ParamIsDefault(theta_range))
367 duplicate /free strip, strip_copy
368 MatrixFilter NanZapMedian strip_copy
372 duplicate /free dist, dist_smoo
373 duplicate /free theta, theta_int
374 theta_int = theta - theta_offset
375 duplicate /free phi, phi_int
376 setscale /p x phi_int[0], phi_int[1] - phi_int[0], waveunits(phi, -1), dist, dist_smoo
378 extract /free /indx dist, red_idx, theta_int < theta_range
379 duplicate /free red_idx, red_dist, red_phi
380 red_dist = dist[red_idx]
381 red_phi = phi_int[red_idx]
383 variable wavg = mean(red_dist)
384 make /n=4 /d /free coef
385 coef[0] = {wavg, wavg/100, pi/180, 0}
386 CurveFit /q /h=
"0010" /g /w=2 sin, kwcWave=coef, red_dist /x=red_phi
387 dist_smoo = coef[0] + coef[1] * sin(coef[2] * phi_int[p] + coef[3])
391 strip = strip / dist_smoo[q] * coef[0]
396 duplicate /o dist, check_dist
397 duplicate /o dist_smoo, check_smoo
398 setscale /p x dimoffset(dist,0), dimdelta(dist,0), waveunits(dist,0), check_dist, check_smoo
436 variable theta_offset
437 variable smooth_method
438 variable smooth_factor
441 if (ParamIsDefault(check))
444 if (ParamIsDefault(theta_offset))
447 if (ParamIsDefault(smooth_method))
450 if (ParamIsDefault(smooth_factor))
455 duplicate /free strip, strip_copy
456 MatrixFilter NanZapMedian strip_copy
460 duplicate /free dist, dist_smoo
461 duplicate /free theta, theta_int
462 theta_int = theta - theta_offset
463 setscale /p x theta_int[0], theta_int[1] - theta_int[0], waveunits(theta,-1), dist, dist_smoo
464 variable nx = dimsize(strip, 0)
467 switch(smooth_method)
469 Smooth /B /E=3 smooth_factor, dist_smoo
472 Smooth /E=3 smooth_factor, dist_smoo
475 loess /dest=dist_smoo /smth=(smooth_factor) srcWave=dist, factors={theta_int}
478 for (ix = 0; ix < nx; ix += 1)
480 if (smooth_factor > 1)
481 CurveFit /nthr=0 /q /w=2 poly smooth_factor+1, dist /x=theta_int /d=dist_smoo
483 CurveFit /nthr=0 /q /w=2 line, dist /x=theta_int /d=dist_smoo
485 strip[ix,ix][] /= dist_smoo[q]
493 strip /= dist_smoo[q]
498 duplicate /o dist, check_dist
499 duplicate /o dist_smoo, check_smoo
500 setscale /p x dimoffset(dist,0), dimdelta(dist,0), waveunits(dist,0), check_dist, check_smoo
537 variable theta_offset
538 variable smooth_method
539 variable smooth_factor
542 if (ParamIsDefault(check))
545 if (ParamIsDefault(theta_offset))
548 if (ParamIsDefault(smooth_method))
551 if (ParamIsDefault(smooth_factor))
556 duplicate /free strip, strip_copy
557 MatrixFilter NanZapMedian strip_copy
561 duplicate /free dist, dist_smoo
562 duplicate /free theta, theta_int
563 theta_int = theta - theta_offset
564 setscale /p x theta_int[0], theta_int[1] - theta_int[0], waveunits(theta,-1), dist, dist_smoo
565 variable nx = dimsize(strip, 0)
568 switch(smooth_method)
570 loess /dest=dist_smoo /smth=(smooth_factor) srcWave=dist, factors={theta_int, phi}
573 abort
"smooth method not supported"
578 strip /= dist_smoo[q]
583 duplicate /o dist, check_dist
584 duplicate /o dist_smoo, check_smoo
585 setscale /p x dimoffset(dist,0), dimdelta(dist,0), waveunits(dist,0), check_dist, check_smoo
597 variable theta_offset
598 variable smooth_method
599 variable smooth_factor
602 if (ParamIsDefault(check))
605 if (ParamIsDefault(theta_offset))
608 if (ParamIsDefault(smooth_method))
611 if (ParamIsDefault(smooth_factor))
616 duplicate /free strip, strip_copy
617 MatrixFilter NanZapMedian strip_copy
621 duplicate /free dist, dist_smoo
622 duplicate /free theta, theta_int
623 theta_int = theta - theta_offset
624 setscale /p x theta_int[0], theta_int[1] - theta_int[0], waveunits(theta,-1), dist, dist_smoo
627 duplicate /free theta_int, d1_theta, d2_theta
628 Differentiate /METH=2 theta_int /D=d1_theta
629 Differentiate /METH=2 d1_theta /D=d2_theta
630 d2_theta = abs(d2_theta)
632 FindLevels /edge=1 /p /q /d=w_levels d2_theta, 0.1
634 abort "unrecognized scanning scheme"
636 w_levels = ceil(w_levels)
637 InsertPoints 0, 1, w_levels
639 InsertPoints numpnts(w_levels), 1, w_levels
640 w_levels[numpnts(w_levels)-1] = numpnts(theta_int)
642 variable n_scans = numpnts(w_levels) - 1
645 for (i_scan = 0; i_scan < n_scans; i_scan += 1)
646 p1 = w_levels[i_scan]
647 p2 = w_levels[i_scan+1] - 1
648 duplicate /free /r=[p1, p2] dist, dist_piece, smooth_piece
649 duplicate /free /r=[p1, p2] theta_int, theta_piece
650 switch(smooth_method)
652 loess /dest=smooth_piece /smth=(smooth_factor) srcWave=dist_piece, factors={theta_piece}
655 abort
"smooth method not supported"
657 dist_smoo[p1, p2] = smooth_piece[p - p1]
662 strip /= dist_smoo[q]
667 duplicate /o dist, check_dist
668 duplicate /o dist_smoo, check_smoo
669 setscale /p x dimoffset(dist,0), dimdelta(dist,0), waveunits(dist,0), check_dist, check_smoo
689 variable theta_offset
690 variable smooth_method
691 variable smooth_factor
694 if (ParamIsDefault(check))
697 if (ParamIsDefault(theta_offset))
700 if (ParamIsDefault(smooth_method))
703 if (ParamIsDefault(smooth_factor))
707 variable nx = dimsize(strip, 0)
708 variable ny = dimsize(strip, 1)
710 duplicate /free strip, dist, alpha_int, theta_int
711 MatrixFilter NanZapMedian dist
712 theta_int = theta[q] - theta_offset
713 alpha_int = dimoffset(strip, 0) + p * dimdelta(strip, 0)
714 redimension /n=(nx * ny) dist, alpha_int, theta_int
716 switch(smooth_method)
718 loess /dest=dist_smoo /smth=(smooth_factor) srcWave=dist, factors={alpha_int, theta_int}
719 redimension /n=(nx, ny) dist_smoo
722 Abort
"undefined smooth method"
734 duplicate /o dist_smoo, check_smoo
752 variable plo = round((xlo - dimoffset(strip, 0)) / dimdelta(strip, 0))
753 variable phi = round((xhi - dimoffset(strip, 0)) / dimdelta(strip, 0))
754 xlo = plo * dimdelta(strip, 0) + dimoffset(strip, 0)
755 xhi = phi * dimdelta(strip, 0) + dimoffset(strip, 0)
756 variable nx = phi - plo + 1
757 variable ny = dimsize(strip, 1)
759 duplicate /free strip, strip_copy
760 redimension /n=(nx,ny) strip
761 strip = strip_copy[p + plo][q]
762 setscale /i x xlo, xhi, waveunits(strip, 0), strip
787 extract /indx /free theta, idx, (theta >= theta_lo) && (theta <= theta_hi)
788 variable nx = dimsize(strip, 0)
789 variable ny = numpnts(idx)
791 theta[0, ny-1] = theta[idx]
792 tilt[0, ny-1] = tilt[idx]
793 phi[0, ny-1] = phi[idx]
794 redimension /n=(ny) theta, tilt, phi
796 duplicate /free strip, strip_copy
797 redimension /n=(nx,ny) strip
798 strip = strip_copy[p][idx[q]]
843 function
pizza_service(data, nickname, theta_offset, tilt_offset, phi_offset, [npolar, nograph, folding, xpdplot])
846 variable theta_offset
854 if (ParamIsDefault(npolar))
857 if (ParamIsDefault(nograph))
860 if (ParamIsDefault(folding))
863 if (ParamIsDefault(xpdplot))
868 dfref saveDF = GetDataFolderDFR()
869 dfref dataDF = GetWavesDataFolderDFR(data)
871 if (DataFolderExists(":attr"))
874 dfref attrDF = GetDataFolderDFR()
876 wave /sdfr=attrDF ManipulatorTheta
877 wave /sdfr=attrDF ManipulatorTilt
878 wave /sdfr=attrDF ManipulatorPhi
880 if ((dimsize(ManipulatorTheta, 0) != dimsize(data, 1)) || (dimsize(ManipulatorTilt, 0) != dimsize(data, 1)) || (dimsize(ManipulatorPhi, 0) != dimsize(data, 1)))
881 Abort "Warning: The dimension size of the manipulator waves does not match the Y dimension of the data wave!\rIf you restructured the data wave, please use
pizza_service_2 with properly scaled manipulator waves."
884 duplicate /free ManipulatorTheta, m_theta
885 duplicate /free ManipulatorTilt, m_tilt
886 duplicate /free ManipulatorPhi, m_phi
888 m_theta -= theta_offset
889 m_tilt -= tilt_offset
892 pizza_service_2(data, nickname, m_theta, m_tilt, m_phi, npolar=npolar, nograph=nograph, folding=folding, xpdplot=xpdplot)
936 function
pizza_service_2(data, nickname, m_theta, m_tilt, m_phi, [npolar, nograph, folding, xpdplot])
947 if (ParamIsDefault(npolar))
950 if (ParamIsDefault(nograph))
953 if (ParamIsDefault(folding))
956 if (ParamIsDefault(xpdplot))
960 if ((dimsize(m_theta, 0) != dimsize(data, 1)) || (dimsize(m_tilt, 0) != dimsize(data, 1)) || (dimsize(m_phi, 0) != dimsize(data, 1)))
961 Abort "Warning: The dimension size of the manipulator waves does not match the Y dimension of the data wave!"
964 string graphname = "graph_" + nickname
965 string outprefix = nickname
968 dfref saveDF = GetDataFolderDFR()
969 dfref dataDF = GetWavesDataFolderDFR(data)
977 newdatafolder /s/o $nickname
980 dfref destDF = GetDataFolderDFR()
984 variable /g pol_perf_secs
985 timerRefNum = startMSTimer
987 duplicate /free m_tilt, corr_tilt
988 duplicate /free m_phi, corr_phi
992 make /n=1/d/free d_polar, d_azi
998 for (ifold = 0; ifold < folding; ifold += 1)
999 d_azi = d_azi >= 360 ? d_azi - 360 : d_azi
1001 d_azi += 360 / folding
1005 if (strlen(outprefix))
1006 string s_prefix = outprefix + "_"
1007 string s_int = s_prefix + "i"
1013 wave values = $s_int
1021 if (timerRefNum >= 0)
1022 pol_perf_secs = stopMSTimer(timerRefNum) / 1e6
1025 setdatafolder saveDF
1053 function
show_analyser_line(theta, tilt, phi, theta_offset, tilt_offset, phi_offset, [npolar, nograph, xpdplot])
1057 variable theta_offset
1058 variable tilt_offset
1064 string nickname = "analyser"
1066 if (ParamIsDefault(npolar))
1069 if (ParamIsDefault(nograph))
1072 if (ParamIsDefault(xpdplot))
1075 string graphname = "graph_" + nickname
1076 string outprefix = nickname
1079 dfref saveDF = GetDataFolderDFR()
1080 dfref dataDF = saveDF
1083 outprefix = nickname
1085 setdatafolder dataDF
1086 newdatafolder /s/o $nickname
1089 dfref destDF = GetDataFolderDFR()
1091 make /n=1 /free m_theta
1092 make /n=1 /free m_tilt
1093 make /n=1 /free m_phi
1094 m_theta = theta - theta_offset
1095 m_tilt = tilt - tilt_offset
1097 m_phi = phi - phi_offset
1100 make /n=60 /free data
1101 setscale /i x -30, 30, data
1103 make /n=1/d/free d_polar, d_azi
1107 d_azi = d_azi >= 360 ? d_azi - 360 : d_azi
1115 setdatafolder saveDF
1124 wave theta, tilt, phi
1129 make /n=(dimsize(data, 0)) /d /free ana
1130 setscale /p x dimoffset(data, 0), dimdelta(data, 0), waveunits(data, 0), ana
1169 variable nn = numpnts(theta)
1170 variable na = numpnts(analyser)
1171 redimension /n=(na, nn) polar, azi
1178 make /n=(3,na) /d /free w_orig_polar, w_orig_cart, w_rot_cart, w_rot_polar
1179 w_orig_polar[0][] = radius
1180 w_orig_polar[1][] = analyser[q]
1181 w_orig_polar[2][] = 0
1187 for (ii = 0; ii < nn; ii += 1)
1193 w_rot_cart = w_orig_cart
1200 polar[][ii] = w_rot_polar[1][p]
1201 azi[][ii] = w_rot_polar[2][p]
1211 variable nn = dimsize(source, 1)
1212 make /n=(dimsize(source, 0))/d/free line
1213 for (ii = 0; ii < nn; ii += 1)
1214 line = source[p][ii]
1216 dest[][ii] = line[p] / v_max
1223 static function
calc_nth(Theta_st, Theta_in, th, Phi_ran, Phi_ref, Holomode)
1224 Variable Theta_st, Theta_in, th, Phi_ran, Phi_ref
1227 Variable deg2rad=0.01745329
1229 if ( cmpstr(Holomode, "Stereographic") == 0)
1230 The_step =trunc( Phi_ran*sin(th*deg2rad)*Phi_ref/Theta_st )
1232 The_step =trunc( Phi_ran*sin(th*pi/180)*Phi_ref/Theta_st )
1235 if (cmpstr(Holomode, "Parallel") == 0)
1236 The_step=trunc( Phi_ran*tan(th*deg2rad)*Phi_ref/Theta_st )
1238 if ( cmpstr(Holomode, "h") == 0)
1239 The_step=trunc( th/Theta_in*Phi_ran/Theta_st )
1252 static function
calc_phi_step(Theta_in, th, Theta_st, Phi_ran, Phi_ref, Holomode)
1253 Variable Theta_in, th, Theta_st, Phi_ran, Phi_ref
1257 Variable deg2rad=0.01745329
1259 if ( cmpstr(Holomode, "Stereographic") == 0 )
1260 if ((th < 0.5) || (trunc(Phi_ran*sin(th*deg2rad)*Phi_ref/Theta_st) == 0))
1263 Phi_st=Phi_ran/(trunc(Phi_ran*sin(th*deg2rad)*Phi_ref/Theta_st))
1270 if ( cmpstr(Holomode, "Parallel") == 0 )
1271 if((th < 0.5) || (trunc(Phi_ran*tan(th*deg2rad)*Phi_ref/Theta_st) == 0))
1274 Phi_st=Phi_ran/(trunc(Phi_ran*tan(th*deg2rad)*Phi_ref/Theta_st))
1278 if ( cmpstr(Holomode, "h") == 0 )
1279 if((th < 0.5) || (trunc(Phi_ran*sin(th*deg2rad)*Phi_ref/Theta_st) == 0))
1282 Phi_st=Phi_ran/trunc(th/Theta_in*Phi_ran/Theta_st)
1298 Variable th, Theta_st
1300 Variable deg2rad=0.01745329, dt_loc,The_step
1302 if ( (cmpstr(Holomode, "Stereographic")) ==0 )
1306 if ( (cmpstr(Holomode, "h")) ==0 )
1310 if ( cmpstr(Holomode, "Parallel") == 0 )
1312 dt_loc = Theta_st/cos(th*deg2rad)
1329 Variable Theta_in,Theta_ran,Theta_st
1330 Variable n_theta, aux, aux1,ii
1333 aux1= Theta_in - Theta_ran
1337 if(aux<=Theta_in-Theta_ran)
1338 aux=Theta_in-Theta_ran
1341 while((aux>aux1)%&(Theta_in-aux<=Theta_ran))
1370 if (ParamIsDefault(xpdplot))
1374 string HoloMode = "h"
1375 variable Theta_in = 90
1376 variable Theta_ran = 90
1377 variable Theta_st = 90 / (npol - 1)
1378 variable Phi_ran = 360
1379 variable Phi_ref = 1
1382 variable n_theta =
CalcN_Theta(HoloMode, Theta_in, Theta_ran, Theta_st)
1385 if (strlen(nickname))
1386 string s_prefix = nickname + "_"
1387 string s_int = s_prefix + "i"
1392 string s_polar = s_prefix + "pol"
1393 string s_azim = s_prefix + "az"
1395 string s_index = s_prefix + "index"
1396 string s_theta = s_prefix + "th"
1397 string s_dphi = s_prefix + "dphi"
1398 string s_nphis = s_prefix + "nphis"
1400 string s_HoloData = s_prefix + "data"
1401 string s_HoloInfo = s_prefix + "info"
1404 string s_tot = s_prefix + "tot"
1405 string s_weight = s_prefix + "wt"
1407 make /O/D/n=(n_theta) $s_index /wave=index
1408 make /O/D/n=(n_theta) $s_theta /wave=theta
1409 make /O/D/n=(n_theta) $s_dphi /wave=dphi
1410 make /O/D/n=(n_theta) $s_nphis /wave=nphis
1414 dphi[0] =
calc_phi_step(Theta_in, Theta_in, aux, Phi_ran, Phi_ref, HoloMode)
1416 nphis[0] =
calc_nth(aux, Theta_in, Theta_in, Phi_ran, Phi_ref, HoloMode)
1422 Theta[ii] = Theta[ii-1] - aux
1423 if(Theta[ii] <= Theta_in-Theta_ran)
1424 Theta[ii] = Theta_in-Theta_ran
1427 dphi[ii] =
calc_phi_step(Theta_in, Theta[ii], aux, Phi_ran, Phi_ref, HoloMode)
1428 nphis[ii] =
calc_nth(aux, Theta_in, Theta[ii], Phi_ran, Phi_ref, HoloMode)
1429 Index[ii] = Index[ii-1] + nphis[ii]
1433 if (Index[n_theta-1]==Index[n_theta-2])
1434 Index[n_theta-1]=Index[n_theta-2]+1
1438 variable NumPoints = sum(nphis, 0, numpnts(nphis))
1441 make /O/D/N=(NumPoints) $s_polar /wave=polar, $s_azim /wave=azim
1445 variable StartIndex = 0
1449 Polar[StartIndex, EndIndex-1]=Theta[ii]
1450 Azim[StartIndex, EndIndex-1]= mod(Phi_ran+(x-StartIndex)*dphi[ii]+Phi_in,Phi_ran)
1452 StartIndex = EndIndex
1455 duplicate /o azim, $s_int /wave=values
1456 duplicate /o azim, $s_tot /wave=totals
1457 duplicate /o azim, $s_weight /wave=weights
1464 string s_FileName = ""
1465 string s_Comment = "created by pearl-anglescan-process.ipf"
1466 string s_HoloMode = "Stereographic"
1467 variable /g gb_SpectraFile = 0
1469 Make/O/D/n=22 $s_HoloData /wave=HoloData
1472 HoloData[6] = NumPoints
1473 HoloData[7] = Theta_in
1474 HoloData[8] = Theta_ran
1475 HoloData[9] = Theta_st
1476 HoloData[11] = Phi_in
1477 HoloData[12] = Phi_ran
1478 HoloData[13] = Theta_st
1479 HoloData[15] = Phi_ref
1480 HoloData[16] = Phi_ran
1483 Make/O/T/n=22 $s_HoloInfo /wave=HoloInfo
1484 HoloInfo[0] = s_FileName
1485 HoloInfo[1] = s_Comment
1486 HoloInfo[10] = s_HoloMode
1490 if (WinType(NickName) == 5)
1491 Notebook $NickName selection={startOfFile, endOfFile}
1492 Notebook $NickName text=
""
1494 NewNotebook /F=0 /K=1 /N=$NickName /W=(5,40,341,260)
1495 Notebook $NickName defaultTab=140
1496 Notebook $NickName statusWidth=300
1497 Notebook $NickName backRGB=(56797,56797,56797)
1498 Notebook $NickName pageMargins={80,80,80,80}
1499 Notebook $NickName fSize=10
1500 Notebook $NickName fStyle=0,textRGB=(65535,0,26214)
1501 Notebook $NickName textRGB=(65535,0,26214)
1503 Notebook $NickName text =
"File:\t" + s_FileName +
"\r"
1504 Notebook $NickName text =
"*** " + s_Comment +
" ***\r\r"
1505 Notebook $NickName text =
"Angle-Mode:\t" + s_HoloMode +
"\r"
1506 Notebook $NickName text =
"XPDplot Nickname:\t" + NickName +
"\r"
1520 string wname = nameofwave(w)
1526 string s_wave_df = GetWavesDataFolder(w, 1)
1527 dfref parent_df = $(s_wave_df + "::")
1528 nickname = GetDataFolder(0, parent_df)
1544 string wname = nameofwave(w)
1546 if (ItemsInList(wname, "_") >= 2)
1547 prefix = StringFromList(0, wname, "_")
1580 if (strlen(nickname))
1581 if (DataFolderExists(nickname))
1584 datadf = getdatafolderdfr()
1585 prefix = nickname + "_"
1586 intwave = prefix + "i"
1587 if (exists(intwave) != 1)
1592 datadf = getdatafolderdfr()
1614 string s_totals = s_prefix + "tot"
1615 string s_weights = s_prefix + "wt"
1617 wave /sdfr=datadf /z w_values = $s_int
1618 wave /sdfr=datadf /z w_totals = $s_totals
1619 wave /sdfr=datadf /z w_weights = $s_weights
1621 if (waveexists(w_totals))
1624 if (waveexists(w_weights))
1627 if (waveexists(w_values))
1654 string source_nickname
1656 string dest_nickname
1659 if (ParamIsDefault(xpdplot))
1663 dfref savedf = getdatafolderdfr()
1666 string s_prefix = ""
1667 string s_int = "values"
1668 dfref source_df =
find_hemi_data(source_nickname, s_prefix, s_int)
1669 string s_polar = s_prefix + "pol"
1670 string s_azim = s_prefix + "az"
1671 string s_theta = s_prefix + "th"
1672 string s_tot = s_prefix + "tot"
1673 string s_weight = s_prefix + "wt"
1674 string s_matrix = s_prefix + "matrix"
1676 wave /sdfr=source_df theta1 = $s_theta
1677 wave /sdfr=source_df polar1 = $s_polar
1678 wave /sdfr=source_df azim1 = $s_azim
1679 wave /sdfr=source_df tot1 = $s_tot
1680 wave /sdfr=source_df weight1 = $s_weight
1681 wave /sdfr=source_df values1 = $s_int
1682 wave /sdfr=source_df /z matrix1 = $s_matrix
1684 variable npol = numpnts(theta1)
1686 setdatafolder dest_folder
1691 s_polar = s_prefix + "pol"
1692 s_azim = s_prefix + "az"
1693 s_theta = s_prefix + "th"
1694 s_tot = s_prefix + "tot"
1695 s_weight = s_prefix + "wt"
1696 s_matrix = s_prefix + "matrix"
1698 wave /sdfr=dest_df theta2 = $s_theta
1699 wave /sdfr=dest_df polar2 = $s_polar
1700 wave /sdfr=dest_df azim2 = $s_azim
1701 wave /sdfr=dest_df tot2 = $s_tot
1702 wave /sdfr=dest_df weight2 = $s_weight
1703 wave /sdfr=dest_df values2 = $s_int
1708 if (waveexists(matrix1))
1709 setdatafolder dest_df
1710 duplicate /o matrix1, $s_matrix
1713 if (!(NumberByKey("
version", note(azim1), "=", "\r") >= 1.6))
1715 azim2 = azim2 >= 360 ? azim2 - 360 : azim2
1718 setdatafolder saveDF
1732 dfref savedf = getdatafolderdfr()
1734 string s_prefix = ""
1735 string s_int = "values"
1738 string s_polar = s_prefix + "pol"
1739 string s_azim = s_prefix + "az"
1740 string s_tot = s_prefix + "tot"
1741 string s_weight = s_prefix + "wt"
1743 wave /sdfr=df polar = $s_polar
1744 wave /sdfr=df azim = $s_azim
1745 wave /sdfr=df tot = $s_tot
1746 wave /sdfr=df weight = $s_weight
1747 wave /sdfr=df values = $s_int
1750 azim = azim < 0 ? azim + 360 : azim
1751 azim = azim >= 360 ? azim - 360 : azim
1753 duplicate /free polar, neg_polar
1755 sort {neg_polar, azim}, polar, azim, tot, weight, values
1757 setdatafolder saveDF
1780 dfref savedf = getdatafolderdfr()
1782 if (ParamIsDefault(projection))
1787 string s_prefix = ""
1788 string s_int = "values"
1791 string s_polar = s_prefix + "pol"
1792 string s_azim = s_prefix + "az"
1794 wave /sdfr=df /z values = $s_int
1795 wave /sdfr=df /z azim = $s_azim
1796 wave /sdfr=df /z polar = $s_polar
1799 string s_ster_rad = s_prefix + "ster_rad"
1800 duplicate /o polar, $s_ster_rad /wave=ster_rad
1803 string s_ster_x = s_prefix + "ster_x"
1804 string s_ster_y = s_prefix + "ster_y"
1805 duplicate /o azim, $s_ster_x /wave=ster_x, $s_ster_y /wave=ster_y
1806 ster_x = ster_rad * cos(azim * pi / 180)
1807 ster_y = ster_rad * sin(azim * pi / 180)
1809 setdatafolder savedf
1866 dfref savedf = getdatafolderdfr()
1868 if (ParamIsDefault(projection))
1871 if (ParamIsDefault(graphtype))
1874 if (ParamIsDefault(do_ticks))
1877 if (ParamIsDefault(do_grids))
1880 if (ParamIsDefault(graphname))
1881 if (strlen(nickname) > 0)
1882 graphname = nickname
1884 graphname = GetDataFolder(0)
1891 string s_prefix = ""
1892 string s_int = "values"
1895 string s_polar = s_prefix + "pol"
1896 string s_azim = s_prefix + "az"
1897 string s_matrix = s_prefix + "matrix"
1898 string s_ster_rad = s_prefix + "ster_rad"
1900 wave /sdfr=df /z values = $s_int
1901 wave /sdfr=df /z azim = $s_azim
1902 wave /sdfr=df /z polar = $s_polar
1903 wave /sdfr=df /z ster_rad = $s_ster_rad
1904 wave /sdfr=df /z matrix = $s_matrix
1907 variable azim_offset = 0
1908 if (!(NumberByKey("
version", note(azim), "=", "\r") >= 1.6))
1909 DoAlert /T="display hemi scan" 0, "your dataset doesn't include the
version 1.6 flag. if it was created with an earlier
version that might be okay. please check that the orientation is correct!"
1916 if (str2num(GetUserData(graphname, "", "graphtype")) == graphtype)
1921 killwindow $graphname
1929 s_trace = WMPolarAppendTrace(graphname, ster_rad, azim, 360)
1930 ModifyGraph /W=$graphname mode($s_trace)=2, lsize($s_trace)=2
1931 ModifyGraph /W=$graphname zColor($s_trace)={values,*,*,BlueGreenOrange,0}
1933 ColorScale /W=$graphname /C /N=text0 /E=2 /F=0 /B=1 /A=RB /X=0.00 /Y=0.00 trace=polarY0
1934 ColorScale /W=$graphname /C /N=text0 side=2, width=5, heightPct=40, frame=0.50, lblMargin=0
1935 ColorScale /W=$graphname /C /N=text0 nticks=2, minor=1, tickLen=4.00, tickThick=0.50
1937 SetWindow $graphname, userdata(projection)=num2str(projection)
1938 SetWindow $graphname, userdata(graphtype)=num2str(graphtype)
1944 s_trace = WMPolarAppendTrace(graphname, ster_rad, azim, 360)
1945 ModifyGraph /W=$graphname mode($s_trace)=0, lsize($s_trace)=0
1946 AppendImage /L=VertCrossing /B=HorizCrossing matrix
1948 ColorScale /W=$graphname /C /N=text0 /E=2 /F=0 /B=1 /A=RB /X=0.00 /Y=0.00 image=$s_matrix
1949 ColorScale /W=$graphname /C /N=text0 side=2, width=5, heightPct=40, frame=0.50, lblMargin=0
1950 ColorScale /W=$graphname /C /N=text0 nticks=2, minor=1, tickLen=4.00, tickThick=0.50
1952 SetWindow $graphname, userdata(projection)=num2str(projection)
1953 SetWindow $graphname, userdata(graphtype)=num2str(graphtype)
1958 setdatafolder savedf
2006 variable angle_offset
2009 dfref savedf = GetDataFolderDFR()
2011 if (ParamIsDefault(angle_offset))
2014 if (ParamIsDefault(do_ticks))
2018 if ((strlen(graphname) == 0) || (wintype(graphname) == 0))
2019 Display /k=1 /W=(10,45,360,345)
2020 DoWindow /C $graphname
2021 graphname = WMNewPolarGraph("", graphname)
2022 WMPolarGraphSetVar(graphname, "zeroAngleWhere", angle_offset)
2024 WMPolarGraphSetVar(graphname, "angleAxisThick", 0.5)
2025 WMPolarGraphSetStr(graphname, "doMajorAngleTicks", "manual")
2026 WMPolarGraphSetVar(graphname, "majorAngleInc", 30)
2027 WMPolarGraphSetVar(graphname, "minorAngleTicks", 2)
2028 WMPolarGraphSetStr(graphname, "angleTicksLocation", "Outside")
2029 WMPolarGraphSetVar(graphname, "doAngleTickLabelSubRange", 1)
2030 WMPolarGraphSetVar(graphname, "angleTickLabelRangeStart", 0)
2031 WMPolarGraphSetVar(graphname, "angleTickLabelRangeExtent", 90)
2032 WMPolarGraphSetStr(graphname, "angleTickLabelNotation", "%g°")
2034 WMPolarGraphSetVar(graphname, "doPolarGrids", 0)
2035 WMPolarGraphSetVar(graphname, "doRadiusTickLabels", 0)
2036 WMPolarGraphSetStr(graphname, "radiusAxesWhere", " Off")
2037 WMPolarGraphSetStr(graphname, "radiusTicksLocation", "Off")
2039 WMPolarGraphSetVar(graphname, "majorTickLength", 2)
2040 WMPolarGraphSetVar(graphname, "majorTickThick", 0.5)
2041 WMPolarGraphSetVar(graphname, "minorTickLength", 1)
2042 WMPolarGraphSetVar(graphname, "minorTickThick", 0.5)
2043 WMPolarGraphSetVar(graphname, "tickLabelOpaque", 0)
2044 WMPolarGraphSetVar(graphname, "tickLabelFontSize", 7)
2048 WMPolarGraphSetStr(graphname, "angleTicksLocation", "Outside")
2050 WMPolarGraphSetStr(graphname, "angleTicksLocation", "Off")
2053 WMPolarGraphSetVar(graphname, "doMinorAngleTicks", 1)
2055 WMPolarGraphSetVar(graphname, "doMinorAngleTicks", 0)
2058 DoWindow /T $graphname, graphname
2061 string graphdf = "root:packages:WMPolarGraphs:" + graphname
2062 setdatafolder graphdf
2064 variable /g csrA_theta
2065 variable /g csrA_phi
2066 variable /g csrB_theta
2067 variable /g csrB_phi
2071 tb = tb + "\
"A = (%.1f, %.1f)\","
2072 tb = tb + graphdf +
":csrA_theta,"
2073 tb = tb + graphdf +
":csrA_phi"
2075 TextBox /W=$graphname /A=LT /B=1 /E=2 /F=0 /N=tb_angles /X=1 /Y=1 /V=0 tb
2077 tb = tb +
"\"B = (%.1f, %.1f)\","
2078 tb = tb + graphdf +
":csrB_theta,"
2079 tb = tb + graphdf +
":csrB_phi"
2081 AppendText /W=$graphname /N=tb_angles tb
2086 DoWindow /F $graphname
2089 setdatafolder savedf
2122 if (ParamIsDefault(do_grids))
2126 dfref savedf = GetDataFolderDFR()
2128 string sproj = GetUserData(graphname, "", "projection")
2129 variable projection = str2num("0" + sproj)
2131 SetDrawLayer /W=$graphname ProgFront
2134 SetDrawEnv /W=$graphname xcoord=HorizCrossing, ycoord=VertCrossing
2135 SetDrawEnv /W=$graphname linethick= 0.5
2136 SetDrawEnv /W=$graphname dash=2
2137 SetDrawEnv /W=$graphname fillpat=0
2138 SetDrawEnv /W=$graphname fname="default", fsize=7
2139 SetDrawEnv /W=$graphname textxjust=1, textyjust=1
2141 SetDrawEnv /W=$graphname save
2144 DrawLine /W=$graphname 0, -2, 0, 2
2145 DrawLine /W=$graphname -2, 0, 2, 0
2151 DrawOval /W=$graphname -radi, radi, radi, -radi
2153 DrawOval /W=$graphname -radi, radi, radi, -radi
2155 DrawOval /W=$graphname -radi, radi, radi, -radi
2157 SetDrawEnv /W=$graphname textxjust= 1,textyjust= 2
2158 SetDrawEnv /W=$graphname save
2160 DrawText /W=$graphname radi, -0.1, "30°"
2162 DrawText /W=$graphname radi, -0.1, "60°"
2165 setdatafolder savedf
2195 variable theta_inner
2203 SetDrawLayer UserFront
2204 DrawAction getgroup=$groupname, delete
2205 SetDrawEnv gstart, gname=$groupname
2206 variable xc, yc, xr, yr
2209 variable r_center = (r_outer + r_inner) / 2
2210 variable r_radius = (r_outer - r_inner) / 2
2211 xc = r_center * cos(phi * pi / 180)
2212 yc = r_center * sin(phi * pi / 180)
2215 SetDrawEnv xcoord=HorizCrossing, ycoord=VertCrossing
2216 SetDrawEnv dash=11, fillpat=0
2217 DrawOval xc - xr, yc - yr, xc + xr, yc + yr
2220 xc = r_axis * cos(phi * pi / 180)
2221 yc = r_axis * sin(phi * pi / 180)
2225 SetDrawEnv xcoord=HorizCrossing, ycoord=VertCrossing
2226 SetDrawEnv fillfgc=(0,0,0)
2227 DrawOval xc - xr, yc - yr, xc + xr, yc + yr
2254 function /s
display_scanlines(nickname, alpha_lo, alpha_hi, m_theta, m_tilt, m_phi, [folding, projection])
2264 if (ParamIsDefault(folding))
2267 if (ParamIsDefault(projection))
2272 dfref saveDF = GetDataFolderDFR()
2273 newdatafolder /s/o $nickname
2274 string graphname = "graph_" + nickname
2276 duplicate /free m_tilt, loc_m_tilt
2277 loc_m_tilt = -m_tilt
2279 make /n=1 /d /free d_polar, d_azi
2280 variable n_alpha = round(alpha_hi - alpha_lo) + 1
2281 make /n=(n_alpha) /d /free analyser
2282 setscale /i x alpha_lo, alpha_hi, "°", analyser
2286 duplicate /free d_polar, d_radius
2291 SetWindow $graphname, userdata(projection)=num2str(projection)
2295 variable nang = numpnts(m_theta)
2299 for (ifold = 0; ifold < folding; ifold += 1)
2300 d_azi = d_azi >= 360 ? d_azi - 360 : d_azi
2301 for (iang = 0; iang < nang; iang += 1)
2302 sprintf s_rad, "rad_%d_%d", ifold, iang
2303 duplicate /o analyser, $s_rad
2305 w_rad = d_radius[p][iang]
2307 sprintf s_azi, "azi_%d_%d", ifold, iang
2308 duplicate /o analyser, $s_azi
2310 w_azi = d_azi[p][iang]
2312 if (numtype(sum(w_rad)) == 0)
2313 s_trace = WMPolarAppendTrace(graphname, w_rad, w_azi, 360)
2314 ModifyGraph /w=$graphname mode($s_trace)=0, lsize($s_trace)=0.5
2317 d_azi += 360 / folding
2322 setdatafolder saveDF
2373 if (ParamIsDefault(projection))
2386 radius = polar < 90 ?
kProjScaleGnom * tan(polar * pi / 180) : inf
2419 if (ParamIsDefault(projection))
2426 radius = sqrt(x^2 + y^2)
2473 if (ParamIsDefault(projection))
2476 if (ParamIsDefault(zeroAngle))
2482 azi = atan(y / x) * 180 / pi
2484 azi = atan(y / x) * 180 / pi + 180
2494 if (numtype(azi) != 0)
2515 dfref savedf = GetDataFolderDFR()
2517 string graphdf = "root:packages:WMPolarGraphs:" + graphname
2518 setdatafolder graphdf
2525 string sproj = GetUserData(graphname, "", "projection")
2526 variable projection = str2num("0" + sproj)
2529 variable x = hcsr(A, graphname)
2530 variable y = vcsr(A, graphname)
2532 csrA_phi =
calc_graph_azi(x, y, projection=projection, zeroAngle=zeroAngleWhere)
2534 x = hcsr(B, graphname)
2535 y = vcsr(B, graphname)
2537 csrB_phi =
calc_graph_azi(x, y, projection=projection, zeroAngle=zeroAngleWhere)
2539 setdatafolder savedf
2548 STRUCT WMWinHookStruct &s
2550 Variable hookResult = 0
2557 TextBox /W=$s.winname /N=tb_angles /C /V=1
2560 TextBox /W=$s.winname /N=tb_angles /C /V=0
2570 variable polar_angle
2574 if (ParamIsDefault(graphname))
2575 if (strlen(nickname) > 0)
2576 graphname = nickname
2578 graphname = GetDataFolder(0)
2582 string s_prefix = ""
2583 string s_int = "values"
2586 string s_polar = s_prefix + "pol"
2587 string s_azim = s_prefix + "az"
2588 wave /sdfr=df /z azim = $s_azim
2589 wave /sdfr=df /z polar = $s_polar
2591 FindLevel /P /Q polar, polar_angle
2593 variable polar_level = floor(v_levelx)
2594 FindLevel /P /Q /R=[polar_level] azim, azim_angle
2596 variable azim_level = round(v_levelx)
2597 string tracename = "polarY0"
2598 Cursor /W=$graphname /P $cursorname $traceName azim_level
2644 dfref savedf = GetDataFolderDFR()
2646 if (ParamIsDefault(weights))
2647 duplicate /free values, weights
2651 string s_prefix = ""
2652 string s_int = "values"
2655 string s_totals = s_prefix + "tot"
2656 string s_weights = s_prefix + "wt"
2657 string s_polar = s_prefix + "pol"
2658 string s_azim = s_prefix + "az"
2659 string s_index = s_prefix + "index"
2660 string s_theta = s_prefix + "th"
2661 string s_dphi = s_prefix + "dphi"
2662 string s_nphis = s_prefix + "nphis"
2664 wave /sdfr=df w_polar = $s_polar
2665 wave /sdfr=df w_azim = $s_azim
2666 wave /sdfr=df w_values = $s_int
2667 wave /sdfr=df w_totals = $s_totals
2668 wave /sdfr=df w_weights = $s_weights
2669 wave /sdfr=df w_index = $s_index
2670 wave /sdfr=df w_theta = $s_theta
2671 wave /sdfr=df w_dphi = $s_dphi
2672 wave /sdfr=df w_nphis = $s_nphis
2675 duplicate /free values, values_copy
2676 duplicate /free polar, polar_copy
2677 duplicate /free azi, azi_copy
2678 duplicate /free weights, weights_copy
2679 variable nn = dimsize(values, 0) * max(dimsize(values, 1), 1)
2680 redimension /n=(nn) values_copy, polar_copy, azi_copy, weights_copy
2681 sort /r polar_copy, polar_copy, azi_copy, values_copy, weights_copy
2683 make /n=(numpnts(w_theta)) /free /df dfw
2685 MultiThread dfw =
add_anglescan_worker(p, values_copy, weights_copy, polar_copy, azi_copy, w_polar, w_azim, w_theta, w_index, w_dphi, w_nphis)
2688 for (pp = 0; pp < numpnts(dfw); pp += 1)
2690 wave df_totals = tdf:w_totals
2691 wave df_weights = tdf:w_weights
2692 w_totals += df_totals
2693 w_weights += df_weights
2695 w_values = w_weights > 0 ? w_totals / w_weights : nan
2697 SetDataFolder savedf
2711 threadsafe static function /df
add_anglescan_worker(ith, values, weights, polar, azi, w_polar, w_azim, w_theta, w_index, w_dphi, w_nphis)
2724 dfref savedf= GetDataFolderDFR()
2725 dfref freedf= NewFreeDataFolder()
2726 SetDataFolder freedf
2727 make /n=(numpnts(w_polar)) /d w_totals, w_weights
2729 variable pol = w_theta[ith]
2730 variable pol_st = abs(w_theta[1] - w_theta[0])
2731 variable pol1 = pol - pol_st / 2
2732 variable pol2 = pol + pol_st / 2
2734 extract /free /indx polar, sel, (pol1 < polar) && (polar <= pol2) && (numtype(values) == 0) && (weights > 0)
2735 if (numpnts(sel) > 0)
2736 duplicate /free /r=[0, numpnts(sel)-1] azi, azi_slice
2737 duplicate /free /r=[0, numpnts(sel)-1] values, values_slice
2738 duplicate /free /r=[0, numpnts(sel)-1] weights, weights_slice
2739 azi_slice = azi[sel]
2740 values_slice = values[sel]
2741 weights_slice = weights[sel]
2742 add_aziscan_core(values_slice, weights_slice, pol, azi_slice, w_theta, w_azim, w_index, w_dphi, w_totals, w_weights)
2745 SetDataFolder savedf
2761 threadsafe static function
add_aziscan_core(values, weights, polar, azi, w_theta, w_azim, w_index, w_dphi, w_totals, w_weights)
2776 variable ipol = BinarySearch(w_theta, polar)
2783 d1 = w_index[ipol - 1]
2787 d2 = w_index[ipol] - 1
2788 variable nd = d2 - d1 + 1
2789 variable dphi = w_dphi[ipol]
2790 make /n=(nd+1) /free bin_index
2791 setscale /i x w_azim[d1] - dphi/2, w_azim[d2] + dphi/2, "deg", bin_index
2795 azi = azi < 0 ? azi + 360 : azi
2796 azi = azi >= 360 - dphi/2 ? azi - 360 : azi
2797 sort azi, values, weights, azi
2798 setscale /p x 0, 1, "", values, weights, azi
2800 bin_index = BinarySearch(azi, x) + 1
2801 bin_index = bin_index == -2 ? 0 : bin_index[p]
2802 bin_index = bin_index == -1 ? numpnts(azi) : bin_index[p]
2803 bin_index[nd] = numpnts(azi)
2807 variable v1, v2, w1, w2
2808 for (
id = 0;
id < nd;
id += 1)
2809 if (bin_index[
id+1] > bin_index[
id])
2810 v1 = w_totals[d1 +
id]
2811 w1 = w_weights[d1 +
id]
2812 if ((numtype(v1) == 2) || (w1 <= 0))
2816 v2 = sum(values, bin_index[
id], bin_index[
id+1] - 1)
2817 w2 = sum(weights, bin_index[
id], bin_index[
id+1] - 1)
2818 w_totals[d1 +
id] = v1 + v2
2819 w_weights[d1 +
id] = w1 + w2
2851 dfref savedf = GetDataFolderDFR()
2853 duplicate /free values, values_copy
2854 duplicate /free azi, azi_copy
2855 if (ParamIsDefault(weights))
2856 duplicate /free values, weights_copy
2859 duplicate /free weights, weights_copy
2863 string s_prefix = ""
2864 string s_int = "values"
2867 string s_totals = s_prefix + "tot"
2868 string s_weights = s_prefix + "wt"
2869 string s_polar = s_prefix + "pol"
2870 string s_azim = s_prefix + "az"
2871 string s_index = s_prefix + "index"
2872 string s_theta = s_prefix + "th"
2873 string s_dphi = s_prefix + "dphi"
2874 string s_nphis = s_prefix + "nphis"
2876 wave /sdfr=df w_polar = $s_polar
2877 wave /sdfr=df w_azim = $s_azim
2878 wave /sdfr=df w_values = $s_int
2879 wave /sdfr=df w_totals = $s_totals
2880 wave /sdfr=df w_weights = $s_weights
2881 wave /sdfr=df w_index = $s_index
2882 wave /sdfr=df w_theta = $s_theta
2883 wave /sdfr=df w_dphi = $s_dphi
2884 wave /sdfr=df w_nphis = $s_nphis
2886 add_aziscan_core(values_copy, weights_copy, polar, azi_copy, w_theta, w_azim, w_index, w_dphi, w_totals, w_weights)
2888 w_values = w_weights > 0 ? w_totals / w_weights : nan
2890 SetDataFolder savedf
2924 dfref savedf = GetDataFolderDFR()
2926 if (ParamIsDefault(projection))
2930 string s_prefix = ""
2931 string s_int = "values"
2935 string s_polar = s_prefix + "pol"
2936 string s_azim = s_prefix + "az"
2937 string s_matrix = s_prefix + "matrix"
2938 string s_ster_rad = s_prefix + "ster_rad"
2939 string s_ster_x = s_prefix + "ster_x"
2940 string s_ster_y = s_prefix + "ster_y"
2942 wave /sdfr=df /z values = $s_int
2943 wave /sdfr=df /z azim = $s_azim
2944 wave /sdfr=df /z polar = $s_polar
2945 wave /sdfr=df /z ster_rad = $s_ster_rad
2946 wave /sdfr=df /z ster_x = $s_ster_x
2947 wave /sdfr=df /z ster_y = $s_ster_y
2949 variable min_ster_x = wavemin(ster_x)
2950 variable max_ster_x = wavemax(ster_x)
2951 variable x0 = min_ster_x
2953 variable dx = (max_ster_x - min_ster_x) / (xn - 1)
2954 make /n=(numpnts(ster_x), 3) /free triplet
2955 triplet[][0] = ster_x[p]
2956 triplet[][1] = ster_y[p]
2957 triplet[][2] = values[p]
2961 make /n=(size, size) /d /o $(s_prefix + "matrix") /wave=matrix
2962 make /n=(size, size) /free mnorm
2963 ImageFromXYZ /as {ster_x, ster_y, values}, matrix, mnorm
2965 matrixfilter NanZapMedian, matrix
2966 matrixfilter gauss, matrix
2968 duplicate /free values, ster_finite
2969 ster_finite = (numtype(values) == 0) * (ster_x^2 + ster_y^2)
2970 variable ster_max = wavemax(ster_finite)
2971 matrix = (x^2 + y^2) <= ster_max ? matrix : nan
2973 setdatafolder savedf
2986 function quick_pizza_image(data, nickname, theta_offset, tilt_offset, phi_offset, [npolar, nograph, folding])
2991 variable theta_offset
2992 variable tilt_offset
3000 if (ParamIsDefault(npolar))
3003 if (ParamIsDefault(nograph))
3006 if (ParamIsDefault(folding))
3009 string graphname =
"graph_" + nickname
3010 string s_prefix =
""
3013 dfref saveDF = GetDataFolderDFR()
3014 dfref dataDF = GetWavesDataFolderDFR(data)
3015 setdatafolder dataDF
3016 if (DataFolderExists(
":attr"))
3019 dfref attrDF = GetDataFolderDFR()
3020 setdatafolder dataDF
3021 newdatafolder /s/o $nickname
3022 dfref destDF = GetDataFolderDFR()
3025 variable timerRefNum
3026 variable /g xyz_perf_secs
3027 timerRefNum = startMSTimer
3029 wave /sdfr=attrDF ManipulatorTheta
3030 wave /sdfr=attrDF ManipulatorTilt
3031 wave /sdfr=attrDF ManipulatorPhi
3032 duplicate /free ManipulatorTheta, m_theta
3033 duplicate /free ManipulatorTilt, m_tilt
3034 duplicate /free ManipulatorPhi, m_phi
3035 m_theta -= theta_offset
3036 m_tilt -= tilt_offset
3041 make /n=1/d/free d_polar, d_azi
3044 d_azi = d_azi >= 360 ? d_azi - 360 : d_azi
3046 duplicate /free data, values
3047 variable nn = dimsize(values, 0) * max(dimsize(values, 1), 1)
3048 redimension /n=(nn) values, d_polar, d_azi
3049 duplicate /o d_polar, ster_rad, ster_x, ster_y
3051 variable projection = 1
3054 ster_rad = 2 * tan(d_polar / 2 * pi / 180)
3057 ster_rad = 2 * cos((180 - d_polar) / 2 * pi / 180)
3060 string s_ster_x = s_prefix + "ster_x"
3061 string s_ster_y = s_prefix + "ster_y"
3064 make /n=(nn, nn) /d /o matrix
3065 make /n=(nn, nn) /free mnorm
3066 setscale /i x -2, +2, matrix, mnorm
3067 setscale /i y -2, +2, matrix, mnorm
3072 for (ifold = 0; ifold < folding; ifold += 1)
3073 ster_x = ster_rad * cos(d_azi * pi / 180)
3074 ster_y = ster_rad * sin(d_azi * pi / 180)
3075 ImageFromXYZ {ster_x, ster_y, values}, matrix, mnorm
3076 d_azi = d_azi >= 180 ? d_azi + 360 / folding - 180 : d_azi + 360 / folding
3080 matrixfilter /n=5 NanZapMedian matrix
3081 matrixfilter /n=3 gauss matrix
3086 modifygraph width={Plan,1,bottom,left}
3089 if (timerRefNum >= 0)
3090 xyz_perf_secs = stopMSTimer(timerRefNum) / 1e6
3093 setdatafolder saveDF
3102 dfref savedf = getdatafolderdfr()
3105 string s_prefix = ""
3106 string s_int = "values"
3109 string s_polar = s_prefix + "pol"
3110 string s_azim = s_prefix + "az"
3111 string s_theta = s_prefix + "th"
3112 string s_tot = s_prefix + "tot"
3113 string s_weight = s_prefix + "wt"
3115 wave /sdfr=df theta1 = $s_theta
3116 wave /sdfr=df polar1 = $s_polar
3117 wave /sdfr=df azim1 = $s_azim
3118 wave /sdfr=df tot1 = $s_tot
3119 wave /sdfr=df weight1 = $s_weight
3120 wave /sdfr=df values1 = $s_int
3122 save /m="\r\n" /o /p=$pathname /t theta1, polar1, azim1, tot1, weight1, values1 as filename
3124 setdatafolder saveDF
3135 dfref savedf = getdatafolderdfr()
3144 setdatafolder saveDF
3179 function
import_tpi_scan(nickname, theta, phi, intensity, [folding, npolar, nograph, xpdplot])
3190 if (ParamIsDefault(npolar))
3193 if (ParamIsDefault(nograph))
3196 if (ParamIsDefault(folding))
3199 if (ParamIsDefault(xpdplot))
3206 duplicate /free phi, fold_phi
3207 for (ifold = 0; ifold < folding; ifold += 1)
3208 fold_phi = fold_phi >= 360 ? fold_phi - 360 : fold_phi
3210 fold_phi += 360 / folding
3233 string s_prefix = ""
3234 string s_int = "values"
3237 string s_totals = s_prefix + "tot"
3238 string s_weights = s_prefix + "wt"
3239 string s_polar = s_prefix + "pol"
3241 wave /sdfr=df w_polar = $s_polar
3242 wave /sdfr=df w_values = $s_int
3243 wave /sdfr=df w_totals = $s_totals
3244 wave /sdfr=df w_weights = $s_weights
3246 w_values = w_polar <= theta_max ? w_totals / w_weights : nan
3272 dfref savedf = getdatafolderdfr()
3273 string s_prefix = ""
3274 string s_int = "values"
3277 string s_totals = s_prefix + "tot"
3278 string s_weights = s_prefix + "wt"
3279 string s_polar = s_prefix + "pol"
3280 string s_azim = s_prefix + "az"
3281 string s_index = s_prefix + "index"
3282 string s_theta = s_prefix + "th"
3283 string s_dphi = s_prefix + "dphi"
3284 string s_nphis = s_prefix + "nphis"
3286 sprintf s_cut, "%s_azi%03u", s_int, round(azim)
3288 wave /sdfr=df w_polar = $s_polar
3289 wave /sdfr=df w_azim = $s_azim
3290 wave /sdfr=df w_values = $s_int
3291 wave /sdfr=df w_totals = $s_totals
3292 wave /sdfr=df w_weights = $s_weights
3293 wave /sdfr=df w_index = $s_index
3294 wave /sdfr=df w_theta = $s_theta
3295 wave /sdfr=df w_dphi = $s_dphi
3296 wave /sdfr=df w_nphis = $s_nphis
3298 variable npol = numpnts(w_theta)
3300 variable pol_st = abs(w_theta[1] - w_theta[0])
3306 make /n=(npol) /o $s_cut
3308 setscale /i x w_theta[0], w_theta[numpnts(w_theta)-1], "deg", w_cut
3309 make /n=1 /free azi_slice
3310 make /n=1 /free values_slice
3312 for (ipol = 0; ipol < npol; ipol += 1)
3314 pol1 = pol - pol_st / 2
3315 pol2 = pol + pol_st / 2
3316 extract /free /indx w_polar, sel, (pol1 < w_polar) && (w_polar <= pol2)
3319 redimension /n=(nsel+2) azi_slice, values_slice
3320 azi_slice[1, nsel] = w_azim[sel[p-1]]
3321 azi_slice[0] = azi_slice[nsel] - 360
3322 azi_slice[nsel+1] = azi_slice[1] + 360
3323 values_slice[1, nsel] = w_values[sel[p-1]]
3324 values_slice[0] = values_slice[nsel]
3325 values_slice[nsel+1] = values_slice[1]
3326 w_cut[ipol] = interp(azim, azi_slice, values_slice)
3332 setdatafolder savedf
3358 dfref savedf = getdatafolderdfr()
3359 string s_prefix = ""
3360 string s_int = "values"
3363 string s_totals = s_prefix + "tot"
3364 string s_weights = s_prefix + "wt"
3365 string s_polar = s_prefix + "pol"
3366 string s_azim = s_prefix + "az"
3367 string s_index = s_prefix + "index"
3368 string s_theta = s_prefix + "th"
3369 string s_dphi = s_prefix + "dphi"
3370 string s_nphis = s_prefix + "nphis"
3372 sprintf s_cut, "%s_pol%03u", s_int, round(pol)
3374 wave /sdfr=df w_polar = $s_polar
3375 wave /sdfr=df w_azim = $s_azim
3376 wave /sdfr=df w_values = $s_int
3377 wave /sdfr=df w_totals = $s_totals
3378 wave /sdfr=df w_weights = $s_weights
3379 wave /sdfr=df w_index = $s_index
3380 wave /sdfr=df w_theta = $s_theta
3381 wave /sdfr=df w_dphi = $s_dphi
3382 wave /sdfr=df w_nphis = $s_nphis
3384 variable pol_st = abs(w_theta[1] - w_theta[0])
3388 pol1 = pol - pol_st / 2
3389 pol2 = pol + pol_st / 2
3390 extract /free /indx w_polar, sel, (pol1 < w_polar) && (w_polar <= pol2)
3394 make /n=(nsel) /o $s_cut
3396 w_cut = w_values[sel]
3397 setscale /i x w_azim[sel[0]], w_azim[sel[nsel-1]], "°", w_cut
3398 setdatafolder savedf
3401 setdatafolder savedf
3404 setdatafolder savedf
3415 dfref save_df = GetDataFolderDFR()
3416 dfref dfr = NewFreeDataFolder()
3418 StatsQuantiles /inan /iw /q /z values
3419 wave /z index = w_quantilesindex
3420 setdatafolder save_df
3422 if (waveexists(index))
3423 variable imin = round(numpnts(index) * pcmin / 100)
3424 variable imax = round(numpnts(index) * (100 - pcmax) / 100)
3425 vmin = values[index[imin]]
3426 vmax = values[index[imax]]
3428 variable d = vmax - vmin
3429 if ((vmax >= d/4) && (-vmin >= d/4))
3430 vmax = min(abs(vmin), abs(vmax))
3435 vmin = wavemin(values)
3436 vmax = wavemax(values)
3463 function
set_contrast(pcmin, pcmax, [graphname, colortable, reversecolors, symmetric])
3468 variable reversecolors
3471 if (ParamIsDefault(graphname))
3474 if (ParamIsDefault(colortable))
3477 if (ParamIsDefault(reversecolors))
3480 if (ParamIsDefault(symmetric))
3484 dfref save_df = GetDataFolderDFR()
3496 string traces = TraceNameList(graphname, ";", 1+4)
3497 n = ItemsInList(traces, ";")
3498 for (i = 0; i < n; i += 1)
3499 objname = StringFromList(i, traces, ";")
3500 info = TraceInfo(graphname, objname, 0)
3501 if (strlen(info) > 0)
3502 info = StringByKey("RECREATION", info, ":", ";")
3503 info = StringByKey("zColor(x)", info, "=", ";")
3504 if (strlen(info) > 2)
3505 info = info[1,strlen(info)-2]
3506 wname = StringFromList(0, info, ",")
3508 ctab = StringFromList(3, info, ",")
3509 rev = str2num("0" + StringFromList(4, info, ","))
3510 if (strlen(colortable) > 0)
3516 ModifyGraph /w=$graphname zColor($objname)={w, vmin, vmax, $ctab, rev}
3522 string images = ImageNameList(graphname,
";")
3523 n = ItemsInList(images, ";")
3524 for (i = 0; i < n; i += 1)
3525 objname = StringFromList(i, images, ";")
3526 wave w = ImageNameToWaveRef(graphname, objname)
3527 info = ImageInfo(graphname, objname, 0)
3528 if (strlen(info) > 0)
3529 info = StringByKey("RECREATION", info, ":", ";")
3530 info = StringByKey("ctab", info, "=", ";")
3531 if (strlen(info) > 2)
3532 info = info[1,strlen(info)-2]
3533 ctab = StringFromList(2, info, ",")
3534 rev = str2num("0" + StringFromList(3, info, ","))
3535 if (strlen(colortable) > 0)
3541 ModifyImage /w=$graphname $objname ctab={vmin, vmax, $ctab, rev}
3547 setdatafolder save_df
3564 String newname = NameofWave(inwave)+
"_k"
3565 Duplicate/O inwave, $newname
3566 Wave outwave = $newname
3567 Variable rows,columns,xdelta,xoffset,ydelta,yoffset,kmin,kmax,Emax
3569 rows = DimSize(inwave,0)
3570 columns = DimSize(inwave,1)
3571 xdelta = DimDelta(inwave,0)
3572 xoffset = DimOffset(inwave,0)
3573 ydelta = DimDelta(inwave,1)
3574 yoffset = DimOffset(inwave,1)
3575 Emax= xoffset + xdelta*(rows-1)
3576 kmin = 0.5123*sqrt(Emax)*sin(pi/180*(yoffset))
3577 kmax = 0.5123*sqrt(Emax)*sin(pi/180*(yoffset+(columns-1)*ydelta))
3578 SetScale/I y kmin,kmax,"Ang^-1", outwave
3580 outwave = interp2D(inwave, x, 180/pi*asin(y/ (0.5123*sqrt(x))))
3581 outwave = (NumType(outwave)==2) ? 0 : outwave