In [ ]:
import matplotlib.pyplot as plt
%matplotlib notebook
import numpy as np
import pandas as pd
import pickle
import xmeos
from xmeos import models
from xmeos import datamod
CONSTS = models.CONSTS
import copy
In [ ]:
analysis_file = 'data/analysis.pkl'
with open(analysis_file, 'rb') as f:
analysis = pickle.load(f)
datasets = analysis['datasets']
param_tex_str = analysis['param_tex_str']
eos_electronic = analysis['eos_electronic']
In [ ]:
data = datasets['deKoker2009']
data_S11 = datasets['Spera2011']
# View data tables
tbl = data['table']
tbl
In [ ]:
In [ ]:
datamodel_S11 = analysis['datamodel']
eos_mod = copy.deepcopy(datamodel_S11['eos_mod'])
datamodel = datamod.init_datamodel(data, eos_mod)
eos_mod.apply_electronic=True
# Set colorbar temperature properties
#cmap = plt.get_cmap('coolwarm',len(data['T_labels']))
cmap = plt.get_cmap('coolwarm')
delT = np.diff(data['T_labels'])[0]
dE0 = 13.75
E0 = eos_mod.get_params()['E0'] + dE0
eos_mod.set_param_values(E0,param_names='E0')
V0 = eos_mod.get_params()['V0']
eos_electronic.set_param_values(param_names=['V0'], param_values=V0)
Tlbl = data['T_labels']
# cmap = plt.get_cmap('coolwarm',len(Tlbl))
clims = [Tlbl[0]-delT/2,Tlbl[-1]+delT/2]
Vmod = V0*np.linspace(.35,1.2,1001)
In [ ]:
P_electron = eos_electronic.press(tbl['V'],tbl['T'])
E_electron = eos_electronic.energy(tbl['V'],tbl['T'])
tbl['P'] -= P_electron
tbl['E'] -= E_electron
In [ ]:
tbl_S11 = data_S11['table']
plt.figure()
plt.scatter(tbl['V'],tbl['P'],c=tbl['T'], cmap=cmap)
plt.scatter(tbl_S11['V'],tbl_S11['P'],c=tbl_S11['T'], s=10, cmap=cmap)
for iT in data['T_labels']:
icol = cmap((iT-clims[0])/(clims[1]-clims[0]))
plt.plot(Vmod, eos_mod.press(Vmod,iT),'--',color=icol)
plt.xlabel(r'Volume [$\AA^3$/atom]')
plt.ylabel(r'Pressure [GPa]')
cbar = plt.colorbar()
cbar.set_ticks(data['T_labels'])
cbar.set_label('Temperature [K]')
plt.clim(data['T_labels'][0]-delT/2,data['T_labels'][-1]+delT/2)
# plt.ylim(-2,15);
plt.plot(Vmod,0*Vmod,'k-')
In [ ]:
In [ ]:
tbl_S11 = data_S11['table']
plt.figure()
plt.scatter(tbl['V'],tbl['P'],c=tbl['T'], cmap=cmap)
plt.scatter(tbl_S11['V'],tbl_S11['P'],c=tbl_S11['T'], s=10, cmap=cmap)
for iT in data['T_labels']:
icol = cmap((iT-clims[0])/(clims[1]-clims[0]))
plt.plot(Vmod, eos_mod.press(Vmod,iT),'--',color=icol)
plt.xlabel(r'Volume [$\AA^3$/atom]')
plt.ylabel(r'Pressure [GPa]')
cbar = plt.colorbar()
cbar.set_ticks(data['T_labels'])
cbar.set_label('Temperature [K]')
plt.clim(data['T_labels'][0]-delT/2,data['T_labels'][-1]+delT/2)
# plt.ylim(-2,15);
plt.plot(Vmod,0*Vmod,'k-')
In [ ]:
eos_mod.apply_electronic=True
In [ ]:
plt.figure()
plt.scatter(tbl['V'],tbl['E'],c=tbl['T'], cmap=cmap)
for iT in data['T_labels']:
icol = cmap((iT-clims[0])/(clims[1]-clims[0]))
plt.plot(Vmod, eos_mod.internal_energy(Vmod,iT),'--',color=icol)
plt.xlabel(r'Volume [$\AA^3$/atom]')
plt.ylabel(r'Energy [eV/atom]')
cbar = plt.colorbar()
cbar.set_ticks(data['T_labels'])
cbar.set_label('Temperature [K]')
plt.clim(data['T_labels'][0]-delT/2,data['T_labels'][-1]+delT/2)
In [ ]:
Tplt = [2000,2500,3000,3500,4000,4500,5000,5500,6000,6500,7000,7500,8000]
cmap = plt.get_cmap('coolwarm',1000)
plt.figure()
plt.scatter(tbl['P'],tbl['E'],c=tbl['T'], cmap=cmap)
plt.scatter(tbl_S11['P'],tbl_S11['E']+dE0,c=tbl_S11['T'], s=10, cmap=cmap)
# for iT in Tplt:
# icol = cmap((iT-clims[0])/(clims[1]-clims[0]))
# plt.plot(eos_mod.press(Vmod,iT),eos_mod.internal_energy(Vmod,iT),'-',color=icol)
plt.xlabel(r'Press [GPa]')
plt.ylabel(r'Energy [eV/atom]')
cbar = plt.colorbar()
cbar.set_ticks(data['T_labels'])
cbar.set_label('Temperature [K]')
plt.clim(data['T_labels'][0]-delT/2,data['T_labels'][-1]+delT/2)
In [ ]:
In [ ]:
fit_calcs = ['compress','refstate','gamma']
fix_params = ['S0','Cvlimfac','mexp']
# fix_params = ['S0','Cvlimfac']
datamodel['eos_mod'].set_param_values([3/5,1], param_names=['mexp','Cvlimfac'])
datamod.select_fit_params(datamodel, fit_calcs, fix_params=fix_params)
datamodel['fit_params']
In [ ]:
datamod.fit(datamodel)
datamod.fit(datamodel, apply_bulk_mod_wt=True)
In [ ]:
display('R2fit = ', datamodel['posterior']['R2fit'])
display('Model Residual Error = ', datamodel['posterior']['fit_err'])
display(datamodel['posterior']['param_tbl'])
In [ ]:
datamodel.keys()
In [ ]:
prior = datamodel['posterior']
prior
In [ ]:
In [ ]:
corr = prior['corr']
param_err = prior['param_err']
cov = np.dot(param_err[:,np.newaxis],param_err[np.newaxis,:])*corr
cov
In [ ]:
np.linalg.inv(cov)
In [ ]:
np.linalg.inv(corr)
In [ ]:
hess = np.dot(1/param_err[:,np.newaxis],1/param_err[np.newaxis,:])*np.linalg.inv(corr)
hess
In [ ]:
U,S,V = np.linalg.svd(cov)
eigvecs = U
eigval = S
eigerr = np.sqrt(eigval)
In [ ]:
np.dot(cov,U[:,3])/S[3]
In [ ]:
U[:,3]
In [ ]:
In [ ]:
eigvec[0]
In [ ]:
In [ ]:
fit_calcs = ['compress','refstate','gamma','bcoef','thermal']
fix_params = ['S0','Cvlimfac','mexp']
# fix_params = ['S0','Cvlimfac']
datamodel['eos_mod'].set_param_values([3/5,1], param_names=['mexp','Cvlimfac'])
datamod.select_fit_params(datamodel, fit_calcs, fix_params=fix_params)
datamodel['fit_params']
In [ ]:
datamod.fit(datamodel)
datamod.fit(datamodel, apply_bulk_mod_wt=True)
In [ ]:
display('R2fit = ', datamodel['posterior']['R2fit'])
display('Model Residual Error = ', datamodel['posterior']['fit_err'])
display(datamodel['posterior']['param_tbl'])
In [ ]:
In [ ]:
In [ ]:
In [ ]:
plt.figure()
posterior = datamodel['posterior']
corr = posterior['corr']
param_labels = [param_tex_str[name] for name in posterior['param_names']]
cmap = plt.get_cmap('coolwarm')
Nparam = len(param_labels)
corr_plt = np.flipud(np.ma.masked_where(np.eye(Nparam),corr))
plt.pcolormesh(corr_plt,cmap=cmap)
# plt.imshow(corr, cmap=cmap)
plt.clim(-1,1)
plt.colorbar(label=r'Correlation Coefficient')
plt.xticks(.5+np.arange(len(param_labels)),param_labels)
plt.yticks(np.flipud(.5+np.arange(len(param_labels))),param_labels)
for (index,val) in np.ndenumerate(np.flipud(corr)):
if index[1]!=Nparam-1-index[0]:
plt.text(index[1]+.5,index[0]+.5,'%+.2f'%(val),fontsize=9,
horizontalalignment='center', verticalalignment='center')
plt.setp(plt.gca().get_xticklines(),visible=False);
plt.setp(plt.gca().get_yticklines(),visible=False);
#plt.plot((0,11),(5,5),'k-',linewidth=2)
#plt.plot((0,11),(7,7),'k-',linewidth=2)
#plt.plot((4,4),(0,11),'k-',linewidth=2)
#plt.plot((6,6),(0,11),'k-',linewidth=2)
#plt.show()
In [ ]:
In [ ]:
In [ ]:
from collections import OrderedDict
eos_mod = datamodel['eos_mod']
Tref = 1673
Vref = eos_mod.volume(0,Tref)
refvals = OrderedDict()
refvals['Vref'] = Vref
refvals['Kref'] = eos_mod.bulk_mod(Vref,Tref)
refvals['Cvref'] = eos_mod.heat_capacity(Vref,Tref)/models.CONSTS['kboltz']
display(refvals)
In [ ]:
# datamod.fit(datamodel, apply_bulk_mod_wt=True)
In [ ]:
In [ ]:
# Set colorbar temperature properties
cmap = plt.get_cmap('coolwarm',len(data['T_labels']))
delT = np.diff(data['T_labels'])[0]
Vmod = V0*np.linspace(.39,1.2,1001)
plt.figure()
plt.scatter(tbl['V'],tbl['P'],c=tbl['T'], cmap=cmap)
for iT in data['T_labels']:
icol = cmap((iT-clims[0])/(clims[1]-clims[0]))
plt.plot(Vmod, eos_mod.press(Vmod,iT),'-',color=icol)
plt.xlabel(r'Volume [$\AA^3$/atom]')
plt.ylabel(r'Pressure [GPa]')
cbar = plt.colorbar()
cbar.set_ticks(data['T_labels'])
cbar.set_label('Temperature [K]')
plt.clim(data['T_labels'][0]-delT/2,data['T_labels'][-1]+delT/2)
In [ ]:
plt.figure()
plt.scatter(tbl['V'],tbl['E'],c=tbl['T'], cmap=cmap)
for iT in data['T_labels']:
icol = cmap((iT-clims[0])/(clims[1]-clims[0]))
plt.plot(Vmod, eos_mod.internal_energy(Vmod,iT),'-',color=icol)
plt.xlabel(r'Volume [$\AA^3$/atom]')
plt.ylabel(r'Energy [eV/atom]')
cbar = plt.colorbar()
cbar.set_ticks(data['T_labels'])
cbar.set_label('Temperature [K]')
plt.clim(data['T_labels'][0]-delT/2,data['T_labels'][-1]+delT/2)
In [ ]:
def material_properties(Pref, Tref, eos_mod, Vref=None):
if Vref is None:
Vref = eos_mod.volume(Pref, Tref, Vinit=12.8)[0]
KT = eos_mod.bulk_mod(Vref,Tref)[0]
CV = eos_mod.heat_capacity(Vref,Tref)
alpha = eos_mod.thermal_exp(Vref,Tref)[0]
gamma = eos_mod.gamma(Vref,Tref)[0]
KS = KT*(1+alpha*gamma*Tref)
props = OrderedDict()
props['P'] = Pref
props['T'] = Tref
props['V'] = Vref
props['KT'] = KT
props['KS'] = KS
props['Cv'] = CV/CONSTS['kboltz']
props['therm_exp'] = alpha
props['gamma'] = gamma
return props
model_props = material_properties(0,1673, eos_mod)
display(model_props)
In [ ]:
display(analysis['props_Lange'])
display(analysis['props_Ghiorso'])
In [ ]:
In [ ]:
# Save fitted model
analysis['datamodel_dK09'] = datamodel
with open(analysis_file, 'wb') as f:
pickle.dump(analysis, f)
In [ ]: