In [1]:
import os
import sys
import random
import time
from random import seed, randint
import argparse
import platform
from datetime import datetime
import imp
import numpy as np
import fileinput
from itertools import product
import pandas as pd
from scipy.interpolate import griddata
from scipy.interpolate import interp2d
import seaborn as sns
from os import listdir
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.interpolate import griddata
import matplotlib as mpl
sys.path.insert(0,'..')
from notebookFunctions import *
# from .. import notebookFunctions
%matplotlib inline
plt.rcParams['figure.figsize'] = (10,6.180) #golden ratio
# %matplotlib notebook
%load_ext autoreload
%autoreload 2
In [204]:
data = pd.read_feather("/Users/weilu/Research/server/apr_2018/sixth/rg_0.15_lipid_1.0_mem_1_go_0.8/rerun_3_18_Apr_220421.feather")
dic = {"T0":280, "T1":290, "T2":300, "T3":310, "T4":320, "T5":335, "T6":350, "T7":365, "T8":380, "T9":410, "T10":440, "T11":470}
a = data
a["Temp"] = a["Temp"].apply(lambda x: dic[x])
rerun3 = data
t = a.query("Temp < 400").groupby(["BiasTo","Temp"])[["DisReal","Run"]].mean().reset_index()
t["Diff"] = t["DisReal"]-t["BiasTo"].apply(pd.to_numeric)
t["BiasTo"] = t["BiasTo"].apply(pd.to_numeric)
fg = sns.FacetGrid(data=t, hue='Temp', size=8, aspect=1.61)
fg.map(plt.scatter, 'BiasTo', 'Diff').add_legend()
Out[204]:
In [36]:
data = pd.read_feather("/Users/weilu/Research/server/may_2018/second/rerun_0_05_May_155022.feather")
dic = {"T0":300, "T1":335, "T2":373, "T3":417, "T4":465, "T5":519, "T6":579, "T7":645, "T8":720, "T9":803, "T10":896, "T11":1000}
a = data
a["Temp"] = a["Temp"].apply(lambda x: dic[x])
rerun0 = data
t = a.query("Temp < 400").groupby(["BiasTo","Temp"])[["DisReal","Run"]].mean().reset_index()
t["Diff"] = t["DisReal"]-t["BiasTo"].apply(pd.to_numeric)
t["BiasTo"] = t["BiasTo"].apply(pd.to_numeric)
fg = sns.FacetGrid(data=t, hue='Temp', size=8, aspect=1.61)
fg.map(plt.scatter, 'BiasTo', 'Diff').add_legend()
Out[36]:
In [5]:
data = pd.read_feather("/Users/weilu/Research/server/may_2018/second/rerun_1_05_May_155022.feather")
dic = {"T0":300, "T1":335, "T2":373, "T3":417, "T4":465, "T5":519, "T6":579, "T7":645, "T8":720, "T9":803, "T10":896, "T11":1000}
a = data
a["Temp"] = a["Temp"].apply(lambda x: dic[x])
rerun1 = data
t = a.query("Temp < 400").groupby(["BiasTo","Temp"])[["DisReal","Run"]].mean().reset_index()
t["Diff"] = t["DisReal"]-t["BiasTo"].apply(pd.to_numeric)
t["BiasTo"] = t["BiasTo"].apply(pd.to_numeric)
fg = sns.FacetGrid(data=t, hue='Temp', size=8, aspect=1.61)
fg.map(plt.scatter, 'BiasTo', 'Diff').add_legend()
Out[5]:
In [11]:
rerun1.query("Temp == 417").plot.hexbin("DisReal", "Qw", cmap="seismic", sharex=False)
Out[11]:
In [12]:
rerun1.query("Temp == 373").plot.hexbin("DisReal", "Qw", cmap="seismic", sharex=False)
Out[12]:
In [179]:
rerun1.query("Temp == 335").plot.hexbin("DisReal", "Qw", cmap="seismic", sharex=False)
Out[179]:
In [203]:
rerun1.query("Temp == 335").plot.hexbin("z_h6", "Qw", cmap="seismic", sharex=False)
Out[203]:
In [6]:
rerun1.query("Temp == 300").plot.hexbin("DisReal", "Qw", cmap="seismic", sharex=False)
Out[6]:
In [82]:
t = rerun1.query("Temp == 300 and DisReal < 45 and Qw < 0.55")
select(t)
Out[82]:
In [75]:
rerun0.query("Temp == 300 and DisReal < 120").plot.hexbin("DisReal", "Qw", cmap="seismic", sharex=False)
Out[75]:
In [7]:
rerun1.query("Temp == 300").plot.hexbin("TotalE", "Qw", cmap="seismic", sharex=False)
Out[7]:
In [39]:
all_data = pd.concat([rerun0,rerun1])
In [69]:
tmp = temperature_exchange_table(all_data.query("BiasTo == '92.0'"))
tmp
Out[69]:
In [70]:
tmp = temperature_exchange_table(all_data.query("BiasTo == '40.0'"))
tmp
Out[70]:
In [57]:
a = all_data.groupby("BiasTo").apply(summarise_temperature_exchange_table)
a.index = a.index.astype("float")
In [68]:
a.sort_index().plot()
Out[68]:
In [71]:
a.describe()
Out[71]:
In [83]:
pre = "/Users/weilu/Research/server/may_2018/01_week"
temp = 300
location = pre + "/second/_280-350/2d_z_qw/quick/"
location2 = location + f"pmf-{temp}.dat"
path, f = shortest_path(location2, start=(10, 10), end=(25,24),save=False, xlabel="z_H6", ylabel="Qw", zmax=30)
# plt.savefig("/Users/weilu/papers/figures/2d_z6_qw.png", dpi=300)
# plt.savefig("/Users/weilu/papers/figures/shortest_path.png", dpi=300)
location2 = location + f"evpb-{temp}.dat"
(xi,yi,zi) = plot2d(location2, zmax=120)
plt.plot(xi[path[:,1]], yi[path[:,0]], 'r.-')
# plt.savefig("/Users/weilu/papers/figures/2d_expected_dis.png", dpi=300)
plt.figure()
f_on_path = [zi[tuple(p)] for p in reversed(path)]
plt.plot(f_on_path)
# plt.savefig("/Users/weilu/papers/figures/shortest_path_expected_dis.png", dpi=300)
Out[83]:
In [88]:
pre = "/Users/weilu/Research/server/may_2018/01_week"
temp = 290
location = pre + "/second/_280-350/2d_z_qw/remove_I_know/"
location2 = location + f"pmf-{temp}.dat"
path, f = shortest_path(location2, start=(10, 10), end=(25,24),save=False, xlabel="z_H6", ylabel="Qw", zmax=30)
# plt.savefig("/Users/weilu/papers/figures/2d_z6_qw.png", dpi=300)
# plt.savefig("/Users/weilu/papers/figures/shortest_path.png", dpi=300)
location2 = location + f"evpb-{temp}.dat"
(xi,yi,zi) = plot2d(location2, zmax=120)
plt.plot(xi[path[:,1]], yi[path[:,0]], 'r.-')
# plt.savefig("/Users/weilu/papers/figures/2d_expected_dis.png", dpi=300)
plt.figure()
f_on_path = [zi[tuple(p)] for p in reversed(path)]
plt.plot(f_on_path)
# plt.savefig("/Users/weilu/papers/figures/shortest_path_expected_dis.png", dpi=300)
Out[88]:
In [151]:
location = location2
data = np.loadtxt(location)
res = 40
zmin = 0
zmax = 20
xi, yi, zi = getxyz(data, res=res, zmin=zmin, zmax=zmax)
zi = np.where(np.isnan(zi), 20, zi)
In [153]:
def raw_2d_plot(location):
data = np.loadtxt(location)
x = data[:,1]
y = data[:,2]
z = data[:,3]
plt.scatter(x,y, c=z, cmap='rainbow')
# plt.gray()
plt.colorbar()
return data
In [155]:
data = raw_2d_plot(location)
In [170]:
data.shape[0]
Out[170]:
In [180]:
np.ones((res**2, 4))*np.nan
Out[180]:
In [194]:
# construct complete res*res array
tmp = np.ones((res**2, 4))*np.nan
pos = 0
count = 0
x = 1
y = 2
z = 3
xi = np.linspace(min(data[:,x]), max(data[:,x]), res)
yi = np.linspace(min(data[:,y]), max(data[:,y]), res)
for i in range(res):
for j in range(res):
tmp[pos,0] = pos
tmp[pos,1] = xi[i]
tmp[pos,2] = yi[j]
if count < data.shape[0] and pos == int(data[count, 0]):
# tmp[pos,1] = data[count, 1]
# tmp[pos,2] = data[count, 2]
tmp[pos,3] = data[count, z]
count += 1
pos += 1
# Assign zmax around for each point if it is nan before.
new_tmp = tmp.copy()
pos = 0
count = 0
for i in range(res):
for j in range(res):
if not np.isnan(tmp[pos,3]):
new_tmp[pos] = tmp[pos]
right_neighbour = i*res + (j+1)
if j < res-1 and np.isnan(tmp[right_neighbour,3]):
new_tmp[right_neighbour, 3] = zmax
left_neighbour = i*res + (j-1)
if j>0 and np.isnan(tmp[left_neighbour,3]):
new_tmp[left_neighbour, 3] = zmax
up_neighbour = (i+1)*res + j
if i < res-1 and np.isnan(tmp[up_neighbour,3]):
new_tmp[up_neighbour, 3] = zmax
down_neighbour = (i-1)*res + j
if i > 0 and np.isnan(tmp[down_neighbour,3]):
new_tmp[down_neighbour, 3] = zmax
pos += 1
tmp = new_tmp[~np.isnan(new_tmp).any(axis=1)]
In [195]:
tmp
Out[195]:
In [173]:
# fill in those nan with zmax
tmp = np.ones((res**2, 4))*zmax
pos = 0
count = 0
x = 1
y = 2
z = 3
xi = np.linspace(min(data[:,x]), max(data[:,x]), res)
yi = np.linspace(min(data[:,y]), max(data[:,y]), res)
for i in range(res):
for j in range(res):
tmp[pos,0] = pos
tmp[pos,1] = xi[i]
tmp[pos,2] = yi[j]
if count < data.shape[0] and pos == int(data[count, 0]):
# tmp[pos,1] = data[count, 1]
# tmp[pos,2] = data[count, 2]
tmp[pos,3] = data[count, z]
count += 1
pos += 1
In [196]:
x = tmp[:,1]
y = tmp[:,2]
z = tmp[:,3]
plt.scatter(x,y, c=z, cmap='rainbow')
# plt.gray()
plt.colorbar()
Out[196]:
In [174]:
x = tmp[:,1]
y = tmp[:,2]
z = tmp[:,3]
plt.scatter(x,y, c=z, cmap='rainbow')
# plt.gray()
plt.colorbar()
Out[174]:
In [ ]:
# fill in those nan with zmax
tmp = np.ones((res**2, 4)) *zmax
count = 0
for i in range(res*res):
tmp[i,0] = i
if i == data[count, 1]:
tmp[i,1] = data[count, 1]
tmp[i,2] = data[count, 2]
tmp[i,3] = data[count, 3]
In [148]:
plt.scatter(x,y, c=z, cmap='rainbow')
# plt.gray()
plt.colorbar()
Out[148]:
In [197]:
pre = "/Users/weilu/Research/server/may_2018/01_week"
temp = 310
location = pre + "/second/_280-350/2d_z_qw/remove_I_know_force_0.1_more_bins/"
location2 = location + f"pmf-{temp}.dat"
path, f = shortest_path(location2, start=(15, 15), end=(30,30),save=False, xlabel="z_H6", ylabel="Qw", zmax=20,res=40)
# plt.savefig("/Users/weilu/papers/figures/2d_z6_qw.png", dpi=300)
# plt.savefig("/Users/weilu/papers/figures/shortest_path.png", dpi=300)
location3 = location + f"evpb-{temp}.dat"
(xi,yi,zi) = plot2d(location3, zmax=120)
plt.plot(xi[path[:,1]], yi[path[:,0]], 'r.-')
# plt.savefig("/Users/weilu/papers/figures/2d_expected_dis.png", dpi=300)
plt.figure()
f_on_path = [zi[tuple(p)] for p in reversed(path)]
plt.plot(f_on_path)
# plt.savefig("/Users/weilu/papers/figures/shortest_path_expected_dis.png", dpi=300)
In [178]:
pre = "/Users/weilu/Research/server/may_2018/01_week"
temp = 310
location = pre + "/second/_280-350/2d_z_qw/remove_I_know_force_0.1_more_bins/"
location2 = location + f"pmf-{temp}.dat"
path, f = shortest_path(location2, start=(15, 15), end=(30,30),save=False, xlabel="z_H6", ylabel="Qw", zmax=20,res=40)
# plt.savefig("/Users/weilu/papers/figures/2d_z6_qw.png", dpi=300)
# plt.savefig("/Users/weilu/papers/figures/shortest_path.png", dpi=300)
location3 = location + f"evpb-{temp}.dat"
(xi,yi,zi) = plot2d(location3, zmax=120)
plt.plot(xi[path[:,1]], yi[path[:,0]], 'r.-')
# plt.savefig("/Users/weilu/papers/figures/2d_expected_dis.png", dpi=300)
plt.figure()
f_on_path = [zi[tuple(p)] for p in reversed(path)]
plt.plot(f_on_path)
# plt.savefig("/Users/weilu/papers/figures/shortest_path_expected_dis.png", dpi=300)
In [133]:
pre = "/Users/weilu/Research/server/may_2018/01_week"
temp = 310
location = pre + "/second/_280-350/2d_z_qw/remove_I_know_force_0.1_more_bins/"
location2 = location + f"pmf-{temp}.dat"
path, f = shortest_path(location2, start=(15, 15), end=(30,30),save=False, xlabel="z_H6", ylabel="Qw", zmax=20,res=40)
# plt.savefig("/Users/weilu/papers/figures/2d_z6_qw.png", dpi=300)
# plt.savefig("/Users/weilu/papers/figures/shortest_path.png", dpi=300)
location3 = location + f"evpb-{temp}.dat"
(xi,yi,zi) = plot2d(location3, zmax=120)
plt.plot(xi[path[:,1]], yi[path[:,0]], 'r.-')
# plt.savefig("/Users/weilu/papers/figures/2d_expected_dis.png", dpi=300)
plt.figure()
f_on_path = [zi[tuple(p)] for p in reversed(path)]
plt.plot(f_on_path)
# plt.savefig("/Users/weilu/papers/figures/shortest_path_expected_dis.png", dpi=300)
In [110]:
pre = "/Users/weilu/Research/server/may_2018/01_week"
temp = 310
location = pre + "/second/_280-350/2d_z_qw/remove_I_know_force_0.1_more_bins/"
location2 = location + f"pmf-{temp}.dat"
path, f = shortest_path(location2, start=(12, 12), end=(25,24),save=False, xlabel="z_H6", ylabel="Qw", zmax=20)
# plt.savefig("/Users/weilu/papers/figures/2d_z6_qw.png", dpi=300)
# plt.savefig("/Users/weilu/papers/figures/shortest_path.png", dpi=300)
location3 = location + f"evpb-{temp}.dat"
(xi,yi,zi) = plot2d(location3, zmax=120)
plt.plot(xi[path[:,1]], yi[path[:,0]], 'r.-')
# plt.savefig("/Users/weilu/papers/figures/2d_expected_dis.png", dpi=300)
plt.figure()
f_on_path = [zi[tuple(p)] for p in reversed(path)]
plt.plot(f_on_path)
# plt.savefig("/Users/weilu/papers/figures/shortest_path_expected_dis.png", dpi=300)
Out[110]:
In [106]:
pre = "/Users/weilu/Research/server/may_2018/01_week"
temp = 310
location = pre + "/second/_280-350/2d_z_qw/remove_I_know_force_0.1_more_bins/"
location2 = location + f"pmf-{temp}.dat"
path, f = shortest_path(location2, start=(10, 10), end=(25,24),block=(-20,-10,0.1,0.4),save=False, xlabel="z_H6", ylabel="Qw", zmax=20)
# plt.savefig("/Users/weilu/papers/figures/2d_z6_qw.png", dpi=300)
# plt.savefig("/Users/weilu/papers/figures/shortest_path.png", dpi=300)
location2 = location + f"evpb-{temp}.dat"
(xi,yi,zi) = plot2d(location2, zmax=120)
plt.plot(xi[path[:,1]], yi[path[:,0]], 'r.-')
# plt.savefig("/Users/weilu/papers/figures/2d_expected_dis.png", dpi=300)
plt.figure()
f_on_path = [zi[tuple(p)] for p in reversed(path)]
plt.plot(f_on_path)
# plt.savefig("/Users/weilu/papers/figures/shortest_path_expected_dis.png", dpi=300)
Out[106]:
In [104]:
pre = "/Users/weilu/Research/server/may_2018/01_week"
temp = 300
location = pre + "/second/_280-350/2d_z_qw/remove_I_know_force_0.1/"
location2 = location + f"pmf-{temp}.dat"
path, f = shortest_path(location2, start=(10, 10), end=(25,24),save=False, xlabel="z_H6", ylabel="Qw", zmax=20)
# plt.savefig("/Users/weilu/papers/figures/2d_z6_qw.png", dpi=300)
# plt.savefig("/Users/weilu/papers/figures/shortest_path.png", dpi=300)
location2 = location + f"evpb-{temp}.dat"
(xi,yi,zi) = plot2d(location2, zmax=120)
plt.plot(xi[path[:,1]], yi[path[:,0]], 'r.-')
# plt.savefig("/Users/weilu/papers/figures/2d_expected_dis.png", dpi=300)
plt.figure()
f_on_path = [zi[tuple(p)] for p in reversed(path)]
plt.plot(f_on_path)
# plt.savefig("/Users/weilu/papers/figures/shortest_path_expected_dis.png", dpi=300)
Out[104]:
In [96]:
pre = "/Users/weilu/Research/server/may_2018/01_week"
temp = 310
location = pre + "/second/_280-350/2d_z_qw/remove_I_know_force_0.1/"
location2 = location + f"pmf-{temp}.dat"
path, f = shortest_path(location2, start=(10, 10), end=(25,24),block=(-20,-10,0.1,0.4),save=False, xlabel="z_H6", ylabel="Qw", zmax=20)
# plt.savefig("/Users/weilu/papers/figures/2d_z6_qw.png", dpi=300)
# plt.savefig("/Users/weilu/papers/figures/shortest_path.png", dpi=300)
location2 = location + f"evpb-{temp}.dat"
(xi,yi,zi) = plot2d(location2, zmax=120)
plt.plot(xi[path[:,1]], yi[path[:,0]], 'r.-')
# plt.savefig("/Users/weilu/papers/figures/2d_expected_dis.png", dpi=300)
plt.figure()
f_on_path = [zi[tuple(p)] for p in reversed(path)]
plt.plot(f_on_path)
# plt.savefig("/Users/weilu/papers/figures/shortest_path_expected_dis.png", dpi=300)
Out[96]:
In [199]:
pre = "/Users/weilu/Research/server/may_2018/01_week"
temp = 310
location = pre + "/second/_280-350/2d_z_qw/remove_I_know_force_0.1/"
location2 = location + f"pmf-{temp}.dat"
path, f = shortest_path(location2, start=(10, 10), end=(25,24),block=(-20,-10,0.1,0.4),save=False, xlabel="z_H6", ylabel="Qw", zmax=20)
# plt.savefig("/Users/weilu/papers/figures/2d_z6_qw.png", dpi=300)
# plt.savefig("/Users/weilu/papers/figures/shortest_path.png", dpi=300)
location2 = location + f"evpb-{temp}.dat"
(xi,yi,zi) = plot2d(location2, zmax=120)
plt.plot(xi[path[:,1]], yi[path[:,0]], 'r.-')
# plt.savefig("/Users/weilu/papers/figures/2d_expected_dis.png", dpi=300)
plt.figure()
f_on_path = [zi[tuple(p)] for p in reversed(path)]
plt.plot(f_on_path)
# plt.savefig("/Users/weilu/papers/figures/shortest_path_expected_dis.png", dpi=300)
In [ ]: