In [14]:
import pandas as pd
import os
import numpy as np
import matplotlib.pylab as plt
from scipy import optimize
from scipy import stats
from scipy import interpolate
from matplotlib import cm
from mpl_toolkits.axes_grid1 import make_axes_locatable
from scipy.stats import pearsonr
# stats.binned_statistic() method 
from scipy import stats
import warnings
warnings.filterwarnings("ignore")
from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable
from sklearn.linear_model import LinearRegression

%matplotlib inline  

def fullprint(df):
    with pd.option_context('display.max_rows', None, 'display.max_columns', None):  # more options can be specified also
        print(df)


file = os.path.join(os.getcwd(),'rundir4983_stitched_rakes_dips_lengths_m6.5.csv')
rsqsim = pd.read_csv(file,sep=',',skipinitialspace=True,low_memory=False,skiprows=None)
rsqsim.dropna(inplace=True)
rsqsim=rsqsim.rename(columns={"Event ID":"Eventid",
                       "Occurrence Time (s)": "OccurT",
                       "Magnitude": "M",
                       "Moment (N-m)":"Moment",
                       "Area (m^2)": "A",
                       "Average Slip (m)":"AD",
                       "Average Element Slip Rate (m/yr)":"SR",
                       "Hypocenter Latitude":"Hlat",
                       "Hypocenter Longitude":"Hlon",
                       "Centroid Latitude":"Clat",
                       "Centroid Longitude":"Clon",
                       "Hypocenter Depth (km)":"HD",
                       "Centroid Depth (km)":"CD",
                       "Upper Depth (km)":"TD",
                       "Lower Depth (km)":"BD",
                       "Average Rake":"ARake",
                       "Average Absolute Rake Deviation":"AdRake",
                       "Max Absolute Rake Deviation":"MdRake",
                             "Average Dip":"ADip",
                              "Average Absolute Dip Deviation":"AdDip",
                              "Max Absolute Dip Deviation":"MdDip",
                              "Full Mapped Subsection Length (km)":"FML",
                              "Full Slipped Length (km)":"FSL",
                              "Mid-Seismogenic Slipped Length (km)":"MSL",
                              "Surface Slipped Length (km)":"SSL"})

rsqsim['A']=rsqsim['A']/1e6
rsqsim['L']=rsqsim['FSL']
rsqsim['W']=rsqsim['A']/rsqsim['L']
rsqsim['Aratio']=rsqsim['L']/rsqsim['W']
rsqsim['SF']=rsqsim['SSL']/rsqsim['L']
rsqsim['SR']=rsqsim['SR']*1e3 #convert to mm/yr
rsqsim['TW']=rsqsim['TD']/np.sin(rsqsim['ADip']*np.pi/180.)
rsqsim['BW']=rsqsim['BD']/np.sin(rsqsim['ADip']*np.pi/180.)
rsqsim['CW']=rsqsim['CD']/np.sin(rsqsim['ADip']*np.pi/180.)
rsqsim['HW']=rsqsim['HD']/np.sin(rsqsim['ADip']*np.pi/180.)

rsqsim['DW']=rsqsim['BW']-rsqsim['TW']
rsqsim['DD']=rsqsim['BD']-rsqsim['TD']
def chinnery_strdrop(LE,AD,WE=15):
    LH=LE/2
    a=np.sqrt(LH**2+WE**2)
    C1=2*LH/(a*WE)+3/LH-(LH*(3*a+4*WE))/(a*(a+WE)**2)
    G=30*1e3
    
    return G*AD*1e-3*C1/2/np.pi
rsqsim['SDP']=chinnery_strdrop(rsqsim['L'].to_numpy(),rsqsim['AD'].to_numpy(),rsqsim['W'].to_numpy())

rsqsim['FM']='Oblique'
rsqsim.loc[(rsqsim['ARake'] >= -180) & (rsqsim['ARake'] <= -170), 'FM'] = 'RSS'
rsqsim.loc[(rsqsim['ARake'] <= 180) & (rsqsim['ARake'] >= 170), 'FM'] = 'RSS'
rsqsim.loc[(rsqsim['ARake'] <= 10) & (rsqsim['ARake'] >= -10), 'FM'] = 'LSS'
rsqsim.loc[(rsqsim['ARake'] <= 100) & (rsqsim['ARake'] >= 80), 'FM'] = 'RV'
rsqsim.loc[(rsqsim['ARake'] <= -80) & (rsqsim['ARake'] >= -100), 'FM'] = 'NM'
In [2]:
SS=((rsqsim['FM']=='RSS') | (rsqsim['FM']=='LSS')) & ((rsqsim['AdRake']<5) & (rsqsim['AdDip']<5))
RV=(rsqsim['FM']=='RV') & ((rsqsim['AdRake']<5) & (rsqsim['AdDip']<5))
NM=(rsqsim['FM']=='NM') & ((rsqsim['AdRake']<5) & (rsqsim['AdDip']<5))
In [3]:
cmap=plt.get_cmap('RdPu',10)
c=['darkblue','green','orange']
sr_range=[0.01,1,10,40]
nbin=np.arange(6.5,8.2,0.2)
plotratio=False

nx = 50
ny = 50

field=[
       'TW',
       'BW',
       'DW',
        'TD',
       'BD',
       'DD',
        'SF']
binx = np.logspace(-2,2,nx)
    
binyarray=[
           np.linspace(0,10,ny),
           np.linspace(5,25,ny),
           np.linspace(5,25,ny),
           np.linspace(0,10,ny),
           np.linspace(5,25,ny),
           np.linspace(5,25,ny),
           np.linspace(0,1,ny),
          ]
logy=[False,False,False,False,False,False,False]

nfield=len(field)
    
    

    

fig = plt.figure( figsize=(15,20))
axe=fig.subplots(nfield, 4)

condition=SS

binx = np.linspace(6.5,8.3,50)

for iff in range(nfield):
    
    xall=rsqsim.loc[condition,'M']
    yall=rsqsim.loc[condition,field[iff]]
    if logy[iff]:
            yall = np.log10(yall)
    meanall,bin_edges,_=stats.binned_statistic(xall, yall, statistic='mean', bins=nbin)
    if logy[iff]:
            meanall=10**meanall
    
    for i in range(len(sr_range)-1):
        
        if iff==0 or iff==1 or iff==3 or iff==4:
            axe[iff,i].invert_yaxis()
        condition2=condition & ((rsqsim['SR']>=sr_range[i]) & (rsqsim['SR']<sr_range[i+1]))
        y=rsqsim.loc[condition2,field[iff]]
        x=rsqsim.loc[condition2,'M']

        biny = binyarray[iff]
        H, yedges, xedges = np.histogram2d(y, x, bins=[biny,binx],density=True)
        
        im1=axe[iff,i].pcolormesh(xedges, yedges, np.log10(H), cmap=cmap)
#         ax1_divider = make_axes_locatable(axe[iff,i])
#         cax1 = ax1_divider.append_axes("right", size="4%", pad="-10%")
#         cb1 = fig.colorbar(im1, cax=cax1,orientation='vertical')
#         cb1.set_label('$log_{10}$(density)',fontsize='large')
        if logy[iff]:
            axe[iff,i].set_yscale('log')
        axe[iff,i].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,i].grid(which='minor', color='silver', linestyle='--')
        axe[iff,i].set_axisbelow(True)
        axe[iff,i].set_ylabel(field[iff],fontsize='large')
        axe[iff,i].set_xlabel('Magnitude')
        
        x = x.to_numpy()
        y = y.to_numpy()
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='mean', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if plotratio:
            axe[iff,3].plot(mean_centers,mean/meanall,'-',color=c[i],linewidth=4,zorder=10,label='Mean for {0}<SR<{1}'.format(sr_range[i],sr_range[i+1]) )
            axe[iff,3].set_ylim([0.1,10])
            axe[iff,3].set_yscale('log')
        else:
            if(len(y)>0):
                axe[iff,3].plot(mean_centers,mean,'-',color=c[i],linewidth=4,zorder=10,label='Mean for {0}<SR<{1}'.format(sr_range[i],sr_range[i+1]) )
            if logy[iff]:
                axe[iff,3].set_yscale('log')
            axe[iff,3].set_ylim([biny.min(),biny.max()])
            
        if iff==0:
            axe[iff,3].legend(loc='best',fontsize='medium') 
        axe[iff,3].set_xlim([binx.min(),binx.max()])
        axe[iff,3].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,3].grid(which='minor', color='silver', linestyle='--')
        axe[iff,3].set_axisbelow(True)
        
        
axe[0,3].invert_yaxis()
axe[1,3].invert_yaxis()
axe[3,3].invert_yaxis()
axe[4,3].invert_yaxis()
plt.tight_layout()
In [4]:
cmap=plt.get_cmap('GnBu',10)
c=['darkblue','green','orange']
sr_range=[0.01,1,10,40]
nbin=np.arange(6.5,8.2,0.2)
plotratio=False

nx = 50
ny = 50

field=[
       'TW',
       'BW',
       'DW',
        'TD',
       'BD',
       'DD',
        'SF']
binx = np.logspace(-2,2,nx)
    
binyarray=[
           np.linspace(0,20,ny),
           np.linspace(5,80,ny),
           np.linspace(5,80,ny),
           np.linspace(0,15,ny),
           np.linspace(5,25,ny),
           np.linspace(5,25,ny),
           np.linspace(0,1,ny),
          ]
logy=[False,False,False,False,False,False,False]

nfield=len(field)
    
    

    

fig = plt.figure( figsize=(15,20))
axe=fig.subplots(nfield, 4)

condition=RV

binx = np.linspace(6.5,8.3,50)

for iff in range(nfield):
    
    xall=rsqsim.loc[condition,'M']
    yall=rsqsim.loc[condition,field[iff]]
    if logy[iff]:
            yall = np.log10(yall)
    meanall,bin_edges,_=stats.binned_statistic(xall, yall, statistic='mean', bins=nbin)
    if logy[iff]:
            meanall=10**meanall
    
    for i in range(len(sr_range)-1):
        
        if iff==0 or iff==1 or iff==3 or iff==4:
            axe[iff,i].invert_yaxis()
        condition2=condition & ((rsqsim['SR']>=sr_range[i]) & (rsqsim['SR']<sr_range[i+1]))
        y=rsqsim.loc[condition2,field[iff]]
        x=rsqsim.loc[condition2,'M']

        biny = binyarray[iff]
        H, yedges, xedges = np.histogram2d(y, x, bins=[biny,binx],density=True)
        
        im1=axe[iff,i].pcolormesh(xedges, yedges, np.log10(H), cmap=cmap)
