-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTiledRSoXS.ipf
4069 lines (3552 loc) · 130 KB
/
TiledRSoXS.ipf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma TextEncoding = "UTF-8"
#pragma rtGlobals=3 // Use modern global access method and strict wave access
#pragma DefaultTab={3,20,4} // Set default tab width in Igor Pro 9 and later
function init_tiled_rsoxs()
dfref foldersave = getdataFolderDFR()
setdatafolder root:
newdatafolder /o/s Packages
newdatafolder /o/s RSoXS_Tiled
get_apikey()
string /g baseurl = "https://tiled.nsls2.bnl.gov/api/v1/"
string /g activeurl = "rsoxs/raw"
string /g output = ""
string /g preurl = "search/"
string /g posturl = "?fields=metadata&page%5Boffset%5D=0&page%5Blimit%5D=100&omit_links=true"
variable /g offset = 0
variable /g max_result
variable /g num_page = 28
variable /g search_type = 5
variable /g live_mode = 0
variable /g tab_mode = 2
string /g key_search = "sample_id"
string /g value_search = "P3HT"
string /g comparison_type_search = "<"
string /g primary_color="BlueRedGreen"
string /g monitor_color="BlueRedGreen"
string /g primary_x_axis="time"
string /g colortab = "Terrain"
variable /g logimage = 1
variable /g min_val = 100
variable /g max_val = 100000
variable /g leftmin = nan
variable /g leftmax = nan
variable /g botmin = nan
variable /g botmax = nan
variable /g clicked_ticks = nan
variable /g primary_plot_indv_axes
variable /g monitor_plot_indv_axes
variable /g monitor_plot_subxoffset
variable /g primary_plot_logy
variable /g monitor_plot_logy
variable /g primary_plot_logx
//string /g monitor_list = ""
//string /g primary_list = ""
make /n=(0,6) /t /o Plans_list
make /n=(0) /o plans_sel_wave
make /n=6 /t/o plans_col_wave = {"scan_id","plan","sample","pnts","time","uid"}
make /n=0 /t/o search_list, plotted_monitors, plotted_primary, image_list, primary_list_wave, monitor_list_wave, metadata_display, baseline_display
make /n=(0,4) /t /o search_settings
make /n=0 /o search_sel_list, image_sel_list, primary_sel_list, monitor_sel_list
dowindow /k RSoXSTiled
Execute "RSoXSTiled()"
setdatafolder foldersave
SetWindow RSoXSTiled,hook(image_updates)=Tiled_RSoXS_window_hook
end
function update_list([variable skip_scan_update, variable only_last])
skip_scan_update = paramisdefault(skip_scan_update)? 0 : skip_scan_update
only_last = paramisdefault(only_last)? 0 : only_last
svar /z output = root:Packages:RSoXS_Tiled:output
dfref FOLDERSAVE = getdatafolderDFR()
setdatafolder root:Packages:RSoXS_Tiled
string /g timings
variable start_time
variable elapsed_time
string url = get_url_search()
if(strlen(url)>5)
start_time = ticks
output = FetchURL(url)
elapsed_time = (ticks-start_time)/60
timings += "\n update_list;"+url+";1;" + num2str(elapsed_time)
//URLRequest /z/time=1 url=url, method=get
if(strlen(output)<500)
// try again - server seems to ocassionally hickup
URLRequest /z/time=30 url=url, method=get
if(v_flag)
setdatafolder foldersave
return v_flag
endif
output = S_serverResponse
endif
JSONXOP_Parse output
if(v_flag)
return v_flag
endif
variable jsonId = V_value
make /n=0 /o /T textwave
JSONXOP_Getvalue /q/z/v jsonId, "meta/count"
nvar /z max_result
max_result = v_value
nvar /z offset
nvar /z num_page
offset = max(offset,0)
if(offset > max_result-num_page)
offset = max(0,max_result-num_page)
URLRequest /z/time=30 url=get_url_search(), method=get
if(v_flag)
// try again - server seems to ocassionally hickup
URLRequest /z/time=30 url=get_url_search(), method=get
if(v_flag)
setdatafolder foldersave
return v_flag
endif
endif
output = S_serverResponse
JSONXOP_release jsonId
JSONXOP_Parse output
if(v_flag)
setdatafolder foldersave
return v_flag
endif
jsonId = V_value
make /n=0 /o /T textwave
JSONXOP_Getvalue /q/z/v jsonId, "meta/count"
max_result = v_value
endif
// how many points
JSONXOP_GetArraySize /q/z jsonId, "/data"
if(v_flag)
JSONXOP_Release jsonID
return -1
endif
variable result_num = v_value
make /n=(result_num,6) /t /o Plans_list
make /n=(result_num) /o plans_sel_wave, has_darks, done
make /n=6 /t/o plans_col_wave = {"scan_id","plan","sample","pnts","time","uid"}
make /o/t /n=(result_num) stream_names, metadata_string = "", metadata_display
variable i,j, keytype, duration
string tempstring, keystring, datastring
for(i=result_num-1;i>=0;i-=1)
// get the scan_id
string prefix = "/data/"+num2str(i)+"/attributes/"
JSONXOP_Getvalue /q/z/v jsonId, prefix + "metadata/start/scan_id"
variable scan_id = v_value
JSONXOP_Getvalue /q/z/t jsonId, prefix + "metadata/start/uid"
string uid = s_value
// get the stop status
JSONXOP_Getvalue /q/z/t jsonId, prefix + "metadata/stop/exit_status"
string stopstatus
if(v_flag)
stopstatus = "..."
done[i]=0
else
stopstatus = ""
done[i]=1
endif
// get the number of primary events
JSONXOP_Getvalue /q/z/v jsonId, prefix + "metadata/start/num_points"
variable count
if(v_flag)
count = nan
else
count = v_value
endif
// get the number of dark events
JSONXOP_Getvalue /q/z/v jsonId, prefix + "metadata/stop/num_events/dark"
if(v_flag)
has_darks[i] = 1
else
has_darks[i] = v_value
endif
// get the number of duration
//JSONXOP_Getvalue /q/z/v jsonId, prefix + "metadata/summary/duration"
//if(v_flag)
// has_darks[i] = 1
//else
// has_darks[i] = v_value
//endif
// get the plan name
JSONXOP_Getvalue /q/z/t jsonId, prefix + "metadata/start/sample_name"
string sample
if(v_flag)
sample = ""
else
sample = s_value
endif
JSONXOP_Getvalue /q/z/t jsonId, prefix + "metadata/start/plan_name"
string plan_name
if(v_flag)
plan_name = ""
else
plan_name = s_value
endif
plans_list[i][0] = num2str(scan_id,"%.15g")
plans_list[i][1] = plan_name
plans_list[i][2] = sample
plans_list[i][3] = num2str(count) + stopstatus
plans_list[i][4] = num2str(duration)
plans_list[i][5] = uid
// get monitor names
JSONXOP_GetValue /free /TWAV=tempstreams jsonId,prefix + "metadata/summary/stream_names"
if(numpnts(tempstreams)>0)
wfprintf tempstring, "%s;" tempstreams
stream_names[i] = tempstring
else
stream_names[i]=""
endif
// get 0 level metadata as a key:value; liststring
JSoNXOP_GetKeys /free/q/z jsonID, prefix + "metadata/start", tempwave
//wave /t tempwave
for(j=0;j<numpnts(tempwave);j+=1)
keystring = tempwave[j]
JSONXOP_GetType jsonID, prefix + "metadata/start/"+ keystring
keytype = v_value
SWITCH(keytype)
case 0: //object - another dictionary. ignore it for now
break
case 1: // array - tricky in case array is of weird kinds - ignore it for now
break
case 2: // Numeric - get the value, convert to string
JSONXOP_Getvalue /v jsonID, prefix + "metadata/start/"+ keystring
metadata_string[i] += keystring + ":" + num2str(v_value) + ";"
break
case 3: //string
JSONXOP_Getvalue /t jsonID, prefix + "metadata/start/"+ keystring
metadata_string[i] += keystring + ":" + s_value + ";"
break
case 4: // Boolean - get the value, convert to string
JSONXOP_Getvalue /v jsonID, prefix + "metadata/start/"+ keystring
metadata_string[i] += keystring + ":" + num2str(v_value) + ";"
break
default:
break
endswitch
endfor
// get primary url (we already have the info we need.
// something like this:
// https://tiled.nsls2.bnl.gov/api/array/full/rsoxs/3fa0ed34-8a1b-41c4-9ba8-e62643a7267f/primary/data/data_vars/
// (the rest looks like this:)Small Angle CCD Detector_stats1_total/variable?format=application/octet-stream
// loading will require listing the contents of /data_vars/ and getting each (in parallel)
endfor
//make metadata_display which has the same number of columns as metadata_string, and the number of rows as the unique keys in metadata_string
string uniquekeys="", key
for(i=0;i<dimsize(metadata_string,0);i++)
for(j=0;j<itemsinlist(metadata_string[i]);j++)
key = stringfromlist(0,stringfromlist(j,metadata_string[i]),":")
if(whichListItem(key,uniquekeys)<0)
uniquekeys += key + ";"
endif
endfor
endfor
redimension /n=(itemsinlist(uniquekeys),dimsize(metadata_string,0)+1) metadata_display
metadata_display[][1,] = stringbykey(stringfromlist(p,uniquekeys),metadata_string[q-1])
metadata_display[][0] = stringfromlist(p,uniquekeys)
setdatafolder foldersave
JSONXOP_Release jsonID
endif
return 0
end
function /s get_url_search()
svar /z apikey = root:Packages:RSoXS_Tiled:apikey
svar /z baseurl = root:Packages:RSoXS_Tiled:baseurl
svar /z activeurl = root:Packages:RSoXS_Tiled:activeurl
svar /z preurl = root:Packages:RSoXS_Tiled:preurl
svar /z posturl = root:Packages:RSoXS_Tiled:posturl
nvar /z offset = root:Packages:RSoXS_Tiled:offset
nvar /z num_page = root:Packages:RSoXS_Tiled:num_page
nvar /z max_result = root:Packages:RSoXS_Tiled:max_result
wave /t searchlist = root:Packages:RSoXS_Tiled:search_list
offset = max(offset,0)
posturl = "?fields=metadata"
variable i
for(i=0;i<numpnts(searchlist);i++)
posturl += "&" + searchlist[i]
endfor
posturl += "&page%5Boffset%5D=" + num2str(offset,"%u") + "&page%5Blimit%5D="+num2str(num_page)+"&omit_links=true"
if(svar_Exists(apikey) && svar_Exists(baseurl) && svar_Exists(activeurl) && svar_Exists(preurl) && svar_Exists(posturl))
return baseurl + preurl + activeurl + posturl + apikey
else
return ""
endif
end
Window RSoXSTiled() : Panel
PauseUpdate; Silent 1 // building window...
NewPanel /K=1 /W=(136,58,1832,908)
SetDrawLayer UserBack
ListBox list0,pos={5.00,266.00},size={386.00,573.00},proc=scanBoxProc
ListBox list0,listWave=root:Packages:RSoXS_Tiled:Plans_list
ListBox list0,selWave=root:Packages:RSoXS_Tiled:plans_sel_wave
ListBox list0,titleWave=root:Packages:RSoXS_Tiled:plans_col_wave,mode=9
ListBox list0,widths={37,74,147,48,26,37},userColumnResize=1
SetVariable requested_results_val,pos={71.00,242.00},size={43.00,18.00},bodyWidth=43,proc=SetVarProc,format="%d"
SetVariable requested_results_val,title=" "
SetVariable requested_results_val,limits={-inf,inf,0},value=root:Packages:RSoXS_Tiled:offset
Button get_URL1,pos={143.00,241.00},size={24.00,21.00},proc=page_toend
Button get_URL1,title=">>"
Button get_URL2,pos={119.00,241.00},size={22.00,21.00},proc=page_forward
Button get_URL2,title=">"
Button get_URL3,pos={15.00,241.00},size={24.00,21.00},proc=page_tobeginning
Button get_URL3,title="<<"
Button get_URL4,pos={42.00,241.00},size={22.00,21.00},proc=page_backward
Button get_URL4,title="<"
SetVariable requested_results_val1,pos={169.00,243.00},size={43.00,18.00},bodyWidth=43,format="%d"
SetVariable requested_results_val1,title=" ",labelBack=(61423,61423,61423)
SetVariable requested_results_val1,frame=0,valueColor=(21845,21845,21845)
SetVariable requested_results_val1,limits={-inf,inf,0},value=root:Packages:RSoXS_Tiled:max_result,noedit=1
Button Tiled_QANT_but,pos={1521.00,3.00},size={150,23.00},proc=Tiled_to_QANT
Button Tiled_QANT_but,title="Import NEXAFS to QANT"
TabControl View_Tab,pos={397.00,8.00},size={1292.00,835.00},proc=TabProc
TabControl View_Tab,tabLabel(0)="Monitors",tabLabel(1)="Primary"
TabControl View_Tab,tabLabel(2)="Images",tabLabel(3)="Baseline"
TabControl View_Tab,tabLabel(4)="Metadata",value=2
Button deselect_all_monitors,pos={416.00,382.00},size={80.00,21.00},disable=1,proc=deselect_monnitor_but_proc
Button deselect_all_monitors,title="deselect all"
Button Select_all_Monitors,pos={513.00,381.00},size={80.00,22.00},disable=1,proc=select_all_monitor_but_proc
Button Select_all_Monitors,title="select all"
SetVariable Catalog_select,pos={9.00,27.00},size={108.00,18.00},bodyWidth=60
SetVariable Catalog_select,title="Catalog:"
SetVariable Catalog_select,value=root:Packages:RSoXS_Tiled:activeurl
SetVariable Server_select,pos={17.00,7.00},size={218.00,18.00},bodyWidth=179
SetVariable Server_select,title="Server:"
SetVariable Server_select,value=root:Packages:RSoXS_Tiled:baseurl
ListBox Catalog_Searches,pos={27.00,130.00},size={287.00,102.00},proc=search_listbox_proc
ListBox Catalog_Searches,listWave=root:Packages:RSoXS_Tiled:search_list
ListBox Catalog_Searches,selWave=root:Packages:RSoXS_Tiled:search_sel_list
ListBox Catalog_Searches,mode=9,widths={500},userColumnResize=1
SetVariable Key_select,pos={34.00,80.00},size={269.00,18.00},bodyWidth=80,proc=change_search_string
SetVariable Key_select,title="Key (sample_name, institution etc):"
SetVariable Key_select,value=root:Packages:RSoXS_Tiled:key_search
SetVariable Value_select1,pos={143.00,104.00},size={162.00,18.00},bodyWidth=127,proc=change_search_string
SetVariable Value_select1,title="value:"
SetVariable Value_select1,value=root:Packages:RSoXS_Tiled:value_search,live=1
PopupMenu catalog_search,pos={28.00,59.00},size={195.00,19.00},proc=catalog_search_kind_proc
PopupMenu catalog_search,title="kind of search"
PopupMenu catalog_search,mode=5,popvalue="regular expression",value=#"\"Full Text;equals;contains;comparison;regular expression\""
PopupMenu catalog_search_comparison,pos={29.00,105.00},size={96.00,19.00},disable=1,proc=Catalog_search_comparison_proc
PopupMenu catalog_search_comparison,title="comparison"
PopupMenu catalog_search_comparison,mode=1,popvalue="<",value=#"\"<;>;in\""
Button Add_to_search,pos={323.00,83.00},size={46.00,36.00},proc=Add_search
Button Add_to_search,title="Add"
Button catalog_search_remove_but,pos={329.00,183.00},size={54.00,37.00},proc=remove_catalog_search_proc
Button catalog_search_remove_but,title="Remove"
Button remove_from_search1,pos={329.00,134.00},size={54.00,37.00},proc=remove_all_catalog_search_proc
Button remove_from_search1,title="Remove\rAll"
CheckBox auto_update_chk,pos={308.00,6.00},size={71.00,15.00},proc=Live_mode_chk_proc
CheckBox auto_update_chk,title="Live Mode"
CheckBox auto_update_chk,variable=root:Packages:RSoXS_Tiled:live_mode
CheckBox log_image,pos={419.00,38.00},size={69.00,15.00},proc=change_image_option_proc
CheckBox log_image,title="log image",variable=root:Packages:RSoXS_Tiled:logimage
PopupMenu color_tab_pop,pos={496.00,36.00},size={200.00,19.00},proc=COlorTab_pop_proc
PopupMenu color_tab_pop,mode=8,value=#"\"*COLORTABLEPOP*\""
SetVariable min_setv,pos={712.00,34.00},size={85.00,18.00},bodyWidth=60,proc=set_image_val_pop
SetVariable min_setv,title="min"
SetVariable min_setv,limits={-10000,500000,1},value=root:Packages:RSoXS_Tiled:min_val
SetVariable max_setv,pos={801.00,34.00},size={87.00,18.00},bodyWidth=60,proc=set_image_val_pop
SetVariable max_setv,title="max"
SetVariable max_setv,limits={3,1e+06,1},value=root:Packages:RSoXS_Tiled:max_val
ListBox Image_sel_lb,pos={417.00,80.00},size={91.00,675.00},proc=Primary_sel_listbox_proc
ListBox Image_sel_lb,listWave=root:Packages:RSoXS_Tiled:image_list
ListBox Image_sel_lb,selWave=root:Packages:RSoXS_Tiled:image_sel_list,mode=9
ListBox Image_sel_lb,widths={500},userColumnResize=1
PopupMenu primary_color_tab_pop,pos={1226.00,37.00},size={200.00,17.00},disable=1,proc=Primary_color_pop_Proc
PopupMenu primary_color_tab_pop,mode=10,value=#"\"*COLORTABLEPOP*\""
PopupMenu monitor_color_tab_pop,pos={1132.00,40.00},size={200.00,17.00},disable=1,proc=monitor_color_pop_proc
PopupMenu monitor_color_tab_pop,mode=13,value=#"\"*COLORTABLEPOP*\""
SetVariable num_requested_results_val,pos={265.00,244.00},size={118.00,18.00},bodyWidth=43,proc=SetVarProc
SetVariable num_requested_results_val,title="results / page"
SetVariable num_requested_results_val,limits={1,100,1},value=root:Packages:RSoXS_Tiled:num_page
Button update_apikey,pos={132.00,29.00},size={96.00,16.00},proc=update_api_but
Button update_apikey,title="update_apikey"
ListBox Monitor_listb,pos={411.00,86.00},size={196.00,289.00},disable=1,proc=monitor_sel_channel_proc
ListBox Monitor_listb,listWave=root:Packages:RSoXS_Tiled:monitor_list_wave
ListBox Monitor_listb,selWave=root:Packages:RSoXS_Tiled:monitor_sel_list,mode=9
Button Select_all_Primary,pos={513.00,381.00},size={80.00,22.00},disable=1,proc=select_all_primary_but_proc
Button Select_all_Primary,title="select all"
ListBox Primary_listb,pos={411.00,86.00},size={196.00,289.00},disable=1,proc=Primary_sel_channel_proc
ListBox Primary_listb,listWave=root:Packages:RSoXS_Tiled:primary_list_wave
ListBox Primary_listb,selWave=root:Packages:RSoXS_Tiled:primary_sel_list,mode=9
Button deselect_all_primary,pos={416.00,382.00},size={80.00,21.00},disable=1,proc=deselect_primary_but_proc
Button deselect_all_primary,title="deselect all"
PopupMenu X_Axis_channel_pop,pos={416.00,47.00},size={191.00,19.00},disable=1,proc=Primary_Xaxis_sel_proc
PopupMenu X_Axis_channel_pop,title="X-Axis"
PopupMenu X_Axis_channel_pop,mode=11,popvalue="m_en_monoen_readback",value=#"get_primary_channels()"
CheckBox individual_y_axis_m_chk,pos={420.00,430.00},size={98.00,16.00},disable=1,proc=Change_monitor_plot_chk
CheckBox individual_y_axis_m_chk,title="individual y axes"
CheckBox individual_y_axis_m_chk,variable=root:Packages:RSoXS_Tiled:monitor_plot_indv_axes
CheckBox log_y_axis_m_chk,pos={420.00,460.00},size={64.00,16.00},disable=1,proc=Change_monitor_plot_chk
CheckBox log_y_axis_m_chk,title="log y axes"
CheckBox log_y_axis_m_chk,variable=root:Packages:RSoXS_Tiled:monitor_plot_logy
CheckBox relative_x_m_axis,pos={420.00,490.00},size={115.00,16.00},disable=1,proc=Change_monitor_plot_chk
CheckBox relative_x_m_axis,title="subtract time offset"
CheckBox relative_x_m_axis,variable=root:Packages:RSoXS_Tiled:monitor_plot_subxoffset
CheckBox individual_y_p_axis_chk,pos={420.00,430.00},size={103.00,15.00},disable=1,proc=change_primary_plot_chk
CheckBox individual_y_p_axis_chk,title="individual y axes"
CheckBox individual_y_p_axis_chk,variable=root:Packages:RSoXS_Tiled:primary_plot_indv_axes
CheckBox log_y_axis_p_chk,pos={420.00,460.00},size={68.00,15.00},disable=1,proc=change_primary_plot_chk
CheckBox log_y_axis_p_chk,title="log y axes"
CheckBox log_y_axis_p_chk,variable=root:Packages:RSoXS_Tiled:primary_plot_logy
CheckBox log_x_axis_p_chk,pos={420.00,490.00},size={65.00,15.00},disable=1,proc=change_primary_plot_chk
CheckBox log_x_axis_p_chk,title="log x axis"
CheckBox log_x_axis_p_chk,variable=root:Packages:RSoXS_Tiled:primary_plot_logx
ListBox Metadata_listb,pos={405.00,42.00},size={1260.00,790.00},disable=1
ListBox Metadata_listb,listWave=root:Packages:RSoXS_Tiled:metadata_display
ListBox Metadata_listb,mode=2,selRow=0,widths={150,100},userColumnResize=1
ListBox baseline_listb,pos={405.00,42.00},size={1260.00,790.00},disable=1
ListBox baseline_listb,listWave=root:Packages:RSoXS_Tiled:baseline_display
ListBox baseline_listb,mode=2,selRow=0,widths={200,100},userColumnResize=1
Button NRBCopyPos,pos={409.00,766.00},size={106.00,63.00},disable=1,proc=copyloc_but_proc
Button NRBCopyPos,title="Copy Location\rfor Spreadsheet"
Display/W=(617,68,1680,833)/HOST=# /HIDE=1
RenameWindow #,Monitors
SetActiveSubwindow ##
Display/W=(617,68,1680,833)/HOST=# /HIDE=1
ModifyGraph rgb=(0,0,65535)
RenameWindow #,Primary
SetActiveSubwindow ##
Display/W=(526,68,1678,833)/HOST=#
RenameWindow #,Images
SetActiveSubwindow ##
EndMacro
Function SetVarProc(sva) : SetVariableControl
STRUCT WMSetVariableAction &sva
sva.blockReentry = 1
switch( sva.eventCode )
case 1: // mouse up
case 2: // Enter key
case 3: // Live update
Variable dval = sva.dval
update_scan_selection()
break
case -1: // control being killed
break
endswitch
return 0
End
Function page_forward(ba) : ButtonControl
STRUCT WMButtonAction &ba
ba.blockReentry = 1
switch( ba.eventCode )
case 2: // mouse up
nvar /z max_result = root:Packages:RSoXS_Tiled:max_result
nvar /z offset = root:Packages:RSoXS_Tiled:offset
nvar /z num_page = root:Packages:RSoXS_Tiled:num_page
//if(offset < max_result - 30)
offset = offset+num_page
update_scan_selection()
//endif
break
case -1: // control being killed
break
endswitch
return 0
End
Function page_backward(ba) : ButtonControl
STRUCT WMButtonAction &ba
ba.blockReentry = 1
switch( ba.eventCode )
case 2: // mouse up
nvar /z max_result = root:Packages:RSoXS_Tiled:max_result
nvar /z offset = root:Packages:RSoXS_Tiled:offset
nvar /z num_page = root:Packages:RSoXS_Tiled:num_page
if(offset > 0)
offset = max(offset-num_page,0)
update_scan_selection()
endif
break
case -1: // control being killed
break
endswitch
return 0
End
Function page_toend(ba) : ButtonControl
STRUCT WMButtonAction &ba
ba.blockReentry = 1
switch( ba.eventCode )
case 2: // mouse up
nvar /z max_result = root:Packages:RSoXS_Tiled:max_result
nvar /z offset = root:Packages:RSoXS_Tiled:offset
nvar /z num_page = root:Packages:RSoXS_Tiled:num_page
offset = max_result-max(num_page-10,1)
update_scan_selection()
break
case -1: // control being killed
break
endswitch
return 0
End
Function page_tobeginning(ba) : ButtonControl
STRUCT WMButtonAction &ba
ba.blockReentry = 1
switch( ba.eventCode )
case 2: // mouse up
nvar /z offset = root:Packages:RSoXS_Tiled:offset
offset = 0
update_scan_selection()
break
case -1: // control being killed
break
endswitch
return 0
End
function /s get_monitors([string monitorlist,variable plot,variable only_last])
only_last = paramIsDefault(only_last)? 0 : only_last
variable nolist = 0
svar /z apikey = root:Packages:RSoXS_Tiled:apikey
svar /z baseurl = root:Packages:RSoXS_Tiled:baseurl
svar /z activeurl = root:Packages:RSoXS_Tiled:activeurl
svar /z output = root:Packages:RSoXS_Tiled:output
if(paramisdefault( monitorlist ))
nolist = 1
monitorlist = ""
endif
plot = paramisdefault(plot)? 0 : plot
DFREF foldersave = getdatafolderDFR()
setdatafolder root:Packages:RSoXS_Tiled
DFREF homedf = getdataFolderDFR()
string /g list_of_monitor_waves = ""
string /g timings
variable start_time
variable elapsed_time
wave/z/t monitor_metadata_urls
wave/z/t monitor_metadata, monitor_list_wave, primary_list_wave
wave/z monitor_sel_list, primary_sel_list
wave /T Plans_list, stream_names
wave plans_sel_wave
variable i,j,k=0
make /wave /n=0 /o monitorwaves
make /free/df/n=(dimsize(plans_sel_wave,0)) monitor_folders
string uid, testname
string list_of_urls = ""
string streambase, stream_url, time_url, safe_stream_base
for(i=0;i<dimsize(plans_sel_wave,0);i++)
if(plans_sel_wave[i])
uid = plans_list[i][5]
setdatafolder homedf
newdatafolder /o/s $cleanupname(uid,0)
monitor_folders[k] = getdataFolderDFR()
newdatafolder /o/s monitors
k+=1
for(j=0;j<itemsinlist(stream_names[i]);j++)
// see if there is already a loaded wave, and if so, load only from there on
// actually there is no difference in loading the whole monitor in most cases, so I will not implement partial downloads.
testname = stringfromlist(j,stream_names[i])
if(stringmatch(testname,"*_monitor") && (whichListItem(testname,monitorlist)>-1 || nolist))
streambase = removeEnding(testname,"_monitor")
safe_stream_base = URLENCODE(streambase)
stream_url = baseurl+"array/full/"+activeurl+ "/"
stream_url += uid+"/"+safe_stream_base+"_monitor/data/"
stream_url += safe_stream_base+"/?format=application/octet-stream" + apikey
time_url = baseurl+"array/full/"+activeurl+ "/"
time_url += uid+"/"+safe_stream_base+"_monitor/data/time"
time_url += "/?format=application/octet-stream" + apikey
list_of_urls += uid + ","+ streambase + "," + stream_url + ";"+ uid +","+ streambase +","+ time_url + ";"
endif
endfor
endif
endfor
if(k==0||itemsinlist(list_of_urls,";")==0)
return ""
endif
redimension /n=(k) monitor_folders
make /o/n=(itemsinlist(list_of_urls,";")) /t uids, urls, list_of_files, streambases, stream_data
uids = stringfromlist(0,stringfromlist(p,list_of_urls,";"),",")
streambases = stringfromlist(1,stringfromlist(p,list_of_urls,";"),",")
urls = stringfromlist(2,stringfromlist(p,list_of_urls,";"),",")
if(waveexists(monitor_metadata_urls) && waveexists(monitor_metadata))
if(!cmpstr(monitor_metadata_urls[0],urls[0]) &&numpnts(monitor_metadata) == numpnts(urls))
stream_data = monitor_metadata //open the cached monitor metadata string which was already pulled
else
start_time = ticks
multithread /NT=(numpnts(list_of_files)) stream_data = fetch_string(urls[p],30)
elapsed_time = (ticks-start_time)/60
timings += "\n monitors 1;"+urls[0]+";" + num2str(numpnts(urls)) + ";" + num2str(elapsed_time)
endif
else
start_time = ticks
multithread /NT=(numpnts(list_of_files)) stream_data = fetch_string(urls[p],30)
elapsed_time = (ticks-start_time)/60
timings += "\n monitors 2;"+urls[0]+";" + num2str(numpnts(urls)) + ";" + num2str(elapsed_time)
endif
variable len1, len2
for(i=0;i<numpnts(uids);i+=2)
len1 = strlen(stream_data[i])
len2 = strlen(stream_data[i+1])
if(min(len1,len2)>1 )
setdatafolder homedf
newdatafolder /o/s $cleanupname(uids[i],0)
string /g monitor_waves = ""
else
print "failed to get "+uids[i]+" channel: "+streambases[i]+ "length 1 , 2 : " + num2str(len1) + " , " + num2str(len2)
endif
endfor
string monitor_names ="", rawstring, rawstring2
for(i=0;i<numpnts(uids);i+=2)
len1 = strlen(stream_data[i])
len2 = strlen(stream_data[i+1])
if(min(len1,len2)>1)
setdatafolder homedf
newdatafolder /o/s $cleanupname(uids[i],0)
svar monitor_waves
newdatafolder /o/s monitors
streambase = streambases[i]
rawstring = stream_data[i]
rawstring2 = stream_data[i+1]
wave stream_wave = StringToUnsignedByteWave(rawstring)
wave time_wave = StringToUnsignedByteWave(rawstring2)
redimension /E=1 /Y=4 /n=(min(len1,len2)/8) stream_wave, time_wave
//if(stringmatch(streambase,"*Sample Current*") || stringmatch(streambase, "*AU Mesh*"))
//time_wave -=0.75
//endif
concatenate /o {stream_wave,time_wave}, $cleanupName(streambase,0)
wave stream = $cleanupName(streambase,0)
list_of_monitor_waves+= getwavesDataFolder(stream,2)+";"
monitor_waves += getwavesDataFolder(stream,2)+";"
monitor_names += nameofwave(stream) +"="+ getwavesdataFolder(stream,2)+";"
endif
endfor
setdatafolder homedf
string /g all_monitor_names_for_sel = monitor_names
svar all_primary_names_for_sel
wave /t wave_names_from_primary_list
string key,value, organized_list=""
variable index
make /t/n=0/o wave_names_from_monitor_list // a list of the waves which correspond to the values in the organized list of primary channels
for(i=0;i<itemsinlist(all_monitor_names_for_sel);i++)
key = stringfromlist(0,stringfromlist(i,all_monitor_names_for_sel),"=")
value = stringfromlist(1,stringfromlist(i,all_monitor_names_for_sel),"=")
index = whichlistitem(key,organized_list)
if(index<0)
organized_list+=key+";"
insertpoints numpnts(wave_names_from_monitor_list),1,wave_names_from_monitor_list
wave_names_from_monitor_list[numpnts(wave_names_from_monitor_list)-1] = value+";"
else
wave_names_from_monitor_list[index] += value+";"
endif
endfor
all_monitor_names_for_sel = organized_list
redimension /n=(itemsinlist(organized_list)) monitor_list_wave, monitor_sel_list
monitor_list_wave = stringfromlist(p,organized_list)
//get the primary time wave, then go through the monitors
for(i=0;i<numpnts(monitor_folders);i++)
setdatafolder monitor_folders[i]
wave times = time0 // the primary time wave (if this changes, it will fail)
if(!waveexists(times))
continue
endif
duplicate /free times, goodpulse, rises, falls
goodpulse = 0
svar monitor_waves
for(j=0;j<itemsinlist(monitor_waves);j+=1)
wave mon_wave = $stringfromlist(j,monitor_waves)
wave newchannelwave = splitsignal(mon_wave, times, rises, falls, goodpulse) // make a primary like wave out of the monitor
if(waveexists(newchannelwave))
// add the new channel wave to the primary list of waves..
key = nameofwave(newchannelwave)
value = getwavesdatafolder(newchannelwave,2)
index = whichlistitem(key,all_primary_names_for_sel)
if(index<0)
all_primary_names_for_sel+=key+";"
insertpoints numpnts(wave_names_from_primary_list),1,wave_names_from_primary_list
wave_names_from_primary_list[numpnts(wave_names_from_primary_list)-1] = value+";"
else
wave_names_from_primary_list[index] += value+";"
endif
endif
endfor
endfor
redimension /n=(itemsinlist(all_primary_names_for_sel)) primary_list_wave, primary_sel_list
primary_list_wave = stringfromlist(p,all_primary_names_for_sel)
setdatafolder foldersave
return list_of_monitor_waves
end
function /s get_primary([variable only_last])
only_last = paramIsDefault(only_last)? 0 : only_last
svar /z apikey = root:Packages:RSoXS_Tiled:apikey
svar /z baseurl = root:Packages:RSoXS_Tiled:baseurl
svar /z activeurl = root:Packages:RSoXS_Tiled:activeurl
DFREF foldersave = getdatafolderDFR()
setdatafolder root:Packages:RSoXS_Tiled
DFREF homedf = getdataFolderDFR()
string /g primary_wave_names = ""
string /g all_primary_names_for_sel = ""
string /g timings
variable start_time
variable elapsed_time
wave /T Plans_list, stream_names
wave plans_sel_wave
variable i,j
make /wave /n=0 /o primary_waves
wave /t primary_list_wave
wave primary_sel_list
string uid,uids="", testname, output
string list_of_urls = ""
string streambase, stream_url, time_url
string list_of_sample_names = ""
string list_of_scan_ids = ""
// if(only_last)
// uids = plans_list[dimsize(plans_sel_wave,0)-1][5]+";"
// list_of_sample_names += plans_list[dimsize(plans_sel_wave,0)-1][2]+";"
// list_of_scan_ids += plans_list[dimsize(plans_sel_wave,0)-1][0]+";"
// else
for(i=0;i<dimsize(plans_sel_wave,0);i++)
if(plans_sel_wave[i])
uids += plans_list[i][5]+";"
list_of_sample_names += plans_list[i][2]+";"
list_of_scan_ids += plans_list[i][0]+";"
endif
endfor
// endif
string fieldsstring
variable jsonId
string dataurls = "", streamurls = "", filenames = ""
for(i=0;i<itemsinlist(uids);i++)
uid = stringfromlist(i,uids)
stream_url = baseurl+"search/"+activeurl+ "/"
stream_url += uid+"/primary?field=metadata" + apikey
streamurls += stream_url + ";"
endfor
make /n=(itemsinlist(streamurls)) /t/o/free streamurl_wave = stringfromlist(p,streamurls), outputs
wave/z/t primary_metadata_urls
wave/z/t primary_metadata
if(waveexists(primary_metadata_urls) && waveexists(primary_metadata))
if(numpnts(primary_metadata_urls))
if(!cmpstr(primary_metadata_urls[0],streamurl_wave[0]) &&numpnts(primary_metadata) == numpnts(streamurl_wave))
outputs = primary_metadata //open the cached primary metadata string which was already pulled
else
start_time = ticks
multithread outputs = fetch_string(streamurl_wave[p],30)
elapsed_time = (ticks-start_time)/60
timings += "\n primary 1;"+streamurl_wave[0]+";" + num2str(numpnts(streamurl_wave)) + ";" + num2str(elapsed_time)
endif
else
start_time = ticks
multithread outputs = fetch_string(streamurl_wave[p],30)
elapsed_time = (ticks-start_time)/60
if(numpnts(streamurl_wave)>0)
timings += "\n primary 2;"+streamurl_wave[0]+";" + num2str(numpnts(streamurl_wave)) + ";" + num2str(elapsed_time)
endif
endif
else
start_time = ticks
multithread outputs = fetch_string(streamurl_wave[p],30)
elapsed_time = (ticks-start_time)/60
timings += "\n primary 3;"+streamurl_wave[0]+";" + num2str(numpnts(streamurl_wave)) + ";" + num2str(elapsed_time)
endif
//multithread outputs = fetch_string(streamurl_wave[p],1) // get the metadata, so we know what columns to grab
make /free /n=(itemsinlist(uids)) images
for(i=0;i<itemsinlist(uids);i++)
output = outputs[i]
uid = stringfromlist(i,uids)
if(strlen(output)<3)
print "couldn't get metadata"
continue
endif
JSONXOP_Parse/q/z output
if(v_flag)
print "bad responce to metadata"
continue
endif
jsonId = V_value
fieldsstring = ""
JSoNXOP_GetKeys /free/q/z jsonID, "data/0/attributes/metadata/descriptors/0/data_keys", tempwave
for(j=0;j<dimsize(tempwave,0);j++)
if(stringmatch(tempwave[j],"*_image"))
images[i] = 1
continue
endif
fieldsstring += "&field="+URLEncode(tempwave[j])
endfor
dataurls += baseurl+"node/full/" + activeurl + "/" + uid + "/primary/data/?field=time"+fieldsstring+"&format=text/csv" + apikey + ";"
dataurls += baseurl+"array/full/" + activeurl + "/" + uid + "/primary/data/time?format=text/csv" + apikey + ";"
filenames +=cleanupname(uid,1,20)+"PRIM.csv;"
filenames +=cleanupname(uid,1,20)+"PRIM_time.csv;"
JSONXOP_release jsonID
endfor
make /n=(itemsinlist(dataurls)) /t /free /o dataurl_wave = stringfromlist(p,dataurls), file_names = stringfromlist(p,filenames), file_paths
start_time = ticks
//multithread outputs = fetch_string(dataurl_wave[p],30) // get the primary
multithread /NT=5 file_paths = fetch_file(dataurl_wave[p], "tempfolder",file_names[p],30)
elapsed_time = (ticks-start_time)/60
if(numpnts(dataurl_wave)>0)
timings += "\n primary metadata;"+dataurl_wave[0]+";" + num2str(numpnts(dataurl_wave)) + ";" + num2str(elapsed_time)
endif
string sample_name,longimagenames="",timeoutput
variable unique_sample, enloc, samxloc, samyloc, samthloc, polloc, numrows
variable ench, polch, samxch, samych, samthch
for(i=0;i<itemsinlist(uids);i++)
//output = outputs[2*i]
//timeoutput = outputs[2*i+1]
uid = stringfromlist(i,uids)
setdatafolder homedf
newdatafolder /o/s $cleanupname(uid,0)
killwaves /z time0
LoadWave/q/O/J/D/A=time/K=0/W file_paths[2*i+1]
deletefile/z file_paths[2*i+1]
wave /z timewave = $(stringfromlist(0,S_waveNames))
LoadWave/q/O/J/D/A/K=0/W file_paths[2*i]
deletefile/z file_paths[2*i+1]
wave /z datawave = $(stringfromlist(0,S_waveNames))
if(!waveexists(datawave))
setdatafolder homedf
continue
endif
// scanlist[scanrow][1] = num2str(dimsize(datawave,0))
// wave /t channellist = root:Packages:NikaNISTRSoXS:channellist
// wave channellistsel = root:Packages:NikaNISTRSoXS:channellistsel
// redimension /n=(itemsinlist(s_wavenames),2) channellist, channellistsel
// channellist[][1] = stringfromlist(p,s_wavenames)
// channellist[][0] = ""
// channellistsel[][0] = 32
// variable num = itemsinlist(output,"\n")-1 // subtract the line for headers
// if(num<1)
// continue
// endif
string /g primary_names = ""//S_waveNames
primary_wave_names += getwavesdataFolder(timewave,2)+";"
primary_names += "time="+ getwavesdataFolder(timewave,2)+";"
for(j=0;j<itemsinlist(s_wavenames);j+=1)
wave datawave = $stringfromlist(j,s_wavenames)
primary_wave_names += getwavesdataFolder(datawave,2)+";"
primary_names += removeending(stringfromlist(j,s_wavenames),"0") +"="+ getwavesdataFolder(datawave,2)+";"
endfor
string /g image_names = ""
string columns = stringfromlist(0,output,"\n")
string dataname
if(images[i])
sample_name = stringfromlist(i,list_of_sample_names)
unique_sample = whichlistitem(sample_name,list_of_sample_names) == i // true if this is the first element with sample_name
unique_sample *= whichlistitem(sample_name,list_of_sample_names,";",i+1) == -1 // true if this is the last element with sample_name
if(unique_sample && itemsinlist(uids)>1)
sample_name = " - " + stringfromlist(i,list_of_sample_names)+" - " // multiple unique samples, start with the sample name
elseif(itemsinlist(uids)>1)
sample_name = " - " + stringfromlist(i,list_of_scan_ids) // multiple non-uniqud samples, use the scan_id
else
sample_name = "" // only one sample, so don't use any name
endif
// check the range of the possible axis names (only needed for IMAGES)
numrows = numpnts(datawave)
ench=0
polch=0
samxch=0
samych=0
samthch=0
wave /z en_energy_setpoint
if(waveexists(en_energy_setpoint))
ench = wavemax(en_energy_setpoint)-wavemin(en_energy_setpoint)
endif
wave /z en_polarization_setpoint
if(waveexists(en_polarization_setpoint))
polch = wavemax(en_polarization_setpoint)-wavemin(en_polarization_setpoint)
endif
wave /z RSoXS_Sample_Rotation
if(waveexists(RSoXS_Sample_Rotation))
samthch = wavemax(RSoXS_Sample_Rotation)-wavemin(RSoXS_Sample_Rotation)
endif
wave /z RSoXS_Sample_Outboard_Inboard
if(waveexists(RSoXS_Sample_Outboard_Inboard))
samxch = wavemax(RSoXS_Sample_Outboard_Inboard)-wavemin(RSoXS_Sample_Outboard_Inboard)
endif
wave /z RSoXS_Sample_Up_Down
if(waveexists(RSoXS_Sample_Up_Down))
samych = wavemax(RSoXS_Sample_Up_Down)-wavemin(RSoXS_Sample_Up_Down)
endif
// make image names for each primary step - ONLY if images
string rowstr
for(j=1;j<=numrows;j+=1)
rowstr = stringfromlist(j,output,"\n")
image_names += num2str(j-1)+") "
if(ench>0.1)
image_names += num2str(round(100*en_energy_setpoint(j-1))/100)+"eV "
endif
if(polch>0.1)
image_names += "" + num2str(round(100*en_polarization_setpoint(j-1))/100) + "pol "
endif
if(samthch>0.1)
image_names += num2str(round(100*RSoXS_Sample_Rotation(j-1))/100)+"deg "
else
if(samxch>0.1)
image_names += num2str(round(100*RSoXS_Sample_Outboard_Inboard(j-1))/100)+"x "
endif
if(samych>0.1)
image_names += num2str(round(100*RSoXS_Sample_Up_Down(j-1))/100)+"y "
endif
endif
image_names += sample_name +";"
endfor
if(itemsinlist(image_names)>itemsinlist(longimagenames))
longimagenames = image_names
endif