imports

import tqdm
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt 
import plotly.express as px
import warnings
warnings.simplefilter("ignore", np.ComplexWarning)
from haversine import haversine
from IPython.display import HTML
import rpy2
import rpy2.robjects as ro 
from rpy2.robjects.vectors import FloatVector 
from rpy2.robjects.packages import importr

load data and clean it

- load

df= pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
df
Date Latitude Longitude Magnitude
0 01/02/1965 19.2460 145.6160 6.0
1 01/04/1965 1.8630 127.3520 5.8
2 01/05/1965 -20.5790 -173.9720 6.2
3 01/08/1965 -59.0760 -23.5570 5.8
4 01/09/1965 11.9380 126.4270 5.8
... ... ... ... ...
23407 12/28/2016 38.3917 -118.8941 5.6
23408 12/28/2016 38.3777 -118.8957 5.5
23409 12/28/2016 36.9179 140.4262 5.9
23410 12/29/2016 -9.0283 118.6639 6.3
23411 12/30/2016 37.3973 141.4103 5.5

23412 rows × 4 columns

df_korea= pd.read_csv('earthquake_korea2.csv').iloc[:,[1,2,5,6]].rename(columns={'규모':'Magnitude'})
df_global= pd.concat([pd.read_csv('00_05.csv'),pd.read_csv('05_10.csv'),pd.read_csv('10_15.csv'),pd.read_csv('15_20.csv')]).iloc[:,[0,1,2,4]].rename(columns={'latitude':'Latitude','longitude':'Longitude','mag':'Magnitude'}).reset_index().iloc[:,1:]

- cleaning

df.Date[df.Date == '1975-02-23T02:58:41.000Z']
3378    1975-02-23T02:58:41.000Z
Name: Date, dtype: object
df.iloc[3378,0] = '02/03/1975'
df.Date[df.Date == '1985-04-28T02:53:41.530Z']
7512    1985-04-28T02:53:41.530Z
Name: Date, dtype: object
df.iloc[7512,0] = '04/28/1985'
df.Date[df.Date == '2011-03-13T02:23:34.520Z']
20650    2011-03-13T02:23:34.520Z
Name: Date, dtype: object
df.iloc[20650,0] = '03/13/2011'
df= df.assign(Year=list(map(lambda x: x.split('/')[-1], df.Date))).iloc[:,1:]
df
Latitude Longitude Magnitude Year
0 19.2460 145.6160 6.0 1965
1 1.8630 127.3520 5.8 1965
2 -20.5790 -173.9720 6.2 1965
3 -59.0760 -23.5570 5.8 1965
4 11.9380 126.4270 5.8 1965
... ... ... ... ...
23407 38.3917 -118.8941 5.6 2016
23408 38.3777 -118.8957 5.5 2016
23409 36.9179 140.4262 5.9 2016
23410 -9.0283 118.6639 6.3 2016
23411 37.3973 141.4103 5.5 2016

23412 rows × 4 columns

df.Year = df.Year.astype(np.float64)
df_korea = df_korea.assign(Year=list(map(lambda x: x.split('/')[0], df_korea.발생시각))).iloc[:,1:]
df_korea = df_korea.assign(Latitude=list(map(lambda x: x.split(' ')[0], df_korea.위도))).iloc[:,[0,2,3,4]]
df_korea = df_korea.assign(Longitude=list(map(lambda x: x.split(' ')[0], df_korea.경도))).iloc[:,[0,2,3,4]]
df_global = df_global.assign(Year=list(map(lambda x: x.split('-')[0], df_global.time))).iloc[:,1:]
df_korea.Year = df_korea.Year.astype(np.float64)
df_korea.Latitude = df_korea.Latitude.astype(np.float64)
df_korea.Longitude = df_korea.Longitude.astype(np.float64)
df_global.Year = df_global.Year.astype(np.float64)

define class