#         ax1_divider = make_axes_locatable(axe[iff,i])
#         cax1 = ax1_divider.append_axes("right", size="4%", pad="-10%")
#         cb1 = fig.colorbar(im1, cax=cax1,orientation='vertical')
#         cb1.set_label('$log_{10}$(density)',fontsize='large')
        if logy[iff]:
            axe[iff,i].set_yscale('log')
        axe[iff,i].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,i].grid(which='minor', color='silver', linestyle='--')
        axe[iff,i].set_axisbelow(True)
        axe[iff,i].set_ylabel(field[iff],fontsize='large')
        axe[iff,i].set_xlabel('Magnitude')
        
        x = x.to_numpy()
        y = y.to_numpy()
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='mean', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if plotratio:
            axe[iff,3].plot(mean_centers,mean/meanall,'-',color=c[i],linewidth=4,zorder=10,label='Mean for {0}<SR<{1}'.format(sr_range[i],sr_range[i+1]) )
            axe[iff,3].set_ylim([0.1,10])
            axe[iff,3].set_yscale('log')
        else:
            if(len(y)>0):
                axe[iff,3].plot(mean_centers,mean,'-',color=c[i],linewidth=4,zorder=10,label='Mean for {0}<SR<{1}'.format(sr_range[i],sr_range[i+1]) )
            if logy[iff]:
                axe[iff,3].set_yscale('log')
            axe[iff,3].set_ylim([biny.min(),biny.max()])
            
        if iff==0:
            axe[iff,3].legend(loc='best',fontsize='medium') 
        axe[iff,3].set_xlim([binx.min(),binx.max()])
        axe[iff,3].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,3].grid(which='minor', color='silver', linestyle='--')
        axe[iff,3].set_axisbelow(True)
        
        
axe[0,3].invert_yaxis()
axe[1,3].invert_yaxis()
axe[3,3].invert_yaxis()
axe[4,3].invert_yaxis()
plt.tight_layout()
In [5]:
cmap=plt.get_cmap('Purples',10)
c=['darkblue','green','orange']
sr_range=[0.01,1,10,40]
nbin=np.arange(6.5,8.2,0.2)
plotratio=False

nx = 50
ny = 50

field=[
       'TW',
       'BW',
       'DW',
        'TD',
       'BD',
       'DD',
        'SF']
binx = np.logspace(-2,2,nx)
    
binyarray=[
           np.linspace(0,5,ny),
           np.linspace(10,30,ny),
           np.linspace(10,30,ny),
           np.linspace(0,5,ny),
           np.linspace(10,20,ny),
           np.linspace(10,20,ny),
           np.linspace(0,1,ny),
          ]
logy=[False,False,False,False,False,False,False]

nfield=len(field)
    
    

    

fig = plt.figure( figsize=(15,20))
axe=fig.subplots(nfield, 4)

condition=NM

binx = np.linspace(6.5,8.3,50)

for iff in range(nfield):
    
    xall=rsqsim.loc[condition,'M']
    yall=rsqsim.loc[condition,field[iff]]
    if logy[iff]:
            yall = np.log10(yall)
    meanall,bin_edges,_=stats.binned_statistic(xall, yall, statistic='mean', bins=nbin)
    if logy[iff]:
            meanall=10**meanall
    
    for i in range(len(sr_range)-1):
        
        if iff==0 or iff==1 or iff==3 or iff==4:
            axe[iff,i].invert_yaxis()
        condition2=condition & ((rsqsim['SR']>=sr_range[i]) & (rsqsim['SR']<sr_range[i+1]))
        y=rsqsim.loc[condition2,field[iff]]
        x=rsqsim.loc[condition2,'M']

        biny = binyarray[iff]
        H, yedges, xedges = np.histogram2d(y, x, bins=[biny,binx],density=True)
        
        im1=axe[iff,i].pcolormesh(xedges, yedges, np.log10(H), cmap=cmap)
#         ax1_divider = make_axes_locatable(axe[iff,i])
#         cax1 = ax1_divider.append_axes("right", size="4%", pad="-10%")
#         cb1 = fig.colorbar(im1, cax=cax1,orientation='vertical')
#         cb1.set_label('$log_{10}$(density)',fontsize='large')
        if logy[iff]:
            axe[iff,i].set_yscale('log')
        axe[iff,i].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,i].grid(which='minor', color='silver', linestyle='--')
        axe[iff,i].set_axisbelow(True)
        axe[iff,i].set_ylabel(field[iff],fontsize='large')
        axe[iff,i].set_xlabel('Magnitude')
        
        x = x.to_numpy()
        y = y.to_numpy()
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='mean', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if plotratio:
            axe[iff,3].plot(mean_centers,mean/meanall,'-',color=c[i],linewidth=4,zorder=10,label='Mean for {0}<SR<{1}'.format(sr_range[i],sr_range[i+1]) )
            axe[iff,3].set_ylim([0.1,10])
            axe[iff,3].set_yscale('log')
        else:
            if(len(y)>0):
                axe[iff,3].plot(mean_centers,mean,'-',color=c[i],linewidth=4,zorder=10,label='Mean for {0}<SR<{1}'.format(sr_range[i],sr_range[i+1]) )
            if logy[iff]:
                axe[iff,3].set_yscale('log')
            axe[iff,3].set_ylim([biny.min(),biny.max()])
            
        if iff==0:
            axe[iff,3].legend(loc='best',fontsize='medium') 
        axe[iff,3].set_xlim([binx.min(),binx.max()])
        axe[iff,3].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,3].grid(which='minor', color='silver', linestyle='--')
        axe[iff,3].set_axisbelow(True)
        
        
axe[0,3].invert_yaxis()
axe[1,3].invert_yaxis()
axe[3,3].invert_yaxis()
axe[4,3].invert_yaxis()
plt.tight_layout()

compare ratio of surface rupture

In [6]:
fmcmap=[plt.get_cmap('RdPu',256),
        plt.get_cmap('GnBu',256),
        plt.get_cmap('Purples',256)]
fm = [SS,RV,NM]
fnm = ['Strike-slip','Reverse','Normal']
nm = ['Immature','Intermediate mature','Mature']
c=['darkblue','green','orange']
sr_range=[0.01,1,10,40]
nbin=np.arange(6.5,8.2,0.2)
plotratio=False

nx = 50
ny = 50

field=['SF','SF','SF']
binx = np.logspace(-2,2,nx)
    
binyarray=[
           np.linspace(0,1,ny),
    np.linspace(0,1,ny),
    np.linspace(0,1,ny),
          ]
logy=[False,False,False]

nfield=len(field)
    

fig = plt.figure( figsize=(20,15))
axe=fig.subplots(nfield, 4)



binx = np.linspace(6.5,8.3,50)

for iff in range(nfield):
    
    condition=fm[iff]
    
    for i in range(len(sr_range)-1):
        
        
        condition2=condition & ((rsqsim['SR']>=sr_range[i]) & (rsqsim['SR']<sr_range[i+1]))
        y=rsqsim.loc[condition2,field[iff]]
        x=rsqsim.loc[condition2,'M']

        biny = binyarray[iff]
        H, yedges, xedges = np.histogram2d(y, x, bins=[biny,binx],density=True)
        
        im1=axe[iff,i].pcolormesh(xedges, yedges, np.log10(H), cmap=fmcmap[iff])
#         ax1_divider = make_axes_locatable(axe[iff,i])
#         cax1 = ax1_divider.append_axes("right", size="4%", pad="-10%")
#         cb1 = fig.colorbar(im1, cax=cax1,orientation='vertical')
#         cb1.set_label('$log_{10}$(density)',fontsize='large')
        if logy[iff]:
            axe[iff,i].set_yscale('log')
        axe[iff,i].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,i].grid(which='minor', color='silver', linestyle='--')
        axe[iff,i].set_axisbelow(True)
        if i==0:
            axe[iff,i].set_ylabel(fnm[iff]+'\n Surface rupture ratio',fontsize='x-large')
        if iff==2:
            axe[iff,i].set_xlabel('Magnitude',fontsize='x-large')
        if iff==0:
            axe[iff,i].set_title(nm[i]+' ({0}<SR<{1})'.format(sr_range[i],sr_range[i+1]),fontsize='x-large',color=c[i])
        
        x = x.to_numpy()
        y = y.to_numpy()
        
        #mean
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='mean', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        else:
            axe[iff,i].axis('off')
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,3].plot(mean_centers,mean,'-',color=c[i],linewidth=4,zorder=10,label='Mean [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,3].set_yscale('log')
        axe[iff,3].set_ylim([biny.min(),biny.max()])
        
        
        #median
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='median', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,3].plot(mean_centers,mean,':',color=c[i],linewidth=4,zorder=10,label='Median [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,3].set_yscale('log')
        axe[iff,3].set_ylim([biny.min(),biny.max()])
        
        
        
        
        if iff==0:
            axe[iff,3].legend(loc='best',fontsize='small') 
        axe[iff,3].set_xlim([binx.min(),binx.max()])
        axe[iff,3].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,3].grid(which='minor', color='silver', linestyle='--')
        axe[iff,3].set_axisbelow(True)
In [7]:
fmcmap=[plt.get_cmap('RdPu',256),
        plt.get_cmap('GnBu',256),
        plt.get_cmap('Purples',256)]
fm = [SS,RV,NM]
fnm = ['Strike-slip','Reverse','Normal']
nm = ['Centroid Depth','Centroid Depth']
c=['darkblue','green','orange']
sr_range=[0.01,1,10,40]
d_range=[0,8,20]
nbin=np.arange(6.5,8.2,0.1)
plotratio=False

nx = 50
ny = 50

field=['SF','SF','SF']
binx = np.logspace(-2,2,nx)
    
binyarray=[
           np.linspace(0,1,ny),
    np.linspace(0,1,ny),
    np.linspace(0,1,ny),
          ]
logy=[False,False,False]

nfield=len(field)
    

fig = plt.figure( figsize=(15,15))
axe=fig.subplots(nfield, 3)



binx = np.linspace(6.5,8.3,50)

