-
Notifications
You must be signed in to change notification settings - Fork 1
/
VizualAgePlotting.ipf
2811 lines (2268 loc) · 97.9 KB
/
VizualAgePlotting.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
//########################################################
// VisualAge add-on for Iolite
// Written by Joe Petrus
// Version 2015.06
//########################################################
#pragma rtGlobals=1
//########################################################
// Histogram related functions
//########################################################
//------------------------------------------------------------------------
// Histogram creation -- called when histogram is selected from the menu
//------------------------------------------------------------------------
Function AgeHistogram()
// Make sure VisualAge has been initialized:
VAInitialized()
// Get some variables from Iolite:
String MatrixName = GetMatrixName()
SVAR ListOfOutputChannels = $ioliteDFpath("Output", "ListOfOutputChannels")
Variable NoOfChannels = ItemsInList(ListOfOutputChannels)
// Get the default histogram plotting parameters:
NVAR DefaultStartAge = root:Packages:VisualAge:Options:HistogramOption_StartAge
NVAR DefaultStopAge = root:Packages:VisualAge:Options:HistogramOption_StopAge
NVAR DefaultBinSize = root:Packages:VisualAge:Options:HistogramOption_BinSize
NVAR hcount = root:Packages:VisualAge:HistogramCount
// Get a list of ages available to plot:
String ListOfHistogramOptions= ""
Variable i
For ( i = 0; i < NoOfChannels; i = i + 1)
String CurrentChannel = StringFromList(i, ListOfOutputChannels)
If ( StrSearch(CurrentChannel, "Age", 0) != -1 )
ListOfHistogramOptions = ListOfHistogramOptions + CurrentChannel + ";"
EndIf
EndFor
// Ask the user which age they'd like to plot and how to plot it:
String HistAge = ""
String HistInt = MatrixName
String HistName = "Hist" + num2str(hcount)
Variable HistStartAge = DefaultStartAge
Variable HistStopAge = DefaultStopAge
Variable HistBinSize = DefaultBinSize
Prompt HistName, "Name of histogram: "
Prompt HistAge, "Which age? ", popup, ListOfHistogramOptions
Prompt HistInt, "Which integration type? ", popup, GetListOfUsefulIntegrations()
Prompt HistStartAge, "Start age [Ma]: "
Prompt HistStopAge, "Stop age [Ma]: "
Prompt HistBinSize, "Bin size [Ma]: "
// Ensure that the name given doesn't conflict with a built in Igor Pro name:
Do
DoPrompt/HELP="" "VisualAge Histogram", HistName, HistStartAge,HistInt, HistStopAge, HistAge, HistBinSize
If ( V_Flag )
Return -1
EndIf
If ( CheckName(HistName, 1) != 0 )
DoAlert/T="VisualAge" 0, "The name you have entered is reserved in Igor Pro. Please try a different name."
Elseif ( !AlphaNumeric(HistName) )
DoAlert/T="VisualAge" 0, "The name you enter must be alphanumeric (no symbols, except \"_\")"
EndIf
While ( CheckName(HistName, 1) != 0 || !AlphaNumeric(HistName))
// Ensure name starts with a letter:
If (char2num(HistName[0]) < 57 && char2num(HistName[0]) > 48 )
HistName = "h" + HistName
EndIf
// Check if histogram exists:
String HistPathAndName = "root:Packages:VisualAge:Histograms:" + HistInt + ":" + HistAge + ":" + HistName + "Counts"
If (WaveExists($HistPathAndName))
DoAlert/T="VisualAge" 1, "A histogram named " + HistName + " for " + HistInt + " already exists. Would you like to replace it?"
If (V_flag != 1)
Return -1
EndIf
String actualWinName = Note($HistPathAndName)
KillWindow $actualWinName
KillWaves/Z root:Packages:VisualAge:Histograms:$(HistInt):$(HistAge):$(HistName + "Counts")
KillWaves/Z root:Packages:VisualAge:Histograms:$(HistInt):$(HistAge):$(HistName + "Bins")
KillWaves/Z root:Packages:VisualAge:Histograms:$(HistInt):$(HistAge):$(HistName + "KDE")
KillWaves/Z root:Packages:VisualAge:Histograms:$(HistInt):$(HistAge):$(HistName + "PDP")
KillWaves/Z root:Packages:VisualAge:Histograms:$(HistInt):$(HistAge):$(HistName + "TicksY")
KillWaves/Z root:Packages:VisualAge:Histograms:$(HistInt):$(HistAge):$(HistName + "TicksX")
EndIf
// Create a folder for the histogram data:
NewDataFolder/O/S root:Packages:VisualAge:Histograms
NewDataFolder/O/S $HistInt
NewDataFolder/O/S $HistAge
// Get matrix for the selected integration:
Wave aim = $ioliteDFpath("integration", "m_" + HistInt)
Variable NoOfIntegrations = DimSize(aim,0) - 1
// Get ages from Iolite + store in a wave:
Make/O/N=(NoOfIntegrations) InputDataNumbers
Make/O/N=(NoOfIntegrations) InputData2SE
Wave ResultWave = $MakeioliteWave("CurrentDRS", "ResultWave", n=2)
For ( i = 1; i <= NoOfIntegrations; i = i + 1 )
GetIntegrationFromIolite(HistAge, HistInt, i, "ResultWave")
InputDataNumbers[i-1] = ResultWave[0]
InputData2SE[i-1][0] = ResultWave[1]
EndFor
Variable MaxAgeInData = WaveMax(InputDataNumbers)
Variable MinAgeInData = WaveMin(InputDataNumbers)
Variable AgeSpread = MaxAgeInData - MinAgeInData
// Variable bw = sqrt(0.28*numpnts(InputDataNumbers)^(-2/5))*(AgeSpread)
NVAR bw = root:Packages:VisualAge:Options:HistogramOption_KDEbw
Variable nx = min(round(1000*(AgeSpread+8*bw)/bw),1000)
Variable xmin=MinAgeInData-4*bw
Variable xmax=MaxAgeInData+4*bw
// If the start and stop ages were specified as -1, try to guess at reasonable values (currently pretty bad):
If ( (HistStartAge == -1 || numtype(HistStartAge) == 2) && (HistStopAge == -1 || numtype(HistStopAge) == 2) )
HistStartAge = FloorToSig(MinAgeInData, ceil(log(AgeSpread)))
HistStopAge = CeilToSig(MaxAgeInData, ceil(log(AgeSpread)))
EndIf
// If the bin size is set to -1 split up the range into about 40 bins:
If ( HistBinSize == -1 || numtype(HistBinSize) == 2)
HistBinSize = FloorToSig((HistStopAge-HistStartAge)/40, 1)
EndIf
Variable NoOfBins = round((HistStopAge-HistStartAge)/HistBinSize)
// Create histogram + display:
Make/N=(NoOfBins)/O $(HistName + "Counts"), $(HistName + "Bins")
Histogram/B={HistStartAge, HistBinSize, NoOfBins} InputDataNumbers,$(HistName + "Counts")
Display/K=1/N=$HistName $(HistName + "Counts") as HistInt + " " + HistAge
// Set some user data for the graph to be accessed by the hook function and others:
SetWindow $S_name, userdata(Name)=HistName
SetWindow $S_name, userdata(IntType)=HistInt
SetWindow $S_name, userdata(AgeType)=HistAge
SetWindow $S_name, userdata(Type)="Histogram"
Note/K $(HistName + "Counts"), S_name
// Make the bin wave:
Wave Bins = $(HistName + "Bins")
For (i = 0; i < NoOfBins; i = i + 1)
Bins[i] = HistStartAge + HistBinSize*i
EndFor
// Calculate a probability distribution if desired (this could use some work!!):
NVAR DoPDF = root:Packages:VisualAge:Options:HistogramOption_ShowPDP
If (DoPDF)
Make/O/N=(nx) $(HistName+"PDP")
Wave pdp = $(HistName+"PDP")
For(i = 0; i < numpnts(InputDataNumbers); i = i + 1)
Variable j
For(j = 0; j < nx; j = j + 1)
pdp[j] += StatsNormalPDF(xmin+j*(xmax-xmin)/nx, InputDataNumbers[i], InputData2SE[i]/2)
EndFor
EndFor
SetScale /P x, xmin, (xmax-xmin)/nx, pdp
Variable pdp_norm = sum(pdp)*deltax(pdp)
pdp = pdp/pdp_norm
AppendToGraph/R pdp
ModifyGraph mode($(HistName+"PDP"))=0
ModifyGraph rgb($(HistName+"PDP"))=(65535,0,0)
EndIf
// Calculate KDE and plot if desired:
NVAR DoKDE = root:Packages:VisualAge:Options:HistogramOption_ShowKDE
If (DoKDE)
Variable kde_norm
Make /d/free/n=(numpnts(InputDataNumbers)) wweights=1
FastGaussTransform /TET=500/WDTH=(bw) /RX=(bw/100)/OUT1={xmin,nx,xmax} InputDataNumbers,wweights // you may need to tweak /RX flag value /RX=(8*bw)/TET=200
Wave M_FGT; kde_norm=sum(M_FGT)*deltax(M_FGT); M_FGT /= kde_norm;
String wn=HistName+"KDE"; duplicate /d/o M_FGT $wn
KillWaves M_FGT
AppendToGraph/R $wn
EndIf
NVAR DoTicks = root:Packages:VisualAge:Options:HistogramOption_ShowTicks
If (DoTicks)
Make/O/N=(numpnts(InputDataNumbers)) $(HistName+"TicksY")=0, $(HistName+"TicksX")=0
Wave TickXData = $(HistName+"TicksX")
TickXData = InputDataNumbers
AppendToGraph $(HistName+"TicksY") vs $(HistName+"TicksX")
EndIf
// Adjust graph properties:
Label bottom HistAge + " [Ma]"
if (DoPDF || DoKDE)
Label right "Probability"
endif
Label left "Counts"
ModifyGraph mirror(bottom)=2, standoff=0, gFont="Helvetica", gfSize=16, axisOnTop(bottom)=1
If (!DoPDF && !DoKDE)
ModifyGraph mirror(left)=1
EndIf
ModifyGraph width=600,height=400
// Histogram:
ModifyGraph rgb($(HistName + "Counts"))=(0,0,0)
ModifyGraph lsize($(HistName + "Counts"))=1.5
ModifyGraph mode($(HistName + "Counts"))=6
// PDP:
If (DoPDF)
ModifyGraph rgb($(HistName + "PDP")) = (65535,0,0)
EndIf
// KDE:;
If (DoKDE)
ModifyGraph rgb($(HistName + "KDE")) = (0,0,65535)
EndIf
// Ticks:
If (DoTicks)
ModifyGraph mode($(HistName+"TicksY"))=3
ModifyGraph marker($(HistName+"TicksY"))=10
ModifyGraph rgb($(HistName+"TicksY"))=(0,0,0)
EndIf
// Legend:
String LegendString = "\\s(" + HistName + "Counts) Histogram\r"
If (DoPDF)
LegendString += "\\s(" + HistName + "PDP) Probability distribution\r"
EndIf
If (DoKDE)
LegendString += "\\s(" + HistName + "KDE) Kernel density estimate\r"
EndIf
If (DoTicks)
LegendString += "\\s(" + HistName + "TicksY) Individual ages\r"
EndIf
LegendString += "N = " + num2str(numpnts(InputDataNumbers))
Legend/C/N=HistLegend/J/A=MC LegendString
Legend/C/N=HistLegend/J/A=LT/X=0.5/Y=0.5
// Round up y-axis max to nearest 10:
Variable CountMax = 10*ceil(WaveMax($(HistName + "Counts"))/10)
SetAxis left 0, CountMax
// Determine some stats and add them as an annotation:
//NVAR ShowStats = root:Packages:VisualAge:Options:HistogramOption_ShowStats
//If (ShowStats)
// WaveStats/Q/Z InputDataNumbers
// String InfoStr = "Mean = " + num2str(V_avg) + " Ma \rStdev = " + num2str(V_sdev) + "\rN = " + num2str(V_npnts)
// TextBox/C/N=HistText/A=RT InfoStr
//EndIf
// Set the histogram hook function:
SetWindow kwTopWin, hook(histHook) = AgeHistogramHook
// Histogram counter increment
hcount = hcount + 1
KillWaves InputDataNumbers, InputData2SE
End
//------------------------------------------------------------------------
// Hook function for histogram window - shows the age corresponding to the mouse position
//------------------------------------------------------------------------
Function AgeHistogramHook(s)
STRUCT WMWinHookStruct &s
// Main hook switch:
Switch(s.eventCode)
// Mouse button down event:
Case 3:
// If shift isn't down break:
If (s.eventmod != 3)
Break
EndIf
// Determine age corresponding to x-coord:
GetWindow kwTopWin, psize
Variable pmin = V_left
Variable pmax = V_right
Variable pvmin = V_top
Variable pvmax = V_bottom
GetAxis/Q bottom
Variable amin = V_min
Variable amax = V_max
Variable xval = (amax-amin)*(s.mouseLoc.h-pmin)/(pmax-pmin) + amin
Variable xa = 100*(s.mouseLoc.h-pmin)/(pmax-pmin)
Variable ya = 100*(s.mouseLoc.v-pvmin)/(pvmax-pvmin)
// Add/move tag:
TextBox/C/N=HistMouseInfo/F=0/A=LT/X=(xa+2)/Y=(ya+2) num2str(xval) + " Ma"
Break
// Window killed:
Case 2:
// Delete data for this window:
String HistName = GetUserData(s.winName,"", "Name")
String IntType = GetUserData(s.winName,"","IntType")
String AgeType = GetUserData(s.winName,"","AgeType")
RemoveFromGraph/Z $(Histname + "Counts")
RemoveFromGraph/Z $(HistName + "PDP")
RemoveFromGraph/Z $(HistName + "KDE")
RemoveFromGraph/Z $(HistName + "TicksY")
KillWaves/Z root:Packages:VisualAge:Histograms:$(IntType):$(AgeType):$(HistName + "Counts")
KillWaves/Z root:Packages:VisualAge:Histograms:$(IntType):$(AgeType):$(HistName + "Bins")
KillWaves/Z root:Packages:VisualAge:Histograms:$(IntType):$(AgeType):$(HistName + "PDP")
KillWaves/Z root:Packages:VisualAge:Histograms:$(IntType):$(AgeType):$(HistName + "KDE")
KillWaves/Z root:Packages:VisualAge:Histograms:$(IntType):$(AgeType):$(HistName + "PDF")
KillWaves/Z root:Packages:VisualAge:Histograms:$(IntType):$(AgeType):$(HistName + "TicksX")
KillWaves/Z root:Packages:VisualAge:Histograms:$(IntType):$(AgeType):$(HistName + "TicksY")
KillWaves/Z root:Packages:VisualAge:Histograms:$(IntType):$(AgeType):$(HistName + "PDFBins")
KillWaves/Z root:Packages:VisualAge:Histograms:$(IntType):$(AgeType):$(HistName + "BinSigma")
Break
EndSwitch
Return 0
End
//########################################################
// Concordia related functions
//########################################################
//------------------------------------------------------------------------
// Concordia creation -- called when the menu item is selected
//------------------------------------------------------------------------
Function Concordia(doTW)
Variable doTW
// Make sure VisualAge is initialized:
VAInitialized()
// Get some info from Iolite:
String MatrixName = GetMatrixName()
SVAR ListOfOutputChannels = $ioliteDFpath("Output", "ListOfOutputChannels")
Variable NoOfChannels = ItemsInList(ListOfOutputChannels)
// Get a list of options... kind of a complicated way to find Final, FinalAnd, or FinalPbC:
String ListOfConcordiaOptions = ""
Variable i
For ( i = 0; i < NoOfChannels; i = i + 1)
String currentChannel = StringFromList(i, ListOfOutputChannels)
If ( StrSearch(currentChannel, "207_235", 0) != -1 && StrSearch(currentChannel, "Age",0) == -1 )
ListOfConcordiaOptions = ListOfConcordiaOptions + RemoveEnding(currentChannel, "207_235") + ";"
EndIf
EndFor
// Ask the user which version and integration they'd like to plot:
NVAR ccount = root:Packages:VisualAge:ConcordiaCount
String ConcVersion = "Final"
String ConcInteg = MatrixName
String ConcName = "Conc" + num2str(ccount) // Defaults to "Conc" + the conc counter value
Prompt ConcName, "Name of diagram: "
Prompt ConcVersion, "Which Version? ", popup, ListOfConcordiaOptions
Prompt ConcInteg, "Which Integration? ", popup, GetListOfUsefulIntegrations()
// Ensure that the name given doesn't conflict with a built in Igor Pro name:
Do
DoPrompt "VisualAge Concordia", ConcName, ConcVersion, ConcInteg
If (V_Flag)
Return -1
EndIf
If ( CheckName(ConcName, 1) != 0 )
DoAlert/T="VisualAge" 0, "The name you have entered is reserved in Igor Pro. Please try a different name."
Elseif( !AlphaNumeric(ConcName) )
DoAlert/T="VisualAge" 0, "The name you enter must be alphanumeric (no symbols, except \"_\")"
EndIf
While ( CheckName(ConcName, 1) != 0 || !AlphaNumeric(ConcName))
// Ensure name starts with a letter:
If (char2num(ConcName[0]) < 57 && char2num(ConcName[0]) > 48 )
ConcName = "c" + ConcName
EndIf
// Check if concordia exists:
If (DataFolderExists("root:Packages:VisualAge:ConcordiaDiagrams:" + ConcInteg + ":" + ConcName) )
DoAlert/T="VisualAge" 1, "A concordia diagram named " + ConcName + " for " + ConcInteg + " already exists. Would you like to replace it?"
If (V_flag != 1)
Return -1
EndIf
KillWindow $ConcName
KillDataFolder/Z root:Packages:VisualAge:ConcordiaDiagrams:$(ConcInteg):$(ConcName)
EndIf
// Set the data folder for this concordia diagram:
NewDataFolder/O/S root:Packages:VisualAge:ConcordiaDiagrams
NewDataFolder/O/S $ConcInteg
NewDataFolder/O/S $ConcName
// Determine the number of integrations:
Wave aim = $ioliteDFpath("integration", "m_" + ConcInteg)
Variable NoOfIntegrations = DimSize(aim,0) -1
// Plot the concordia:
NVAR MarkerSep = root:Packages:VisualAge:Options:ConcordiaOption_MarkerSep
GenerateConcordia(ConcName, 0, 5e9, NoOfPoints=100000, NoOfMarkers=5e9/(MarkerSep*1e6), doTW=doTW,ConcFolder=GetDataFolder(1))
Wave conX = $(ConcName + "X"), conY = $(ConcName + "Y")
Wave conMX = $(ConcName + "MarkerX"), conMY = $(ConcName + "MarkerY")
DoWindow/K $ConcName
Display/N=$ConcName/K=1
AppendToGraph conY vs conX
AppendToGraph conMY vs conMX
// Create tags:
For (i = 1; i < 5e9/(markerSep*1e6); i = i +1)
String tagStr = "tag" + num2str(i)
String tagValue = num2str(markerSep*(i)) + " Ma"
String traceStr = ConcName + "MarkerY"
Tag/N=$tagStr/A=RC/F=0/Z=1/I=1/B=1/X=-0.5/Y=0.5/L=0/AO=0 $traceStr, i, tagValue
EndFor
// Set properties of concordia wave:
ModifyGraph lStyle($(ConcName + "Y")) = 0
ModifyGraph lSize($(ConcName + "Y")) = 1.5
ModifyGraph rgb($(ConcName + "Y"))=(0,0,0)
// Set properties for time symbols:
ModifyGraph marker($(ConcName + "MarkerY"))=19
ModifyGraph msize($(ConcName + "MarkerY"))=5
ModifyGraph mode($(ConcName + "MarkerY"))=3
ModifyGraph rgb($(ConcName + "MarkerY"))=(65000,0,0)
// Set general graph properties:
ModifyGraph standoff(bottom)=0
ModifyGraph standoff(left)=0
ModifyGraph gFont="Helvetica",gfSize=14
ModifyGraph width=600,height=475
ModifyGraph mirror=2
// Set labels according to which plotting style was used:
If (!doTW)
Label bottom "\\S207\\MPb \\Z20/\\M \\S235\\MU"
Label left "\\S206\\MPb \\Z20/\\M\\S238\\MU"
Else
Label bottom "\\S238\\MU \\Z20/\\M \\S206\\MPb"
Label left "\\S207\\MPb \\Z20/\\M\\S206\\MPb"
EndIf
// Add integrations to the diagram; hide if ellipse size or discordance is outside specified values:
For (i = 1; i <= NoOfIntegrations; i = i + 1)
String EllipseInfo = AddToConcordiaByIntegration(i, concVersion, concInteg, ConcName, doTW=doTW)
If ( str2num(StringByKey("ErrorIsBig", EllipseInfo)) == 1 || str2num(StringByKey("DiscPercentGreaterThanCutoff", EllipseInfo)) == 1 || str2num(StringByKey("DiscPercentLessThanCutoff", EllipseInfo)) == 1)
ModifyGraph hideTrace($StringByKey("Handle", EllipseInfo))=1
EndIf
EndFor
// Calculate the ConcAge:
NVAR DoConcAge = root:Packages:VisualAge:Options:ConcordiaOption_ShowConcAge
If (DoConcAge)
CalculateConcAge(ConcVersion, ConcInteg, ConcFolder=GetDataFolder(1), AddToPlot=1, AddAnnotation=1, doTW=doTW)
EndIf
// Fit a line:
NVAR FitLine = root:Packages:VisualAge:Options:ConcordiaOption_FitLine
If (FitLine)
ConcordiaFitLine(ConcVersion, ConcInteg, doTW)
EndIf
// Set some window data variables
SetDataFolder root:Packages:VisualAge:ConcordiaDiagrams:$(ConcInteg):$(ConcName)
SetWindow $ConcName, userdata(CurrentTraces) = TraceNameList(ConcName, ";", 1)
SetWindow $ConcName, userdata(PreviouslyActiveTrace) = ""
SetWindow $ConcName, userdata(ConcName) = ConcName
SetWindow $ConcName, userdata(ConcVersion) = ConcVersion
SetWindow $ConcName, userdata(ConcInteg) = ConcInteg
SetWindow $ConcName, userdata(doTW) = num2str(doTW)
SetWindow $ConcName, userdata(ConcFolder) = "root:Packages:VisualAge:ConcordiaDiagrams:" + ConcInteg + ":" + ConcName
SetWindow $ConcName, userdata(NameFolder)= ConcName
SetWindow $ConcName, userdata(IntegFolder) = ConcInteg
SetWindow $ConcName, userdata(Type) = "Concordia"
// Auto scale:
Variable DataMinX, DataMaxX, DataMinY, DataMaxY
If (!doTW)
DataMinX = GetMin(concInteg, concVersion + "207_235")
DataMaxX = GetMax(concInteg, concVersion + "207_235")
DataMinY = GetMin(concInteg, concVersion + "206_238")
DataMaxY = GetMax(concInteg, concVersion + "206_238")
Else
DataMinX = GetMin(concInteg, concVersion + "238_206")
DataMaxX = GetMax(concInteg, concVersion + "238_206")
DataMinY = GetMin(concInteg, concVersion + "207_206")
DataMaxY = GetMax(concInteg, concVersion + "207_206")
EndIf
Variable NewMinX = FloorToSig((DataMinX+DataMaxX)/2 - 2*(DataMaxX-DataMinX), 2)
Variable NewMaxX = CeilToSig((DataMinX+DataMaxX)/2 + 2*(DataMaxX-DataMinX), 2)
Variable NewMinY = FloorToSig((DataMinY+DataMaxY)/2 - 2*(DataMaxY-DataMinY), 2)
Variable NewMaxY = CeilToSig((DataMinY+DataMaxY)/2 + 2*(DataMaxY-DataMinY), 2)
SetAxis bottom, NewMinX, NewMaxX
SetAxis left, NewMinY, NewMaxY
// Increment concordia counter:
ccount = ccount + 1
// Set the concordia window hook function:
SetWindow kwTopWin, hook(concHook) = ConcordiaHook
End
// The below code is useful for filled in ellipses... not currently activated.
//Menu "TracePopup", dynamic
// "-"
// SubMenu "Ellipse"
// "None", ModifyEllipse()
// "Solid", ModifyEllipse()
// SubMenu "Color"
// "*COLORPOP*", ModifyEllipse()
// End
// SubMenu "Pattern"
// "*PATTERNPOP*", ModifyEllipse()
// End
// End
//End
//
//Function ModifyEllipse()
// GetLastUserMenuInfo
//
// String GraphType = GetUserData(WinName(0,1), "", "Type")
// If (cmpstr(GraphType, "Concordia") != 0)
// Return 0
// EndIf
//
// If (cmpstr(S_traceName[strlen(S_traceName)-1],"b")==0)
// S_traceName = S_traceName[0,strlen(S_traceName)-2]
// EndIf
//
// Print V_flag
// print V_value
// print s_value
// print S_traceName
//
//
// Switch(V_flag)
// // None selected:
// Case 0:
// // Remove fill:
// If (V_value == 1)
// ModifyGraph mode($S_traceName)=0,lsize($S_traceName)=1
// ModifyGraph mode($(S_traceName + "b"))=0, lsize($(S_traceName + "b"))=1
// Elseif (V_value == 2)
// ModifyGraph rgb($S_traceName)=(0,0,0), lstyle($S_traceName)=0, lsize($S_traceName)=0
// ModifyGraph rgb($(S_traceName +"b"))=(0,0,0), lstyle($(S_traceName + "b"))=0, lsize($(S_traceName + "b"))=0
// ModifyGraph mode($S_traceName)=7,hbFill($S_traceName)=2,useNegPat($S_traceName)=1,toMode($S_traceName)=1
// EndIf
// Break
//
// Case 7:
// ModifyGraph hbFill($S_traceName)=V_value+5
// Break
//
// Case 10:
// ModifyGraph rgb($S_traceName)=(V_red,V_green,V_blue)
// Break
//
// EndSwitch
//End
//------------------------------------------------------------------------
// Hook function for the concordia window that shows some age info for the nearest ellipse
//------------------------------------------------------------------------
Function ConcordiaHook(s)
STRUCT WMWinHookStruct &s
// Make sure VisualAge is initialized:
VAInitialized()
// If the concordia diagram isn't the top window, exit:
If (CmpStr(WinName(0,1), s.winName) != 0)
Return 0
EndIf
// Get required data from the graph:
String PreviouslyActiveTrace = GetUserData(s.winName, "", "PreviouslyActiveTrace")
String CurrentTraces = GetUserData(s.winName, "", "CurrentTraces")
String ConcFolder = GetUserData(s.winName, "", "ConcFolder")
String ConcVersion = GetUserData(s.winName, "", "ConcVersion")
String ConcInteg = GetUserData(s.winName, "", "ConcInteg")
String ConcName = GetUserData(s.winName, "", "ConcName")
Variable doTW = str2num(GetUserData(s.winName, "", "doTW"))
Wave aim = $ioliteDFpath("integration", "m_" + ConcInteg)
Variable NoOfIntegrations = DimSize(aim,0)
// Main switch control:
Switch(s.eventCode)
// Mouse scroll event:
Case 22:
GetAxis/W=$s.winname/Q Bottom
Variable cMinx = V_min
Variable cMaxx = V_max
GetAxis/W=$s.winname/Q Left
Variable cMiny = V_min
Variable cMaxy = V_max
Variable cMeanx = (cMinx+cMaxx)/2
Variable cMeany = (cMiny+cMaxy)/2
Variable axisScaler =s.wheelDy/50
Variable nMinx = cMinx + (cMeanx-cMinx)*axisScaler
Variable nMaxx = cMaxx - (cMaxx-cMeanx)*axisScaler
Variable nMiny = cMiny + (cMeany-cMiny)*axisScaler
Variable nMaxy = cMaxy - (cMaxy-cMeany)*axisScaler
If ( (s.eventMod & 8) == 8 || s.eventMod == 0)
SetAxis/W=$s.winname Bottom, nMinx, nMaxx
EndIf
If ( (s.eventMod & 4) == 4 || s.eventMod == 0)
SetAxis/W=$s.winname Left, nMiny, nMaxy
EndIf
Break
// Key pressed event:
Case 11:
// Switch depending on which key was pressed:
Switch (s.keycode)
// r pressed:
Case 114:
// Auto scale the diagram:
Variable DataMinX, DataMaxX, DataMinY, DataMaxY
If (!doTW)
DataMinX = GetMin(concInteg, concVersion + "207_235")
DataMaxX = GetMax(concInteg, concVersion + "207_235")
DataMinY = GetMin(concInteg, concVersion + "206_238")
DataMaxY = GetMax(concInteg, concVersion + "206_238")
Else
DataMinX = GetMin(concInteg, concVersion + "238_206")
DataMaxX = GetMax(concInteg, concVersion + "238_206")
DataMinY = GetMin(concInteg, concVersion + "207_206")
DataMaxY = GetMax(concInteg, concVersion + "207_206")
EndIf
Variable NewMinX = FloorToSig((DataMinX+DataMaxX)/2 - 2*(DataMaxX-DataMinX), 2)
Variable NewMaxX = CeilToSig((DataMinX+DataMaxX)/2 + 2*(DataMaxX-DataMinX), 2)
Variable NewMinY = FloorToSig((DataMinY+DataMaxY)/2 - 2*(DataMaxY-DataMinY), 2)
Variable NewMaxY = CeilToSig((DataMinY+DataMaxY)/2 + 2*(DataMaxY-DataMinY), 2)
SetAxis bottom, NewMinX, NewMaxX
SetAxis left, NewMinY, NewMaxY
Break
// z pressed:
Case 122:
// Draw a contour on the diagram:
If ( FindListItem("ContourData", ContourNameList(s.winname, ";")) == -1)
// Add contour if it isn't already there:
KillWaves/Z ContourData, ContourX, ContourY
If (!doTW)
Wave xwave = $ioliteDFpath("CurrentDRS", ConcVersion + "207_235")
Wave ywave = $ioliteDFpath("CurrentDRS", ConcVersion + "206_238")
Else
Wave xwave = $ioliteDFpath("CurrentDRS", ConcVersion + "238_206")
Wave ywave = $ioliteDFpath("CurrentDRS", ConcVersion + "207_206")
EndIf
Wave Index_Time = $ioliteDFpath("CurrentDRS", "Index_Time")
Variable startTime, stopTime
Variable startIndex, stopIndex
Variable Nbins = 100
GetAxis/W=$s.winname/Q Bottom
Variable MinX = V_min
Variable MaxX = V_max
GetAxis/W=$s.winname/Q Left
Variable MinY = V_min
Variable MaxY = V_max
Make/O/N=(Nbins,Nbins) ContourData
Make/O/N=(Nbins) ContourX, ContourY
Variable StartX = MinX, StopX = MaxX, BinX = (StopX-StartX)/Nbins
Variable StartY = MinY, StopY = MaxY, BinY = (StopY-StartY)/Nbins
Variable i
For ( i = 0; i < Nbins; i = i + 1)
ContourX[i] = (i )*BinX + StartX
ContourY[i] = (i )*BinY + StartY
EndFor
// Fill data matrix:
For ( i = 1; i <= NoOfIntegrations; i = i + 1)
startTime = aim[i][0][%$"Median Time"]-aim[i][0][%$"Time Range"]
stopTime = aim[i][0][%$"Median Time"]+aim[i][0][%$"Time Range"]
startIndex = ForBinarySearch(Index_Time, startTime) + 1
If (numtype(Index_Time[startIndex]) == 2)
startIndex += 1
EndIf
stopIndex = ForBinarySearch(Index_Time, stopTime)
If (stopIndex == -2)
stopIndex = numpnts(Index_Time) - 1
EndIf
Variable j
For ( j = startIndex; j < stopIndex; j = j + 1)
Variable cx = xwave[j]
Variable cy = ywave[j]
Variable ix = (cx-StartX)/BinX
Variable iy = (cy-StartY)/BinY
if (numtype(ix) == 2 || numtype(iy) == 2 || ix < 0 || iy < 0 || ix > Nbins || iy > Nbins)
continue
endif
ContourData[ix][iy] = ContourData[ix][iy] + 1
EndFor
EndFor
// Append + modify contour:
AppendMatrixContour ContourData vs {ContourX, ContourY}
ModifyContour ContourData update=1,labels=0,autoLevels={*,*,100}, ctabLines={*,*,Rainbow,1}
Else
// Remove the contour if it is already there:
RemoveContour/W=$s.winname ContourData
EndIf
Break
// a pressed:
Case 97:
// Add the individual data points to the graph:
If (FindListItem("ywave", TraceNameList(s.winname, ";", 1)) == -1)
// Add points to graph if they aren't already there:
KillWaves/Z $(ConcFolder + ":ywave"), $(ConcFolder + ":xwave")
If (!doTW)
Duplicate root:Packages:iolite:output:VisualAgeDRS:$(ConcVersion + "206_238"), $(ConcFolder + ":ywave")
Duplicate root:Packages:iolite:output:VisualAgeDRS:$(ConcVersion + "207_235"), $(ConcFolder + ":xwave")
Else
Duplicate root:Packages:iolite:output:VisualAgeDRS:$(ConcVersion + "207_206"), $(ConcFolder + ":ywave")
Duplicate root:Packages:iolite:output:VisualAgeDRS:$(ConcVersion + "238_206"), $(ConcFolder + ":xwave")
EndIf
Wave xwave = $(ConcFolder + ":xwave")
Wave ywave = $(ConcFolder + ":ywave")
GenerateIntegrationIndex(ConcFolder)
Wave IntInd = $(ConcFolder + ":IntInd")
Variable Cind = GetIntInd(ConcInteg)
Variable xi
For (xi = 0; xi < numpnts(xwave); xi = xi + 1)
If ( numtype(xwave[xi]) == 2 )
Continue
EndIf
// Note: doing bitwise comparison here...
If ((IntInd[xi] & Cind) != CInd)
xwave[xi] = Nan
ywave[xi] = Nan
EndIf
EndFor
AppendToGraph $(ConcFolder + ":ywave") vs $(ConcFolder + ":xwave")
ModifyGraph mode(ywave)=2
ModifyGraph rgb(ywave)=(0,0,0)
Else
// Remove points from graph if already there:
RemoveFromGraph/W=$s.winname/Z ywave
KillWaves $(ConcFolder + ":ywave"), $(ConcFolder + ":xwave")
EndIf
Break
// d or D pressed:
Case 100:
Case 68:
NVAR FitLine = root:Packages:VisualAge:Options:ConcordiaOption_FitLine
NVAR ThroughZero = root:Packages:VisualAge:Options:ConcordiaOption_ThroughZero
// Check if fit is already on the graph:
If (FindListItem("fit_yWave", TraceNameList(s.winname, ";", 1)) == -1)
// If not on the graph, add a fit:
FitLine = 1
If (s.eventMod == 2)
// If shift is down, force through zero:
ThroughZero = 1
ConcordiaFitLine(ConcVersion, ConcInteg, doTW, anchor=1)
Else
// Otherwise, do a free fit:
ThroughZero = 0
ConcordiaFitLine(ConcVersion, ConcInteg, doTW)
EndIf
Else
// If a fit is already on the graph, remove it:
FitLine = 0
RemoveFromGraph/W=$s.winname/Z fit_yWave
TextBox/K/N=InterceptAgeText
EndIf
Break
// c pressed:
Case 99:
NVAR DoConcAge = root:Packages:VisualAge:Options:ConcordiaOption_ShowConcAge
// Check if ConcAge is already on the graph:
If (FindListItem("WtdMeany", TraceNameList(s.winname, ";", 1)) == -1)
// If not, calculate + add:
DoConcAge = 1
CalculateConcAge(ConcVersion, ConcInteg, ConcFolder=ConcFolder, AddToPlot=1, AddAnnotation=1, doTW=doTW)
Else
// If yes, remove it:
DoConcAge = 0
RemoveFromGraph/W=$s.winname/Z WtdMeany
TextBox/K/N=ConcAgeText
EndIf
Break
EndSwitch
// Tell Igor we've handled the keypress event:
Return 1
// Graph modified event:
Case 8:
// Check if we want to delete integrations when they're removed from a diagram:
NVAR RemoveIntegrations = root:Packages:VisualAge:Options:ConcordiaOption_RemoveIntegs
If (!RemoveIntegrations)
Return 0
EndIf
// Determine if any waves have been removed:
String NewTraces = TraceNameList(s.winName,";",1)
String RemovedTraces = CurrentTraces
For (i = 0; i < ItemsInList(NewTraces); i = i + 1)
RemovedTraces=RemoveFromList(StringFromList(i, NewTraces), RemovedTraces)
EndFor
CurrentTraces = NewTraces
SetWindow $ConcName, userdata(CurrentTraces) = CurrentTraces
// Remove integrations:
For (i = 0; i < ItemsInList(RemovedTraces); i = i + 1)
// Integration traces are of the form "Int#y" where # is the integration number
String CurrentInt = StringFromList(i, RemovedTraces)
// Make sure it was an ellipse:
If (StrSearch(CurrentInt, "Int", 0) == -1)
Return 0
EndIf
// Extra the number from the string
Variable IntegNum = str2num(CurrentInt[3, strlen(CurrentInt)-2])
RemoveIntegrationByIndex(ConcInteg, IntegNum)
EndFor
// Replot integrations:
If ( ItemsInList(RemovedTraces) > 0)
// Remove all integration ellipses:
For (i=0; i < ItemsInList(NewTraces); i = i + 1)
String TraceToRemove = StringFromList(i, NewTraces)
If ( StrSearch(TraceToRemove, "Int", 0) != -1 )
RemoveFromGraph/Z $TraceToRemove
EndIf
EndFor
// Replot integrations:
For (i = 1; i <= NoOfIntegrations; i = i + 1)
String EllipseInfo = AddToConcordiaByIntegration(i, ConcVersion, ConcInteg, s.winName, doTW=doTW)
If ( str2num(StringByKey("ErrorIsBig", EllipseInfo)) == 1 || str2num(StringByKey("DiscPercentGreaterThanCutoff", EllipseInfo)) == 1 || str2num(StringByKey("DiscPercentLessThanCutoff", EllipseInfo)) == 1)
ModifyGraph hideTrace($StringByKey("Handle", EllipseInfo))=1
EndIf
CurrentTraces = TraceNameList(s.winName, ";", 1)
SetWindow $ConcName, userdata(CurrentTraces) = CurrentTraces
EndFor
// Recalculate ConcAge if desired:
NVAR DoConcAge = root:Packages:VisualAge:Options:ConcordiaOption_ShowConcAge
If ( DoConcAge )
CalculateConcAge(ConcVersion, ConcInteg, ConcFolder=ConcFolder, AddToPlot=1, AddAnnotation=1, doTW=doTW)
EndIf
// Recalculate the fit if desired:
NVAR FitLine = root:Packages:VisualAge:Options:ConcordiaOption_FitLine
If ( FitLine )
ConcordiaFitLine(ConcVersion, ConcInteg, doTW)
EndIf
EndIf
// Tell Igor we've handled the event:
Return 1
// Mouse moved event:
Case 4:
// Update the info annotation if desired:
NVAR ShowInfoOption = root:Packages:VisualAge:Options:ConcordiaOption_ShowInfo
If (ShowInfoOption)
// Determine which trace is closest to the mouse:
String ActiveTraceInfo = TraceFromPixel(s.mouseLoc.h, s.mouseLoc.v,"")
String ActiveTrace = StringByKey("TRACE", activeTraceInfo)
// If the trace isn't an ellipse then return:
If (StrSearch(ActiveTrace, "Int", 0) == -1)
Return 1
EndIf
// Determine the integration number of the trace:
Variable IntegrationNo = str2num(ActiveTrace[3, strlen(ActiveTrace)-2])
// Change ellipse color to indicate which is active:
ModifyGraph/Z rgb($PreviouslyActiveTrace)=(0,0,0)
ModifyGraph/Z rgb($ActiveTrace)=(65535,0,0)
PreviouslyActiveTrace = ActiveTrace
SetWindow $ConcName, userdata(PreviouslyActiveTrace) = PreviouslyActiveTrace
// Contruct annotation:
Wave/T IntLabels = $ioliteDFpath("integration", "IntegNoLabels")
String AgeStr = ConcVersion[0,4] + "Age" + ConcVersion[5,inf]
Variable a68, s68, a75, s75, a82, s82, a76, s76
Variable aavg, savg, asd2, asd3, asd4
Variable gval = 60000
String info = ""
Wave ResultWave = $MakeioliteWave("CurrentDRS", "ResultWave", n = 2)
// Get age and uncert for all uncorrected ages:
GetIntegrationFromIolite(AgeStr + "206_238", ConcInteg, IntegrationNo, "ResultWave")
a68 = ResultWave[0]
s68 = ResultWave[1]
GetIntegrationFromIolite(AgeStr + "207_235", ConcInteg, IntegrationNo, "ResultWave")
a75 = ResultWave[0]
s75 = ResultWave[1]
GetIntegrationFromIolite(AgeStr + "208_232", ConcInteg, IntegrationNo, "ResultWave")
a82 = ResultWave[0]
s82 = ResultWave[1]
GetIntegrationFromIolite(AgeStr + "207_206", ConcInteg, IntegrationNo, "ResultWave")
a76 = ResultWave[0]
s76 = ResultWave[1]
// Do some tests on ages + uncerts to color the ages according to how well they agree:
aavg = (a68+a75)/2
savg = sqrt(s68^2 + s75^2)
asd4 = sqrt( ( (a68-aavg)^2 + (a75-aavg)^2 + (a82-aavg)^2 + (a76-aavg)^2 )/4 )
asd3 = sqrt( ( (a68-aavg)^2 + (a75-aavg)^2 + (a82-aavg)^2 )/3 )
asd2 = sqrt( ( (a68-aavg)^2 + (a75-aavg)^2)/2)
If ( abs(a68-aavg) < (s68+savg) )
gval = 60000*(2/asd2)
If (gval > 60000)
gval = 60000
EndIf
Info += "\K(0," + num2str(gval) +",0)"
EndIf
info += "\f00\M\S206\MPb/\S238\MU Age = " + num2str(a68) + " ± " + num2str(s68)+ "\r\K(0,0,0)"
If ( abs(a75-aavg) < (s75+savg) )
gval = 60000*(2/asd2)
If (gval > 60000)
gval = 60000
EndIf
Info += "\K(0," + num2str(gval) +",0)"
EndIf
info += "\f00\M\S207\MPb/\S235\MU Age = " + num2str(a75) + " ± " + num2str(s75)+ "\r\K(0,0,0)"
If ( abs(a82-aavg) < (s82+savg))
gval = 60000*(2/asd3)
If (gval > 60000)
gval = 60000
EndIf
Info += "\K(0," + num2str(gval) +",0)"
aavg = (a68+a75+a82)/3
savg = sqrt(s68^2 + s75^2 + s82^2)
EndIf
info += "\f00\M\S208\MPb/\S232\MTh Age = " + num2str(a82) + " ± " + num2str(s82)+ "\r\K(0,0,0)"