-
Notifications
You must be signed in to change notification settings - Fork 0
/
exploratoryAnalysis.R
5844 lines (5057 loc) · 229 KB
/
exploratoryAnalysis.R
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
# This file loads all the data and functions for the analysis and sets the working directory
library(fields)
setwd("~/git/M9/")
source('plotSubfault.R')
source('loadTestData.r')
source('fitModel.R')
##### plot slip rates inferred from GPS data
slipDat = read.table("Cascadia-lockingrate-hdr.txt", header=TRUE)
names(slipDat) = c("lon", "lat", "slip", "Depth", "slipErr")
attach(slipDat)
quilt.plot(lon, lat, slip)
map("world", "Canada", add=TRUE)
US(add=TRUE)
quilt.plot(lon, lat, Depth)
map("world", "Canada", add=TRUE)
world(add=TRUE)
quilt.plot(lon, lat, slipErr)
map("world", "Canada", add=TRUE)
world(add=TRUE)
faultGeom = read.csv("CSZe01.csv")
faultGeom$longitude = faultGeom$longitude - 360
kmCols = c(4, 6, 7)
faultGeom[,kmCols] = faultGeom[,kmCols] * 10^3
plot(lon, lat, type="n")
quilt.plot(lon, lat, rep(NA, length=length(Depth)), zlim=c(range(Depth)))
#plotSubfault(faultGeom[1,], varRange=range(Depth))
#apply(faultGeom, 1, plotSubfault, varRange=range(Depth))
#plotSubfaultGeom(faultGeom[1,], varRange=range(Depth))
plotFault(faultGeom, new=FALSE, plotData=FALSE)
world(add=TRUE)
quilt.plot(lon, lat, Depth, nx=80, ny=80)
world(add=TRUE, lwd=2)
plotFault(faultGeom, plotData=FALSE, new=FALSE, lwd=2)
quilt.plot(lon, lat, slip, nx=120, ny=120, main="Locking Rate (mm/yr)", ylab="Latitude", xlab="Longitude")
world(add=TRUE, lwd=2)
plotFault(faultGeom, plotData=FALSE, new=FALSE, lwd=2)
quilt.plot(lon, lat, Depth, nx=120, ny=120, main="Depth (km)", ylab="Latitude", xlab="Longitude")
world(add=TRUE, lwd=2)
plotFault(faultGeom, plotData=FALSE, new=FALSE, lwd=2)
quilt.plot(lon, lat, slipErr, nx=120, ny=120, main="Locking Rate SE (mm/yr)", ylab="Latitude", xlab="Longitude")
world(add=TRUE, lwd=2)
plotFault(faultGeom, plotData=FALSE, new=FALSE, lwd=2)
##### plot subsidence inferred from turbidite data
load("DR1.RData")
dr1$bpSE = dr1$bpMOE/qnorm(.975)
dr1$rcybpSE = dr1$rcybpMOE/qnorm(.975)
attach(dr1)
plot(dr1$Lon, dr1$Lat, col="red", pch="+")
map("world", "Canada", add=TRUE)
US(add=TRUE)
# plot histogram of different estimated ages for events (everything's so muddled...)
hist(c(dr1$bpCntr, dr1$rcybpCntr) + 66, breaks=200)
events = as.character(event)
uniqueEvents = unique(events)
sortI = rev(c(1, 11, 10, 13, 2, 14, 3, 4, 17, 5, 12, 6, 18, 7, 19, 9, 20, 8, 15, 16)) # T1 is most recent, so reverse
uniqueEvents = uniqueEvents[sortI]
latRange = range(Lat)
subRange = range(range(subsidence - Uncertainty), range(subsidence + Uncertainty))
par(mar=c(4, 4.5, 1.093333, 0.50000))
for(i in 1:length(uniqueEvents)) {
# get event data for the given event from table
e = uniqueEvents[i]
eventDat = dr1[events == e,]
print(paste0("Amount of data for event ", e, ": ", nrow(eventDat)))
# plot the data (reverse order for consistency with Leonard et al. 2010 paper) with error bars
plot(eventDat$Lat, eventDat$subsidence, main=e, xlab="Latitude", ylab="Subsidence (m)",
xlim=rev(latRange), ylim=rev(subRange), type = "n")
arrows(eventDat$Lat, eventDat$subsidence, eventDat$Lat,
eventDat$subsidence + eventDat$Uncertainty,
angle=90, col="grey")
arrows(eventDat$Lat, eventDat$subsidence, eventDat$Lat,
eventDat$subsidence - eventDat$Uncertainty,
angle=90, col="grey")
points(eventDat$Lat, eventDat$subsidence, pch=19, cex=.7)
}
plot(rev(dr1$Lat), rev(dr1$subsidence), main="All events",
xlab="Latitude", ylab="Subsidence (m)", xlim=rev(latRange), ylim=rev(subRange), type="n")
arrows(dr1$Lat, dr1$subsidence, dr1$Lat,
dr1$subsidence + dr1$Uncertainty,
angle=90, col="grey")
arrows(dr1$Lat, dr1$subsidence, dr1$Lat,
dr1$subsidence - dr1$Uncertainty,
angle=90, col="grey")
points(rev(dr1$Lat), rev(dr1$subsidence), pch=19, cex=.7)
##### plot subsidence inferred from turbidite data with slip rates from GPS data
# first show where all the data is
plot(lon, lat, pch=19, cex=.1, col="blue")
world(add=TRUE)
points(dr1$Lon, dr1$Lat, pch=3, cex=.5, col="red")
# now compute closest slip data point for each subsidence data point
distMat = rdist(dr1[,c(4, 3)], slipDat[,1:2])
slipI = apply(distMat, 1, which.min)
slipDatPaired = slipDat[slipI,]
# check to make sure it makes sense
points(slipDatPaired[,1:2])
lonRange = range(slipDatPaired$lon)
latRange = range(slipDatPaired$lat)
slipRange = range(slipDatPaired$slip)
quilt.plot(lon, lat, slip, xlim=lonRange, ylim=latRange, zlim=slipRange)
world(add=TRUE)
quilt.plot(slipDatPaired[,1:2], slipDatPaired$slip, xlim=lonRange, ylim=latRange, zlim=slipRange)
world(add=TRUE)
# now plot subsidence versus slip rate
# NOTE: This looks terrible
plot(Lat, subsidence, pch=19, cex=.5)
points(Lat, slipDatPaired$slip/15, col="blue", cex=.7)
plot(Lat, subsidence[event == "T1"], pch=19, cex=.5)
points(Lat, slipDatPaired$slip/15, col="blue", cex=.7)
plot(Lat[event != "T1"], subsidence[event != "T1"], pch=19, cex=.5)
points(Lat, slipDatPaired$slip/15, col="blue", cex=.7)
# plot slip rate with subsidence as a second plot on the side
par(mai=c(1.360000, 1.093333, 1.093333, 0.560000))
par(mar=c(4, 2.5, 1.093333, 0.50000))
# layout(matrix(c(1, 2), 1, 2), widths=c(3, 1), heights=2)
par(mfrow=c(1,2), mar=c(4, 3.5, 2, 0.50000))
quilt.plot(lon, lat, slip, xlim=lonRange, ylim=latRange, nx = 120, ny=120,
main="Slip rate (mm/yr)", xlab="Longitude", ylab="Latitude")
world(add=TRUE)
points(dr1$Lon, dr1$Lat, pch=3, cex=.7)
plot(dr1$subsidence, dr1$Lat, pch=19, cex=.3, ylim=latRange,
main="All Subsidence", ylab="", xlab="Subsidence (m)")
quilt.plot(lon, lat, slip, xlim=lonRange, ylim=latRange, nx = 120, ny=120,
main="Slip rate (mm/yr)", xlab="Longitude", ylab="Latitude")
world(add=TRUE)
points(dr1$Lon[event == "T1"], dr1$Lat[event == "T1"], pch=3, cex=.7)
plot(dr1$subsidence[event == "T1"], dr1$Lat[event == "T1"], pch=19, cex=.3, ylim=latRange,
main="T1 Subsidence", ylab="", xlab="Subsidence (m)")
# final plots including fault geometry
lonRange = range(lon)
latRange = range(lat)
slipRange = range(slip)
pdf(file="lockRateVsSub.pdf", width=4, height=5)
quilt.plot(lon, lat, slip, xlim=lonRange, ylim=latRange, nx = 120, ny=120,
main="Locking rate (mm/yr)", xlab="Longitude", ylab="Latitude")
world(add=TRUE, lwd=2)
points(dr1$Lon[event == "T1"], dr1$Lat[event == "T1"], cex=1, pch=3, col="red")
plotFault(faultGeom, plotData=FALSE, new=FALSE, lwd=2)
plot(dr1$subsidence[event == "T1"], dr1$Lat[event == "T1"], pch=19, cex=.3, ylim=latRange,
main="T1 Subsidence", ylab="", xlab="Subsidence (m)")
dev.off()
par(mfrow=c(1,3))
pdf(file="lockRateVsSubFull.pdf", width=4, height=5)
quilt.plot(lon, lat, slip, xlim=lonRange, ylim=latRange, nx = 120, ny=120,
main="Locking rate (mm/yr)", xlab="Longitude", ylab="Latitude")
world(add=TRUE, lwd=2)
points(dr1$Lon[event == "T1"], dr1$Lat[event == "T1"], cex=1, pch=3, col="red")
plotFault(faultGeom, plotData=FALSE, new=FALSE, lwd=2)
plot(dr1$subsidence[event == "T1"], dr1$Lat[event == "T1"], pch=19, cex=.3, ylim=latRange,
main="T1 Subsidence", ylab="", xlab="Subsidence (m)")
plot(slipDatPaired$slip/15, slipDatPaired$lat, pch=19, cex=.3, ylim=latRange,
main="GPS lock rate / 15", ylab="", xlab="Subsidence (m)")
dev.off()
pdf(file="depthVsSub.pdf", width=4, height=5)
quilt.plot(lon, lat, Depth, xlim=lonRange, ylim=latRange, nx = 120, ny=120,
main="Depth (km)", xlab="Longitude", ylab="Latitude")
world(add=TRUE, lwd=2)
points(dr1$Lon[event == "T1"], dr1$Lat[event == "T1"], cex=1, pch=3, col="red")
plotFault(faultGeom, plotData=FALSE, new=FALSE, lwd=2)
plot(dr1$subsidence[event == "T1"], dr1$Lat[event == "T1"], pch=19, cex=.3, ylim=latRange,
main="T1 Subsidence", ylab="", xlab="Subsidence (m)")
dev.off()
pdf(file="slipErrVsSub.pdf", width=4, height=5)
quilt.plot(lon, lat, slipErr, xlim=lonRange, ylim=latRange, nx = 120, ny=120,
main="Locking rate SE (mm/yr)", xlab="Longitude", ylab="Latitude")
world(add=TRUE, lwd=2)
points(dr1$Lon[event == "T1"], dr1$Lat[event == "T1"], cex=1, pch=3, col="red")
plotFault(faultGeom, plotData=FALSE, new=FALSE, lwd=2)
plot(dr1$subsidence[event == "T1"], dr1$Lat[event == "T1"], pch=19, cex=.3, ylim=latRange,
main="T1 Subsidence", ylab="", xlab="Subsidence (m)")
dev.off()
par(mfrow=c(1,1))
##### test Okada
nx = 300
ny= 900
lonGrid = seq(lonRange[1], lonRange[2], l=nx)
latGrid = seq(latRange[1], latRange[2], l=ny)
tmp = okadaSubfault(faultGeom[1,], lonGrid, latGrid, slip=10)
quilt.plot(lon, lat, rep(NA, length(lon)), xlim=lonRange, ylim=latRange,
main="Seafloor deformation (m)", xlab="Longitude", ylab="Latitude")
plotSubfault(faultGeom[1,], plotData=FALSE)
quilt.plot()
testRow = faultGeom[1,]
testRow[1,4] = testRow[1,4] * 10^3
# set up the test case from okada.ipynb
nx = 200
ny= 200
lonGrid = seq(-.5, 1.5, l=nx)
latGrid = seq(-1, 1, l=ny)
testRow = data.frame(rbind(c(Fault=30.1, longitude=0, latitude=0, depth=5e3,
strike=0, length=100e3, width=50e3, dip=10)))
dZ = okadaSubfault(testRow, lonGrid, latGrid, slip=1)
plotTopo(list(lon=lonGrid, lat=latGrid, dat=t(dZ)))
# It works!!!
# now test across entire CSZ geometry
nx = 300
ny= 900
lonGrid = seq(lonRange[1], lonRange[2], l=nx)
latGrid = seq(latRange[1], latRange[2], l=ny)
testFault = faultGeom
dZ = okada(testFault, lonGrid, latGrid, slips=10)
plotTopo(list(lon=lonGrid, lat=latGrid, dat=t(dZ)), nx=120, ny=120)
world(add=TRUE, lwd=2)
##### now plot versus subsidence data
# calculate the simulated subsidence at the data locations
# round the data locations to the lon lat grid
roundToRange = function(coordVec, coordRange) {
inds = (coordVec - min(coordRange))/(max(coordRange) - min(coordRange))
inds = round(inds*(length(coordRange)-1)) + 1
roundedCoordVec = coordRange[inds]
return(roundedCoordVec)
}
roundLon = roundToRange(dr1$Lon, lonGrid)
roundLat = roundToRange(dr1$Lat, latGrid)
roundCoords = cbind(roundLon, roundLat)
# find indices of grid coords corresponding to rounded data coords
findIndex = function(rCoords, gCoords) {
return(match(data.frame(t(rCoords)), data.frame(t(gCoords))))
}
coordGrid = make.surface.grid(list(lonGrid, latGrid))
inds = findIndex(roundCoords, coordGrid)
simDef = c(t(dZ))[inds]
par(mfrow=c(1,3))
pdf(file="slip10Subsidence.pdf", width=4, height=5)
plotTopo(list(lon=lonGrid, lat=latGrid, dat=t(dZ)), nx=120, ny=120)
world(add=TRUE, lwd=2)
points(dr1$Lon[event == "T1"], dr1$Lat[event == "T1"], cex=1, pch=3, col="red")
apply(faultGeom, 1, plotData=FALSE, new=FALSE, lwd=2)
plot(dr1$subsidence[event == "T1"], dr1$Lat[event == "T1"], pch=19, cex=.3, ylim=latRange,
main="T1 Subsidence", ylab="", xlab="Subsidence (m)", xlim=range(-simDef))
plot(-simDef, coordGrid[inds,2], pch=19, cex=.3, ylim=latRange,
main="Simulated Subsidence", ylab="", xlab="Subsidence (m)")
dev.off()
par(mfrow=c(1,1))
##### test for subdivided faults
plotFault(testFault, xlim=c(-128, -123.75), ylim=c(40, 50))
world(add=TRUE)
test = divideSubfault(testRow)
plotFault(test, xlim=c(0, .45), ylim=c(-.45, .45))
plotSubfault(testRow, xlim=c(0, .45), ylim=c(-.45, .45), new=TRUE)
points(test$longitude, test$latitude)
test = divideFault(testFault)
plotFault(testFault, xlim=c(-128, -123.75), ylim=c(40, 50))
plotFault(test, xlim=c(-128, -123.75), ylim=c(40, 50))
# make sure the subdivided depths are correct
quilt.plot(test$longitude, test$latitude, test$depth, xlim=c(-128, -123.75), ylim=c(40, 50), zlim=c(0, 20000))
quilt.plot(testFault$longitude, testFault$latitude, testFault$depth, xlim=c(-128, -123.75), ylim=c(40, 50), zlim=c(0, 20000))
#It works!
# test okada on subfaults
csz = divideFault(testFault)
test = okada(csz, lonGrid, latGrid, slips=10)
plotTopo(list(lon=lonGrid, lat=latGrid, dat=t(test)), nx=120, ny=120)
world(add=TRUE, lwd=2)
##### Assume the slip is proportional to the GPS data. Plot the Okada results
distMat = rdist(cbind(csz$longitude, csz$latitude), slipDat[,1:2])
slipI = apply(distMat, 1, which.min)
slipDatCSZ = slipDat[slipI,]
lockRates = slipDatCSZ$slip
# plot them to make sure they're correct (NOTE: the large number of bottom red locations
# are a consequence of the nearest neighbor prediction. Hopefully that won't cause problems)
quilt.plot(csz$longitude, csz$latitude, lockRates, xlim=c(-128, -123.75), ylim=c(40, 50))
world(add=TRUE, lwd=2)
quilt.plot(lon, lat, slip, nx=120, ny=120, main="Locking Rate (mm/yr)", ylab="Latitude", xlab="Longitude")
world(add=TRUE, lwd=2)
plotFault(faultGeom, plotData=FALSE, new=FALSE, lwd=2)
gpsTest = okada(csz, lonGrid, latGrid, slips=lockRates)
simDef = c(t(gpsTest))[inds]
par(mfrow=c(2,2))
pdf(file="lockRateOkadaFull.pdf", width=4, height=5)
# quilt.plot(lon, lat, slip, xlim=lonRange, ylim=latRange, nx = 120, ny=120,
# main="Locking rate (mm/yr)", xlab="Longitude", ylab="Latitude")
# world(add=TRUE, lwd=2)
# plotFault(testFault, cols=c(NA, NA), new=FALSE, lwd=2)
# slip using GPS locking rates
propFac = 1/2.25
quilt.plot(csz$longitude, csz$latitude, lockRates*propFac, xlim=lonRange, ylim=latRange, nx = 30, ny=30,
main="Slip (m)", xlab="Longitude", ylab="Latitude")
map("world", "Canada", add=TRUE)
US(add=TRUE)
plotFault(testFault, new=FALSE, lwd=2, plotData=FALSE)
points(dr1$Lon[event == "T1"], dr1$Lat[event == "T1"], cex=1, pch=3, col="red")
# seadef from Okada model generated from the slips
plotTopo(list(lon=lonGrid, lat=latGrid, dat=t(gpsTest)), nx=120, ny=120, main="Seafloor Deformation (m)")
map("world", "Canada", add=TRUE)
US(add=TRUE)
points(dr1$Lon[event == "T1"], dr1$Lat[event == "T1"], cex=1, pch=3, col="red")
plotFault(testFault, new=FALSE, lwd=2, plotData=FALSE)
# T1 subsidence data
plot(dr1$subsidence[event == "T1"], dr1$Lat[event == "T1"], pch=19, cex=.3, ylim=latRange,
xlim=range(-simDef*propFac), main="T1 Subsidence", ylab="", xlab="Subsidence (m)")
# simulated subsidence data from Okada model using GPS locking rates
plot(-simDef*propFac, coordGrid[inds,2], pch=19, cex=.3, ylim=latRange,
main="Simulated Subsidence", ylab="", xlab="Subsidence (m)")
dev.off()
par(mfrow=c(1,1))
##### profile okada functions to figure out how to speed them up. This will be helpful
##### when recomputing the okada output for different Poisson ratios and/or rakes
library(profvis)
nx = 300
ny= 900
lonGrid = seq(lonRange[1], lonRange[2], l=nx)
latGrid = seq(latRange[1], latRange[2], l=ny)
profvis({dZ1 <- okadaAll(csz, lonGrid, latGrid, cbind(Lon, Lat), slips=1)})
profvis({dZ2 <- okadaAll(csz, lonGrid, latGrid, cbind(Lon, Lat), slips=1, rakes=100)})
system.time(dZ1 <- okadaAll(csz, lonGrid, latGrid, cbind(Lon, Lat), slips=1))
system.time(dZ2 <- okadaAll(csz, lonGrid, latGrid, cbind(Lon, Lat), slips=1, rakes=100))
# also make sure the results are right
# here we see small changes in rake have little affect on subsidence so we can probably
# ignore rake. Biggest difference is at near 0 subsidence in Cali.
totRange = range(c(colSums(dZ1), colSums(dZ2)))
quilt.plot(Lon, Lat, colSums(dZ1), zlim=totRange)
quilt.plot(Lon, Lat, colSums(dZ2), zlim=totRange)
# 128 seconds -> 10 seconds
##### test affect of poisson ratio on results
dZ1 <- okada(csz, lonGrid, latGrid, slips=1, poisson=.25)
dZ2 <- okada(csz, lonGrid, latGrid, slips=1, poisson=.1)
dZ3 <- okada(csz, lonGrid, latGrid, slips=1, poisson=1)
totRange = range(dZ1, dZ2, dZ3)
plotTopo(list(lon=lonGrid, lat=latGrid, dat=t(dZ1)), nx=120, ny=120,
main="Seafloor Deformation (m)", zlim=totRange)
points(dr1$Lon[event == "T1"], dr1$Lat[event == "T1"], cex=1, pch=3, col="red")
plotTopo(list(lon=lonGrid, lat=latGrid, dat=t(dZ2)), nx=120, ny=120,
main="Seafloor Deformation (m)", zlim=totRange)
points(dr1$Lon[event == "T1"], dr1$Lat[event == "T1"], cex=1, pch=3, col="red")
plotTopo(list(lon=lonGrid, lat=latGrid, dat=t(dZ3)), nx=120, ny=120,
main="Seafloor Deformation (m)", zlim=totRange)
points(dr1$Lon[event == "T1"], dr1$Lat[event == "T1"], cex=1, pch=3, col="red")
# higher poisson ratio tends to have more uplift. Effect seems to be very nonlinear, though
##### Test differences between CSZ fault geometry that Randy uses to Pollitz GPS geometry
# subset GPS data so we only have data within boundaries of CSZ geometry
getGPSSubfaultDepths = function() {
# helper function for determining if GPS data is within a specific subfault geometry
getSubfaultGPSDat = function(i) {
row = csz[i,]
geom = calcGeom(row)
corners = geom$corners[,1:2]
in.poly(cbind(slipDat$lon, slipDat$lat), corners)
}
# construct logical matrix, where each column is the result of getSubfaultGPSDat(j)
# Hence, row represents data index, column represents subfault index.
inSubfaults = sapply(1:nrow(csz), getSubfaultGPSDat)
# get the depth of each subfault by taking mean
subfaultDepth = function(inds) {
subfaultDat = slipDat[inds,]
mean(subfaultDat$Depth)
}
apply(inSubfaults, 1, subfaultDepth)
}
par(mfrow=c(1, 2))
origDepths = getFaultCenters(csz)[,3]
depthsGPS = getGPSSubfaultDepths()
slipDatCSZ = getFaultGPSDat()
depthRange = range(c(depthsGPS, origDepths, slipDatCSZ$Depth), na.rm=TRUE)
plotFault(csz, plotVar=origDepths, main="Original Geometry", varRange=depthRange)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(csz, plotVar=depthsGPS, main="GPS Geometry", varRange=depthRange)
xRange = range(csz$longitude)
yRange = range(csz$latitude)
quilt.plot(slipDatCSZ$lon, slipDatCSZ$lat, slipDatCSZ$Depth,
main="GPS Data", xlab="Langitude", ylab="Latitude",
zlim=depthRange, nx=80, ny=160)
plotFault(csz, plotData = FALSE, new = FALSE)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(csz, plotVar=depthsGPS, main="GPS Geometry",
xlim=xRange, ylim=yRange, varRange=depthRange)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
##### Functions testing spline basis
library(splines)
# generate spline basis functions in subsidence space
latRange = c(40, 50)
lats = seq(40, 50, l=50)
Xi = bs(lats, knots=5, intercept=TRUE, Boundary.knots=latRange)
# test Xi
par(mfrow=c(1,1))
matplot(lats, Xi, main="Spline Basis", xlab="Latitude")
latRange = c(40, 50)
nKnots=2
knots = seq(40, 50, l=nKnots+2)[2:(nKnots+1)]
# Xi = ns(dr1$Lat, knots=knots, intercept=TRUE, Boundary.knots=latRange)
Xi = ns(lats, knots=knots, intercept=FALSE, Boundary.knots=latRange)
# test Xi
par(mfrow=c(1,1))
matplot(lats, Xi, main="Spline Basis", xlab="Latitude")
latRange = c(40, 50)
nKnots=3
knots = seq(40, 50, l=nKnots+2)[2:(nKnots+1)]
Xi = ns(dr1$Lat, knots=knots, intercept=FALSE, Boundary.knots=latRange)
Xi = cbind(rep(1, nrow(Xi)), Xi)
mod = lm(dr1$subsidence ~ Xi - 1)
Xi = ns(lats, knots=knots, intercept=FALSE, Boundary.knots=latRange)
Xi = cbind(rep(1, nrow(Xi)), Xi)
preds = Xi %*% coef(mod)
plot(dr1$Lat, dr1$subsidence)
lines(lats, preds)
knots = seq(40, 50, l=nKnots+2)[2:(nKnots+1)]
Xi = ns(dr1$Lat, knots=knots, intercept=TRUE, Boundary.knots=latRange)
mod = lm(dr1$subsidence ~ Xi - 1)
Xi = ns(lats, knots=knots, intercept=TRUE, Boundary.knots=latRange)
preds = Xi %*% coef(mod)
plot(dr1$Lat, dr1$subsidence)
lines(lats, preds)
df=4
Xi = bs(dr1$Lat, df=df, intercept=FALSE, Boundary.knots=latRange)
mod = lm(dr1$subsidence ~ Xi)
Xi = bs(lats, df=df, intercept=FALSE, Boundary.knots=latRange)
preds = coef(mod)[1] + Xi %*% coef(mod)[2:length(coef(mod))]
plot(dr1$Lat, dr1$subsidence)
lines(lats, preds)
matplot(Xi)
# get Okada linear transformation matrix
nx = 300
ny= 900
lonGrid = seq(lonRange[1], lonRange[2], l=nx)
latGrid = seq(latRange[1], latRange[2], l=ny)
G = okadaAll(csz, lonGrid, latGrid, cbind(dr1$Lon, dr1$Lat), slip=1, poisson=0.25)
# get taper values
load("fixedFit_MVN.RData")
tvec = taper(csz$depth, lambda=fixedFitMVN$lambdaMLE)
# embed spline basis on CSZ fault plane
GQR = qr(G)
Q1 = qr.Q(GQR)
R1 = qr.R(GQR)
R1Inv = backsolve(r = R1, x = diag(ncol(R1)))
embedMat = diag(tvec^(-1)) %*% R1Inv %*% t(Q1)
XiPrime = embedMat %*% Xi
hist(log10(abs(XiPrime)), breaks=100)
par(mfrow=c(3,2))
quilt.plot(slipDatCSZ$lon, slipDatCSZ$lat, slipDatCSZ$slip, main="Observed Locking Rate (mm/yr)",
xlab="Longitude", ylab="Latitude", xlim=lonRange, ylim=latRange)
plotFault(csz, new=FALSE, plotData=FALSE)
plotFault(csz, plotVar=XiPrime[,5])
for(i in 1:nrow(Xi)) {
plotFault(csz, plotVar=XiPrime[,i], main=paste0("Spline ", i), xlab="Longitude", ylab="Latitude",
xlim=lonRange, ylim=latRange)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
}
# reconstruct Xi
XiReconstruct = G %*% diag(tvec) %*% XiPrime
par(mfrow=c(2,1))
matplot(dr1$Lat, Xi, main="Splines", xlab="Latitude")
matplot(dr1$Lat, XiReconstruct, main="Reconstructed Splines (with QR)", xlab="Latitude")
test = diag(tvec^(-1)) %*% backsolve(r=R1, x=Xi)
XiPrime[1,]
test[1,]
# since that looks so terrible, maybe it's because of conditioning?
# check the condition number
test = svd(G)
sqrt(test$d[1]/test$d[240])
test = svd(R1)
sqrt(test$d[1]/test$d[240])
# now try using svd instead of QR
test = svd(G %*% diag(tvec))
par(mfrow=c(1,1))
hist(test$d)
plot(1:240, cumsum(test$d)/sum(test$d), ylim=c(0,1), type="l", ylab="Condition Number", xlab="Rank of G %*% T",
main="99% Variance Explained")
abline(h=.99, col="red")
plot(1:240, sqrt(test$d[1]/test$d), type="l", log="y", ylab="Condition Number", xlab="Rank of G %*% T",
main="Condition Number is 1000")
abline(h=1000, col="red")
rank = min(which(cumsum(test$d)/sum(test$d) > .99999)) - 1
pseudoInv = test$v %*% diag(c(test$d[1:rank]^(-1), rep(0, 240-rank))) %*% t(test$u)
# generate OLS model of splines fit to subsidence data
mod = lm(dr1$subsidence ~ Xi-1)
summary(mod)
# make plots
par(mfrow=c(3,2))
for(i in 1:nrow(Xi)) {
plotFault(csz, plotVar=pseudoInv %*% Xi[,i], main=paste0("Spline ", i), xlab="Longitude", ylab="Latitude",
xlim=lonRange, ylim=latRange)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
}
plotFault(csz, plotVar=pseudoInv %*% Xi %*% cbind(coef(mod)), main="Fitted Splines",
xlim=lonRange, ylim=latRange)
##### Do the same analysis but with low res fault
# generate spline basis functions in subsidence space
library(splines)
Xi = bs(dr1$Lat, df=5, intercept=TRUE)
par(mfrow=c(1,1))
matplot(dr1$Lat, Xi, main="Spline Basis", xlab="Latitude")
# make low res fault
fault = divideFault(faultGeom, nDown=1, nStrike=2)
n = nrow(fault)
# get Okada linear transformation matrix
nx = 300
ny= 900
lonGrid = seq(lonRange[1], lonRange[2], l=nx)
latGrid = seq(latRange[1], latRange[2], l=ny)
G = okadaAll(fault, lonGrid, latGrid, cbind(dr1$Lon, dr1$Lat), slip=1, poisson=0.25)
# get taper values
load("fixedFit_MVN.RData")
tvec = taper(fault$depth, lambda=fixedFitMVN$lambdaMLE)
# embed spline basis on fault fault plane
GQR = qr(G)
Q1 = qr.Q(GQR)
R1 = qr.R(GQR)
R1Inv = backsolve(r = R1, x = diag(ncol(R1)))
embedMat = diag(tvec^(-1)) %*% R1Inv %*% t(Q1)
XiPrime = embedMat %*% Xi
hist(log10(abs(XiPrime)), breaks=100)
par(mfrow=c(3,2))
quilt.plot(slipDatCSZ$lon, slipDatCSZ$lat, slipDatCSZ$slip, main="Observed Locking Rate (mm/yr)",
xlab="Longitude", ylab="Latitude", xlim=lonRange, ylim=latRange)
plotFault(fault, new=FALSE, plotData=FALSE)
for(i in 1:ncol(Xi)) {
plotFault(fault, plotVar=XiPrime[,i], main=paste0("Spline ", i), xlab="Longitude", ylab="Latitude",
xlim=lonRange, ylim=latRange)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
}
# reconstruct Xi
XiReconstruct = G %*% diag(tvec) %*% XiPrime
# this works for:
# n=80 (2,2)
# doesn't work for:
# n=120 (2,3), n=120 (3,2)
par(mfrow=c(2,1))
matplot(dr1$Lat, Xi, main="Spline Basis", xlab="Latitude")
matplot(dr1$Lat, XiReconstruct, main="Reconstructed Spline Basis (with QR)", xlab="Latitude")
test = diag(tvec^(-1)) %*% backsolve(r=R1, x=Xi)
XiPrime[1,]
test[1,]
# since that looks so terrible, maybe it's because of conditioning?
# check the condition number of G %*% diag(tvec)
# n = 80 (2,2,8760120)
# check the condition number of G
# n = 80 (2,2,1144600)
test = svd(G)
sqrt(test$d[1]/test$d[n])
test = svd(G %*% diag(tvec))
sqrt(test$d[1]/test$d[n])
test = svd(R1)
sqrt(test$d[1]/test$d[n])
# now try using svd instead of QR
test = svd(G %*% diag(tvec))
par(mfrow=c(1,1))
hist(test$d)
plot(1:n, cumsum(test$d)/sum(test$d), ylim=c(0,1), type="l", ylab="Condition Number", xlab="Rank of G %*% T",
main="99% Variance Explained")
abline(h=.99, col="red")
plot(1:n, sqrt(test$d[1]/test$d), type="l", log="y", ylab="Condition Number", xlab="Rank of G %*% T",
main="Condition Number is 1000")
abline(h=1000, col="red")
# rank = min(which(cumsum(test$d)/sum(test$d) > .9999)) - 1
rank = n
sqrt(test$d[1]/test$d[rank]) # condition number
pseudoInv = test$v %*% diag(c(test$d[1:rank]^(-1), rep(0, n-rank))) %*% t(test$u)
# generate OLS model of splines fit to subsidence data
mod = lm(dr1$subsidence ~ Xi-1)
summary(mod)
# plot back-projected splines
par(mfrow=c(3,2))
for(i in 1:ncol(Xi)) {
plotFault(fault, plotVar=pseudoInv %*% Xi[,i], main=paste0("Spline ", i), xlab="Longitude", ylab="Latitude",
xlim=lonRange, ylim=latRange)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
}
plotFault(fault, plotVar=pseudoInv %*% Xi %*% cbind(coef(mod)), main=paste0("Fitted Splines, rank ", rank),
xlim=lonRange, ylim=latRange)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
# plot reconstructed spline basis
par(mfrow=c(2,1))
matplot(dr1$Lat, Xi, main="Spline Basis", xlab="Latitude")
matplot(dr1$Lat, G %*% diag(tvec) %*% pseudoInv %*% Xi, main="Reconstructed Spline Basis (with SVD)", xlab="Latitude")
# plot back-projected subsidence data with uncertainty
par(mfrow=c(2,2))
# GPS dat
# quilt.plot(slipDatCSZ$lon, slipDatCSZ$lat, slipDatCSZ$slip, main="GPS Observations (mm/yr)",
# xlim=lonRange, ylim=latRange)
# map("world", "Canada", add=TRUE, lwd=1.5)
# US(add=TRUE, lwd=1.5)
# plotFault(fault, plotData=FALSE, new=FALSE)
# subsidence dat
quilt.plot(dr1$Lon, dr1$Lat, -dr1$subsidence, main="Observed Uplift (m)",
xlim=lonRange, ylim=latRange, nx=40, ny=40)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# subsidence unvertainty
quilt.plot(dr1$Lon, dr1$Lat, dr1$Uncertainty, main="Subsidence Uncertainty (m)",
xlim=lonRange, ylim=latRange, nx=40, ny=40)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# backprojected subsidence data
plotFault(fault, plotVar=pseudoInv %*% (-dr1$subsidence), xlim=lonRange, ylim=latRange,
main="Back-Projected Coastal Uplift Data (m)", logScale=TRUE, na.rm = TRUE)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# backprojected uncertainty
newSigma = diag(pseudoInv %*% diag(dr1$Uncertainty) %*% t(pseudoInv))
plotFault(fault, plotVar=newSigma, xlim=lonRange, ylim=latRange,
main="Back-Projected Coastal Uplift SE (m)", legend.mar = 10,
logScale=TRUE, na.rm = TRUE)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
# Get minimum standard error
# ~2800 (2,2, rank=47), 237 (1,2, rank=40), 7.9 (1,1, rank=20)!
min(newSigma)
##### Now try penalized regression
library(lars)
# generate spline basis functions in subsidence space
library(splines)
Xi = bs(dr1$Lat, df=5, intercept=TRUE)
par(mfrow=c(1,1))
matplot(dr1$Lat, Xi, main="Spline Basis", xlab="Latitude")
# make low res fault
fault = divideFault(faultGeom, nDown=2, nStrike=2)
n = nrow(fault)
# get Okada linear transformation matrix
nx = 300
ny= 900
lonGrid = seq(lonRange[1], lonRange[2], l=nx)
latGrid = seq(latRange[1], latRange[2], l=ny)
G = okadaAll(fault, lonGrid, latGrid, cbind(dr1$Lon, dr1$Lat), slip=1, poisson=0.25)
# get taper values
load("fixedFit_MVN.RData")
tvec = taper(fault$depth, lambda=fixedFitMVN$lambdaMLE)
##### do LASSO regression for regularized back-projection
GT = G %*% diag(tvec)
XiPrime = matrix(nrow=n, ncol=ncol(Xi))
for(i in 1:ncol(Xi)) {
lassoMod = lars(GT, as.matrix(Xi[,i], ncol=1), type="lasso", intercept=FALSE, trace=TRUE, max.steps=5000)
XiPrime[,i] = coef(lassoMod)[nrow(coef(lassoMod)),]
}
# plot back-projected splines
par(mfrow=c(3,2))
for(i in 1:ncol(XiPrime)) {
plotFault(fault, plotVar=XiPrime[,i], main=paste0("Spline ", i), xlab="Longitude", ylab="Latitude",
xlim=lonRange, ylim=latRange)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
}
plotFault(fault, plotVar=XiPrime %*% cbind(coef(mod)), main=paste0("Fitted Splines, rank ", rank),
xlim=lonRange, ylim=latRange)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
# plot reconstructed spline basis
par(mfrow=c(2,1))
matplot(dr1$Lat, Xi, main="Spline Basis", xlab="Latitude")
matplot(dr1$Lat, G %*% diag(tvec) %*% XiPrime, main="Reconstructed Spline Basis (with LASSO)", xlab="Latitude")
##### do ridge regression for regularized back-projection
library(glmnet)
# matrix for storing back-projected splines
XiPrime = matrix(nrow=n, ncol=ncol(Xi))
# use leave one out cross validation to get regularization param for ridge regression
# getRidgeLambda = function(lambdaGrid) {
getRidgeLambda = function(lambdaGrid) {
allRMSE = matrix(nrow=m, ncol=0)
for(i in 1:ncol(Xi)) {
print(paste0("i: ", i))
# leave one out cross-validation. Returns rmse for each value of lambda
LOOCV = function(j, lambdaGrid) {
print(paste0("j: ", j))
# ridgeMod = glmnet(GT[-j,], as.matrix(Xi[-j,i], ncol=1), family="gaussian", alpha=0,
# intercept=FALSE, lambda=lambdaGrid)
getSqErr = function(k) {
ridgeMod = glmnet(GT[-j,], as.matrix(Xi[-j,i], ncol=1), family="gaussian", alpha=0,
intercept=FALSE, lambda=lambdaGrid[k])
pred = predict(ridgeMod, rbind(GT[j,]), type="link")
(pred - Xi[j,i])^2
}
sapply(1:m, getSqErr)
}
# get rmse versus lambda matrix
CVMat = sapply(1:nrow(Xi), LOOCV, lambdaGrid=lambdaGrid)
allRMSE = cbind(allRMSE, rowMeans(CVMat))
}
# choose the best lambda
rmse = rowMeans(allRMSE)
minI = which.min(rmse)
lambda = lambdaGrid[minI]
list(lambda=lambda, rmse=rmse)
}
# range for lambda regularization parameter based on some previous results
lambdaMax = 100
lambdaMin = .01
m=100
lambdaGrid = rev(exp(seq(log(lambdaMin), log(lambdaMax), length=m)))
# get best value for lambda
# long story short: optimal lambda is near 0, so no point in ridge regression
out = getRidgeLambda(lambdaGrid)
plot(lambdaGrid, out$rmse, log="x", main="RMSE", xlab="lambda")
##### Test backprojecting subsidence data from just one event
event = dr1[dr1$event=="T5",]
# make low res fault
fault = divideFault(faultGeom, nDown=1, nStrike=1)
n = nrow(fault)
# get Okada linear transformation matrix
nx = 300
ny= 900
lonGrid = seq(lonRange[1], lonRange[2], l=nx)
latGrid = seq(latRange[1], latRange[2], l=ny)
G = okadaAll(fault, lonGrid, latGrid, cbind(event$Lon, event$Lat), slip=1, poisson=0.25)
# get taper values
load("fixedFit_MVN.RData")
tvec = taper(fault$depth, lambda=fixedFitMVN$lambdaMLE)
# try using lm function (WLS)
wts = (1/event$Uncertainty^2)/sum(1/event$Uncertainty^2)
mod = lm(-event$subsidence ~ G %*% diag(tvec) - 1, weights=wts)
summary(mod)
ests = coef(summary(mod))[,1]
SEs = coef(summary(mod))[,2]
# plot back-projected subsidence data with uncertainty
par(mfrow=c(2,2))
# GPS dat
# quilt.plot(slipDatCSZ$lon, slipDatCSZ$lat, slipDatCSZ$slip, main="GPS Observations (mm/yr)",
# xlim=lonRange, ylim=latRange)
# map("world", "Canada", add=TRUE, lwd=1.5)
# US(add=TRUE, lwd=1.5)
# plotFault(fault, plotData=FALSE, new=FALSE)
# subsidence dat
quilt.plot(event$Lon, event$Lat, -event$subsidence, main="Observed Uplift (m)",
xlim=lonRange, ylim=latRange, nx=40, ny=40)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# subsidence unvertainty
quilt.plot(event$Lon, event$Lat, event$Uncertainty, main="Subsidence Uncertainty (m)",
xlim=lonRange, ylim=latRange, nx=40, ny=40)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# backprojected subsidence data
plotFault(fault, plotVar=ests, xlim=lonRange, ylim=latRange,
main="Back-Projected Coastal Uplift Data (m)", logScale=TRUE)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# backprojected uncertainty
plotFault(fault, plotVar=SEs, xlim=lonRange, ylim=latRange,
main="Back-Projected Coastal Uplift SE (m)", legend.mar = 10,
logScale=TRUE)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
min(SEs)
##### now try using svd instead of QR
test = svd(G %*% diag(tvec))
# par(mfrow=c(1,1))
# hist(test$d)
# plot(1:n, cumsum(test$d)/sum(test$d), ylim=c(0,1), type="l", ylab="Condition Number", xlab="Rank of G %*% T",
# main="99% Variance Explained")
# abline(h=.99, col="red")
# plot(1:n, sqrt(test$d[1]/test$d), type="l", log="y", ylab="Condition Number", xlab="Rank of G %*% T",
# main="Condition Number is 1000")
# abline(h=1000, col="red")
# rank = min(which(cumsum(test$d)/sum(test$d) > .999)) - 1
rank = min(n, nrow(event))
sqrt(test$d[1]/test$d[rank]) # condition number
pseudoInv = test$v %*% diag(c(test$d[1:rank]^(-1), rep(0, n-rank))) %*% t(test$u)
# plot back-projected subsidence data with uncertainty
par(mfrow=c(2,2))
# GPS dat
# quilt.plot(slipDatCSZ$lon, slipDatCSZ$lat, slipDatCSZ$slip, main="GPS Observations (mm/yr)",
# xlim=lonRange, ylim=latRange)
# map("world", "Canada", add=TRUE, lwd=1.5)
# US(add=TRUE, lwd=1.5)
# plotFault(fault, plotData=FALSE, new=FALSE)
# subsidence dat
quilt.plot(event$Lon, event$Lat, -event$subsidence, main="Observed Uplift (m)",
xlim=lonRange, ylim=latRange, nx=40, ny=40)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# subsidence unvertainty
quilt.plot(event$Lon, event$Lat, event$Uncertainty, main="Subsidence Uncertainty (m)",
xlim=lonRange, ylim=latRange, nx=40, ny=40)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# backprojected subsidence data
plotFault(fault, plotVar=pseudoInv %*% (-event$subsidence), xlim=lonRange, ylim=latRange,
main="Back-Projected Coastal Uplift Data (m)", logScale=TRUE)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# backprojected uncertainty
newSigma = diag(pseudoInv %*% diag(event$Uncertainty) %*% t(pseudoInv))
plotFault(fault, plotVar=newSigma, xlim=lonRange, ylim=latRange,
main="Back-Projected Coastal Uplift SE (m)", legend.mar = 10,
logScale=TRUE)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
# Get minimum standard error
# 122.9 (1,1,rank=full, T1), 6.6e34 (1,1,rank=full,T2), 1306 (1,1,full,T5)
min(newSigma)
# 5 (1,1, T1), 23/FAIL (1,1,T2), 15 (1,1,T5)
min(SEs)
##### try using generalized least squares
library(GLSME)
# get fit MLEs
lambda = fixedFitMVN$MLEs[1]
muZeta = fixedFitMVN$MLEs[2]
sigmaZeta = fixedFitMVN$MLEs[3]
lambda0 = fixedFitMVN$MLEs[4]
muXi = fixedFitMVN$MLEs[5]
# set other relevant parameters
nuZeta = 3/2 # Matern smoothness
phiZeta = 232.5722 # fit from fitGPSCovariance()
# get CSZ covariance matrix
xp = cbind(fault$longitude, fault$latitude)
Vt = stationary.cov(xp, Covariance="Matern", Distance="rdist.earth", Dist.args=list(miles=FALSE),
theta=phiZeta, smoothness=nuZeta) * sigmaZeta^2
Vt = G %*% diag(tvec) %*% Vt %*% diag(tvec) %*% t(G) # why negative eignvalues?
Ve = diag(event$Uncertainty^2)
glsMod = GLSME(-event$subsidence, G %*% diag(tvec), Vt, Ve, 0, 0, c(FALSE, FALSE),
CenterPredictor = FALSE, Vttype="Matrix")
estsGLS = glsMod$GLSestimate
SEsGLS = glsMod$errorGLSestim
# plot back-projected subsidence data with uncertainty
par(mfrow=c(2,2))
# GPS dat
# quilt.plot(slipDatCSZ$lon, slipDatCSZ$lat, slipDatCSZ$slip, main="GPS Observations (mm/yr)",
# xlim=lonRange, ylim=latRange)
# map("world", "Canada", add=TRUE, lwd=1.5)
# US(add=TRUE, lwd=1.5)
# plotFault(fault, plotData=FALSE, new=FALSE)
# subsidence dat
quilt.plot(event$Lon, event$Lat, -event$subsidence, main="Observed Uplift (m)",
xlim=lonRange, ylim=latRange, nx=40, ny=40)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# subsidence unvertainty
quilt.plot(event$Lon, event$Lat, event$Uncertainty, main="Subsidence Uncertainty (m)",
xlim=lonRange, ylim=latRange, nx=40, ny=40)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# backprojected subsidence data
plotFault(fault, plotVar=estsGLS, xlim=lonRange, ylim=latRange,
main="Back-Projected Coastal Uplift Data (m)", logScale=TRUE)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# backprojected uncertainty
plotFault(fault, plotVar=SEsGLS, xlim=lonRange, ylim=latRange,
main="Back-Projected Coastal Uplift SE (m)", legend.mar = 10,
logScale=TRUE)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
# Make same plots except don't use log scale, only plot reasonable values
quilt.plot(event$Lon, event$Lat, -event$subsidence, main="Observed Uplift (m)",
xlim=lonRange, ylim=latRange, nx=40, ny=40)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# subsidence unvertainty
quilt.plot(event$Lon, event$Lat, event$Uncertainty, main="Subsidence Uncertainty (m)",
xlim=lonRange, ylim=latRange, nx=40, ny=40)
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# backprojected subsidence data
plotFault(fault, plotVar=estsGLS, xlim=lonRange, ylim=latRange,
main="Back-Projected Coastal Uplift Data (m)", varRange=c(0, 100))
map("world", "Canada", add=TRUE, lwd=1.5)
US(add=TRUE, lwd=1.5)
plotFault(fault, plotData=FALSE, new=FALSE)
# backprojected uncertainty