class MooYaHo:
    def __init__(self,df):
        self.df = df 
        self.f = df.Magnitude.to_numpy()
        self.year = df.Year.to_numpy()
        self.lat = df.Latitude.to_numpy()
        self.long = df.Longitude.to_numpy()
        self.n = len(self.f)
        
        self.theta= None
    def get_distance(self):
        self.D = np.zeros([self.n,self.n])
        locations = np.stack([self.lat, self.long],axis=1)
        for i in tqdm.tqdm(range(self.n)):
            for j in range(i,self.n): 
                self.D[i,j]=haversine(locations[i],locations[j])
        self.D = self.D+self.D.T
    def get_weightmatrix(self,theta=1,beta=0.5,kappa=4000):
        self.theta = theta
        dist = np.where(self.D<kappa,self.D,0)
        self.W = np.exp(-(dist/self.theta)**2)

    def _eigen(self):
        d= self.W.sum(axis=1)
        D= np.diag(d)
        self.L = np.diag(1/np.sqrt(d)) @ (D-self.W) @ np.diag(1/np.sqrt(d))
        self.lamb, self.Psi = np.linalg.eigh(self.L)
        self.Lamb = np.diag(self.lamb)        
    def fit(self,m):
        self._eigen()
        self.fhat = self.Psi[:,0:m]@self.Psi[:,0:m].T@self.f
        self.df = self.df.assign(MagnitudeHat = self.fhat)
        self.df = self.df.assign(Residual = self.df.Magnitude- self.df.MagnitudeHat)
        plt.plot(self.f,'.')
        plt.plot(self.fhat,'x')
        
    def vis(self,MagThresh=7,ResThresh=1):
        fig = px.density_mapbox(self.df, 
                        lat='Latitude', 
                        lon='Longitude', 
                        z='Magnitude', 
                        radius=5,
                        center=dict(lat=37, lon=160), 
                        zoom=1.5,
                        height=900,
                        opacity = 0.4,
                        mapbox_style="stamen-terrain",
                        range_color=[-7,7])
        fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
        fig.add_scattermapbox(lat = self.df.query('Magnitude > @MagThresh')['Latitude'],
                      lon = self.df.query('Magnitude > @MagThresh')['Longitude'],
                      text = self.df.query('Magnitude > @MagThresh')['Magnitude'],
                      marker_size= 8,
                      marker_color= 'red',
                      opacity = 0.6
                      )
        fig.add_scattermapbox(lat = self.df.query('Residual**2 > @ResThresh')['Latitude'],
                      lon = self.df.query('Residual**2 > @ResThresh')['Longitude'],
                      text = self.df.query('Magnitude > @ResThresh')['Magnitude'],
                      marker_size= 8,
                      marker_color= 'blue',
                      opacity = 0.5
                      )
        return HTML(fig.to_html(include_mathjax=False, config=dict({'scrollZoom':False})))
    def visf(self):
        fig = px.density_mapbox(self.df, 
                        lat='Latitude', 
                        lon='Longitude', 
                        z='Magnitude', 
                        radius=5,
                        center=dict(lat=37, lon=160), 
                        zoom=1.5,
                        height=900,
                        opacity = 0.7,
                        mapbox_style="stamen-terrain",
                        range_color=[-7,7])
        fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
        return HTML(fig.to_html(include_mathjax=False, config=dict({'scrollZoom':False})))
    def visfhat(self):
        fig = px.density_mapbox(self.df, 
                        lat='Latitude', 
                        lon='Longitude', 
                        z='MagnitudeHat', 
                        radius=5,
                        center=dict(lat=37, lon=160), 
                        zoom=1.5,
                        height=900,
                        opacity = 0.7,
                        mapbox_style="stamen-terrain",
                        range_color=[-7,7])
        fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
        return HTML(fig.to_html(include_mathjax=False, config=dict({'scrollZoom':False})))
    def visres(self,MagThresh=7,ResThresh=1):
        fig = px.density_mapbox(self.df, 
                        lat='Latitude', 
                        lon='Longitude', 
                        z=[0] * len(self.df), 
                        radius=5,
                        center=dict(lat=37, lon=160), 
                        zoom=1.5,
                        height=900,
                        opacity = 0.7,
                        mapbox_style="stamen-terrain",
                        range_color=[-7,7])
        fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
        fig.add_scattermapbox(lat = self.df.query('Residual**2 > @ResThresh')['Latitude'],
                      lon = self.df.query('Residual**2 > @ResThresh')['Longitude'],
                      text = self.df.query('Magnitude > @ResThresh')['Magnitude'],
                      marker_size= 8,
                      marker_color= 'blue',
                      opacity = 0.7
                      )
        return HTML(fig.to_html(include_mathjax=False, config=dict({'scrollZoom':False})))
class MooYaHo2(MooYaHo): # ebayesthresh 기능추가
    def fit2(self,ref=0.5): # fit with ebayesthresh
        self._eigen()
        self.fbar = self.Psi.T @ self.f # fbar := graph fourier transform of f
        self.power = self.fbar**2 
        ebayesthresh = importr('EbayesThresh').ebayesthresh
        self.power_threshed=np.array(ebayesthresh(FloatVector(self.fbar**2)))
        self.fbar_threshed = np.where(self.power_threshed>0,self.fbar,0)
        self.fhat = self.Psi@self.fbar_threshed
        self.df = self.df.assign(MagnitudeHat = self.fhat)
        self.df = self.df.assign(Residual = self.df.Magnitude- self.df.MagnitudeHat)
        self.con = np.where(self.df.Residual>0.7,1,0)
        #plt.plot(self.f,'.')
        #plt.plot(self.fhat,'x')

#         fig, axs = plt.subplots(2,2,figsize=(16,10))

#         axs[0,0].plot(self.f,'b')
#         axs[0,0].set_title('Magnitude')
#         axs[0,0].set_ylim([4.5,9])

#         axs[0,1].plot(self.fhat,'k')
#         axs[0,1].set_title('MagnitudeHat')
#         axs[0,1].set_ylim([4.5,9])

#         axs[1,0].plot(self.con,'r*')
#         axs[1,0].set_title('Residual square')

#         axs[1,1].plot(self.f,'b')
#         axs[1,1].plot(self.fhat,'k')
#         axs[1,1].plot(self.con,'r*')
#         axs[1,1].set_title('Graph')
#         axs[1,1].set_ylim([4.5,9])

#         plt.tight_layout()
#         plt.show()
class MooYaHo3(MooYaHo2):
    def vis(self,MagThresh=7,ResThresh=1):
        fig = px.density_mapbox(self.df, 
                        lat='Latitude', 
                        lon='Longitude', 
                        z='Magnitude', 
                        radius=5,
                        center=dict(lat=37, lon=126), 
                        zoom=5.7,
                        height=900,
                        opacity = 0.3,
                        mapbox_style="stamen-terrain")
        fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
        fig.add_scattermapbox(lat = self.df.query('Magnitude > @MagThresh')['Latitude'],
                      lon = self.df.query('Magnitude > @MagThresh')['Longitude'],
                      text = self.df.query('Magnitude > @MagThresh')['Magnitude'],
                      marker_size= 8,
                      marker_color= 'red',
                      opacity = 0.5
                      )
        fig.add_scattermapbox(lat = self.df.query('Residual**2 > @ResThresh')['Latitude'],
                      lon = self.df.query('Residual**2 > @ResThresh')['Longitude'],
                      text = self.df.query('Magnitude > @ResThresh')['Magnitude'],
                      marker_size= 8,
                      marker_color= 'blue',
                      opacity = 0.5
                      )
        return HTML(fig.to_html(include_mathjax=False, config=dict({'scrollZoom':False})))
       ebayesthresh = importr('EbayesThresh').ebayesthresh

analysis_df_global(2010~2015)

- make instance for analysis

moo_global=MooYaHo2(df_global.query("2010 <= Year < 2015"))

- get distance

moo_global.get_distance()
100%|██████████| 12498/12498 [03:37<00:00, 57.37it/s]  
moo_global.D[moo_global.D>0].mean()
8810.865423093777
plt.hist(moo_global.D[moo_global.D>0])
(array([14176290., 16005894., 21186674., 22331128., 19394182., 17548252.,
        16668048., 13316436., 12973260.,  2582550.]),
 array([8.97930163e-02, 2.00141141e+03, 4.00273303e+03, 6.00405465e+03,
        8.00537626e+03, 1.00066979e+04, 1.20080195e+04, 1.40093411e+04,
        1.60106627e+04, 1.80119844e+04, 2.00133060e+04]),
 <BarContainer object of 10 artists>)

