Raw data:
http://earthquake.usgs.gov/data/centennial/centennial_Y2K.CAT
README: http://earthquake.usgs.gov/data/centennial/centennial_README.rtf
Stable Continental Regions:
In [1]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
In [2]:
import pandas
from karmapi import base, maps, show
from karmapi import usgs
from matplotlib import pyplot
In [3]:
cd ~/karmapi
In [4]:
# if you don't already have the data this downloads and saves it -- uncomment to get the data
# df = usgs.get()
# base.save('data/quake/centennial', df)
In [5]:
pandas.set_option('display.notebook', False)
pandas.set_eng_float_format(1, True)
In [6]:
df = base.load('data/quake/centennial')
In [7]:
df.index = pandas.to_datetime(df.apply(usgs.timestamp, axis=1))
In [64]:
#pandas.set_eng_float_format(3, False)
min_severity = 7.2
df['flag'] = 1
# sum this month with six months from now
df['six'] = (df.flag[:-6] + df.flag[6:]).fillna(df.flag)
df = df[df.severity >= min_severity]
df = df.resample('M', how='sum').fillna(0)
In [65]:
df.head()
Out[65]:
In [66]:
df['dim'] = df.index.days_in_month
df['dimsix'] = (df.dim[:-6] + df.dim[6:]).fillna(df.dim)
In [67]:
df.head()
Out[67]:
In [68]:
df.tail()
Out[68]:
In [69]:
df.value.plot()
Out[69]:
In [71]:
df.describe()
Out[71]:
In [78]:
value = df.value
In [79]:
len(df), len(value)
Out[79]:
In [80]:
so = base.sono(value.values, 12 * 48)
In [81]:
offset = 138
end = offset + 12
show.sono2(so, offset=offset, end=end, cmap=None)
In [82]:
def isprime(n):
for k in range(2, 1 + int(n ** 0.5)):
#print(k, n/k)
if (n // k) == (n/k):
#print(n, k)
return False
return True
In [90]:
# look at first k fourier compoments
k = 96
p = set([1+x for x in range(k) if isprime(1+x)])
len(p)
Out[90]:
In [91]:
k = 96
vfft = base.fft.fft(value.values)
points = p
points = set(range(1, k))
for x in range(1, int(len(vfft)/2)):
if x not in points:
vfft[x] = 0
vfft[-x] = 0
iso = base.fft.ifft(vfft)
xdf = value.copy().to_frame()
xdf['kvalue'] = iso.real
xdf['delta'] = xdf.value - (xdf.kvalue +.05)
show.wide()
pyplot.grid(True)
pyplot.plot(xdf['1935':'1965'])
Out[91]:
In [92]:
a = xdf.value.std()
b = xdf.delta.std()
(a-b)/a
Out[92]:
In [88]:
xdf.describe()
Out[88]:
In [26]:
sfft = base.fft.fft(value.values)
In [27]:
pyplot.plot(sfft.real[1:600])
Out[27]:
In [28]:
k = 119
a = [x[k] for x in so]
afft = base.fft.fft(a)
pyplot.plot(afft.imag[:3*15])
pyplot.grid(True)
In [ ]: