-
Notifications
You must be signed in to change notification settings - Fork 2
/
PlotPTResidualsJake.py
858 lines (753 loc) · 29.4 KB
/
PlotPTResidualsJake.py
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
# -*- coding: utf-8 -*-
"""
Created on Wed May 25 16:39:30 2011
@author: a1185872
This script will plot phase tensor residuals. The things that you need to
change before you run are:
edipathb,edipathi -> these are the paths to where the edi files for the
base survey and the post injection survey, respectively.
pkfn -> is a pickle file to where all the calculated data is stored so
each time you run the program it won't have to calculate the
residual over again.
The things you can change are:
ctype = 'fm' for the the forward model, your edi files,
or 'data' to plot the residuals from the Paralana data
ttype = 'pt' to plot the phase tensor residuals
'rt' to plot the resistivity tensor residuals
plottype = 'pseudo' to plot a pseudo section of the tensor residuals
'map' to plot a map view of the tensor residuals
for plotting you can change:
prange = list of periods to plot
xlimits = limits of the plot in the x-direction (only works for maps)
ylimits = limits of the plot in the y-direction (km)
esize = size of ellipses
ecmax = maximum of the color, anything above will be colored red
"""
import os
import matplotlib.pyplot as plt
import numpy as np
import scipy.signal as sps
from matplotlib.colors import LinearSegmentedColormap, Normalize
import Z
from matplotlib.colorbar import *
from matplotlib.patches import Ellipse
import pickle
import LatLongUTMconversion as utm2ll
# ==============================================================================
# Inputs
# ==============================================================================
ctype = "data" # data or fm for data or forward model
ttype = "pt" # or pt
plottype = "pseudo" # map of pseudo for map or pseudo section
diffyn = "y"
sline = "ns"
# ==============================================================================
# a few constants
# ==============================================================================
refe = 23
# phase tensor map
ptcmapdict = {
"red": ((0.0, 1.0, 1.0), (1.0, 1.0, 1.0)),
"green": ((0.0, 0.0, 1.0), (1.0, 0.0, 1.0)),
"blue": ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)),
}
ptcmap = LinearSegmentedColormap("ptcmap", ptcmapdict, 256)
# phase tensor map for difference (reverse)
ptcmapdictr = {
"red": ((0.0, 1.0, 1.0), (1.0, 1.0, 1.0)),
"green": ((0.0, 1.0, 0.0), (1.0, 1.0, 0.0)),
"blue": ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)),
}
ptcmapr = LinearSegmentedColormap("ptcmapr", ptcmapdictr, 256)
# resistivity tensor map for calculating delta
ptcmapdict2 = {
"red": ((0.0, 0.0, 1.0), (1.0, 0.0, 1.0)),
"green": ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0)),
"blue": ((0.0, 1.0, 0.0), (1.0, 1.0, 0.0)),
}
ptcmap2 = LinearSegmentedColormap("ptcmap2", ptcmapdict2, 256)
# resistivity tensor map for calcluating resistivity difference
rtcmapdict3 = {
"red": ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 1.0, 0.0)),
"green": ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)),
"blue": ((0.0, 0.0, 1.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)),
}
rtcmap3 = LinearSegmentedColormap("rtcmap3", rtcmapdict3, 256)
# resistivity tensor map for calcluating apparent resistivity
rtcmapdict3r = {
"red": ((0.0, 1.0, 1.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)),
"green": ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)),
"blue": ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)),
}
rtcmap3r = LinearSegmentedColormap("rtcmap3r", rtcmapdict3r, 256)
# borehole location
bhll = (139.72851, -30.2128)
bhz, bhe, bhn = utm2ll.LLtoUTM(refe, bhll[1], bhll[0])
ecmin = 0
# ===============================================================================
# Initialize parameters
# ===============================================================================
if ctype == "data":
ncol = 5
# set edipaths
# set edipaths
if ttype == "pt":
edipathi = (
r"E:\Uni_Work\Hons2012\Data\EDI_Files\Paralana\InjectionEDIfiles\CFA\Backup"
)
edipathb = r"E:\Uni_Work\Hons2012\Data\EDI_Files\Paralana\EDIFilesBaseSurvey\CFA\Backup"
elif ttype == "rt":
edipathi = r"C:\Peacock\My Dropbox\Paralana\InjectionEDIfiles\CFA\SS\DR"
edipathb = r"C:\Peacock\My Dropbox\Paralana\EDIFilesBaseSurvey\CFA\SS\DR"
# pickle file name
pkfn = "C:\\Users\\a1194409\\" + ttype.upper() + "FM.pkl"
# make list of existing edifiles
if diffyn == "y":
edilst = [
[os.path.join(edipathb, edib), os.path.join(edipathi, edii)]
for edib in os.listdir(edipathb)
for edii in os.listdir(edipathi)
if edib.find(".") > 0
if edib[0:4] == edii[0:4]
]
mfs = (3, 5)
elif diffyn == "n":
edilst = [
os.path.join(edipathi, edii)
for edii in os.listdir(edipathi)
if edii.find(".edi") > 0
]
mfs = (1, 1)
a = 1
# number of frequencies
nf = 43
ns = len(edilst)
noise = None
# plot parameters
# -------MAP-----------------------
if plottype == "map":
prange = [18, 24, 28, 30, 33, 35]
xlimits = (-3.4, 3.4)
ylimits = (-2.4, 2.8)
# xlimits=(-1.5,1.5)
# ylimits=(-1.5,1.5)
if ttype == "pt":
esize = 2
if diffyn == "y":
ecmax = 0.25
fignum = 10
elif diffyn == "n":
ecmax = 90
fignum = 11
elif ttype == "rt":
esize = 2
if diffyn == "y":
ecmax = 2
fignum = 12
elif diffyn == "n":
ecmax = 2
fignum = 13
# ------PSEUDO SECTION----------------------------
elif plottype == "pseudo":
esize = 1
yspacing = 0.3
ylimits = (-yspacing / 2, nf * (yspacing) + yspacing / 2)
xstep = 1
xscaling = 1
if ttype == "rt":
ecmax = 2.50
elif ttype == "pt":
# ecmax=20
ecmax = 90
if sline == "ew":
pstationlst = ["pb{0:}".format(ii) for ii in range(44, 33, -1)] + [
"pb{0:}".format(ii) for ii in range(23, 34)
]
# stationlst.remove('pb27')
fignum = 14
elif sline == "ns":
pstationlst = (
["pb{0:}".format(ii) for ii in range(22, 11, -1)]
+ ["pb0{0:}".format(ii) for ii in range(1, 10)]
+ ["pb10", "pb11"]
)
pstationlst.remove("pb05")
pstationlst.remove("pb06")
pstationlst.remove("pb12")
fignum = 15
# ---------Forward Model-------------------------------------------------------
elif ctype == "fm":
ncol = 6
edipathb = r"E:\Uni_Work\PhD2013\Elsevier\Models\Isotropic\MT_TAB_ROT_Para_New5_Iso_200\DAT2Edi"
edipathi = r"E:\Uni_Work\PhD2013\Elsevier\Models\Anisotropic\MT_TAB_ROT_Para_New5_1_167_30_1\DAT2Edi"
pkfn = "C:\\Users\\a1194409\\" + ttype.upper() + "FM.pkl"
# pkfn=r'c:\Users\Own er\Documents\PHD\Geothermal\Paralana\RTBAComparisonFM.pkl'
# make list of existing edifiles
edilst = [
[os.path.join(edipathb, edib), os.path.join(edipathi, edii)]
for edib in os.listdir(edipathb)
for edii in os.listdir(edipathi)
if edib.find(".edi") > 0
if edib[0:-4] == edii[0:-4]
]
# number of frequencies
nf = 30
ns = len(edilst)
# set some plotting parameters
a = 1
noise = None
yspacing = 1
xscaling = 10
xstep = 2
ncols = 3
mfs = (1, 1)
if plottype == "map":
prange = [6, 10, 14, 18, 22, 26]
xlimits = (0, 10)
ylimits = (0, 10)
esize = 0.7
fignum = 1
ecmax = 5
elif plottype == "pseudo":
prange = range(nf)
xlimits = (-xscaling - 10, xscaling + 10)
ylimits = (-1, (nf + 1) * yspacing)
esize = 2.0
fignum = 2
ecmax = 0.23
bhe = 433.43376579
bhn = 0.0
# set station names
pstationlst = ["station{0}".format(ii) for ii in range(43, 48)]
# ==============================================================================
# Make a pickle file with all the data so you don't have to calculate each time
# ==============================================================================
if not os.path.isfile(pkfn):
azimutharr = np.zeros((nf, ns))
phimaxarr = np.zeros((nf, ns))
phiminarr = np.zeros((nf, ns))
betaarr = np.zeros((nf, ns))
colorarr = np.zeros((nf, ns))
latlst = np.zeros(ns)
lonlst = np.zeros(ns)
stationlst = []
for ss, station in enumerate(edilst):
# if the resistivity tensors are to be plotted
if ttype == "rt":
# make a data type Z
z1 = Z.Z(station[0], ncol=ncol)
z2 = Z.Z(station[1], ncol=ncol)
stationlst.append(z1.station)
sz, se, sn = utm2ll.LLtoUTM(refe, z1.lat, z1.lon)
latlst[ss] = (sn - bhn) / 1000.0
lonlst[ss] = (se - bhe) / 1000.0
# get the phase tensor information
pt1 = z1.getResTensor(rotate=180)
pt2 = z2.getResTensor(rotate=180)
# loop over period plotting the difference between phase tensors
period = z1.period
nf = len(period)
for ii in range(nf):
# add noise if desired
if noise != None:
sigman = np.sqrt(abs(pt1.rho[ii, 0, 1] * pt1.rho[ii, 1, 0])) * noise
pt1.rho[ii] = pt1.rho[ii] + sigman * np.random.normal(size=(2, 2))
pt2.rho[ii] = pt2.rho[ii] + sigman * np.random.normal(size=(2, 2))
# calculate the resistivity tensor
rho = np.eye(2) - (np.dot(np.linalg.inv(pt1.rho[ii]), pt2.rho[ii]))
pi1 = 0.5 * np.sqrt(
(rho[0, 0] - rho[1, 1]) ** 2 + (rho[0, 1] + rho[1, 0]) ** 2
)
pi2 = 0.5 * np.sqrt(
(rho[0, 0] + rho[1, 1]) ** 2 + (rho[0, 1] - rho[1, 0]) ** 2
)
phimax = pi1 + pi2
phimin = pi2 - pi1
alpha = 0.5 * np.arctan(
(rho[0, 1] + rho[1, 0]) / (rho[0, 0] - rho[1, 1])
)
beta = 0.5 * np.arctan(
(rho[0, 1] - rho[1, 0]) / (rho[0, 0] + rho[1, 1])
)
azimuth = (alpha - beta) * 180 / np.pi
ecolor = (
np.sign(pt1.rhomax[ii] - pt2.rhomin[ii])
* (abs(rho.min()) + abs(rho.max()))
/ 2
)
# put things into arrays
phimaxarr[ii, ss] = phimax
phiminarr[ii, ss] = phimin
azimutharr[ii, ss] = azimuth
betaarr[ii, ss] = pt1.rhodet[ii] - pt2.rhodet[ii]
colorarr[ii, ss] = ecolor
# if plotting the phase tensor
elif ttype == "pt":
# make a data type Z
z1 = Z.Z(station[0], ncol=ncol)
z2 = Z.Z(station[1], ncol=ncol)
stationlst.append(z1.station)
sz, se, sn = utm2ll.LLtoUTM(refe, z1.lat, z1.lon)
latlst[ss] = (sn - bhn) / 1000.0
lonlst[ss] = (se - bhe) / 1000.0
# get the phase tensor information
pt1 = z1.getPhaseTensor(rotate=180)
pt2 = z2.getPhaseTensor(rotate=180)
# add noise if desired
if noise != None:
sigman = np.sqrt(abs(pt1.phi[ii, 0, 1] * pt1.phi[ii, 1, 0])) * noise
pt1.phi[ii] = pt1.phi[ii] + sigman * np.random.normal(size=(2, 2))
pt2.phi[ii] = pt2.phi[ii] + sigman * np.random.normal(size=(2, 2))
# calculate the difference between the two phase tensor ellipses
for ii in range(nf):
phi = np.eye(2) - (np.dot(np.linalg.inv(pt1.phi[ii]), pt2.phi[ii]))
# compute the trace
tr = phi[0, 0] + phi[1, 1]
# Calculate skew of phi and the cooresponding error
skew = phi[0, 1] - phi[1, 0]
# calculate the determinate and determinate error of phi
phidet = abs(np.linalg.det(phi))
# calculate reverse trace and error
revtr = phi[0, 0] - phi[1, 1]
# calculate reverse skew and error
revskew = phi[1, 0] + phi[0, 1]
beta = 0.5 * np.arctan2(skew, tr) * (180 / np.pi)
alpha = 0.5 * np.arctan2(revskew, revtr) * (180 / np.pi)
# calculate azimuth
azimuth = alpha - beta
# calculate phimax
phimax = np.sqrt(abs((0.5 * tr) ** 2 + (0.5 * skew) ** 2)) + np.sqrt(
abs((0.5 * tr) ** 2 + (0.5 * skew) ** 2 - np.sqrt(phidet) ** 2)
)
# calculate minimum value for phi
if phidet >= 0:
phimin = np.sqrt(
abs((0.5 * tr) ** 2 + (0.5 * skew) ** 2)
) - np.sqrt(
abs((0.5 * tr) ** 2 + (0.5 * skew) ** 2 - np.sqrt(phidet) ** 2)
)
elif phidet < 0:
phimin = -1 * np.sqrt(
abs((0.5 * tr) ** 2 + (0.5 * skew) ** 2)
) - np.sqrt(
abs(
(0.5 * tr) ** 2 + (0.5 * skew) ** 2 - (np.sqrt(phidet)) ** 2
)
)
# set the color of the array as the geometric mean of the
# residual phase tensor
# ecolor=np.sqrt(abs(phi.min())*abs(phi.max()))
ecolor = np.sqrt(abs(phimin) * abs(phimax))
# put things into arrays
phimaxarr[ii, ss] = phimax
phiminarr[ii, ss] = phimin
azimutharr[ii, ss] = azimuth
betaarr[ii, ss] = abs(beta)
colorarr[ii, ss] = ecolor
# ===============================================================================
# Filter the arrays if desired
# ===============================================================================
phimaxarr = sps.medfilt2d(phimaxarr, kernel_size=mfs)
phiminarr = sps.medfilt2d(phiminarr, kernel_size=mfs)
azimutharr = sps.medfilt2d(azimutharr, kernel_size=mfs)
betaarr = sps.medfilt2d(betaarr, kernel_size=mfs)
colorarr = sps.medfilt2d(colorarr, kernel_size=mfs)
# ===============================================================================
# Pickle results so don't have to reload them everytime
# ===============================================================================
fid = file(pkfn, "w")
pickle.dump(
(
phimaxarr,
phiminarr,
azimutharr,
betaarr,
colorarr,
latlst,
lonlst,
stationlst,
z1.period,
),
fid,
)
fid.close()
# ==============================================================================
# Print what you are plotting
# ==============================================================================
print "pkfn:\t", pkfn
print "ctype:\t", ctype
print "tensor:\t", ttype
print "Plotting:\t", plottype
# ===============================================================================
# Plot ellipses in map view
# ===============================================================================
# load pickled file
pkfid = file(pkfn, "r")
(
phimaxarr,
phiminarr,
azimutharr,
betarr,
ecolorarr,
latlst,
lonlst,
stationlst,
period,
) = pickle.load(pkfid)
pkfid.close()
print "ecolorarr.max()= {0:.5f}".format(ecolorarr.max())
if plottype == "map":
ecolorarr = np.nan_to_num(ecolorarr)
nrows = len(prange) / ncols
plt.rcParams["font.size"] = 6
plt.rcParams["figure.subplot.left"] = 0.1
plt.rcParams["figure.subplot.right"] = 0.92
plt.rcParams["figure.subplot.bottom"] = 0.08
plt.rcParams["figure.subplot.top"] = 0.95
plt.rcParams["figure.subplot.hspace"] = 0.005
plt.rcParams["figure.subplot.wspace"] = 0.005
emax = 2 * esize
fig = plt.figure(fignum, [14, 14], dpi=300)
plt.clf()
for ii, ff in enumerate(prange, 1):
ax1 = fig.add_subplot(nrows, ncols, ii, aspect="equal")
for ss in range(ns):
if ctype == "data":
eheightd = phiminarr[ff, ss] / (np.median(phimaxarr[ff, :]) * 3) * esize
ewidthd = phimaxarr[ff, ss] / (np.median(phimaxarr[ff, :]) * 3) * esize
else:
eheightd = phiminarr[ff, ss] / phimaxarr[ff, :].max() * esize
ewidthd = phimaxarr[ff, ss] / phimaxarr[ff, :].max() * esize
if eheightd > emax or ewidthd > emax:
pass
else:
if diffyn == "y":
ellipd = Ellipse(
(lonlst[ss], latlst[ss]),
width=ewidthd,
height=eheightd,
angle=azimutharr[ff, ss] - 90,
)
elif diffyn == "n":
ellipd = Ellipse(
(lonlst[ss], latlst[ss]),
width=ewidthd,
height=eheightd,
angle=azimutharr[ff, ss],
)
# color ellipse
if ttype == "pt":
if diffyn == "y":
cvar = ecolorarr[ff, ss] / ecmax
elif diffyn == "n":
cvar = ecolorarr[ff, ss] / 90
if abs(cvar) > 1:
ellipd.set_facecolor((1, 0, 0.1))
else:
ellipd.set_facecolor((1, 1 - abs(cvar), 0.1))
elif ttype == "rt":
if diffyn == "y":
cvar = betarr[ff, ss] / ecmax
if cvar < 0:
if cvar < -1:
ellipd.set_facecolor((0, 0, 1))
else:
ellipd.set_facecolor((1 - abs(cvar), 1 - abs(cvar), 1))
else:
if cvar > 1:
ellipd.set_facecolor((1, 0, 0))
else:
ellipd.set_facecolor((1, 1 - abs(cvar), 1 - abs(cvar)))
elif diffyn == "n":
cvar = (ecolorarr[ff, ss] - ecmin) / (ecmax - ecmin)
if cvar > 0.5:
if cvar > 1:
ellipd.set_facecolor((0, 0, 1))
else:
ellipd.set_facecolor((1 - abs(cvar), 1 - abs(cvar), 1))
else:
if cvar < -1:
ellipd.set_facecolor((1, 0, 0))
else:
ellipd.set_facecolor((1, 1 - abs(cvar), 1 - abs(cvar)))
ax1.add_patch(ellipd)
ax1.set_xlim(xlimits)
ax1.set_ylim(ylimits)
ax1.text(
xlimits[0] + 0.20,
ylimits[1] - 0.2,
"T={0:.2g} s".format(period[ff]),
verticalalignment="top",
horizontalalignment="left",
fontdict={"size": 8, "weight": "bold"},
bbox={"facecolor": "white"},
)
ax1.text(
0,
0,
"X",
verticalalignment="center",
horizontalalignment="center",
fontdict={"size": 9, "weight": "bold"},
)
ellips = Ellipse(
(xlimits[0] + 0.85, ylimits[0] + 0.65), width=1, height=1, angle=0
)
ellips.set_facecolor((0.1, 0.1, 0.1))
ax1.add_artist(ellips)
ax1.grid(alpha=0.2)
if ctype == "fm":
ax1.text(
xlimits[0] + 0.20,
ylimits[0] + 1.4,
"$\Delta$={0:.2g}".format(phimaxarr[ff, :].max() * a),
horizontalalignment="left",
verticalalignment="bottom",
bbox={"facecolor": "white"},
)
elif ctype == "data":
ax1.text(
xlimits[0] + 0.20,
ylimits[0] + 1.4,
"$\Delta$={0:.2g}".format(np.median(phimaxarr[ff, :]) * 3),
horizontalalignment="left",
verticalalignment="bottom",
bbox={"facecolor": "white"},
)
if ii > nrows:
ax1.set_xlabel("easting (km)", fontdict={"size": 9, "weight": "bold"})
if ii < (nrows - 1) * ncols + 1:
ax1.xaxis.set_ticklabels(
["" for hh in range(len(ax1.xaxis.get_ticklabels()))]
)
if ii == 1 or ii == ncols + 1 or ii == 2 * ncols + 1 or ii == 3 * ncols + 1:
pass
else:
ax1.yaxis.set_ticklabels(
["" for hh in range(len(ax1.yaxis.get_ticklabels()))]
)
if ii == ncols * int(nrows / 2) + 1 or ii == 1:
ax1.set_ylabel("northing (km)", fontdict={"size": 9, "weight": "bold"})
# add colorbar
ax2 = fig.add_subplot(1, 1, 1)
ax2.set_visible(False)
cbax = make_axes(ax2, shrink=0.99, fraction=0.015, pad=10.2)
if ttype == "rt":
if diffyn == "y":
cbx = ColorbarBase(
cbax[0],
cmap=rtcmap3,
norm=Normalize(vmin=-ecmax, vmax=ecmax),
orientation="vertical",
format="%.2g",
)
cbx.set_label(
"App. Res. ($\Omega \cdot$m) ", fontdict={"size": 7, "weight": "bold"}
)
if diffyn == "n":
cbx = ColorbarBase(
cbax[0],
cmap=rtcmap3r,
norm=Normalize(vmin=ecmin, vmax=ecmax),
orientation="vertical",
format="%.2g",
)
cbx.set_label(
"App. Res. ($\Omega \cdot$m) ", fontdict={"size": 7, "weight": "bold"}
)
elif ttype == "pt":
if diffyn == "y":
cbx = ColorbarBase(
cbax[0],
cmap=ptcmap,
norm=Normalize(vmin=0, vmax=ecmax),
orientation="vertical",
)
cbx.set_label(
"(|$\Delta_{max}$|+|$\Delta_{min}$|)/2 ",
fontdict={"size": 7, "weight": "bold"},
)
elif diffyn == "n":
cbx = ColorbarBase(
cbax[0],
cmap=ptcmap,
norm=Normalize(vmin=0, vmax=90),
orientation="vertical",
)
cbx.set_label("Phimin (deg) ", fontdict={"size": 7, "weight": "bold"})
####----Make scale ellipse
rect = Rectangle((xlimits[1] - 0.2, 0), 0.5, 0.5)
rect.set_facecolor((1, 1, 1))
rect.set_edgecolor((1, 1, 1))
ax1.add_artist(rect)
ax1.text(
xlimits[1] - 0.12,
0.5,
"$\Delta = 0.15$",
fontdict={"size": 8},
horizontalalignment="center",
verticalalignment="baseline",
bbox={"facecolor": "white", "edgecolor": "white"},
)
ellips = Ellipse((xlimits[1] - 0.1, esize * 2), width=esize, height=esize, angle=0)
ellips.set_facecolor((0.1, 0.1, 1.0))
ax1.add_artist(ellips)
plt.show()
# ==============================================================================
# Plot Data Pseudo section
# ==============================================================================
elif plottype == "pseudo":
if ctype == "data":
sdict = dict([(station[0:4], ii) for ii, station in enumerate(stationlst)])
pslst = []
xlabels = []
offsetlst = []
for pss in pstationlst:
try:
pslst.append(sdict[pss])
xlabels.append(pss[2:4])
if sline == "ew":
offsetlst.append(lonlst[sdict[pss]])
elif sline == "ns":
offsetlst.append(latlst[sdict[pss]])
except KeyError:
pass
if ctype == "fm":
sdict = dict([(station, ii) for ii, station in enumerate(stationlst)])
pslst = []
xlabels = []
offsetlst = []
for pss in pstationlst:
try:
pslst.append(sdict[pss])
xlabels.append(pss[7:9])
offsetlst.append(lonlst[sdict[pss]] * 10)
except KeyError:
pass
nx = len(xlabels)
xtks = list(offsetlst)
xtks.sort()
xtks = np.array(xtks)
plt.rcParams["font.size"] = 8
plt.rcParams["figure.subplot.left"] = 0.1
plt.rcParams["figure.subplot.right"] = 0.94
plt.rcParams["figure.subplot.bottom"] = 0.08
plt.rcParams["figure.subplot.top"] = 0.95
plt.rcParams["figure.subplot.hspace"] = 0.05
emax = 5 * esize
# create a plot instance
fig = plt.figure(fignum, [8, 6], dpi=300)
plt.clf()
ax1 = fig.add_subplot(1, 1, 1, aspect="equal")
for jj, ss in enumerate(pslst):
for ff in range(nf):
if ctype == "data":
eheightd = phiminarr[ff, ss] / (np.median(phimaxarr[:, :]) * 3) * esize
ewidthd = phimaxarr[ff, ss] / (np.median(phimaxarr[:, :]) * 3) * esize
else:
eheightd = phiminarr[ff, ss] / phimaxarr[:, :].max() * esize
ewidthd = phimaxarr[ff, ss] / phimaxarr[:, :].max() * esize
if eheightd > emax or ewidthd > emax:
pass
else:
ellipd = Ellipse(
(lonlst[ss] * xscaling, yspacing * (nf - ff)),
width=ewidthd,
height=eheightd,
angle=azimutharr[ff, ss] - 90,
)
# color ellipse
if ttype == "pt":
if diffyn == "y":
cvar = ecolorarr[ff, ss] / ecmax
elif diffyn == "n":
cvar = ecolorarr[ff, ss] / ecmax
if abs(cvar) > 1:
ellipd.set_facecolor((1, 0, 0.1))
else:
ellipd.set_facecolor((1, 1 - abs(cvar), 0.1))
elif ttype == "rt":
cvar = betarr[ff, ss] / ecmax
if cvar < 0:
if cvar < -1:
ellipd.set_facecolor((0, 0, 1))
else:
ellipd.set_facecolor((1 - abs(cvar), 1 - abs(cvar), 1))
else:
if cvar > 1:
ellipd.set_facecolor((1, 0, 0))
else:
ellipd.set_facecolor((1, 1 - abs(cvar), 1 - abs(cvar)))
ax1.add_artist(ellipd)
yticklabels = []
for yy in np.arange(start=1, stop=nf + 1, step=2):
if period[nf - yy] < 100:
yticklabels.append("{0:.3g}".format(period[nf - yy]))
else:
yticklabels.append("{0:.0f}".format(period[nf - yy]))
# yticklabels=['%2.3g' % period[nf-ii] for ii in np.arange(start=1,stop=nf+1,
# step=2)]
ax1.set_ylabel("period (s)", fontdict={"size": 9, "weight": "bold"})
ax1.set_yticks(np.arange(start=yspacing, stop=yspacing * nf + 1, step=2 * yspacing))
ax1.set_yticklabels(yticklabels)
# ax1.xaxis.set_tick_params(labelbottom='on',labeltop='on')
ax1.set_xticks(xtks[range(0, nx, xstep)])
# ax1.xaxis.set_ticklabels(['{0:.2g}'.format(nn) for nn in xtks[range(0,nx+1,2)]])
ax1.set_xticklabels([xlabels[xx] for xx in range(0, nx, xstep)])
ax1.set_xlim(min(offsetlst) - 0.5, max(offsetlst) + 0.5)
ax1.set_ylim(ylimits)
ax1.set_xlabel("station", fontdict={"size": 10, "weight": "bold"})
# ax1.set_title('Before and After Injection',fontdict={'size':12,'weight':'bold'})
ax1.grid()
ax4 = make_axes(ax1, shrink=0.5, fraction=0.1, orientation="vertical", pad=0.005)
if ttype == "pt":
if diffyn == "y":
cb1 = ColorbarBase(
ax4[0],
cmap=ptcmap,
norm=Normalize(vmin=0, vmax=ecmax),
orientation="vertical",
)
elif diffyn == "n":
cb1 = ColorbarBase(
ax4[0],
cmap=ptcmap,
norm=Normalize(vmin=0, vmax=ecmax),
orientation="vertical",
)
# cb1.set_label('(|$\Delta_{max}$|+|$\Delta_{min}$|)/2')
cb1.set_label("$\sqrt{\Delta \Phi_{max} \, \Delta \Phi_{min}}$")
elif ttype == "rt":
cb1 = ColorbarBase(
ax4[0],
cmap=rtcmap3,
norm=Normalize(vmin=-ecmax, vmax=ecmax),
orientation="vertical",
)
cb1.set_label(
"App. Res. ($\Omega \cdot$m) ", fontdict={"size": 7, "weight": "bold"}
)
####----Make scale ellipse
rect = Rectangle(
(kk * xspacing - 1.5 * xspacing, -yspacing / 2), 2 * xspacing, 3 * yspacing
)
rect.set_facecolor((1, 1, 1))
rect.set_edgecolor((1, 1, 1))
ax1.add_artist(rect)
ax1.text(
nx * xspacing - 0.85 * xspacing,
yspacing * 2.3,
"$\Delta = 0.15$",
fontdict={"size": 8},
horizontalalignment="center",
verticalalignment="baseline",
bbox={"facecolor": "white", "edgecolor": "white"},
)
ellips = Ellipse(
(kk * xspacing - 0.5 * xspacing, yspacing), width=esize, height=esize, angle=0
)
ellips.set_facecolor((0.1, 0.1, 1.0))
ax1.add_artist(ellips)
# plt.savefig(os.path.join(savepath,station+'PhaseTensorsComparison.png'))
# plt.close()
plt.show()