- weight matrix

moo_global.get_weightmatrix(theta=(8810.865423093777),kappa=2500) 

- fit

moo_global.fit2()
moo_global.df.sort_values("Residual",ascending=False).iloc[:40,:]
Latitude Longitude Magnitude Year MagnitudeHat Residual
11094 -36.1220 -72.8980 8.8 2010.0 7.754649 1.045351
10727 -36.2170 -73.2570 6.7 2010.0 5.750555 0.949445
27513 0.8020 92.4630 8.2 2012.0 7.253721 0.946279
26109 -10.9280 166.0180 7.1 2013.0 6.194467 0.905533
30291 38.0580 144.5900 7.7 2011.0 6.804163 0.895837
31673 -17.5410 168.0690 7.3 2010.0 6.431399 0.868601
27527 2.3270 93.0630 8.6 2012.0 7.736731 0.863269
30311 38.2970 142.3730 9.1 2011.0 8.255988 0.844012
24388 -19.6097 -70.7691 8.2 2014.0 7.394885 0.805115
28408 -28.9930 -176.2380 7.4 2011.0 6.596810 0.803190
23863 -55.4703 -28.3669 6.9 2014.0 6.097310 0.802690
32803 -36.1220 -72.8980 8.8 2010.0 7.999521 0.800479
27672 -22.1410 170.3400 6.6 2012.0 5.830724 0.769276
24958 -60.2738 -46.4011 7.7 2013.0 6.938609 0.761391
31196 -56.5860 -142.2920 6.4 2010.0 5.641422 0.758578
26943 2.1900 126.8370 6.6 2012.0 5.849246 0.750754
9118 -19.7020 167.9470 7.3 2010.0 6.550810 0.749190
32001 7.8810 91.9360 7.5 2010.0 6.785405 0.714595
31229 -3.4870 100.0820 7.8 2010.0 7.086996 0.713004
29640 38.2760 141.5880 7.1 2011.0 6.387718 0.712282
11356 18.4430 -72.5710 7.0 2010.0 6.288026 0.711974
30296 36.2810 141.1110 7.9 2011.0 7.197845 0.702155
28574 -21.6110 -179.5280 7.3 2011.0 6.601124 0.698876
23633 -32.6953 -71.4416 6.4 2014.0 5.705553 0.694447
25517 10.7010 -42.5940 6.6 2013.0 5.908930 0.691070
28001 -10.6170 165.1600 6.4 2012.0 5.722428 0.677572
25773 30.3080 102.8880 6.6 2013.0 5.922831 0.677169
29004 38.0340 143.2640 7.0 2011.0 6.332486 0.667514
23815 14.7240 -92.4614 6.9 2014.0 6.237697 0.662303
24360 -20.3113 -70.5756 6.5 2014.0 5.839327 0.660673
25633 -23.0090 -177.2320 7.4 2013.0 6.743190 0.656810
30256 36.8230 141.8240 6.1 2011.0 5.446211 0.653789
9520 -3.4870 100.0820 7.8 2010.0 7.146346 0.653654
29133 52.0500 -171.8360 7.3 2011.0 6.646652 0.653348
32492 -34.2900 -71.8910 6.9 2010.0 6.247025 0.652975
24066 4.2485 92.7574 6.0 2014.0 5.353450 0.646550
24359 -20.5709 -70.4931 7.7 2014.0 7.056532 0.643468
26083 -10.9940 165.7410 6.6 2013.0 5.958927 0.641073
32768 -37.7730 -75.0480 7.4 2010.0 6.762054 0.637946
10845 -36.6650 -73.3740 6.6 2010.0 5.963286 0.636714

(2010~2014 시도)

  • 21번째 Ouest Department, Haiti 아이티 지진 2010년 진도 7.0
  • 24번쨰 Puchuncavi, Valparaíso, Chile 칠레 지진 2014년 진도 6.4
  • 28번째 Baoxing County, Yaan, Sichuan, China 중국 쓰촨성 지진 2013년 진도 6.6