for iff in range(nfield):
    
    condition=fm[iff]
    
    for i in range(len(d_range)-1):
        
        
        condition2=condition & ((rsqsim['CD']>=d_range[i]) & (rsqsim['CD']<d_range[i+1]))
        y=rsqsim.loc[condition2,field[iff]]
        x=rsqsim.loc[condition2,'M']

        biny = binyarray[iff]
        H, yedges, xedges = np.histogram2d(y, x, bins=[biny,binx],density=True)
        
        im1=axe[iff,i].pcolormesh(xedges, yedges, np.log10(H), cmap=fmcmap[iff])
#         ax1_divider = make_axes_locatable(axe[iff,i])
#         cax1 = ax1_divider.append_axes("right", size="4%", pad="-10%")
#         cb1 = fig.colorbar(im1, cax=cax1,orientation='vertical')
#         cb1.set_label('$log_{10}$(density)',fontsize='large')
        if logy[iff]:
            axe[iff,i].set_yscale('log')
        axe[iff,i].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,i].grid(which='minor', color='silver', linestyle='--')
        axe[iff,i].set_axisbelow(True)
        if i==0:
            axe[iff,i].set_ylabel(fnm[iff]+'\n Surface rupture ratio',fontsize='x-large')
        if iff==2:
            axe[iff,i].set_xlabel('Magnitude',fontsize='x-large')
        if iff==0:
            axe[iff,i].set_title('{0}<{2}<{1}'.format(d_range[i],d_range[i+1],nm[i]),fontsize='x-large',color=c[i])
        
        x = x.to_numpy()
        y = y.to_numpy()
        
        #mean
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='mean', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        else:
            axe[iff,i].axis('off')
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,2].plot(mean_centers,mean,'-',color=c[i],linewidth=4,zorder=10,label='Mean {0}<{2}<{1}'.format(d_range[i],d_range[i+1],nm[i]) )
        if logy[iff]:
            axe[iff,2].set_yscale('log')
        axe[iff,2].set_ylim([biny.min(),biny.max()])
        
        
        #median
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='median', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,2].plot(mean_centers,mean,':',color=c[i],linewidth=4,zorder=10,label='Median {0}<{2}<{1}'.format(d_range[i],d_range[i+1],nm[i]) )
        if logy[iff]:
            axe[iff,2].set_yscale('log')
        axe[iff,2].set_ylim([biny.min(),biny.max()])
        
        
        
        
        if iff==0:
            axe[iff,2].legend(loc='best',fontsize='small') 
        axe[iff,2].set_xlim([binx.min(),binx.max()])
        axe[iff,2].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,2].grid(which='minor', color='silver', linestyle='--')
        axe[iff,2].set_axisbelow(True)
In [8]:
fmcmap=[plt.get_cmap('RdPu',256),
        plt.get_cmap('GnBu',256),
        plt.get_cmap('Purples',256)]
fm = [SS,RV,NM]
fnm = ['Strike-slip','Reverse','Normal']
nm = ['Hypocentral Depth','Hypocentral Depth']
c=['darkblue','green','orange']
sr_range=[0.01,1,10,40]
d_range=[0,8,20]
nbin=np.arange(6.5,8.2,0.1)
plotratio=False

nx = 50
ny = 50

field=['SF','SF','SF']
binx = np.logspace(-2,2,nx)
    
binyarray=[
           np.linspace(0,1,ny),
    np.linspace(0,1,ny),
    np.linspace(0,1,ny),
          ]
logy=[False,False,False]

nfield=len(field)
    

fig = plt.figure( figsize=(15,15))
axe=fig.subplots(nfield, 3)



binx = np.linspace(6.5,8.3,50)

for iff in range(nfield):
    
    condition=fm[iff]
    
    for i in range(len(d_range)-1):
        
        
        condition2=condition & ((rsqsim['HD']>=d_range[i]) & (rsqsim['HD']<d_range[i+1]))
        y=rsqsim.loc[condition2,field[iff]]
        x=rsqsim.loc[condition2,'M']

        biny = binyarray[iff]
        H, yedges, xedges = np.histogram2d(y, x, bins=[biny,binx],density=True)
        
        im1=axe[iff,i].pcolormesh(xedges, yedges, np.log10(H), cmap=fmcmap[iff])
#         ax1_divider = make_axes_locatable(axe[iff,i])
#         cax1 = ax1_divider.append_axes("right", size="4%", pad="-10%")
#         cb1 = fig.colorbar(im1, cax=cax1,orientation='vertical')
#         cb1.set_label('$log_{10}$(density)',fontsize='large')
        if logy[iff]:
            axe[iff,i].set_yscale('log')
        axe[iff,i].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,i].grid(which='minor', color='silver', linestyle='--')
        axe[iff,i].set_axisbelow(True)
        if i==0:
            axe[iff,i].set_ylabel(fnm[iff]+'\n Surface rupture ratio',fontsize='x-large')
        if iff==2:
            axe[iff,i].set_xlabel('Magnitude',fontsize='x-large')
        if iff==0:
            axe[iff,i].set_title('{0}<{2}<{1}'.format(d_range[i],d_range[i+1],nm[i]),fontsize='x-large',color=c[i])
        
        x = x.to_numpy()
        y = y.to_numpy()
        
        #mean
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='mean', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        else:
            axe[iff,i].axis('off')
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,2].plot(mean_centers,mean,'-',color=c[i],linewidth=4,zorder=10,label='Mean {0}<{2}<{1}'.format(d_range[i],d_range[i+1],nm[i]) )
        if logy[iff]:
            axe[iff,2].set_yscale('log')
        axe[iff,2].set_ylim([biny.min(),biny.max()])
        
        
        #median
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='median', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,2].plot(mean_centers,mean,':',color=c[i],linewidth=4,zorder=10,label='Median {0}<{2}<{1}'.format(d_range[i],d_range[i+1],nm[i]) )
        if logy[iff]:
            axe[iff,2].set_yscale('log')
        axe[iff,2].set_ylim([biny.min(),biny.max()])
        
        
        
        
        if iff==0:
            axe[iff,2].legend(loc='best',fontsize='small') 
        axe[iff,2].set_xlim([binx.min(),binx.max()])
        axe[iff,2].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,2].grid(which='minor', color='silver', linestyle='--')
        axe[iff,2].set_axisbelow(True)
