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 strconstant
package_name =
"pearl_anglescan_tracker" 68 static strconstant
package_path =
"root:packages:pearl_anglescan_tracker:" 70 static strconstant
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
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
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
312 if (ParamIsDefault(xpdplot))
316 dfref savedf = getdatafolderdfr()
332 dfref savedf = getdatafolderdfr()
361 dfref savedf = getdatafolderdfr()
362 setdatafolder $(package_path)
367 KillWindow $graphname
373 dfref savedf = getdatafolderdfr()
374 setdatafolder $(package_path)
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()
406 setdatafolder $(package_path)
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()
436 setdatafolder $(package_path)
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
459 dfref savedf = getdatafolderdfr()
460 setdatafolder $(package_path)
467 svar red_func_name = reduction_func
468 svar red_params = reduction_params
470 variable nx = dimsize(image, 0)
471 string loc_params = red_params
472 wave /wave red_results = red_func(image, loc_params)
473 if (numpnts(red_results) < 1)
478 wave profile1 = red_results[0]
479 nx = numpnts(profile1)
490 if ((buf_count >= buf_size) || (nx > buf_width))
492 setscale /p x dimoffset(profile1,0), dimdelta(profile1,0), waveunits(profile1,0), buf_i
495 buf_i[][buf_count] = profile1[p]
496 buf_th[buf_count] = theta - theta_offset
497 buf_ti[buf_count] = -(tilt - tilt_offset)
498 buf_ph[buf_count] = phi - phi_offset
513 dfref savedf = getdatafolderdfr()
514 setdatafolder $(package_path)
526 duplicate /free /R=[0,buf_width-1][0,buf_count-1] buf_i, buf_n
527 duplicate /free /R=[0,buf_count-1] buf_th, w_th
528 duplicate /free /R=[0,buf_count-1] buf_ti, w_ti
529 duplicate /free /R=[0,buf_count-1] buf_ph, w_ph
535 if (dimoffset(buf_i,0) < -20)
541 make /n=1 /free d_polar, d_azi
544 d_azi = d_azi >= 360 ? d_azi - 360 : d_azi
565 dfref savedf = getdatafolderdfr()
566 setdatafolder $(package_path)
571 make /n=1 /free m_theta
572 make /n=1 /free m_tilt
573 make /n=1 /free m_phi
574 m_theta = theta - theta_offset
575 m_tilt = tilt - tilt_offset
577 m_phi = phi - phi_offset
580 wave detector_angle, detector_pol, detector_az, detector_rad
581 setscale /i x -range/2, +range/2, "°", detector_angle
585 redimension /n=(numpnts(detector_pol)) detector_rad
586 detector_rad = 2 * tan(detector_pol / 2 * pi / 180)
588 detector_az = detector_az >= 360 ? detector_az - 360 : detector_az
595 dfref savedf = getdatafolderdfr()
596 setdatafolder $(package_path)
603 svar tracename = detector_tracename
606 tracename = WMPolarAppendTrace(graphname, detector_rad, detector_az, 360)
607 ModifyGraph /w=$graphname lstyle($tracename)=0
608 ModifyGraph /w=$graphname lsize($tracename)=1.5
609 ModifyGraph /w=$graphname zColor($tracename)={detector_angle,*,*,RedWhiteBlue,0}
610 ColorScale /w=$graphname /C /N=text1 trace=$tracename
611 ColorScale /w=$graphname /C /N=text1 /F=0 /B=1 /A=LB /X=0.00 /Y=0.00
612 ColorScale /w=$graphname /C /N=text1 width=1.5, heightPct=20, frame=0.00
613 ColorScale /w=$graphname /C /N=text1 lblMargin=0
614 ColorScale /w=$graphname /C /N=text1 nticks=2, tickLen=2.00, tickThick=0.50
616 TextBox /w=$graphname /C /N=tb_manip /F=0 /B=1 /X=0.00 /Y=0.00 /E=2
"\\{\"manip = (%.1f, %.1f, %.1f)\", " 617 AppendText /w=$graphname /N=tb_manip /NOCR
"root:packages:pearl_anglescan_tracker:curTheta, " 618 AppendText /w=$graphname /N=tb_manip /NOCR
"root:packages:pearl_anglescan_tracker:curTilt, " 619 AppendText /w=$graphname /N=tb_manip /NOCR
"root:packages:pearl_anglescan_tracker:curPhi}" 622 DoWindow /T $graphname,
"Angle Scan Tracker" 625 ControlBar /w=$graphname 21
627 Button b_capture win=$graphname, fColor=(65535,65535,65535), fSize=10
628 Button b_capture win=$graphname, help={
"Start/stop capturing."}
629 PopupMenu pm_params win=$graphname, mode=0, value=
"load preferences;save preferences;reduction parameters;manipulator offsets", title=
"parameters" 631 PopupMenu pm_params win=$graphname, help={
"Load/save/edit data processing parameters"}
632 PopupMenu pm_data win=$graphname, mode=0, value=
"import;export;load file;save file", title=
"data" 634 PopupMenu pm_data win=$graphname, help={
"Load/save data from/to independent dataset or file"}
636 SetDrawLayer /w=$graphname ProgFront
637 SetDrawEnv /w=$graphname xcoord=rel, ycoord=rel
638 DrawPict /w=$graphname 0, 0, 1, 1, pict_tracker_sample
646 dfref savedf = getdatafolderdfr()
658 dfref savedf = getdatafolderdfr()
681 dfref savedf = getdatafolderdfr()
688 make /n=(1)/o arraydata, xscale, yscale
689 make /n=(1,1)/o image
690 variable /g ndimensions
691 variable /g arraysize0, arraysize1
693 variable /g colormode
694 string /g controls, monitors
695 string /g xunits, yunits
698 variable /g chidDetectorState = 0
699 variable /g chidArrayData = 0
700 variable /g chidXScale = 0
701 variable /g chidYScale = 0
702 variable /g chidNDimensions = 0
703 variable /g chidArraySize0 = 0
704 variable /g chidArraySize1 = 0
705 variable /g chidDataType = 0
706 variable /g chidColorMode = 0
707 variable /g chidLensMode = 0
708 variable /g chidTheta = 0
709 variable /g chidTilt = 0
710 variable /g chidPhi = 0
711 variable /g curDetectorState = 0
712 variable /g curLensMode = 0
713 variable /g curTheta = 0
714 variable /g curTilt = 0
715 variable /g curPhi = 0
716 variable /g acqTheta = 0
717 variable /g acqTilt = 0
718 variable /g acqPhi = 0
719 variable /g connected = 0
721 string epicsname = "X03DA-SCIENTA:"
722 string imagename = epicsname + "image1:"
723 string camname = epicsname + "cam1:"
724 string manipname = "X03DA-ES2-MA:"
729 pvOpen /Q chidDetectorState, camname +
"DetectorState_RBV" 730 pvOpen /Q chidLensMode, camname +
"LENS_MODE_RBV" 731 pvOpen /Q chidXScale, camname +
"CHANNEL_SCALE_RBV" 732 pvOpen /Q chidYScale, camname +
"SLICE_SCALE_RBV" 733 pvOpen /Q chidArrayData, imagename +
"ArrayData" 734 pvOpen /Q chidNDimensions, imagename +
"NDimensions_RBV" 735 pvOpen /Q chidArraySize0, imagename +
"ArraySize0_RBV" 736 pvOpen /Q chidArraySize1, imagename +
"ArraySize1_RBV" 737 pvOpen /Q chidDataType, imagename +
"DataType_RBV" 738 pvOpen /Q chidColorMode, imagename +
"ColorMode_RBV" 740 pvOpen /Q chidTheta, manipname +
"THT.RBV" 741 pvOpen /Q chidTilt, manipname +
"TLT.RBV" 742 pvOpen /Q chidPhi, manipname +
"PHI.RBV" 749 #elif exists("pvOpen") 751 pvOpen /T=(timeout) chidDetectorState, camname +
"DetectorState_RBV" 752 pvOpen /T=(timeout) chidLensMode, camname +
"LENS_MODE_RBV" 753 pvOpen /T=(timeout) chidXScale, camname +
"CHANNEL_SCALE_RBV" 754 pvOpen /T=(timeout) chidYScale, camname +
"SLICE_SCALE_RBV" 755 pvOpen /T=(timeout) chidArrayData, imagename +
"ArrayData" 756 pvOpen /T=(timeout) chidNDimensions, imagename +
"NDimensions_RBV" 757 pvOpen /T=(timeout) chidArraySize0, imagename +
"ArraySize0_RBV" 758 pvOpen /T=(timeout) chidArraySize1, imagename +
"ArraySize1_RBV" 759 pvOpen /T=(timeout) chidDataType, imagename +
"DataType_RBV" 760 pvOpen /T=(timeout) chidColorMode, imagename +
"ColorMode_RBV" 762 pvOpen /T=(timeout) chidTheta, manipname +
"THT.RBV" 763 pvOpen /T=(timeout) chidTilt, manipname +
"TLT.RBV" 764 pvOpen /T=(timeout) chidPhi, manipname +
"PHI.RBV" 771 #
if exists(
"pvMonitor")
783 print
"angle scan tracker: online" 785 print
"angle scan tracker: offline" 795 #if exists("pvClose") 796 nvar /z chid = $chid_var_name
797 if (nvar_exists(chid))
807 dfref savedf = GetDataFolderDFR()
831 print "angle scan tracker: offline"
842 STRUCT WMWinHookStruct &s
844 Variable hookResult = 0
864 dfref savedf = GetDataFolderDFR()
866 #if exists("pvGetWave") 896 pvGet chidNDimensions, ndimensions
897 pvGet chidArraySize0, arraysize0
898 pvGet chidArraySize1, arraysize1
899 pvGet chidDataType, datatype
900 pvGet chidColorMode, colormode
903 if (ndimensions != 2)
910 redimension /n=(arraysize0 * arraysize1) arraydata
911 redimension /n=(arraysize0, arraysize1) image
912 redimension /n=(arraysize0) xscale
913 redimension /n=(arraysize1) yscale
917 redimension /b arraydata, image
920 redimension /b/u arraydata, image
923 redimension /w arraydata, image
926 redimension /w/u arraydata, image
929 redimension /i arraydata, image
932 redimension /i/u arraydata, image
935 redimension /s arraydata, image
938 redimension /d arraydata, image
942 pvGetWave chidArrayData, arraydata
943 pvGetWave chidXScale, xscale
944 pvGetWave chidYScale, yscale
946 image = arraydata[p + q * arraysize0]
947 setscale /i x xscale[0], xscale[numpnts(xscale)-1], image
948 setscale /i y yscale[0], yscale[numpnts(yscale)-1], image
964 dfref savedf = GetDataFolderDFR()
968 nvar curDetectorState
977 if (curDetectorState == 1)
993 dfref savedf = GetDataFolderDFR()
997 nvar lensmode = curLensMode
998 nvar theta = curTheta
1017 setdatafolder savedf
1024 STRUCT WMButtonAction &ba
1026 switch( ba.eventCode )
1038 dfref savedf = getdatafolderdfr()
1044 capturing = !capturing
1047 Button b_capture win=$graphname, title="stop"
1049 Button b_capture win=$graphname, title="start"
1052 setdatafolder saveDF
1056 dfref savedf = getdatafolderdfr()
1063 Button b_capture win=$graphname, title="stop"
1065 Button b_capture win=$graphname, title="start"
1068 setdatafolder saveDF
1072 STRUCT WMPopupAction &pa
1074 switch( pa.eventCode )
1086 STRUCT WMPopupAction &pa
1106 dfref savedf = getdatafolderdfr()
1109 svar export_folderpath
1112 string folderpath = export_folderpath
1113 string nickname = ""
1114 variable format = export_format
1116 prompt folderpath, "Folder Path"
1117 prompt nickname, "Nick Name"
1118 prompt format, "Format", popup, "PEARL;XPDplot"
1120 doprompt "Export Parameters", folderpath, nickname, format
1123 export_folderpath = folderpath
1124 export_format = format
1126 newdatafolder /o $folderpath
1127 variable xpdplot = format == 2
1128 ast_export($folderpath, nickname, xpdplot=xpdplot)
1131 setdatafolder saveDF
1136 dfref savedf = getdatafolderdfr()
1139 svar export_folderpath
1140 string folderpath = export_folderpath
1141 string nickname = ""
1143 dfref dfBefore = GetDataFolderDFR()
1144 Execute /q/z "CreateBrowser prompt=\"Select wave from dataset\", showWaves=1, showVars=0, showStrs=0"
1145 dfref dfAfter = GetDataFolderDFR()
1146 SetDataFolder dfBefore
1148 SVAR list = S_BrowserList
1151 if ((flag != 0) && (ItemsInList(list) >= 1))
1152 string wname = StringFromList(0, list)
1155 dfref df = GetWavesDataFolderDFR(w)
1160 setdatafolder saveDF
1165 dfref savedf = getdatafolderdfr()
1171 setdatafolder saveDF
1176 dfref savedf = getdatafolderdfr()
1179 NewDataFolder /O/S load_data
1182 string wname = StringFromList(0, s_wavenames, ";")
1189 KillDataFolder /Z load_data
1191 setdatafolder saveDF
1195 STRUCT WMPopupAction &pa
1197 switch( pa.eventCode )
1209 STRUCT WMPopupAction &pa
1229 dfref savedf = getdatafolderdfr()
1232 svar pref_func = reduction_func
1233 svar pref_params = reduction_params
1235 string loc_func = pref_func
1236 string loc_params = pref_params
1241 setdatafolder saveDF
1245 dfref savedf = getdatafolderdfr()
1252 variable loc_theta = theta_offset
1253 variable loc_tilt = tilt_offset
1254 variable loc_phi = phi_offset
1256 prompt loc_theta, "theta offset"
1257 prompt loc_tilt, "tilt offset"
1258 prompt loc_phi, "phi offset"
1260 doprompt "manipulator offsets", loc_theta, loc_tilt, loc_phi
1262 theta_offset = loc_theta
1263 tilt_offset = loc_tilt
1264 phi_offset = loc_phi
1267 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()
threadsafe wave int_linbg_reduction(wave source, string *param)
linear-background subtracted integration reduction function.
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 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.
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.
threadsafe wave adh5_default_reduction(wave source, string *param)
function prototype for adh5_load_reduced_detector
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 const string package_name
package name is used as data folder name
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)