@@ -1137,7 +1137,7 @@ def write_synthetics(home,project_name,run_name,GF_list,G,sol,ds,num,decimate):
11371137
11381138
11391139def write_log (home ,project_name ,run_name ,k ,rupture_speed ,num_windows ,lambda_spatial ,lambda_temporal ,
1140- beta ,L2 ,Lm ,VR ,ABIC ,Mo ,Mw ,velmod ,fault ,g_name ,gflist ,solver ):
1140+ beta ,L2 ,Lm ,VR ,ABIC ,Mo ,Mw ,velmod ,fault ,g_name ,gflist ,solver , L2data ):
11411141 '''
11421142 Write inversion sumamry to .log file
11431143
@@ -1188,6 +1188,11 @@ def write_log(home,project_name,run_name,k,rupture_speed,num_windows,lambda_spat
11881188 f .write ('VR velocity(%) = ' + repr (VR [2 ])+ '\n ' )
11891189 f .write ('VR tsunami(%) = ' + repr (VR [3 ])+ '\n ' )
11901190 f .write ('VR InSAR LOS(%) = ' + repr (VR [4 ])+ '\n ' )
1191+ f .write ('RMS static(%) = ' + repr (L2data [0 ])+ '\n ' )
1192+ f .write ('RMS displacement(%) = ' + repr (L2data [1 ])+ '\n ' )
1193+ f .write ('RMS velocity(%) = ' + repr (L2data [2 ])+ '\n ' )
1194+ f .write ('RMS tsunami(%) = ' + repr (L2data [3 ])+ '\n ' )
1195+ f .write ('RMS InSAR LOS(%) = ' + repr (L2data [4 ])+ '\n ' )
11911196 f .write ('Lm = ' + repr (Lm )+ '\n ' )
11921197 f .write ('ABIC = ' + repr (ABIC )+ '\n ' )
11931198 f .write ('M0(N-m) = ' + repr (Mo )+ '\n ' )
@@ -1482,7 +1487,7 @@ def get_stats(WG,sol,wd):
14821487 return L2 ,Lm
14831488
14841489
1485- def get_VR (home ,project_name ,GF_list ,sol ,d ,ds ,decimate ):
1490+ def get_VR (home ,project_name ,GF_list ,sol ,d ,ds ,decimate , WG , wd ):
14861491 '''
14871492 Compute Variance reduction to the data
14881493
@@ -1497,6 +1502,7 @@ def get_VR(home,project_name,GF_list,sol,d,ds,decimate):
14971502 from numpy import genfromtxt ,where ,r_ ,nan
14981503 from obspy import read
14991504 from mudpy .green import stdecimate
1505+ from numpy .linalg import norm
15001506
15011507 print ('... calcualting variance reduction...' )
15021508
@@ -1508,22 +1514,32 @@ def get_VR(home,project_name,GF_list,sol,d,ds,decimate):
15081514 #Separate into its constituent parts (statics,displacaments, velocities, etc...)
15091515 kstart = 0
15101516 kend = 0
1517+
1518+ #Calculate weighted syntehtic data
1519+ wds = WG .dot (sol )
1520+
15111521 #Statics
15121522 kgf = 0
15131523 i = where (GF [:,kgf ]== 1 )[0 ]
15141524 VRstatic = nan
1525+ L2static = nan
15151526 if len (i )> 0 :
15161527 for ksta in range (len (i )):
15171528 kend += 3
15181529 #Variance reduction
15191530 res = ((d [kstart :kend ]- ds [kstart :kend ])** 2 )** 0.5
15201531 dnorm = (d [kstart :kend ]** 2 )** 0.5 #Yes i know this is dumb, shush
15211532 VRstatic = (1 - (res .sum ()/ dnorm .sum ()))* 100
1533+
1534+ #Get RMS (L2 norm) of weigtehd data misfit
1535+ L2static = norm (wds [kstart :kend ]- wd [kstart :kend ])
1536+
15221537 #Displacement
15231538 kstart = kend
15241539 kgf = 1
15251540 i = where (GF [:,kgf ]== 1 )[0 ]
15261541 VRdisp = nan
1542+ L2disp = nan
15271543 if len (i )> 0 :
15281544 for ksta in range (len (i )):
15291545 sta = stations [i [ksta ]]
@@ -1536,11 +1552,16 @@ def get_VR(home,project_name,GF_list,sol,d,ds,decimate):
15361552 res = ((d [kstart :kend ]- ds [kstart :kend ])** 2 )** 0.5
15371553 dnorm = (d [kstart :kend ]** 2 )** 0.5 #Yes i know this is dumb, shush
15381554 VRdisp = (1 - (res .sum ()/ dnorm .sum ()))* 100
1555+
1556+ #Get RMS (L2 norm) of weigtehd data misfit
1557+ L2disp = norm (wds [kstart :kend ]- wd [kstart :kend ])
1558+
15391559 #Velocity
15401560 kstart = kend
15411561 kgf = 2
15421562 i = where (GF [:,kgf ]== 1 )[0 ]
15431563 VRvel = nan
1564+ L2vel = nan
15441565 if len (i )> 0 :
15451566 for ksta in range (len (i )):
15461567 sta = stations [i [ksta ]]
@@ -1553,11 +1574,16 @@ def get_VR(home,project_name,GF_list,sol,d,ds,decimate):
15531574 res = ((d [kstart :kend ]- ds [kstart :kend ])** 2 )** 0.5
15541575 dnorm = (d [kstart :kend ]** 2 )** 0.5 #Yes i know this is dumb, shush
15551576 VRvel = (1 - (res .sum ()/ dnorm .sum ()))* 100
1577+
1578+ #Get RMS (L2 norm) of weigtehd data misfit
1579+ L2vel = norm (wds [kstart :kend ]- wd [kstart :kend ])
1580+
15561581 #Tsunami
15571582 kstart = kend
15581583 kgf = 3
15591584 i = where (GF [:,kgf ]== 1 )[0 ]
15601585 VRtsun = nan
1586+ L2tsun = nan
15611587 if len (i )> 0 :
15621588 for ksta in range (len (i )):
15631589 sta = stations [i [ksta ]]
@@ -1568,20 +1594,32 @@ def get_VR(home,project_name,GF_list,sol,d,ds,decimate):
15681594 res = ((d [kstart :kend ]- ds [kstart :kend ])** 2 )** 0.5
15691595 dnorm = (d [kstart :kend ]** 2 )** 0.5 #Yes i know this is dumb, shush
15701596 VRtsun = (1 - (res .sum ()/ dnorm .sum ()))* 100
1597+
1598+ #Get RMS (L2 norm) of weigtehd data misfit
1599+ L2tsun = norm (wds [kstart :kend ]- wd [kstart :kend ])
1600+
15711601 # InSAR
15721602 kstart = kend
15731603 kgf = 4
15741604 i = where (GF [:,kgf ]== 1 )[0 ]
15751605 VRinsar = nan
1606+ L2insar = nan
15761607 if len (i )> 0 :
15771608 for ksta in range (len (i )):
15781609 kend += 1
15791610 #Variance reduction
15801611 res = ((d [kstart :kend ]- ds [kstart :kend ])** 2 )** 0.5
15811612 dnorm = (d [kstart :kend ]** 2 )** 0.5 #Yes i know this is dumb, shush
1582- VRinsar = (1 - (res .sum ()/ dnorm .sum ()))* 100
1613+ VRinsar = (1 - (res .sum ()/ dnorm .sum ()))* 100
1614+
1615+ #Get RMS (L2 norm) of weigtehd data misfit
1616+ L2insar = norm (wds [kstart :kend ]- wd [kstart :kend ])
1617+
1618+
15831619 VR = r_ [VRstatic ,VRdisp ,VRvel ,VRtsun ,VRinsar ]
1584- return VR
1620+ L2 = r_ [L2static ,L2disp ,L2vel ,L2tsun ,L2insar ]
1621+
1622+ return VR ,L2
15851623
15861624
15871625
@@ -1868,6 +1906,8 @@ def ds2rot(sol,beta):
18681906 #Split into strike-slip and dip-slip
18691907 iss = 2 * arange (0 ,len (sol )/ 2 ,1 )
18701908 ids = 2 * arange (0 ,len (sol )/ 2 ,1 )+ 1
1909+ iss = iss .astype ('int' )
1910+ ids = ids .astype ('int' )
18711911 if len (iss )== 1 :
18721912 ss = sol [0 ]
18731913 ds = sol [1 ]
0 commit comments