In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
In [2]:
import pandas as pd
In [3]:
from __future__ import division
In [4]:
res = pd.DataFrame.from_csv('results.csv', index_col='Time')
In [5]:
res['diff'] = res.timesec.diff()
In [6]:
res.head(20)
Out[6]:
In [7]:
grouped = res.groupby('success')
In [8]:
xx = grouped.get_group(0)
fails = xx.copy(deep=True)
fails['timeDelta'] = fails.timesec.diff()
yy = grouped.get_group(1)
success = yy.copy(deep=True)
success['timeDelta'] = success.timesec.diff()
In [9]:
fails.head()
Out[9]:
In [10]:
success.head()
Out[10]:
In [11]:
plt.plot(fails.timesec - fails.timesec.iloc[0], fails.timeDelta.values, 'o')
plt.axhline(fails.timeDelta.mean())
Out[11]:
In [12]:
res.index
Out[12]:
In [13]:
fails.plot(kind='scatter',x='record', y='timeDelta')
fails.plot(y='timeDelta')
Out[13]:
In [14]:
failure_rate = len(fails) / len(res)
print failure_rate
In [15]:
failfig, ax = plt.subplots()
fails.hist('timeDelta', bins=100, ax=ax)
ax.set_xlabel('Time Diffs (sec)')
ax.set_ylabel('Freq')
failfig.savefig('failTimeDiffs')
In [16]:
success.hist('timeDelta', bins=100)
Out[16]:
In [25]:
from scipy.signal import lombscargle
import numpy as np
In [50]:
periods = np.arange(0.5, 400., 0.5)
angfreq = 2 * np.pi / periods
In [51]:
power = lombscargle(res.timesec.values, res.success.values - res.success.mean(), angfreq)
In [32]:
# power *= 2.0 / (len(res) * res.success.std() ** 2)
In [52]:
# plot the results
xt = np.arange(0., 400., 20.)
fig, ax = plt.subplots()
ax.plot(periods, power)
ax.set(ylim=(0, 0.8), xlabel='period (sec)',
ylabel='Lomb-Scargle Power');
ax.set_xticks(xt)
ax.grid(True)
# xtl = ax.get_xticklabels(visi)
# ax.set_xticklabels(xtl, rotation=30)
In [47]:
power
Out[47]:
In [17]:
from gatspy.periodic import LombScargle
In [40]:
model = LombScargle().fit(res.timesec.values, res.success.values, np.zeros(len(res.success.values)))
In [42]:
periods, power = model.periodogram_auto(nyquist_factor=10)