Created
April 1, 2020 22:13
-
-
Save 13Ducks/460a0f0ac4a31d19320b596441110c62 to your computer and use it in GitHub Desktop.
analysis project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
from mpl_toolkits.mplot3d import Axes3D | |
import matplotlib.pyplot as plt | |
from matplotlib import cm | |
from colour import Color | |
color_table = [Color("red"), Color("orange"), Color( | |
"yellow"), Color("green"), Color("blue")] | |
df = pd.read_csv('analysis/covid19_data.csv') | |
df = df.loc[(df["Country/Region"] == "US")] | |
df = df.loc[df["Province/State"].str.contains(r', CA')] | |
last_date = '3/31/20' | |
last_index = np.where(df.columns.values == last_date)[0][0] | |
eqs = [] | |
for index, row in df.iterrows(): | |
min_d, min_i = 100000, None | |
for index2, row2 in df.iterrows(): | |
if index != index2: | |
d = np.sqrt((row2["Lat"]-row["Lat"])**2 + | |
(row2["Long"]-row["Long"])**2) | |
if d < min_d and row2[last_date] < row[last_date]: | |
min_d, min_i = d, row2 | |
if min_i is not None: | |
print("main point", row["Lat"], row["Long"], | |
row[last_date], row["Response Severity"]) | |
print("closest point", min_d, | |
min_i["Lat"], min_i["Long"], min_i[last_date], min_i["Response Severity"]) | |
d_calc = (-(row["Lat"] - min_i["Lat"])**2 - | |
(row["Long"] - min_i["Long"])**2)/(-row[last_date]) | |
eqs.append((row["Lat"], row["Long"], d_calc, row[last_date], | |
color_table[int(row["Response Severity"]-1)], color_table[int(min_i["Response Severity"]-1)])) | |
print(eqs[-1]) | |
def elliptic_parab(eq, x, y): | |
return [(-((x - eq[0])**2 / eq[2]) - ((y - eq[1])**2 / eq[2]))+eq[3], eq[4]] | |
x = np.arange(df["Lat"].min().round(1)-1, df["Lat"].max().round(1)+1, 0.01) | |
y = np.arange(df["Long"].min().round(1)-1, df["Long"].max().round(1)+1, 0.01) | |
x, y = np.meshgrid(x, y) | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
colors = np.empty(x.shape, dtype='|U18') | |
colors.fill(color_table[4].hex_l) | |
z_final = np.zeros(x.shape) | |
for eq in eqs: | |
z, c = elliptic_parab(eq, x, y) | |
# z_final = np.maximum(z_final, z) | |
for yi in range(x.shape[1]): | |
for xi in range(x.shape[0]): | |
if z_final[xi][yi] < z[xi][yi]: | |
z_final[xi][yi] = z[xi][yi] | |
colors[xi][yi] = c.hex_l | |
ax.plot(df["Lat"].round(1), df["Long"].round(1), df[last_date], | |
marker='o', linestyle='', alpha=1) | |
surf = ax.plot_surface(x, y, z_final, linewidth=0, facecolors=colors) | |
ax.set_xlabel('Latitude') | |
ax.set_ylabel('Longitude') | |
ax.set_zlabel('# of Cases') | |
plt.show() |
SheepTester
commented
Apr 15, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment