3 #pragma IgorVersion = 6.2 4 #pragma ModuleName = PearlAnglescanTracker 5 #include "pearl-area-profiles",
version > 1.04
6 #include
"pearl-area-import",
version > 1.05
7 #include
"pearl-scienta-preprocess",
version > 1.00
8 #include
"pearl-anglescan-process",
version >= 1.6
9 #include <New Polar Graphs>
66 static const string package_name =
"pearl_anglescan_tracker";
68 static const string package_path =
"root:packages:pearl_anglescan_tracker:";
70 static const string prefs_objects =
"projection;theta_offset;tilt_offset;phi_offset;reduction_func;reduction_params";
75 dfref savedf = GetDataFolderDFR()
80 if (nvar_exists(init_done))
91 variable /g init_done = 1
99 dfref savedf = getdatafolderdfr()
101 newdatafolder /o/s packages
102 newdatafolder /o/s $package_name
105 string /g graphname =
"graph_anglescan_tracker" 106 string /g dataname =
"tracker" 107 string /g projection =
"stereographic" 110 variable /g theta_offset = 0
111 variable /g tilt_offset = 0
112 variable /g phi_offset = 0
113 string /g reduction_func =
"int_linbg_reduction" 114 string /g reduction_params =
"Lcrop=0.1;Hcrop=0.1;Lsize=0.2;Hsize=0.2;Cpos=0.5;Csize=0.4" 117 string /g export_folderpath =
"root:" 118 variable /g export_format = 1
121 string /g detector_tracename
122 variable /g capturing = 0
123 variable /g buf_size = 0
124 variable /g buf_count = 0
125 variable /g buf_width = 0
128 string path = FunctionPath(
"")
129 path = ParseFilePath(1, path,
":", 1, 0) +
"tracker-sample-picture.png" 130 LoadPict /O/Q path, pict_tracker_sample
140 dfref saveDF = GetDataFolderDFR()
142 string fullPath = SpecialDirPath(
"Packages", 0, 0, 0)
144 NewPath/O/C/Q tempPackagePrefsPath, fullPath
145 fullPath +=
":preferences.pxp" 147 SetDataFolder root:packages
148 SetDataFolder $package_name
151 KillPath/Z tempPackagePrefsPath
164 dfref saveDF = GetDataFolderDFR()
168 NewDataFolder /O/S packages
169 NewDataFolder /O/S $package_name
170 string fullPath = SpecialDirPath(
"Packages", 0, 0, 0)
173 GetFileFolderInfo /Q /Z fullPath
175 fullPath +=
":preferences.pxp" 176 GetFileFolderInfo /Q /Z fullPath
178 LoadData /O /R /Q fullPath
211 variable
ast_prepare(variable theta_offset = defaultValue, variable tilt_offset = defaultValue, variable phi_offset = defaultValue){
212 variable theta_offset
216 dfref savedf = getdatafolderdfr()
219 if (!ParamIsDefault(theta_offset))
220 nvar v_theta_offset = theta_offset
221 v_theta_offset = theta_offset
223 if (!ParamIsDefault(tilt_offset))
224 nvar v_tilt_offset = tilt_offset
225 v_tilt_offset = tilt_offset
227 if (!ParamIsDefault(phi_offset))
228 nvar v_phi_offset = phi_offset
229 v_phi_offset = phi_offset
242 wave values = $(dataname +
"_i")
243 values[numpnts(values) - 1] = 0
262 string reduction_func
263 string reduction_params
265 dfref savedf = getdatafolderdfr()
268 svar red_func = reduction_func
269 svar red_params = reduction_params
271 red_func = reduction_func
272 red_params = reduction_params
285 variable
ast_add_image(wave image, variable theta, variable tilt, variable phi){
307 variable
ast_export(dfref folder,
string nickname, variable xpdplot = defaultValue){
312 if (ParamIsDefault(xpdplot))
316 dfref savedf = getdatafolderdfr()
332 dfref savedf = getdatafolderdfr()
361 dfref savedf = getdatafolderdfr()
367 KillWindow $graphname
373 dfref savedf = getdatafolderdfr()
382 make /n=(1,1) /o buf_i
383 make /n=(1) /o buf_th, buf_ph, buf_ti
390 wave values = $(dataname +
"_i")
391 values[numpnts(values) - 1] = 0
405 dfref savedf = getdatafolderdfr()
412 variable new_size = buf_size + 91
413 buf_width = num_slices
420 redimension /n=(buf_width,new_size) buf_i
421 redimension /n=(new_size) buf_th, buf_ph, buf_ti
423 buf_i[][buf_size, new_size-1] = nan
424 buf_th[buf_size, new_size-1] = nan
425 buf_ph[buf_size, new_size-1] = nan
426 buf_ti[buf_size, new_size-1] = nan
435 dfref savedf = getdatafolderdfr()
438 make /n=31 /o detector_angle, detector_pol, detector_az, detector_rad
439 setscale /i x -30, 30,
"°", detector_angle, detector_pol, detector_az, detector_rad
453 static variable
add_image_data(wave image, variable theta, variable tilt, variable phi){
459 dfref savedf = getdatafolderdfr()
467 svar red_func_name = reduction_func
468 svar red_params = reduction_params
470 variable nx = dimsize(image, 0)
471 make /n=(nx) /free profile1, profile2
472 string loc_params = red_params
473 red_func(image, profile1, profile2, loc_params)
474 nx = numpnts(profile1)
485 if ((buf_count >= buf_size) || (nx > buf_width))
487 setscale /p x dimoffset(profile1,0), dimdelta(profile1,0), waveunits(profile1,0), buf_i
490 buf_i[][buf_count] = profile1[p]
491 buf_th[buf_count] = theta - theta_offset
492 buf_ti[buf_count] = -(tilt - tilt_offset)
493 buf_ph[buf_count] = phi - phi_offset
508 dfref savedf = getdatafolderdfr()
521 duplicate /free /R=[0,buf_width-1][0,buf_count-1] buf_i, buf_n
522 duplicate /free /R=[0,buf_count-1] buf_th, w_th
523 duplicate /free /R=[0,buf_count-1] buf_ti, w_ti
524 duplicate /free /R=[0,buf_count-1] buf_ph, w_ph
530 if (dimoffset(buf_i,0) < -20)
536 make /n=1 /free d_polar, d_azi
539 d_azi = d_azi >= 360 ? d_azi - 360 : d_azi
554 static variable
update_detector(variable theta, variable tilt, variable phi, variable range){
560 dfref savedf = getdatafolderdfr()
566 make /n=1 /free m_theta
567 make /n=1 /free m_tilt
568 make /n=1 /free m_phi
569 m_theta = theta - theta_offset
570 m_tilt = tilt - tilt_offset
572 m_phi = phi - phi_offset
575 wave detector_angle, detector_pol, detector_az, detector_rad
576 setscale /i x -range/2, +range/2,
"°", detector_angle
580 redimension /n=(numpnts(detector_pol)) detector_rad
581 detector_rad = 2 * tan(detector_pol / 2 * pi / 180)
583 detector_az = detector_az >= 360 ? detector_az - 360 : detector_az
590 dfref savedf = getdatafolderdfr()
598 svar tracename = detector_tracename
601 tracename = WMPolarAppendTrace(graphname, detector_rad, detector_az, 360)
602 ModifyGraph /w=$graphname lstyle($tracename)=0
603 ModifyGraph /w=$graphname lsize($tracename)=1.5
604 ModifyGraph /w=$graphname zColor($tracename)={detector_angle,*,*,RedWhiteBlue,0}
605 ColorScale /w=$graphname /C /N=text1 trace=$tracename
606 ColorScale /w=$graphname /C /N=text1 /F=0 /B=1 /A=LB /X=0.00 /Y=0.00
607 ColorScale /w=$graphname /C /N=text1 width=1.5, heightPct=20, frame=0.00
608 ColorScale /w=$graphname /C /N=text1 lblMargin=0
609 ColorScale /w=$graphname /C /N=text1 nticks=2, tickLen=2.00, tickThick=0.50
611 TextBox /w=$graphname /C /N=tb_manip /F=0 /B=1 /X=0.00 /Y=0.00 /E=2
"\\{\"manip = (%.1f, %.1f, %.1f)\", " 612 AppendText /w=$graphname /N=tb_manip /NOCR
"root:packages:pearl_anglescan_tracker:curTheta, " 613 AppendText /w=$graphname /N=tb_manip /NOCR
"root:packages:pearl_anglescan_tracker:curTilt, " 614 AppendText /w=$graphname /N=tb_manip /NOCR
"root:packages:pearl_anglescan_tracker:curPhi}" 617 DoWindow /T $graphname,
"Angle Scan Tracker" 620 ControlBar /w=$graphname 21
622 Button b_capture win=$graphname, fColor=(65535,65535,65535), fSize=10
623 Button b_capture win=$graphname, help={
"Start/stop capturing."}
624 PopupMenu pm_params win=$graphname, mode=0, value=
"load preferences;save preferences;reduction parameters;manipulator offsets", title=
"parameters" 626 PopupMenu pm_params win=$graphname, help={
"Load/save/edit data processing parameters"}
627 PopupMenu pm_data win=$graphname, mode=0, value=
"import;export;load file;save file", title=
"data" 629 PopupMenu pm_data win=$graphname, help={
"Load/save data from/to independent dataset or file"}
631 SetDrawLayer /w=$graphname ProgFront
632 SetDrawEnv /w=$graphname xcoord=rel, ycoord=rel
633 DrawPict /w=$graphname 0, 0, 1, 1, pict_tracker_sample
641 dfref savedf = getdatafolderdfr()
653 dfref savedf = getdatafolderdfr()
676 dfref savedf = getdatafolderdfr()
683 make /n=(1)/o arraydata, xscale, yscale
684 make /n=(1,1)/o image
685 variable /g ndimensions
686 variable /g arraysize0, arraysize1
688 variable /g colormode
689 string /g controls, monitors
690 string /g xunits, yunits
693 variable /g chidDetectorState = 0
694 variable /g chidArrayData = 0
695 variable /g chidXScale = 0
696 variable /g chidYScale = 0
697 variable /g chidNDimensions = 0
698 variable /g chidArraySize0 = 0
699 variable /g chidArraySize1 = 0
700 variable /g chidDataType = 0
701 variable /g chidColorMode = 0
702 variable /g chidLensMode = 0
703 variable /g chidTheta = 0
704 variable /g chidTilt = 0
705 variable /g chidPhi = 0
706 variable /g curDetectorState = 0
707 variable /g curLensMode = 0
708 variable /g curTheta = 0
709 variable /g curTilt = 0
710 variable /g curPhi = 0
711 variable /g acqTheta = 0
712 variable /g acqTilt = 0
713 variable /g acqPhi = 0
714 variable /g connected = 0
716 string epicsname =
"X03DA-SCIENTA:" 717 string imagename = epicsname +
"image1:" 718 string camname = epicsname +
"cam1:" 719 string manipname =
"X03DA-ES2-MA:" 724 pvOpen /Q chidDetectorState, camname +
"DetectorState_RBV" 725 pvOpen /Q chidLensMode, camname +
"LENS_MODE_RBV" 726 pvOpen /Q chidXScale, camname +
"CHANNEL_SCALE_RBV" 727 pvOpen /Q chidYScale, camname +
"SLICE_SCALE_RBV" 728 pvOpen /Q chidArrayData, imagename +
"ArrayData" 729 pvOpen /Q chidNDimensions, imagename +
"NDimensions_RBV" 730 pvOpen /Q chidArraySize0, imagename +
"ArraySize0_RBV" 731 pvOpen /Q chidArraySize1, imagename +
"ArraySize1_RBV" 732 pvOpen /Q chidDataType, imagename +
"DataType_RBV" 733 pvOpen /Q chidColorMode, imagename +
"ColorMode_RBV" 735 pvOpen /Q chidTheta, manipname +
"THT.RBV" 736 pvOpen /Q chidTilt, manipname +
"TLT.RBV" 737 pvOpen /Q chidPhi, manipname +
"PHI.RBV" 744 #elif exists(
"pvOpen")
746 pvOpen /T=(timeout) chidDetectorState, camname +
"DetectorState_RBV" 747 pvOpen /T=(timeout) chidLensMode, camname +
"LENS_MODE_RBV" 748 pvOpen /T=(timeout) chidXScale, camname +
"CHANNEL_SCALE_RBV" 749 pvOpen /T=(timeout) chidYScale, camname +
"SLICE_SCALE_RBV" 750 pvOpen /T=(timeout) chidArrayData, imagename +
"ArrayData" 751 pvOpen /T=(timeout) chidNDimensions, imagename +
"NDimensions_RBV" 752 pvOpen /T=(timeout) chidArraySize0, imagename +
"ArraySize0_RBV" 753 pvOpen /T=(timeout) chidArraySize1, imagename +
"ArraySize1_RBV" 754 pvOpen /T=(timeout) chidDataType, imagename +
"DataType_RBV" 755 pvOpen /T=(timeout) chidColorMode, imagename +
"ColorMode_RBV" 757 pvOpen /T=(timeout) chidTheta, manipname +
"THT.RBV" 758 pvOpen /T=(timeout) chidTilt, manipname +
"TLT.RBV" 759 pvOpen /T=(timeout) chidPhi, manipname +
"PHI.RBV" 766 #
if exists(
"pvMonitor")
778 print
"angle scan tracker: online" 780 print
"angle scan tracker: offline" 790 #if exists("pvClose") 791 nvar /z chid = $chid_var_name
792 if (nvar_exists(chid))
802 dfref savedf = GetDataFolderDFR()
821 print
"angle scan tracker: offline" 832 STRUCT WMWinHookStruct &s
834 Variable hookResult = 0
854 dfref savedf = GetDataFolderDFR()
856 #
if exists(
"pvGetWave")
886 pvGet chidNDimensions, ndimensions
887 pvGet chidArraySize0, arraysize0
888 pvGet chidArraySize1, arraysize1
889 pvGet chidDataType, datatype
890 pvGet chidColorMode, colormode
893 if (ndimensions != 2)
900 redimension /n=(arraysize0 * arraysize1) arraydata
901 redimension /n=(arraysize0, arraysize1) image
902 redimension /n=(arraysize0) xscale
903 redimension /n=(arraysize1) yscale
907 redimension /b arraydata, image
910 redimension /b/u arraydata, image
913 redimension /w arraydata, image
916 redimension /w/u arraydata, image
919 redimension /i arraydata, image
922 redimension /i/u arraydata, image
925 redimension /s arraydata, image
928 redimension /d arraydata, image
932 pvGetWave chidArrayData, arraydata
933 pvGetWave chidXScale, xscale
934 pvGetWave chidYScale, yscale
936 image = arraydata[p + q * arraysize0]
937 setscale /i x xscale[0], xscale[numpnts(xscale)-1], image
938 setscale /i y yscale[0], yscale[numpnts(yscale)-1], image
954 dfref savedf = GetDataFolderDFR()
958 nvar curDetectorState
967 if (curDetectorState == 1)
983 dfref savedf = GetDataFolderDFR()
987 nvar lensmode = curLensMode
988 nvar theta = curTheta
1007 setdatafolder savedf
1014 STRUCT WMButtonAction &ba
1016 switch( ba.eventCode )
1028 dfref savedf = getdatafolderdfr()
1034 capturing = !capturing
1037 Button b_capture win=$graphname, title=
"stop" 1039 Button b_capture win=$graphname, title=
"start" 1042 setdatafolder saveDF
1046 dfref savedf = getdatafolderdfr()
1053 Button b_capture win=$graphname, title=
"stop" 1055 Button b_capture win=$graphname, title=
"start" 1058 setdatafolder saveDF
1062 STRUCT WMPopupAction &pa
1064 switch( pa.eventCode )
1076 STRUCT WMPopupAction &pa
1096 dfref savedf = getdatafolderdfr()
1099 svar export_folderpath
1102 string folderpath = export_folderpath
1103 string nickname =
"" 1104 variable format = export_format
1106 prompt folderpath,
"Folder Path" 1107 prompt nickname,
"Nick Name" 1108 prompt format,
"Format", popup,
"PEARL;XPDplot" 1110 doprompt
"Export Parameters", folderpath, nickname, format
1113 export_folderpath = folderpath
1114 export_format = format
1116 newdatafolder /o $folderpath
1117 variable xpdplot = format == 2
1118 ast_export($folderpath, nickname, xpdplot=xpdplot)
1121 setdatafolder saveDF
1126 dfref savedf = getdatafolderdfr()
1129 svar export_folderpath
1130 string folderpath = export_folderpath
1131 string nickname =
"" 1133 dfref dfBefore = GetDataFolderDFR()
1134 Execute /q/z
"CreateBrowser prompt=\"Select wave from dataset\", showWaves=1, showVars=0, showStrs=0" 1135 dfref dfAfter = GetDataFolderDFR()
1136 SetDataFolder dfBefore
1138 SVAR list = S_BrowserList
1141 if ((flag != 0) && (ItemsInList(list) >= 1))
1142 string wname = StringFromList(0, list)
1145 dfref df = GetWavesDataFolderDFR(w)
1150 setdatafolder saveDF
1155 dfref savedf = getdatafolderdfr()
1161 setdatafolder saveDF
1166 dfref savedf = getdatafolderdfr()
1169 NewDataFolder /O/S load_data
1172 string wname = StringFromList(0, s_wavenames,
";")
1179 KillDataFolder /Z load_data
1181 setdatafolder saveDF
1185 STRUCT WMPopupAction &pa
1187 switch( pa.eventCode )
1199 STRUCT WMPopupAction &pa
1219 dfref savedf = getdatafolderdfr()
1222 svar pref_func = reduction_func
1223 svar pref_params = reduction_params
1225 string loc_func = pref_func
1226 string loc_params = pref_params
1231 setdatafolder saveDF
1235 dfref savedf = getdatafolderdfr()
1242 variable loc_theta = theta_offset
1243 variable loc_tilt = tilt_offset
1244 variable loc_phi = phi_offset
1246 prompt loc_theta,
"theta offset" 1247 prompt loc_tilt,
"tilt offset" 1248 prompt loc_phi,
"phi offset" 1250 doprompt
"manipulator offsets", loc_theta, loc_tilt, loc_phi
1252 theta_offset = loc_theta
1253 tilt_offset = loc_tilt
1254 phi_offset = loc_phi
1257 setdatafolder saveDF
variable ast_set_processing(string reduction_func, string reduction_params)
set the data processing parameters
variable ast_close()
stop tracker, close graph, release data structures.
variable normalize_strip_theta(wave strip, wave theta, variable theta_offset=defaultValue, variable smooth_method=defaultValue, variable smooth_factor=defaultValue, variable check=defaultValue)
divide the strip by the average polar distribution.
static variable epics_connect()
connect the angle scan tracker to EPICS
static variable update_detector_graph()
static variable bp_capture(WMButtonAction *ba)
variable crop_strip(wave strip, variable xlo, variable xhi)
crop a strip at the sides.
variable make_hemi_grid(variable npol, string nickname, variable xpdplot=defaultValue)
create a hemispherical, constant solid angle grid
variable hemi_add_anglescan(string nickname, wave values, wave polar, wave azi, wave weights=defaultValue)
add an arbitrary angle scan to a hemispherical scan grid.
static variable setup_detector()
static variable pmp_parameters(WMPopupAction *pa)
string get_hemi_prefix(wave w)
finds the prefix given any hemi wave
string display_hemi_scan(string nickname, variable projection=defaultValue, variable graphtype=defaultValue, variable do_ticks=defaultValue, variable do_grids=defaultValue, string graphname=defaultValue)
display a plot of a hemispherical angle scan.
static variable epics_disconnect()
static variable update_data_graph()
variable ast_setup()
set up data structures, display graph, and try to connect to analyser.
variable convert_angles_ttpd2polar(wave theta, wave tilt, wave phi, wave data, wave polar, wave azi)
convert angles from TTPA (theta-tilt-phi-analyser) scheme to polar coordinates.
static const string prefs_objects
semicolon-separated list of persistent variable, string, and wave names
static variable setup_graph()
create the graph window.
static variable import_tracker_data()
import tracker data (with prompt)
variable clear_hemi_grid(string nickname)
clear a hemispherical scan grid
static variable extend_data(variable num_slices)
extend the data buffer for the next polar scan
static variable pmp_data_mouseup(WMPopupAction *pa)
variable ast_prepare(variable theta_offset=defaultValue, variable tilt_offset=defaultValue, variable phi_offset=defaultValue)
prepare for new measurement and clear the data buffer.
static variable setup_data()
static variable epics_disconnect_chid(string chid_var_name)
static variable AfterCompiledHook()
initialize package data once when the procedure is first loaded
static variable save_prefs()
save persistent package data to the preferences file.
static const string package_name
static variable edit_offsets()
static variable add_image_data(wave image, variable theta, variable tilt, variable phi)
reduce a detector image and add the result to the data buffer.
static const string package_path
data folder path
static variable load_tracker_data()
import tracker data from file (with prompt)
static variable save_tracker_data()
save tracker data to file (with prompt)
static variable update_capture()
variable ast_export(dfref folder, string nickname, variable xpdplot=defaultValue)
export tracker data to a separate, independent data set.
variable ast_update_detector(variable theta, variable tilt, variable phi, variable range)
update the current position indicator.
threadsafe variable adh5_default_reduction(wave source, wave dest1, wave dest2, string *param)
function prototype for adh5_load_reduced_detector
static variable process_image_data()
process the data buffer to generate the tracker dataset.
variable save_hemi_scan(string nickname, string pathname, string filename)
save a hemispherical scan to an Igor text file
static variable IgorQuitHook(string app)
disconnect EPICS channels before Igor quits.
variable ast_callback_manip(variable chan)
callback function for new manipulator position from EPICS.
variable ast_callback_detector(variable chan)
callback function for new detector state from EPICS.
static variable pmp_parameters_mouseup(WMPopupAction *pa)
variable prompt_func_params(string func_name, string *func_param)
variable convert_angles_ttpa2polar(wave theta, wave tilt, wave phi, wave analyser, wave polar, wave azi)
convert angles from TTPA (theta-tilt-phi-analyser) scheme to polar coordinates.
variable ast_add_image(wave image, variable theta, variable tilt, variable phi)
process and add a detector image to the tracker scan.
static variable pmp_data(WMPopupAction *pa)
variable duplicate_hemi_scan(string source_nickname, dfref dest_folder, string dest_nickname, variable xpdplot=defaultValue)
duplicate a hemispherical scan dataset.
static variable init_package()
static variable ast_window_hook(WMWinHookStruct *s)
window hook
static variable edit_reduction_params()
static variable toggle_capture()
variable ast_callback_data(variable chan)
callback function for new analyser data from EPICS.
variable ast_import(string nickname)
import tracker data from an existing angle scan dataset.
static variable load_prefs()
load persistent package data from the preferences file.
variable normalize_strip_x(wave strip, variable smooth_method=defaultValue, variable smooth_factor=defaultValue, variable check=defaultValue)
divide the strip by the average X distribution.
static variable update_detector(variable theta, variable tilt, variable phi, variable range)
update the current position indicator.
static variable export_tracker_data()
export tracker data (with prompt)