In [9]:
fmcmap=[plt.get_cmap('RdPu',256),
        plt.get_cmap('GnBu',256),
        plt.get_cmap('Purples',256)]
fm = [SS,RV,NM]
fnm = ['Strike-slip','Reverse','Normal']
nm = ['Immature','Intermediate mature','Mature']
c=['darkblue','green','orange']
sr_range=[0.01,1,10,40]
nbin=np.arange(6.5,8.2,0.2)
plotratio=False

nx = 50
ny = 50

field=['SF','SF','SF']
binx = np.logspace(-2,2,nx)
    
binyarray=[
           np.linspace(0,1,ny),
    np.linspace(0,1,ny),
    np.linspace(0,1,ny),
          ]
logy=[False,False,False]

nfield=len(field)
    

fig = plt.figure( figsize=(20,15))
axe=fig.subplots(nfield, 4)



binx = np.linspace(6.5,8.3,50)

for iff in range(nfield):
    
    condition=fm[iff]
    
    for i in range(len(sr_range)-1):
        
        
        condition2=condition & ((rsqsim['SR']>=sr_range[i]) & (rsqsim['SR']<sr_range[i+1])) & ((rsqsim['CD']>=0) & (rsqsim['CD']<8))
        y=rsqsim.loc[condition2,field[iff]]
        x=rsqsim.loc[condition2,'M']

        biny = binyarray[iff]
        H, yedges, xedges = np.histogram2d(y, x, bins=[biny,binx],density=True)
        
        im1=axe[iff,i].pcolormesh(xedges, yedges, np.log10(H), cmap=fmcmap[iff])
#         ax1_divider = make_axes_locatable(axe[iff,i])
#         cax1 = ax1_divider.append_axes("right", size="4%", pad="-10%")
#         cb1 = fig.colorbar(im1, cax=cax1,orientation='vertical')
#         cb1.set_label('$log_{10}$(density)',fontsize='large')
        if logy[iff]:
            axe[iff,i].set_yscale('log')
        axe[iff,i].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,i].grid(which='minor', color='silver', linestyle='--')
        axe[iff,i].set_axisbelow(True)
        if i==0:
            axe[iff,i].set_ylabel(fnm[iff]+'\n Surface rupture ratio',fontsize='x-large')
        if iff==2:
            axe[iff,i].set_xlabel('Magnitude',fontsize='x-large')
        if iff==0:
            axe[iff,i].set_title(nm[i]+' ({0}<SR<{1})'.format(sr_range[i],sr_range[i+1]),fontsize='x-large',color=c[i])
        
        x = x.to_numpy()
        y = y.to_numpy()
        
        #mean
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='mean', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        else:
            axe[iff,i].axis('off')
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,3].plot(mean_centers,mean,'-',color=c[i],linewidth=4,zorder=10,label='Mean [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,3].set_yscale('log')
        axe[iff,3].set_ylim([biny.min(),biny.max()])
        
        
        #median
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='median', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,3].plot(mean_centers,mean,':',color=c[i],linewidth=4,zorder=10,label='Median [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,3].set_yscale('log')
        axe[iff,3].set_ylim([biny.min(),biny.max()])
        
        
        
        
        if iff==0:
            axe[iff,3].legend(loc='best',fontsize='small') 
        axe[iff,3].set_xlim([binx.min(),binx.max()])
        axe[iff,3].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,3].grid(which='minor', color='silver', linestyle='--')
        axe[iff,3].set_axisbelow(True)
In [10]:
fmcmap=[plt.get_cmap('RdPu',256),
        plt.get_cmap('GnBu',256),
        plt.get_cmap('Purples',256)]
fm = [SS,RV,NM]
fnm = ['Strike-slip','Reverse','Normal']
nm = ['Immature','Intermediate mature','Mature']
c=['darkblue','green','orange']
sr_range=[0.01,1,10,40]
nbin=np.arange(6.5,8.2,0.2)
plotratio=False

nx = 50
ny = 50

field=['SF','SF','SF']
binx = np.logspace(-2,2,nx)
    
binyarray=[
           np.linspace(0,1,ny),
    np.linspace(0,1,ny),
    np.linspace(0,1,ny),
          ]
logy=[False,False,False]

nfield=len(field)
    

fig = plt.figure( figsize=(20,15))
axe=fig.subplots(nfield, 4)



binx = np.linspace(6.5,8.3,50)

