--- layout: post title: "Welcome to Jekyll!" date: 2016-02-12 17:50:00 categories: main ---
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from astropy.time import Time
def convert_to_ap_Time(df, key):
print(key)
df[key] = pd.to_datetime(df[key])
df[key] = Time([t1.astype(str) for t1 in df[key].values], format="isot")
return df
def convert_times_to_datetime(df):
columns = ["Gun Time", "Chip Time", "TOD", "Beat the Bridge", "Beat the Bridge.1"]
for key in columns:
df = convert_to_ap_Time(df, key)
df = convert_Time_to_seconds(df, key)
return df
def convert_Time_to_seconds(df, key):
t0 = Time("2017-05-04T00:00:00.000", format="isot")
df["sub" + key] = df[key] - t0
df["sub" + key] = [t.sec for t in df["sub" + key].values]
return df
def find_astronomers(df):
astronomers = ("Robert FIRTH", "Stephen BROWETT", "Mathew SMITH", "Sadie JONES")
astro_df = df[df["Name"].isin((astronomers))]
return astro_df
def plot_hist_with_astronomers(df, astro_df, key):
rob_time = astro_df[key][158]/60.
mat_time = astro_df[key][737]/60.
steve_time = astro_df[key][1302]/60.
sadie_time = astro_df[key][576]/60.
mean_time = df[key].mean()/60
median_time = df[key].median()/60
plt.hist(df[key]/60., bins = 100)
plt.plot([rob_time, rob_time], [0, 70], lw = 2, label = "Rob")
plt.plot([mat_time, mat_time], [0, 70], lw = 2, label = "Mat")
plt.plot([steve_time, steve_time], [0, 70], lw = 2, label = "Steve")
plt.plot([sadie_time, sadie_time], [0, 70], lw = 2, label = "Sadie")
plt.plot([mean_time, mean_time], [0, 70], lw = 2, color = "Black", ls = ":", label = "Mean")
plt.plot([median_time, median_time], [0, 70], lw = 2, color = "Black", ls = "--", label = "Median")
plt.xlabel(key.replace("sub", "") + " Minutes")
plt.legend()
results_path = "/Users/berto/Code/zoidberg/ABPSoton10k/data/Results10k.csv"
df = pd.read_csv(results_path)
# df = df.drop(df.index[len(df)-10:])
df = df.drop(df.loc[df["Gun Time"] == "DNF"].index)
df = df.drop(df.loc[df["Gun Time"] == "QRY"].index)
df = df.drop(df.loc[df["Beat the Bridge"] == "99:99:99"].index)
df.columns
df = convert_times_to_datetime(df)
astro_df = find_astronomers(df)
astro_df
# key = "subGun Time"
key = "subChip Time"
rob_time = astro_df[key][158]/60.
mat_time = astro_df[key][737]/60.
steve_time = astro_df[key][1302]/60.
sadie_time = astro_df[key][576]/60.
mean_time = df[key].mean()/60
median_time = df[key].median()/60
plt.hist(df[key]/60., bins = 100)
plt.plot([rob_time, rob_time], [0, 70], lw = 2, label = "Rob")
plt.plot([mat_time, mat_time], [0, 70], lw = 2, label = "Mat")
plt.plot([steve_time, steve_time], [0, 70], lw = 2, label = "Steve")
plt.plot([sadie_time, sadie_time], [0, 70], lw = 2, label = "Sadie")
plt.plot([mean_time, mean_time], [0, 70], lw = 2, color = "Black", ls = ":", label = "Mean")
plt.plot([median_time, median_time], [0, 70], lw = 2, color = "Black", ls = "--", label = "Median")
plt.xlabel(key.replace("sub", "") + " Minutes")
plt.legend()
plot_hist_with_astronomers(df=df, astro_df=astro_df, key="subBeat the Bridge")
keyx = "subChip Time"
keyy = "subBeat the Bridge"
corr_co = np.corrcoef(df[keyx]/60., df[keyy]/60.)
plt.scatter(df[keyx]/60., df[keyy]/60.)
plt.xlabel(keyx.replace("sub", "") + " Minutes")
plt.ylabel(keyy.replace("sub", "") + " Minutes")
print(corr_co[1,0])
keyx = "subChip Time"
keyy = "Bib No"
corr_co = np.corrcoef(df[keyx]/60., df[keyy])
plt.scatter(df[keyx]/60., df[keyy])
plt.xlabel(keyx.replace("sub", "") + " Minutes")
plt.ylabel(keyy.replace("sub", ""))
print(corr_co[1,0])
# plt.scatter(df["Pos"], df["subChip Time"])
# plt.scatter(df["subChip Time"], df["subBeat the Bridge"])
plt.scatter(df["Pos"], df["G/Pos"])
# print(df.groupby("Gender"))
plt.scatter((df["subGun Time"] - df["subChip Time"])/60., df["subGun Time"]/60.)
plt.scatter(df["subChip Time"]/60., df["Bib No"])
df.
df.columns
fig = plt.figure(figsize=[8, 4])
fig.subplots_adjust(left = 0.09, bottom = 0.13, top = 0.99,
right = 0.99, hspace=0, wspace = 0)
ax1 = fig.add_subplot(111)
ax1.scatter(df[df["Club"] == "NaN"]["subChip Time"]/60., df[df["Club"] == "NaN"]["subBeat the Bridge"]/60., color = "Orange")
# ax1.scatter(df[df["Club"] != "NaN"]["subChip Time"]/60., df[df["Club"] != "NaN"]["subBeat the Bridge"]/60., color = "Blue")
clubs = df["Club"].unique()
clubs = [clubs[i] for i in np.arange(len(clubs)) if i != 1]
keyx = "subChip Time"
keyy = "subBeat the Bridge"
corr_co = np.corrcoef(df[keyx][df["Club"].isin(clubs)]/60., df[keyy][df["Club"].isin(clubs)]/60.)
plt.scatter(df[keyx][df["Club"].isin(clubs)]/60., df[keyy][df["Club"].isin(clubs)]/60.)
# plt.scatter(df[keyx][df["Club"].isin(np.invert(clubs))]/60., df[keyy][df["Club"].isin(np.invert(clubs))]/60.)
plt.xlabel(keyx.replace("sub", "") + " Minutes")
plt.ylabel(keyy.replace("sub", "") + " Minutes")
df[["Club", "Name", "subChip Time"]][df["Club"].isin(clubs)]
# convert_to_ap_Time(df)
t0 = Time("2017-04-26T00:00:00.000", format="isot")
t1 = df["Gun Time"].values[0]
t1
t1 - t0
col = df["Gun Time"] - t0
x = col[0]
x.
col.sec