Skip to content

Commit fdb78f6

Browse files
author
Diego Melgar
committed
Some py3x updates and otehr tibits
1 parent cbc3dbe commit fdb78f6

5 files changed

Lines changed: 199 additions & 75 deletions

File tree

src/python/mudpy/gmttools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def insar_xyz(home,project_name,run_name,run_number,GF_list,outfile):
589589
from numpy import genfromtxt,where,zeros,c_,savetxt
590590

591591
#Decide what to plot
592-
sta=genfromtxt(home+project_name+'/data/station_info/'+GF_list,usecols=0,dtype='S')
592+
sta=genfromtxt(home+project_name+'/data/station_info/'+GF_list,usecols=0,dtype='U')
593593
lon_all=genfromtxt(home+project_name+'/data/station_info/'+GF_list,usecols=[1],dtype='f')
594594
lat_all=genfromtxt(home+project_name+'/data/station_info/'+GF_list,usecols=[2],dtype='f')
595595
gf=genfromtxt(home+project_name+'/data/station_info/'+GF_list,usecols=[7],dtype='f')

src/python/mudpy/hfsims_parallel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def run_parallel_hfsims(home,project_name,rupture_name,N,M0,sta,sta_lon,sta_lat,
181181
###Apply multiplier?
182182
if in_smga==True:
183183
stress=stress_parameter*stress_multiplier
184-
print "%.4f,%.4f is in SMGA, stress is %d" % (lon_source,lat_source,stress)
184+
print("%.4f,%.4f is in SMGA, stress is %d" % (lon_source,lat_source,stress))
185185
else:
186186
stress=stress_parameter
187187

src/python/mudpy/inverse.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ def write_synthetics(home,project_name,run_name,GF_list,G,sol,ds,num,decimate):
11371137

11381138

11391139
def 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]

src/python/mudpy/runslip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ def run_inversion(home,project_name,run_name,fault_name,model_name,GF_list,G_fro
711711
ds=dot(G,sol)
712712
#Get stats
713713
L2,Lmodel=inv.get_stats(Kinv,sol,x)
714-
VR=inv.get_VR(home,project_name,GF_list,sol,d,ds,decimate)
714+
VR,L2data=inv.get_VR(home,project_name,GF_list,sol,d,ds,decimate,WG,wd)
715715
#VR=inv.get_VR(WG,sol,wd)
716716
#ABIC=inv.get_ABIC(WG,K,sol,wd,lambda_spatial,lambda_temporal,Ls,LsLs,Lt,LtLt)
717717
ABIC=inv.get_ABIC(G,K,sol,d,lambda_spatial,lambda_temporal,Ls,LsLs,Lt,LtLt)
@@ -722,7 +722,7 @@ def run_inversion(home,project_name,run_name,fault_name,model_name,GF_list,G_fro
722722
sol=inv.rot2ds(sol,beta)
723723
#Write log
724724
inv.write_log(home,project_name,run_name,kout,rupture_speed,num_windows,lambda_spatial,lambda_temporal,beta,
725-
L2,Lmodel,VR,ABIC,Mo,Mw,model_name,fault_name,G_name,GF_list,solver)
725+
L2,Lmodel,VR,ABIC,Mo,Mw,model_name,fault_name,G_name,GF_list,solver,L2data)
726726
#Write output to file
727727
inv.write_synthetics(home,project_name,run_name,GF_list,G,sol,ds,kout,decimate)
728728
inv.write_model(home,project_name,run_name,fault_name,model_name,rupture_speed,num_windows,epicenter,sol,kout,onset_file=onset_file)

0 commit comments

Comments
 (0)