for iff in range(nfield):
    
    condition=fm[iff]
    
    for i in range(len(sr_range)-1):
        
        
        condition2=condition & ((rsqsim['SR']>=sr_range[i]) & (rsqsim['SR']<sr_range[i+1])) & ((rsqsim['CD']>=8) & (rsqsim['CD']<20))
        y=rsqsim.loc[condition2,field[iff]]
        x=rsqsim.loc[condition2,'M']

        biny = binyarray[iff]
        H, yedges, xedges = np.histogram2d(y, x, bins=[biny,binx],density=True)
        
        im1=axe[iff,i].pcolormesh(xedges, yedges, np.log10(H), cmap=fmcmap[iff])
#         ax1_divider = make_axes_locatable(axe[iff,i])
#         cax1 = ax1_divider.append_axes("right", size="4%", pad="-10%")
#         cb1 = fig.colorbar(im1, cax=cax1,orientation='vertical')
#         cb1.set_label('$log_{10}$(density)',fontsize='large')
        if logy[iff]:
            axe[iff,i].set_yscale('log')
        axe[iff,i].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,i].grid(which='minor', color='silver', linestyle='--')
        axe[iff,i].set_axisbelow(True)
        if i==0:
            axe[iff,i].set_ylabel(fnm[iff]+'\n Surface rupture ratio',fontsize='x-large')
        if iff==2:
            axe[iff,i].set_xlabel('Magnitude',fontsize='x-large')
        if iff==0:
            axe[iff,i].set_title(nm[i]+' ({0}<SR<{1})'.format(sr_range[i],sr_range[i+1]),fontsize='x-large',color=c[i])
        
        x = x.to_numpy()
        y = y.to_numpy()
        
        #mean
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='mean', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        else:
            axe[iff,i].axis('off')
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,3].plot(mean_centers,mean,'-',color=c[i],linewidth=4,zorder=10,label='Mean [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,3].set_yscale('log')
        axe[iff,3].set_ylim([biny.min(),biny.max()])
        
        
        #median
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='median', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,3].plot(mean_centers,mean,':',color=c[i],linewidth=4,zorder=10,label='Median [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,3].set_yscale('log')
        axe[iff,3].set_ylim([biny.min(),biny.max()])
        
        
        
        
        if iff==0:
            axe[iff,3].legend(loc='best',fontsize='small') 
        axe[iff,3].set_xlim([binx.min(),binx.max()])
        axe[iff,3].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,3].grid(which='minor', color='silver', linestyle='--')
        axe[iff,3].set_axisbelow(True)
In [11]:
fmcmap=[plt.get_cmap('RdPu',256),
        plt.get_cmap('GnBu',256),
        plt.get_cmap('Purples',256)]
fm = [SS,RV,NM]
fnm = ['Strike-slip','Reverse','Normal']
nm = ['Immature','Intermediate mature','Mature']
dnm = ['Centroid Depth','Centroid Depth']

c=['darkblue','green','orange']
sr_range=[0.01,1,10,40]
nbin=np.arange(6.5,8.2,0.2)
plotratio=False

nx = 50
ny = 50

field=['SF','SF','SF']
binx = np.logspace(-2,2,nx)
    
binyarray=[
            np.linspace(0,1,ny),
            np.linspace(0,1,ny),
            np.linspace(0,1,ny),
          ]
logy=[False,False,False]

nfield=len(field)
    

fig = plt.figure( figsize=(10,15))
axe=fig.subplots(nfield, 2)



binx = np.linspace(6.5,8.3,50)

for iff in range(nfield):
    
    condition=fm[iff]
    
    for i in range(len(sr_range)-1):
        biny = binyarray[iff]
        

        condition2=condition & ((rsqsim['SR']>=sr_range[i]) & (rsqsim['SR']<sr_range[i+1])) & ((rsqsim['CD']>=0) & (rsqsim['CD']<8))
        y=rsqsim.loc[condition2,field[iff]]
        x=rsqsim.loc[condition2,'M']

        
        x = x.to_numpy()
        y = y.to_numpy()
        
        #mean
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='mean', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,0].plot(mean_centers,mean,'-',color=c[i],linewidth=4,zorder=10,label='Mean [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,0].set_yscale('log')
        axe[iff,0].set_ylim([biny.min(),biny.max()])
        
        
        #median
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='median', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,0].plot(mean_centers,mean,':',color=c[i],linewidth=4,zorder=10,label='Median [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,0].set_yscale('log')
        axe[iff,0].set_ylim([biny.min(),biny.max()])
        
        
        
        
        
        if iff==0:
            axe[iff,0].legend(loc='best',fontsize='medium') 
        axe[iff,0].set_xlim([binx.min(),binx.max()])
        axe[iff,0].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,0].grid(which='minor', color='silver', linestyle='--')
        axe[iff,0].set_axisbelow(True)
        
        
        if i==0:
            axe[iff,i].set_ylabel(fnm[iff]+'\n Surface rupture ratio',fontsize='x-large')
        if iff==2:
            axe[iff,0].set_xlabel('Magnitude',fontsize='x-large')
            axe[iff,1].set_xlabel('Magnitude',fontsize='x-large')
        if iff==0:
            axe[iff,0].set_title('{0}<{2}<{1}'.format(d_range[0],d_range[0+1],dnm[0]),fontsize='x-large')
            axe[iff,1].set_title('{0}<{2}<{1}'.format(d_range[1],d_range[1+1],dnm[1]),fontsize='x-large')
            
            
            
            
            
            
            
            
        
        condition2=condition & ((rsqsim['SR']>=sr_range[i]) & (rsqsim['SR']<sr_range[i+1])) & ((rsqsim['CD']>=8) & (rsqsim['CD']<20))
        y=rsqsim.loc[condition2,field[iff]]
        x=rsqsim.loc[condition2,'M']

        
        x = x.to_numpy()
        y = y.to_numpy()
        
        #mean
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='mean', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,1].plot(mean_centers,mean,'-',color=c[i],linewidth=4,zorder=10,label='Mean [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,1].set_yscale('log')
        axe[iff,1].set_ylim([biny.min(),biny.max()])
        
        
        #median
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='median', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,1].plot(mean_centers,mean,':',color=c[i],linewidth=4,zorder=10,label='Median [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,1].set_yscale('log')
        axe[iff,1].set_ylim([biny.min(),biny.max()])
        
        
        
        
        axe[iff,1].set_xlim([binx.min(),binx.max()])
        axe[iff,1].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,1].grid(which='minor', color='silver', linestyle='--')
        axe[iff,1].set_axisbelow(True)

