-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMTplot.m
1623 lines (1592 loc) · 70.3 KB
/
MTplot.m
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
%MTplot
%
%Moment Tensor Plotting
%
% 2014 David J Pugh, Bullard Labs, University of Cambridge and Schlumberger
% Cambridge Research (Version 1.0)
%
% Syntax
%
% MTplot(MT)
% MTplot(MT,mode)
% MTplot(MT,mode,stations)
% MTplot(...,'PropertyName',PropertyValue)
%
% Description
%
% The input moment tensor can be either [strike,dip,rake],
% [Mxx,Myy,Mzz,sqrt(2)*Mxy,sqrt(2)*Mxz,sqrt(2)*Myz] or the full Moment Tensor:
% [Mxx,Mxy,Mxz;Myx,Myy,Myz;Mzx,Mzy,Mzz]. To plot multiple moment tensors
% the input should be a cell array of the moment tensors as above i.e.
% {[strike,dip,rake],[strike,dip,rake]}, or an array of 6 by n MT six
% vectors. Mixing the formats is ok. For more information see <a href="matlab:doc MTcheck;">MTcheck</a>
%
% Required Modules: <a
% href="http://www.mathworks.co.uk/matlabcentral/fileexchange/20003-panel">Panel</a>, <a
% href="http://www.mathworks.co.uk/matlabcentral/fileexchange/7943-freezecolors---unfreezecolors">freezeColors</a>,MTcheck
% (in the complete Moment Tensor module)
%
%
%
% MTplot(MT) creates a Equal Area lower hemisphere projection plot of the
% moment Tensor MT.
%
% MTplot(MT,mode) plots the moment tensor according to the specified mode.
% Allowed modes are:
% beachball [default]
% radiation
% riedeseljordan
% hudson
% faultplane
% tnp
% lune
% component
% eigenvalues
% tape
% orientation
% sdr
% sdrsilhouette
% 3dlocation
% hx (Equal area source type)
%
%
% MTplot(MT,mode,stations) plots the moment tensor as above, adding (where
% possible) the station information and polarities. The stations must be
% specified as a cell array: {Name,Azimuth,ToA,Polarity} where the polarity
% is positive - upwards triangles, negative downwards triangles and zero is
% a circle (no information).
% E.g.
% {'ASK',123,56,1;'BAR',246,76,0;'MIL',11,5,-1}
%
% MTplot(...,'PropertyName',PropertyValue) plots as above, but with certain
% properties being adjusted from their defaults. The editable properties
% and their defaults are:
% 'Projection':'EqualArea'
% 'ProjectionAxis':[]
% 'Dimension':'2d'
% 'Lower':true
% 'FullSphere':false
% 'Phase':'P'
% 'Logarithm':false
% 'Superposition':false
% 'Presentation':false
% 'StationMarkerSize':8
% 'StationProjection':true
% 'StationDistribution':{}
% 'PolarityErrorHighlight':false
% 'Radians':false
% 'Colormap':'Clear'
% 'PT':true
% 'FP':false
% 'BA':false
% 'MaxSource':false
% 'Contour':false
% 'Probability':[]
% 'Marginalised':true
% 'Resolution':300
% 'WindowTitle':''
% 'Subtitle':false
% 'Roman':false
% 'AxisTitle':false
% 'AxisLines':true
% 'Text':true
% 'AxisLabel':true
% 'TypeLabel':false
% 'Marker':'o'
% 'MarkerSize':6
% 'C':[3,1,1,0,0,0,...
% 3,1,0,0,0,...
% 3,0,0,0,...
% 1,0,0,...
% 1,0,...
% 1]
% 'FigureHandle':0
% 'Panel':false
% 'FontSize':12
% 'LineWidth':1
% 'Color':'b'
% 'Legend':false
% 'Names':{}
% 'Chain':false
% 'Movie':false
% 'R':6371
% 'Locations':[]
% 'LocationUnits':'latlon'
% 'Samples':0
% 'Interp':0
% 'InteriorLines':true
% 'Scale':false
%
%
% Properties
%
% 'Projection':2 dimensional projection functions: 'EqualAngle','EqualArea','u-v','tau-k' - The latter are
% for Hudson plots
% 'ProjectionAxis':Array =
% 'Dimension':Plotting dimension (if available): '2d', '3d', 'default'
% 'Lower':Boolean - For 2d projections, whether to do a lower or upper
% hemisphere projection.
% 'FullSphere':Boolean - Plot the full sphere or just the inner hemisphere
% 'Phase':Char - select phase from 'P','S','SH','SV','P/S','P/SH','P/SV','SH/SV'
% 'Logarithm':Boolean - set logarithm for amplitude and amplitude ratio
% calculations, and probability plots.
% 'Superposition':Boolean - show event superposition, requires location
% option.
% 'Presentation':Boolean - plot in presentation mode (large stations and
% no names) or not
% 'StationMarkerSize':Numeric - station marker plot size.
% 'StationProjection':Boolean - Project Stations from non plotted
% hemisphere in beachball plots.
% 'StationDistribution':Struct - Station Distribution from MTINV output
% (struct containing Distribution and Probability Attributes - Cell
% struct of stations and numeric array respectively.)
% 'PolarityErrorHighlight':Boolean - Highlight 'incorrect' station polarities.
% 'Radians': Boolean - station angles are in radians
% 'Colormap':'Clear', 'BlueRed' (Has high contrast between positive and negative) or
% the standard <a href="matlab: doc colormap;">colormaps</a>
% 'PT':Boolean - whether to plot TNP axes and Fault Plane
% normals or not
% 'FP':Boolean - plot the fault planes on the plot.
% 'BA':Boolean - plot the bi-axes faultplane and slip plane on the plot
% instead of the fault planes
% 'MaxSource':Boolean - plot max probability source on hudson plot
% instead of PDF
% 'Contour':Boolean/numeric - plot contours if numeric and hudson or lune
% selected, plots the probability contour for that value.
% 'Probability':Array - array of probability values for the given MTs, used in
% FocalPlane2dProb, FocalPlaneProb,TNP2dProb and TNPProb
% 'Marginalised': Plots marginalised PDFs for PDF type plots, if false
% plots the max value prob for each bin.% 'AxisLabel':true
% 'Resolution':Integer - the number of points to use in the generation of
% the figure.
% 'WindowTitle':String - Plot window title
% 'Subtitle':String or Cell-Array- plot subtitles - array for panel plot, if
% false, standard character labels are used in panel plot
% 'Roman':Boolean - use roman numerals in panel plot when fewer than 26 panels
% 'AxisTitle':Boolean - show axis title
% 'AxisLines':Boolean - show north/east lines, show prior distribution in Tape
% parameters plots
% 'AxisLabel':Boolean - show axis labels.
% 'Text':Boolean - enable/disable all plot text except Axis Labels (i.e. T,N,P axes, North and East axes
% markers and station labels.
% 'TypeLabel': Boolean - Shows the source type positions on the plot.
% 'Marker':Char - Marker type for Hudson and lune type plots. (from
% <a href="matlab: doc plot">default matlab styles</a>.
% 'MarkerSize':Numeric - Marker size.
% 'C':Array describing the upper triangular part of the anisotropy tensor.
% 'FigureHandle':Handle - handle to existing figure to use.
% 'Panel':Boolean - uses panel to do multiplots, each cell of MTs/stations is plotted
% into a panel with the specified geometries in the MT cell
% 'FontSize':Numeric - Font size
% 'LineWidth':Numeric - Line width.
% 'Color':Char or rgb array describing marker colours for hudson and lune
% type plots.
% 'Legend':Boolean - Show a legend for hudson and lune type plots.
% 'Chain': Boolean - Plots the McMC chain if lune is selected.
% 'Movie': Boolean - Plots the McMC chain as a movie if Chain and lune is selected.
% 'R':Numeric - Radius in km to use for locations conversion.
% 'Locations':Array - event locations for each moment Tensor - expect Lat,
% Lon, Depth or N,E,Depth. Unit type (km/latlon) specified using
% 'LocationUnits'
% 'LocationUnits':'km' or 'latlon' - specifies location unit types for
% conversions
% 'Samples':Numeric - number of samples to plot (useful for e.g.
% faultplane plots as large numbers of lines plotted can be very
% slow) defaults is to plot all samples (0)
% 'Interp':Boolean - use Facecolor interpolation or not on surface plots.
% 'InteriorLines':Boolean - plot interior dashed lines on hudson and lune plots.
% 'Coordinate':Char - name of coordinate to use for coordinate plot
% (default=g)
% 'Normalise': Boolean - normalise the probability plot for histogram
% based plots.
% 'Scale': Boolean - scale probabilities to max P for all events(Fault plane plots)
%
%
%
%
%
%Main Function
function [h,options]=MTplot(MT,varargin)
global plot_types
plot_types={'radiation',...
'beachball',...
'faultplane',...
'riedeseljordan',...
'hudson',...
'lune',...
'tape',...
'orientation',...
'tnp',...
'sdr',...
'sdrsilhouette',...
'component',...
'eigenvalues',...
'3dlocation',...
'coordinate',...
'hx'};
try
[options]=Parser(MT,varargin{:});
catch ME
if strcmpi(ME.message,'Not enough input arguments.')
help MTplot
end
ME.rethrow()
end
options=parse_options(options);
if options.PanelMode && numel(options.PanelIndex)==2&&~iscell(options.Mode) && ~any(strcmpi(options.Mode,{'sdr','sdrsilhouette','orientation','tape'}))
i=options.PanelIndex(1);
j=options.PanelIndex(2);
p=panel.recover();
p(i,j).select();
end
MT=options.MT;
[MT,options]=sample_check(MT,options);
if options.FigureHandle>0 ||isa(options.FigureHandle,'matlab.ui.Figure')
h=figure(options.FigureHandle);
else
h=figure('NumberTitle','off','Name',[options.WindowTitle,options.TitleFn(options)]);
end
if ~feature('ShowFigureWindows')
set(h,'visible','off')
% close; %NOTE: In MATLAB 6.5 (R13) there is an issue with headless printing, i.e.,
% %when the DISPLAY is unset, which causes the PS file to be created without any plot in it.
% %In order to create "file.ps" that contains a plot you need to add the commands "figure;close" before the PLOT statement:
% h=gcf;
end
options.PlotFn(MT,h,options);
options.BackgroundFn(MT,h,options);
set(h,'Color','w');
end
%Parser
function output=validate_modes(mode,check)
if nargin<2
check=false;
end
if iscell(mode)
if ~check
output=true;
else
output=mode;
end
return
end
if ~ischar(mode)
error('MTplot:type_check',['Plot type ',mode,'not recognised, must be cell array or char from ',strjoin(plot_types,'\n')]);
end
mode=strrep(mode,'-','');
mode=strrep(mode,' ','');
mode=lower(mode);
valid=false;
global plot_types
if any(strcmpi(mode,plot_types))
valid=true;
end
if ~check
if ~valid
error('MTplot:type_check',['Plot type "',mode,'" not recognised, must be cell array or char from:\n\t',[plot_types{1} sprintf('\n\t%s', plot_types{2:end})]]);
end
output=valid;
elseif valid
output=mode;
else
error('MTplot:type_check',['Plot type ',mode,'not recognised, must be cell array or char from \n',[plot_types{1} sprintf('\n%s', plot_types{2:end})]])
end
end
function output=validate_dimensions(dim,mode,panel)
default_2d={'radiation','beachball','faultplane','riedeseljordan','lune','tnp'};
default_3d={};
fixed_dim={'3dlocation','hudson','tape','orientation','sdr','sdrsilhouette','component','eigenvalues','hx','coordinate'};
if iscell(mode)||panel
output=dim;
return
end
if ~ischar(dim)||~any(strcmpi(dim,{'2d','3d','default'}))
error('MTplot:type_check',['Dimension ',dim,' not recognised, must be cell array or char from 2d, 3d']);
end
if any(strcmpi(mode,fixed_dim))
output='default';
elseif strcmpi(dim,'default')
if any(strcmpi(mode,default_2d))
output='2d';
elseif any(strcmpi(mode,default_3d))
output='3d';
end
else
output=dim;
end
end
function output=validate_stations(mode)
station_modes={'beachball','faultplane'};
output=any(strcmpi(mode,station_modes));
end
function output=validate_pt(mode)
pt_modes={'beachball','radiation','faultplane'};
output=any(strcmpi(mode,pt_modes));
end
function [options]=Parser(MT,varargin)
parser=inputParser();
parser.KeepUnmatched=false;
parser.FunctionName='MTplot';
parser.addRequired('MT',@(x) assert(any([isnumeric(x),iscell(x),isstruct(x),ischar(x)&&exist(x,'file')==2]),'Value must be numeric or cell array or the filename and path'));
parser.addOptional('Mode','beachball',@(x) validate_modes(x));
parser.addOptional('Stations',{},@(x) assert(iscell(x),'Value must be cell array'));
parser.addParamValue('Dimension','default',@(x) assert(any(validatestring(x,{'2d','3d','default'}))||iscell(x),'Value must be cell array or char from 2d,3d,default'));
parser.addParamValue('StationMarkerSize',0,@(x) assert(isnumeric(x)||iscell(x),'Value must be cell array or numeric'));
parser.addParamValue('Projection','EqualArea',@(x) assert(iscell(x)||any(validatestring(x,{'EqualAngle','EqualArea','u-v','tau-k'})),'Value must be cell array or from EqualAngle, EqualArea or u-v,tau-k depending on plot type'))
parser.addParamValue('Colormap','Default',@(x) assert(any(validatestring(x,{'Parula','Default','Clear','BlueRed','BR','Jet','HSV','Hot','Cool','Spring','Summer','Autumn','Winter','Gray','Bone','Copper','Pink','Lines'})),'Value must be cell array or from Default,Clear,BlueRed,Jet,HSV,Hot,Cool,Spring,Summer,Autumn,Winter,Gray,Bone,Copper,Pink,Lines'))
parser.addParamValue('WindowTitle','',@(x) assert(ischar(x),'Value must be char'));
parser.addParamValue('Subtitle',false,@(x) assert(ischar(x)||iscell(x)||islogical(x),'Value must be cell array or char or boolean (for default alphabetical subtitles)'));
parser.addParamValue('AxisTitle',false,@islogical);
parser.addParamValue('Text',true,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('AxisLabel',true,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('TypeLabel',true,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('AxisLines',true,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Contour',false,@(x) assert(isnumeric(x)||islogical(x)||iscell(x),'Value must be cell array, numeric value or boolean'));
parser.addParamValue('StationProjection',true,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('PT',true,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Lower',true,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('FullSphere',false,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Phase','P', @(x) assert(iscell(x)||any(validatestring(x,{'P','S','SH','SV','P/SH','P/SV','SH/SV','P/S'})),'Value must be cell array or char from P, S, SH, SV, P/SH, P/SV, SH/SV or P/S'));
parser.addParamValue('Abs',false, @(x) assert(iscell(x)||islogical(x),'Value must be cell array or logical'));
parser.addParamValue('Presentation',false, @(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('PolarityErrorHighlight',false, @(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Resolution',300, @(x) assert(isnumeric(x)||iscell(x),'Value must be cell array or numeric'));
parser.addParamValue('FP',true, @(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('BA',false,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('C',[3,1,1,0,0,0,...
3,1,0,0,0,...
3,0,0,0,...
1,0,0,...
1,0,...
1],@(x) assert(isnumeric(x)||iscell(x),'Value must be cell array or numeric'));
parser.addParamValue('Legend',false,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Color','r',@(x) assert(ischar(x)||iscell(x)||(isnumeric(x)&&size(x,2)==3),'Value must be cell array or char'));
parser.addParamValue('Names',{},@(x) assert(iscell(x),'Value must be cell array'));
parser.addParamValue('StationDistribution',{},@(x) assert(iscell(x)||isstruct(x),'Value must be cell array or struct'));
parser.addParamValue('Locations',[],@(x) assert(iscell(x)||(isnumeric(x) && size(x,2)==3),'Value must be cell array or numeric n by 3 array'));
parser.addParamValue('R',6371,@isnumeric);
parser.addParamValue('LocationUnits','latlon',@(x) assert(any(validatestring(x,{'latlon','km'}))||iscell(x),'Value must be cell array or char from latlon or km'));
parser.addParamValue('Probability',[],@(x) assert(isnumeric(x)||iscell(x),'Value must be cell array or numeric'));
parser.addParamValue('Panel',false,@(x) assert(islogical(x),'Value must be boolean'));
parser.addParamValue('Options',false,@(x) isstruct(x)||islogical(x));
parser.addParamValue('FigureHandle',0,@(x) assert(ishandle(x),'Value must correspond to valid figure handle'));
parser.addParamValue('FontSize',12,@(x) assert(isnumeric(x),'Value must be numeric'));
parser.addParamValue('LineWidth',1,@(x) assert(isnumeric(x),'Value must be numeric'));
parser.addParamValue('Roman',false,@(x) assert(islogical(x),'Value must be boolean'));
parser.addParamValue('Marker','o',@(x) assert(ischar(x)||iscell(x),'Value must be cell array or char'));
parser.addParamValue('MarkerSize',6,@(x) assert(isnumeric(x)||iscell(x),'Value must be cell array or numeric'));
parser.addParamValue('Radians',false,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Marginalised',true,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Superposition',false,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Chain',[],@(x) assert(isnumeric(x)||iscell(x),'Value must be cell array or numeric'));
parser.addParamValue('Movie',false,@(x) assert(islogical(x),'Value must be boolean'))
parser.addParamValue('Logarithm',false,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'))
parser.addParamValue('ProjectionAxis',[],@(x) assert(isnumeric(x)||iscell(x),'Value must be cell array or numeric'));
parser.addParamValue('MaxSource',false,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Interp',false,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('InteriorLines',true,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Samples',0,@(x) assert(isnumeric(x)||iscell(x),'Value must be cell array or numeric'));
parser.addParamValue('SNR',0,@(x) assert(isnumeric(x)||iscell(x),'Value must be cell array or numeric'));
parser.addParamValue('Coordinate','u',@(x) assert(ischar(x)||iscell(x),'Value must be cell array or char'));
parser.addParamValue('Normalise',false,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Scale',true,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
parser.addParamValue('Only_Picked',false,@(x) assert(islogical(x)||iscell(x),'Value must be cell array or boolean'));
% HIDDEN FOR PANEL INTERFACING
parser.addParamValue('PanelIndex',false,@(x) assert(islogical(x)||isnumeric(x),'Value must be numeric array or boolean'))
function s=getString(z)
if strcmpi(char(class(z)),'char')
s={z};
else
s={''};
end
end
stringargs=cellfun(@getString,varargin);
if ismember('help',stringargs)
help MTplot;
error('MTplot:helpError','No Input Arguments Specified')
end
parser.parse(MT,varargin{:});
options=parser.Results;
unmatched=parser.Unmatched;
options.PanelIndex=false;
options.PanelMode=false;
end
function options=parse_options(options)
%MTcheck
options.MT=MTcheck(options.MT,false);
if (islogical(options.Probability)&&options.Probability)&&isstruct(options.MT)
options.Probability=options.MT.Probability;
if max(options.Probability)==0
options.Probability=exp(options.MT.ln_pdf-max(options.MT.ln_pdf));
end
elseif ~numel(options.Probability)
try
if islogical(options.Options.Probability)&&options.Options.Probability&&isstruct(options.MT)
options.Options.Probability=options.MT.Probability;
if max(options.Options.Probability)==0
options.Options.Probability=exp(options.MT.ln_pdf-max(options.MT.ln_pdf));
end
end
catch
end
end
%superposition_modes={'radiation','amplitude','amplituderatio'};
multiple_modes={'faultplane',...
'hudson',...
'lune',...
'tape',...
'orientation',...
'tnp',...
'component',...
'eigenvalues',...
'sdr','sdrsilhouette'...
'3dlocation',...
'coordinate',...
'hx'};
prob_multiple_modes={};
%Options struct passed - other arguments ignored
if isstruct(options.Options)
%Handle different MT inputs
options.Options.MT=options.MT;
options=options.Options;
else
%What does PanelMode do?
options.PanelMode=false;
if options.Panel
options.PanelMode=true;
end
end
%Handle mode check
options.Mode=validate_modes(options.Mode,true);
if isstruct(options.MT)
if ~any(strcmpi(options.Mode,multiple_modes))&&(~(isnumeric(options.Probability)&&numel(options.Probability)&&any(strcmpi(options.Mode,prob_multiple_modes))))&&size(options.MT.MTSpace,2)>1
error(['Cannot use Events structure for ',options.Mode,' plots with MTSpace dimension > 1'])
elseif ~any(strcmpi(options.Mode,multiple_modes))
options.MT=MTcheck(options.MT.MTSpace);
end
end
%Check panel and return
if iscell(options.Mode)||iscell(options.Dimension)||iscell(options.Projection)||(iscell(options.MT)&&~any(strcmpi(options.Mode,multiple_modes)))||options.Panel||(iscell(options.MT)&&iscell(options.Probability)&&~options.MaxSource&&any(strcmpi(options.Mode,multiple_modes)))&&~sum(options.PanelIndex)
options.Panel=true;
options.PanelMode=true;
%No validation with panel plot - just set plot fns etc
%Check geometry
if iscell(options.MT)
options.Geometry=size(options.MT);
elseif iscell(options.Mode)
options.Geometry=size(options.Mode);
elseif iscell(options.Dimension)
options.Geometry=size(options.Dimension);
end
[options.TitleFn,options.PlotFn,options.BackgroundFn]=getFunctionHandles(options);
if ~iscell(options.Scale)&&options.Scale&&(numel(options.Probability)>0&&any(cellfun(@isnumeric,reshape(options.Probability,1,numel(options.Probability)))))
mP=0;
for i=1:size(options.Probability,1)
for j=1:size(options.Probability,2)
if isnumeric(options.Probability{i,j})
mP=max([mP,max(options.Probability{i,j})]);
end
end
end
for i=1:size(options.Probability,1)
for j=1:size(options.Probability,2)
if isnumeric(options.Probability{i,j})
options.Probability{i,j}=options.Probability{i,j}/mP;
end
end
end
end
return
end
if iscell(options.Probability)&&numel(options.Probability)==1
if isstruct(options.MT)
options.Probability=ones(1,size(options.MT.MTSpace,2));
else
options.Probability=ones(1,size(options.MT,2));
end
end
if options.Scale&&numel(options.Probability)
options.Probability=options.Probability/max(options.Probability);
end
%Check stations
options.StationPlot=validate_stations(options.Mode);
%Check PT
options.PT=options.PT&&validate_pt(options.Mode);
%Not panel plot - plotting
%Handle dimension checks - no fails, dimension is forced in cases with
% fixed dimension (not checked in plot fns)
options.Dimension=validate_dimensions(options.Dimension,options.Mode,options.Panel);
if (iscell(options.MT)||isstruct(options.MT))&&(~any(strcmpi(options.Mode,multiple_modes))&&(isnumeric(options.Probability)&&numel(options.Probability)&&~any(strcmpi(options.Mode,prob_multiple_modes))))
error(['Cannot plot multiple events for ',options.Mode,'\nPanel option not set.'])
end
%Default Settings
%Station Marker Size
if ~iscell(options.StationMarkerSize)&&options.StationMarkerSize==0
options.StationMarkerSize=8;
if options.Presentation
options.StationMarkerSize=15;
end
end
%Text
if iscell(options.Text)&&numel(options.Text)
options.Text=true;
if options.Presentation
options.Text=false;
end
end
%Legend set up
if iscell(options.MT)
if ~iscell(options.Color)
options.Color={options.Color};
end
if any(strcmpi(options.Mode,{'hudson','lune'}))
if length(options.Color)~=length(options.MT)
DefaultColor=[1,0,0];
for i=length(options.Color)+1:length(options.MT)
options.Color{i}=DefaultColor;
end
end
if options.Legend
if length(options.Names)~=length(options.MT)
DefaultName='Solution ';
for i=length(options.Color)+1:length(options.MT)
options.Name{i}=[DefaultName,mat2str(i)];
end
end
options.LegendColors=mat2cell(ones(1,3*length(options.MT)),1,3*ones(1,length(options.MT)));
for i=1:size(options.MT,2)
rgbcolor=options.Color{i};
options.LegendColors{i}=sprintf('[rgb]{%4.2f %4.2f %4.2f}',rgbcolor);
end
options.LegendColors=options.LegendColors';
end
end
end
%Projection Function Set-up
if strcmpi(options.Mode,'hudson') && ~any(strcmpi(options.Projection,{'u-v','tau-k'}))
options.Projection='u-v';
elseif strcmpi(options.Dimension,'2d')&&~any(strcmpi(options.Projection,{'EqualAngle','EqualArea'}))
options.Projection='EqualArea';
elseif ~strcmpi(options.Dimension,'2d') && ~(strcmpi(options.Mode,'hudson') && any(strcmpi(options.Projection,{'u-v','tau-k'})))
options.Projection='PassThrough';
end
if strcmpi(options.Projection,'EqualAngle')
options.ProjFn=@EqualAngleProj;
elseif strcmpi(options.Projection,'EqualArea')
options.ProjFn=@EqualAreaProj;
elseif strcmpi(options.Projection,'tau-k')
options.ProjFn=@taukProj;
elseif strcmpi(options.Projection,'u-v')
options.ProjFn=@uvProj;
else
options.ProjFn=@passthrough;
options.StationProjection=false;
end
%Convert Locations to km
if strcmpi(options.Mode,'3dLocations')
if size(options.Locations,1)~=max(size(MT))
error('Error Using 3D Location Plot, number of locations do not match number of events. Please provide locations as an array of either [Lat,Lon,Depth] or [N,E,Depth]')
end
if strcmpi(options.LocationUnits,'latlon')
R=options.R;
convertLatToKm=@(x) pi*R*x/180;
convertLonToKm=@(x,y) R*x.*cosd(y)*pi/180;
options.Locations(:,1)=convertLatToKm(options.Locations(:,1));
options.Locations(:,2)=convertLonToKm(options.Locations(:,2),options.Locations(:,1));
end
end
options.Colormap=getColormap(options);
[options.TitleFn,options.PlotFn,options.BackgroundFn]=getFunctionHandles(options);
%Probability normalisation
if ~options.Scale&&numel(options.Probability)&&isnumeric(options.Probability)&&max(options.Probability)>1
options.Probability=options.Probability/max(options.Probability);
end
end
function [MT,options]=sample_check(MT,options)
sample_plot_types={'FaultPlanePlot'};
if options.Samples>0 && ~strcmpi(char(options.PlotFn),'PanelPlot') &&any(strcmpi(char(options.PlotFn),sample_plot_types))
indices=[];
if isstruct(MT)
if options.Samples<size(MT.MTSpace,2)
if strcmpi(char(options.PlotFn),'FaultPlanePlot')
[~,indices]=sort(MT.Probability,'descend');
indices=indices(1:options.Samples);
else
indices=randsample(size(MT.MTSpace,2),options.Samples);
end
fn = fieldnames(MT);
event=MT;
for str = fn'
if size(MT.(char(str)),2)==size(MT.MTSpace,2)
event.(char(str)) = MT.(char(str))(:,indices);
end
end
MT=event;
end
elseif options.Samples<size(MT,2)
indices=randsample(size(MT,2),options.Samples);
MT=MT(indices);
end
if numel(options.Probability)&&numel(indices)
options.Probability=options.Probability(indices);
if ~options.Scale
options.Probability=options.Probability/max(options.Probability);
end
end
end
end
%
% Helper Functions
%
function [titleHandle,plotHandle,backgroundHandle]=getFunctionHandles(options)
if options.Panel
titleHandle=@PanelTitle;
plotHandle=@PanelPlot;
backgroundHandle=@PanelBackground;
elseif strcmpi(options.Mode,'radiation')
titleHandle=@RadiationTitle;
plotHandle=@AmplitudePlot;
backgroundHandle=@GenericBackground;
elseif strcmpi(options.Mode,'beachball')
titleHandle=@BeachBallTitle;
plotHandle=@AmplitudePlot;
backgroundHandle=@GenericBackground;
elseif strcmpi(options.Mode,'hudson')
titleHandle=@HudsonTitle;
plotHandle=@HudsonPlot;
backgroundHandle=@HudsonBackground;
elseif strcmpi(options.Mode,'lune')
titleHandle=@LuneTitle;
plotHandle=@LunePlot;
backgroundHandle=@LuneBackground;
elseif strcmpi(options.Mode,'hx')
titleHandle=@HXTitle;
plotHandle=@HXPlot;
backgroundHandle=@HXBackground;
elseif strcmpi(options.Mode,'coordinate')
titleHandle=@CoordinateTitle;
plotHandle=@CoordinatePlot;
backgroundHandle=@CoordinateBackground;
elseif strcmpi(options.Mode,'tape')
titleHandle=@TapeTitle;
plotHandle=@TapePlot;
backgroundHandle=@OrientationBackground;
elseif strcmpi(options.Mode,'orientation')
titleHandle=@OrientationTitle;
plotHandle=@OrientationDistPlot;
backgroundHandle=@OrientationBackground;
elseif strcmpi(options.Mode,'riedeseljordan')
titleHandle=@RiedeselJordanTitle;
plotHandle=@RiedeselJordanPlot;
backgroundHandle=@GenericBackground;
elseif strcmpi(options.Mode,'faultplane')
titleHandle=@FaultPlaneTitle;
plotHandle=@FaultPlanePlot;
backgroundHandle=@FaultPlaneBackground;
elseif strcmpi(options.Mode,'tnp')
titleHandle=@TNPPDFTitle;
plotHandle=@TNPPDFPlot;
backgroundHandle=@TNPPDFBackground;
elseif any(strcmpi(options.Mode,{'sdr','sdrsilhouette'}))
titleHandle=@SDRPDFTitle;
plotHandle=@SDRPDFPlot;
backgroundHandle=@SDRPDFBackground;
elseif strcmpi(options.Mode,'3dlocation')
titleHandle=@LocationTitle;
plotHandle=@LocationBeachBalls;
backgroundHandle=@LocationBackground;
elseif strcmpi(options.Mode,'component')
titleHandle=@ComponentTitle;
plotHandle=@ComponentPlot;
backgroundHandle=@ComponentBackground;
elseif strcmpi(options.Mode,'eigenvalues')
titleHandle=@EigDistTitle;
plotHandle=@EigDistPlot;
backgroundHandle=@ComponentBackground;
end
end
%
% Projection Passthrough Function
%
function [x,y,z]=passthrough(x,y,z,~)
end
%
% Additional Information Plotting Functions
%
function PT(MT,h,options)
set(0, 'currentfigure', h);
hold on;
[T,N,P]=MT2TNPE(MT);
[N1,N2]=TP2FP(T,P);
Normals=[N1,N2,-N1,-N2];
[~,I]=sort(Normals(1,:));
Normals=Normals(:,I);
[Tx,Ty,Tz]=options.ProjFn([T(1,:),-T(1,:)],[T(2,:),-T(2,:)],[T(3,:),-T(3,:)],options);
[Nx,Ny,Nz]=options.ProjFn([N(1,:),-N(1,:)],[N(2,:),-N(2,:)],[N(3,:),-N(3,:)],options);
[Px,Py,Pz]=options.ProjFn([P(1,:),-P(1,:)],[P(2,:),-P(2,:)],[P(3,:),-P(3,:)],options);
[N1x,N1y,N1z]=options.ProjFn([Normals(1,1:size(Normals,2)/4),Normals(1,3*size(Normals,2)/4+1:end)],[Normals(2,1:size(Normals,2)/4),Normals(2,3*size(Normals,2)/4+1:end)],[Normals(3,1:size(Normals,2)/4),Normals(3,3*size(Normals,2)/4+1:end)],options);
[N2x,N2y,N2z]=options.ProjFn(Normals(1,size(Normals,2)/4+1:3*size(Normals,2)/4),Normals(2,size(Normals,2)/4+1:3*size(Normals,2)/4),Normals(3,size(Normals,2)/4+1:3*size(Normals,2)/4),options);
Tx=sort(Tx);
Ty=sort(Ty);
Tz=sort(Tz);
Nx=sort(Nx);
Ny=sort(Ny);
Nz=sort(Nz);
Px=sort(Px);
Py=sort(Py);
Pz=sort(Pz);
N1x=sort(N1x);
N1y=sort(N1y);
N1z=sort(N1z);
N2x=sort(N2x);
N2y=sort(N2y);
N2z=sort(N2z);
if any(strcmpi(options.Mode, {'Lune3d','Lune3dPDF'}))
for i=1:size(Tx,2)
line([-Tx(i)',Tx(i)'],[-Ty(i)',Ty(i)'],[-Tz(i)',Tz(i)'],'Color','red','LineWidth',options.LineWidth);
line([-Px(i)',Px(i)'],[-Py(i)',Py(i)'],[-Pz(i)',Pz(i)'],'Color','blue','LineWidth',options.LineWidth);
end
% elseif iscell(MT)%||isstruct(MT)
% if ~isempty(options.Probability)
% scatter3(Tx,Ty,Tz,'.','CData',[ones(size(Tx));0.8-0.8*[options.Probability,options.Probability];0.8-0.8*[options.Probability,options.Probability]]');
% scatter3(Px,Py,Pz,'.','CData',[0.8-0.8*[options.Probability,options.Probability];0.8-0.8*[options.Probability,options.Probability];ones(size(Px))]');
% scatter3(Nx,Ny,Nz,'.','CData',[0.8-0.8*[options.Probability,options.Probability];ones(size(Nx));0.8-0.8*[options.Probability,options.Probability]]');
% scatter3(N1x,N1y,N1z,'.','CData',0.5*[1-[options.Probability,options.Probability];1-[options.Probability,options.Probability];1-[options.Probability,options.Probability]]');
% scatter3(N2x,N2y,N2z,'.','CData',0.5*[1-[options.Probability,options.Probability];1-[options.Probability,options.Probability];1-[options.Probability,options.Probability]]');
% else
% scatter3(Tx,Ty,Tz,'.r');
% scatter3(Px,Py,Pz,'.b');
% scatter3(Nx,Ny,Nz,'.g');
% scatter3(N1x,N1y,N1z,'.k');
% scatter3(N2x,N2y,N2z,'.k');
% end
elseif strcmpi(options.Dimension,'2d')
grey=[0.5 0.5 0.5];
if ~isempty(options.Probability)
scatter3(Tx,Ty,Tz,'.','CData',[ones(size(Tx));0.8-0.8*[options.Probability,options.Probability];0.8-0.8*[options.Probability,options.Probability]]');
scatter3(Px,Py,Pz,'.','CData',[0.8-0.8*[options.Probability,options.Probability];0.8-0.8*[options.Probability,options.Probability];ones(size(Px))]');
scatter3(Nx,Ny,Nz,'.','CData',[0.8-0.8*[options.Probability,options.Probability];ones(size(Nx));0.8-0.8*[options.Probability,options.Probability]]');
scatter3(N1x,N1y,N1z,'.','CData',0.5*[1-[options.Probability,options.Probability];1-[options.Probability,options.Probability];1-[options.Probability,options.Probability]]');
scatter3(N2x,N2y,N2z,'.','CData',0.5*[1-[options.Probability,options.Probability];1-[options.Probability,options.Probability];1-[options.Probability,options.Probability]]');
else
plot3(Tx,Ty,Tz,'h','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8);
plot3(Px,Py,Pz,'h','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8);
plot3(Nx,Ny,Nz,'h','MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',8);
plot3(N1x,N1y,N1z,'h','MarkerEdgeColor',grey,'MarkerFaceColor',grey,'MarkerSize',8);
plot3(N2x,N2y,N2z,'h','MarkerEdgeColor',grey,'MarkerFaceColor',grey,'MarkerSize',8);
end
elseif strcmpi(options.Dimension,'3d')
line([-Tx,Tx],[-Ty,Ty],[-Tz,Tz],'Color','red','LineWidth',options.LineWidth);
line([-Nx,Nx],[-Ny,Ny],[-Nz,Nz],'LineWidth',options.LineWidth);
line([-Px,Px],[-Py,Py],[-Pz,Pz],'Color','blue','LineWidth',options.LineWidth);
line([-N1x,N1x],[-N1y,N1y],[-N1z,N1z],'Color','black','LineWidth',options.LineWidth);
line([-N2x,N2x],[-N2y,N2y],[-N2z,N2z],'LineWidth',options.LineWidth);
if options.Text
text(Tx,Ty,Tz-2,'T-axis','FontSize',options.FontSize);
text(Nx,Ny,Nz-2,'N-axis','FontSize',options.FontSize);
text(Px,Py,Pz-2,'P-axis','FontSize',options.FontSize);
text(N1x,N1y,N1z-2,'Normal1','FontSize',options.FontSize);
text(N2x,N2y,N2z-2,'Normal2','FontSize',options.FontSize);
end
end
if ~strcmpi(options.Dimension,'3d') && options.Text
text(mean(Tx(1:size(T,2))),mean(Ty(1:size(T,2))),mean(Tz(1:size(T,2))),'T-axis','HorizontalAlignment','Left','VerticalAlignment','bottom','FontSize',options.FontSize);
text(mean(Tx(size(T,2)+1:end)),mean(Ty(size(T,2)+1:end)),mean(Tz(size(T,2)+1:end)),'T-axis','HorizontalAlignment','Left','VerticalAlignment','bottom','FontSize',options.FontSize);
text(mean(Px(1:size(P,2))),mean(Py(1:size(P,2))),mean(Pz(1:size(P,2))),'P-axis','HorizontalAlignment','Left','VerticalAlignment','bottom','Color',grey,'FontSize',options.FontSize);
text(mean(Px(size(P,2)+1:end)),mean(Py(size(P,2)+1:end)),mean(Pz(size(P,2)+1:end)),'P-axis','HorizontalAlignment','Left','VerticalAlignment','bottom','Color',grey,'FontSize',options.FontSize);
text(mean(Nx(1:size(N,2))),mean(Ny(1:size(N,2))),mean(Nz(1:size(N,2))),'N-axis','HorizontalAlignment','Left','VerticalAlignment','bottom','Color','white','FontSize',options.FontSize);
text(mean(Nx(size(N,2)+1:end)),mean(Ny(size(N,2)+1:end)),mean(Nz(size(N,2)+1:end)),'N-axis','HorizontalAlignment','Left','VerticalAlignment','bottom','Color','white','FontSize',options.FontSize);
text(mean(N1x(1:size(N1,2))),mean(N1y(1:size(N1,2))),mean(N1z(1:size(N1,2))),'Normal 1','HorizontalAlignment','Left','VerticalAlignment','bottom','FontSize',options.FontSize);
text(mean(N1x(size(N1,2)+1:end)),mean(N1y(size(N1,2)+1:end)),mean(N1z(size(N1,2)+1:end)),'Normal 1','HorizontalAlignment','Left','VerticalAlignment','bottom','FontSize',options.FontSize);
text(mean(N2x(1:size(N2,2))),mean(N2y(1:size(N2,2))),mean(N2z(1:size(N2,2))),'Normal 2','HorizontalAlignment','Left','VerticalAlignment','bottom','FontSize',options.FontSize);
text(mean(N2x(size(N2,2)+1:end)),mean(N2y(size(N2,2)+1:end)),mean(N2z(size(N2,2)+1:end)),'Normal 2','HorizontalAlignment','Left','VerticalAlignment','bottom','FontSize',options.FontSize);
end
hold off;
end
function Axis(h,options)
set(0, 'currentfigure', h);
maxValues=(options.ProjFn([1;0;0;0],[0;1;0;0],[0;0;1;-1]));
maxValues(maxValues==Inf)=0;
maxValue=max(maxValues);
if options.AxisLines
line(1.2*[-maxValue,maxValue],[0,0],'Color','black','LineWidth',0.5*options.LineWidth);
line([0,0],1.2*[-maxValue,maxValue],'Color','black','LineWidth',0.5*options.LineWidth);
if options.AxisLabel
text(1.3*maxValue,0,0,'North','Color','black','HorizontalAlignment','Center','VerticalAlignment','Bottom','FontSize',options.FontSize);
text(0,1.3*maxValue,0,'East','Color','black','FontSize',options.FontSize);
end
end
if strcmpi(options.Dimension,'3d') && options.AxisLines
line([0,0],[0,0],1.2*[-maxValue,maxValue],'Color','black','LineWidth',options.LineWidth);
if options.AxisLabel
text(0,0,1.3*maxValue,'Down','Color','black','FontSize',options.FontSize)
end
set(gca,'Zdir','rev')
end
end
function Stations(h,options)
if isstruct(options.StationDistribution)&&~isempty(options.StationDistribution.Distribution)
set(0, 'currentfigure', h);
hold on
if ~iscell(options.StationDistribution.Distribution)
[nSamples,nStations,~]=size(options.StationDistribution.Distribution);
newflag=false;
else
nSamples=numel(options.StationDistribution.Distribution);
nStations=size(options.StationDistribution.Distribution{1}.Azimuth,1);
newflag=true;
end
xsta=zeros(nSamples,nStations)';
ysta=zeros(nSamples,nStations)';
zsta=zeros(nSamples,nStations)';
if newflag
for i=1:nSamples
[xsta(:,i),ysta(:,i),zsta(:,i)]=toa2xyz(options.StationDistribution.Distribution{i}.Azimuth,options.StationDistribution.Distribution{i}.TakeOffAngle,options);
end
sampleName=mat2cell(options.StationDistribution.Distribution{1}.Name,ones(size(options.StationDistribution.Distribution{1}.Name,1),1));
else
for i=1:nStations
[xsta(i,:),ysta(i,:),zsta(i,:)]=toa2xyz(cell2mat(options.StationDistribution.Distribution(:,i,2))',cell2mat(options.StationDistribution.Distribution(:,i,3))',options);
end
sampleName=options.StationDistribution.Distribution(1,:,1);
end
[Xsta,Ysta,Zsta]=options.ProjFn(xsta,ysta,zsta,options);
Polarity=zeros(nStations,1);
if ~isempty(options.Stations)
[xtext,ytext,ztext,name,pol,Pol]=ExtractStations(options);
xt=0*xtext;
yt=0*ytext;
zt=0*ztext;
for n=1:nStations
flag=true;
for m=1:numel(name)
if strcmp(strtrim(sampleName{n}),strtrim(name(m)))
%Match sample name to station name
Polarity(n)=Pol(m);
Ptext(n,:)=pol(m,:);
xt(n)=xtext(m);
yt(n)=ytext(m);
zt(n)=ztext(m);
flag=false;
end
end
if flag
xt(n)=mean(xsta(n,:));
yt(n)=mean(ysta(n,:));
zt(n)=mean(zsta(n,:));
if Polarity(n)>0
Ptext(n,:)=['^','r'];
elseif Polarity(n)<0
Ptext(n,:)=['v','b'];
else
Ptext(n,:)=['o','w'];
end
end
end
[Xtext,Ytext,Ztext]=options.ProjFn(xt,yt,zt,options);
end
P=options.StationDistribution.Probability/max(options.StationDistribution.Probability);
if size(P,2)==1
P=P';
end
if ~isempty(options.Stations)
if options.Only_Picked
Polarity(Polarity==0)=nan;
end
C=kron(Polarity,ones(1,nSamples)).*kron((P/(max(P)*2)+0.5),ones(nStations,1));
else
C=kron((P/(max(P)*2)+0.5),ones(nStations,1));
end
scatter3(reshape(Xsta,1,nSamples*nStations),reshape(Ysta,1,nSamples*nStations),reshape(Zsta,1,nSamples*nStations)+0.5,options.MarkerSize,reshape(C,1,nSamples*nStations),'.')
set(gca,'CLim',[-1,1])
if ~options.Presentation && options.Text && ~isempty(options.Stations)
text(Xtext,Ytext,Ztext,sampleName,'HorizontalAlignment','left','VerticalAlignment','bottom','FontSize',options.FontSize)
end
hold off
if ~isempty(options.Stations)&&options.StationMarkerSize>1
hold on
[xtext,ytext,ztext,name,pol,Pol]=ExtractStations(options);
[Xtext,Ytext,Ztext]=options.ProjFn(xtext,ytext,ztext,options);
Ztext=Ztext+1;
for i=1:length(Xtext)
for m=1:length(sampleName)
if strcmp(strtrim(sampleName{m}),strtrim(name(i)))
if pol(i,2)=='b'||pol(i,2)=='r'
markerEdge='w';
else
markerEdge=[0.3,0.3,0.3];
end
plot3(Xtext(i),Ytext(i),Ztext(i),'Marker',pol(i,1),'MarkerFaceColor',pol(i,2),'MarkerEdgeColor',markerEdge,'LineWidth',2,'MarkerSize',options.StationMarkerSize)
end
end
end
hold off
end
elseif ~isempty(options.Stations)
set(0, 'currentfigure', h);
hold on
[xsta,ysta,zsta,name,pol,polVals]=ExtractStations(options);
[Xsta,Ysta,Zsta]=options.ProjFn(xsta,ysta,zsta,options);
Zsta=Zsta+1;
errors=ones(1,length(Xsta));
if options.PolarityErrorHighlight
errors=checkStationPol(xsta,ysta,zsta,polVals,options.MT);
end
for i=1:length(Xsta)
if options.PolarityErrorHighlight && errors(i)>0
plot3(Xsta(i),Ysta(i),Zsta(i),'Marker',pol(i,1),'MarkerFaceColor',pol(i,2),'MarkerEdgeColor','white','LineWidth',2,'MarkerSize',options.StationMarkerSize)
else
plot3(Xsta(i),Ysta(i),Zsta(i),'Marker',pol(i,1),'MarkerFaceColor',pol(i,2),'MarkerEdgeColor','black','MarkerSize',options.StationMarkerSize)
end
if ~options.Presentation && options.Text
text(Xsta(i),Ysta(i),Zsta(i),name(i),'HorizontalAlignment','left','VerticalAlignment','bottom','FontSize',options.FontSize)
end
end
hold off
end
end
function errors=checkStationPol(xsta,ysta,zsta,pol,MT)
mt=MTcheck(MT);
MT=[mt(1,1);mt(2,2);mt(3,3);sqrt(2)*mt(1,2);sqrt(2)*mt(1,3);sqrt(2)*mt(2,3)];
theta=acos(zsta)';
phi=atan2(ysta,xsta)';
staCoeffs=[cos(phi).*cos(phi).*sin(theta).*sin(theta),...
sin(phi).*sin(phi).*sin(theta).*sin(theta),...
cos(theta).*cos(theta),...
sqrt(2)*sin(phi).*cos(phi).*sin(theta).*sin(theta),...
sqrt(2)*cos(phi).*cos(theta).*sin(theta),...
sqrt(2)*sin(phi).*cos(theta).*sin(theta)];
errors=(sign(staCoeffs*MT).*double(pol));
errors=errors==-1;
end
function [x,y,z,name,pol,polVals]=ExtractStations(options)
%sta is a cell array of station information - name,azimuth and take off
%angle and polarity
n=size(options.Stations);
for i=1:n(1)
[x(i),y(i),z(i)]=toa2xyz(cell2mat(options.Stations(i,2)),cell2mat(options.Stations(i,3)),options);
name(i)=options.Stations(i,1);
p=cell2mat(options.Stations(i,4));
if p>0
pol(i,:)=['^','r'];
elseif p<0
pol(i,:)=['v','b'];
else
pol(i,:)=['o','w'];
end
polVals(1,i)=p;
end
polVals=polVals';
end
%
% Title Functions