(2010~2015 시도_결과 좋지 않음?!)

  • 23번째 2010년 West New Britain Province, Papua New Guinea 진도 7.3
  • 24번째 2011년 Kuzawa Terayama, Tanagura, Higashishirakawa District, Fukushima 963-5671, Japan 진도 6.6
  • 29번째 2015년 Kishim, Afghanistan 진도 7.5

- vis

 
 
 
 

analysis_df_global(2015~2020)

- make instance for analysis

moo_global=MooYaHo2(df_global.query("2015 <= Year <= 2020"))

- get distance

moo_global.get_distance()
100%|██████████| 11239/11239 [02:40<00:00, 70.23it/s]  
moo_global.D[moo_global.D>0].mean()
8814.318793468068
plt.hist(moo_global.D[moo_global.D>0])
(array([10894274., 13618924., 16426520., 17583818., 16025000., 15684642.,
        13794372., 10946494.,  9072574.,  2254138.]),
 array([2.54728455e-02, 2.00123511e+03, 4.00244475e+03, 6.00365439e+03,
        8.00486402e+03, 1.00060737e+04, 1.20072833e+04, 1.40084929e+04,
        1.60097026e+04, 1.80109122e+04, 2.00121218e+04]),
 <BarContainer object of 10 artists>)

- weight matrix

moo_global.get_weightmatrix(theta=(8814.318793468068),kappa=2500) 

- fit

moo_global.fit2()
moo_global.df.sort_values("Residual",ascending=False).iloc[:30,:]
Latitude Longitude Magnitude Year MagnitudeHat Residual
41735 -31.5729 -71.6744 8.3 2015.0 7.247889 1.052111
36993 -18.1125 -178.1530 8.2 2018.0 7.151339 1.048661
21952 -31.5729 -71.6744 8.3 2015.0 7.377015 0.922985
36363 -21.9496 169.4266 7.5 2018.0 6.641801 0.858199
39771 -10.6812 161.3273 7.8 2016.0 6.952781 0.847219
41015 -4.9521 94.3299 7.8 2016.0 6.982741 0.817259
33896 -33.2927 -177.8571 7.4 2020.0 6.584337 0.815663
39932 -42.7373 173.0540 7.8 2016.0 6.994644 0.805356
21719 -8.3381 124.8754 6.5 2015.0 5.698561 0.801439
33404 54.6020 -159.6258 7.6 2020.0 6.825914 0.774086
33593 -27.9686 -71.3062 6.8 2020.0 6.068130 0.731870
21559 38.2107 72.7797 7.2 2015.0 6.476211 0.723789
36263 55.0999 164.6993 7.3 2018.0 6.591954 0.708046
42106 -36.3601 -73.8120 6.4 2015.0 5.712923 0.687077
37769 -6.0699 142.7536 7.5 2018.0 6.826692 0.673308
36848 -18.4743 179.3502 7.9 2018.0 7.233195 0.666805
39584 -43.4064 -73.9413 7.6 2016.0 6.936485 0.663515
22246 -9.3070 158.4030 6.7 2015.0 6.036540 0.663460
36301 -58.5446 -26.3856 7.1 2018.0 6.448234 0.651766
42271 27.8087 86.0655 7.3 2015.0 6.651371 0.648629
40675 -56.2409 -26.9353 7.2 2016.0 6.551931 0.648069
42622 -10.7598 164.1216 6.1 2015.0 5.469452 0.630548
35487 -30.6441 -178.0995 7.3 2019.0 6.673190 0.626810
22521 -7.2175 154.5567 7.1 2015.0 6.493164 0.606836
42475 -4.7294 152.5623 7.5 2015.0 6.897835 0.602165
36101 -30.0404 -71.3815 6.7 2019.0 6.098721 0.601279
37927 56.0039 -149.1658 7.9 2018.0 7.307120 0.592880
38520 15.0222 -93.8993 8.2 2017.0 7.608529 0.591471
21912 -31.5173 -71.8040 6.7 2015.0 6.110265 0.589735
41887 -9.3438 158.0525 6.6 2015.0 6.012902 0.587098

바다 아닌 거

  • 8번째 2016년 Rotherham, New Zealand 뉴질랜드 카이코우라 지진 진도 7.8
  • 9번째 2015년 Langkuru Utara, Pureman, Alor Regency, East Nusa Tenggara, Indonesia 수마트라 진도 6.5
  • 15번째 2018년 Hela Province, Papua New Guinea 파푸아뉴기니 진도 7.5
  • 20번째 2015년 Kalinchok, Nepal 네팔 진도 7.3
  • 26번째 2019년 Coquimbo, Chile 칠레 코킴보주 진도 6.7

- vis

 

pd.read_html('https://en.wikipedia.org/wiki/Lists_of_21st-century_earthquakes',encoding='utf-8')[0].query('Magnitude<=7')# List of deadliest earthquakes
Rank Fatalities Magnitude Location Event Date
1 2 160000 7.0 Haiti 2010 Haiti earthquake January 12, 2010
4 5 26271 6.6 Iran 2003 Bam earthquake December 26, 2003
8 9 5782 6.4 Indonesia 2006 Yogyakarta earthquake May 26, 2006
10 11 2968 6.9 China 2010 Yushu earthquake April 13, 2010
11 12 2266 6.8 Algeria 2003 Boumerdès earthquake May 21, 2003
14 15 1163 6.0 Afghanistan June 2022 Afghanistan earthquake June 21, 2022
pd.read_html('https://en.wikipedia.org/wiki/Lists_of_21st-century_earthquakes',encoding='utf-8')[3] # Deadliest earthquakes by year
Year Fatalities Magnitude Event Location Date Death toll
0 2001 20085 7.7 2001 Gujarat earthquake India January 26 21357
1 2002 1000 6.1 2002 Hindu Kush earthquakes Afghanistan March 25 1685
2 2003 26271 6.6 2003 Bam earthquake Iran December 26 33819
3 2004 227898 9.1 2004 Indian Ocean earthquake and tsunami Indonesia, Indian Ocean December 26 227898
4 2005 87351 7.6 2005 Kashmir earthquake Pakistan October 8 87992
5 2006 5782 6.4 2006 Yogyakarta earthquake Indonesia May 26 6605
6 2007 519 8.0 2007 Peru earthquake Peru August 15 708
7 2008 87587 7.9 2008 Sichuan earthquake China May 12 88708
8 2009 1115 7.6 2009 Sumatra earthquakes Indonesia September 30 1790
9 2010 160000 7.0 2010 Haiti earthquake Haiti January 12 164627
10 2011 20896 9.0 2011 Tōhoku earthquake and tsunami Japan March 11 21492
11 2012 306 6.4 2012 East Azerbaijan earthquakes Iran August 11 689
12 2013 825 7.7 2013 Balochistan earthquakes Pakistan September 24 1572
13 2014 729 6.1 2014 Ludian earthquake China August 3 756
14 2015 8964 7.8 2015 Nepal earthquake Nepal April 25 9624
15 2016 673 7.8 2016 Ecuador earthquake Ecuador April 16 1339
16 2017 630 7.3 2017 Iran–Iraq earthquake Iran November 12 1232
17 2018 4340 7.5 2018 Sulawesi earthquake and tsunami Indonesia September 28 5239
18 2019 51 6.4 2019 Albania earthquake Albania November 26 288
19 2020 119 7.0 2020 Aegean Sea earthquake Turkey/ Greece October 30 207
20 2021 2248 7.2 2021 Haiti earthquake Haiti August 14 2476
21 2022 1163 6.0 June 2022 Afghanistan earthquake Afghanistan June 21 1405

class eachlocation(MooYaHo3):
    def haiti(self,MagThresh=7,ResThresh=1):
        fig = px.density_mapbox(self.df, 
                        lat='Latitude', 
                        lon='Longitude', 
                        z='Magnitude', 
                        radius=5,
                        center=dict(lat=18.4430, lon=-72.5710), 
                        zoom=5,
                        height=900,
                        opacity = 0.6,
                        mapbox_style="stamen-terrain",
                        range_color=[-7,7])
        fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
        fig.add_scattermapbox(lat = self.df.query('Magnitude > @MagThresh')['Latitude'],
                      lon = self.df.query('Magnitude > @MagThresh')['Longitude'],
                      text = self.df.query('Magnitude > @MagThresh')['Magnitude'],
                      marker_size= 5,
                      marker_color= 'red',
                      opacity = 0.1
                      )
        fig.add_scattermapbox(lat = self.df.query('Residual**2 > @ResThresh')['Latitude'],
                      lon = self.df.query('Residual**2 > @ResThresh')['Longitude'],
                      text = self.df.query('Magnitude > @ResThresh')['Magnitude'],
                      marker_size= 20,
                      marker_color= 'blue',
                      opacity = 1
                      )
        fig.show()
    def lquique(self,MagThresh=7,ResThresh=1):
        fig = px.density_mapbox(self.df, 
                        lat='Latitude', 
                        lon='Longitude', 
                        z='Magnitude', 
                        radius=5,
                        center=dict(lat=-32.6953, lon=-71.4416), 
                        zoom=5,
                        height=900,
                        opacity = 0.6,
                        mapbox_style="stamen-terrain",
                        range_color=[-7,7])
        fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
        fig.add_scattermapbox(lat = self.df.query('Magnitude > @MagThresh')['Latitude'],
                      lon = self.df.query('Magnitude > @MagThresh')['Longitude'],
                      text = self.df.query('Magnitude > @MagThresh')['Magnitude'],
                      marker_size= 5,
                      marker_color= 'red',
                      opacity = 0.1
                      )
        fig.add_scattermapbox(lat = self.df.query('Residual**2 > @ResThresh')['Latitude'],
                      lon = self.df.query('Residual**2 > @ResThresh')['Longitude'],
                      text = self.df.query('Magnitude > @ResThresh')['Magnitude'],
                      marker_size= 20,
                      marker_color= 'blue',
                      opacity = 1
                      )
        fig.show()        
    def sichuan(self,MagThresh=7,ResThresh=1):
        fig = px.density_mapbox(self.df, 
                        lat='Latitude', 
                        lon='Longitude', 
                        z='Magnitude', 
                        radius=3,
                        center=dict(lat=30.3080, lon=102.8880), 
                        zoom=5,
                        height=900,
                        opacity = 0.6,
                        mapbox_style="stamen-terrain",
                        range_color=[-7,7])
        fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
        fig.add_scattermapbox(lat = self.df.query('Magnitude > @MagThresh')['Latitude'],
                      lon = self.df.query('Magnitude > @MagThresh')['Longitude'],
                      text = self.df.query('Magnitude > @MagThresh')['Magnitude'],
                      marker_size= 5,
                      marker_color= 'red',
                      opacity = 0.1
                      )
        fig.add_scattermapbox(lat = self.df.query('Residual**2 > @ResThresh')['Latitude'],
                      lon = self.df.query('Residual**2 > @ResThresh')['Longitude'],
                      text = self.df.query('Magnitude > @ResThresh')['Magnitude'],
                      marker_size= 20,
                      marker_color= 'blue',
                      opacity = 1
                      )
        fig.show()
each_location=eachlocation(df_global.query("2010 <= Year < 2015"))

- get distance

each_location.get_distance()
100%|██████████| 12498/12498 [03:17<00:00, 63.14it/s] 
each_location.D[each_location.D>0].mean()
8810.865423093777
plt.hist(each_location.D[each_location.D>0])
(array([14176290., 16005894., 21186674., 22331128., 19394182., 17548252.,
        16668048., 13316436., 12973260.,  2582550.]),
 array([8.97930163e-02, 2.00141141e+03, 4.00273303e+03, 6.00405465e+03,
        8.00537626e+03, 1.00066979e+04, 1.20080195e+04, 1.40093411e+04,
        1.60106627e+04, 1.80119844e+04, 2.00133060e+04]),
 <BarContainer object of 10 artists>)

- weight matrix

each_location.get_weightmatrix(theta=(8810.865423093777),kappa=2500) 

- fit

each_location.fit2()
each_location.haiti(MagThresh=6.9,ResThresh=0.5)
each_location.lquique(MagThresh=6.4,ResThresh=0.4)
each_location.sichuan(MagThresh=6.5,ResThresh=0.4)