Check hypocentral and centroid depth vs mag

In [22]:
fmcmap=[plt.get_cmap('RdPu',256),
        plt.get_cmap('GnBu',256),
        plt.get_cmap('Purples',256)]
fm = [SS,RV,NM]
fnm = ['Strike-slip','Reverse','Normal']
nm = ['Immature','Intermediate mature','Mature']
c=['darkblue','green','orange']
sr_range=[0.01,1,10,40]
nbin=np.arange(6.5,8.2,0.2)
plotratio=False

nx = 50
ny = 50

field=['CD','CD','CD']
binx = np.logspace(-2,2,nx)
    
binyarray=[
           np.linspace(0,20,ny),
    np.linspace(0,20,ny),
    np.linspace(0,20,ny),
          ]
logy=[False,False,False]

nfield=len(field)
    

fig = plt.figure( figsize=(20,15))
axe=fig.subplots(nfield, 4)



binx = np.linspace(6.5,8.3,50)

for iff in range(nfield):
    
    condition=fm[iff]
    
    for i in range(len(sr_range)-1):
        
        
        condition2=condition & ((rsqsim['SR']>=sr_range[i]) & (rsqsim['SR']<sr_range[i+1]))
        y=rsqsim.loc[condition2,field[iff]]
        x=rsqsim.loc[condition2,'M']

        biny = binyarray[iff]
        H, yedges, xedges = np.histogram2d(y, x, bins=[biny,binx],density=True)
        
        im1=axe[iff,i].pcolormesh(xedges, yedges, np.log10(H), cmap=fmcmap[iff])
#         ax1_divider = make_axes_locatable(axe[iff,i])
#         cax1 = ax1_divider.append_axes("right", size="4%", pad="-10%")
#         cb1 = fig.colorbar(im1, cax=cax1,orientation='vertical')
#         cb1.set_label('$log_{10}$(density)',fontsize='large')
        if logy[iff]:
            axe[iff,i].set_yscale('log')
        axe[iff,i].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,i].grid(which='minor', color='silver', linestyle='--')
        axe[iff,i].set_axisbelow(True)
        if i==0:
            axe[iff,i].set_ylabel(fnm[iff]+'\n Surface rupture ratio',fontsize='x-large')
        if iff==2:
            axe[iff,i].set_xlabel('Magnitude',fontsize='x-large')
        if iff==0:
            axe[iff,i].set_title(nm[i]+' ({0}<SR<{1})'.format(sr_range[i],sr_range[i+1]),fontsize='x-large',color=c[i])
        
        x = x.to_numpy()
        y = y.to_numpy()
        
        #mean
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='mean', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        else:
            axe[iff,i].axis('off')
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,3].plot(mean_centers,mean,'-',color=c[i],linewidth=4,zorder=10,label='Mean [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,3].set_yscale('log')
        axe[iff,3].set_ylim([biny.min(),biny.max()])
        
        
        #median
        if logy[iff]:
            y = np.log10(y)
        if(len(y)>0):
            mean,bin_edges,_=stats.binned_statistic(x, y, statistic='median', bins=nbin)
            mean_centers = (bin_edges[1:] + bin_edges[0:-1])/2
        if logy[iff]:
            mean=10**mean
        if(len(y)>0):
            axe[iff,3].plot(mean_centers,mean,':',color=c[i],linewidth=4,zorder=10,label='Median [{0}]'.format(nm[i].lower()) )
        if logy[iff]:
            axe[iff,3].set_yscale('log')
        axe[iff,3].set_ylim([biny.min(),biny.max()])
        
        
        
        
        if iff==0:
            axe[iff,3].legend(loc='best',fontsize='small') 
        axe[iff,3].set_xlim([binx.min(),binx.max()])
        axe[iff,3].grid(b=True,which='major', color='silver', linestyle='-')
        axe[iff,3].grid(which='minor', color='silver', linestyle='--')
        axe[iff,3].set_axisbelow(True)
In [ ]: