In [93]:
import numpy as np
import pandas as pd
from scipy import integrate
In [80]:
stellar_freqs = pd.DataFrame(np.loadtxt('Sun-freqs.dat', skiprows=1),
columns=['n', 'l', 'nu_s', 'sigma'])
stellar_freqs.head()
Out[80]:
In [81]:
model_freqs = pd.DataFrame(np.loadtxt('modelS/modelS.freq'),
columns=['l', 'n', 'nu_m', 'Q'])
model_freqs.head()
Out[81]:
In [31]:
nu = pd.merge(nu_s, nu_m)
nu.head()
Out[31]:
In [84]:
nls = [(int(n), int(l))
for (n,l) in np.array(nu[['n', 'l']])]
In [85]:
K = {(int(n),int(l)) :
pd.DataFrame(np.loadtxt('modelS_ker/c^2-\\rho_l='+\
str(int(l))+'_n='+str(int(n))+'.dat'),
columns=['r', 'c2_m', 'rho_m'])
for (n,l) in nls}
In [86]:
K[6,0].head()
Out[86]:
In [90]:
modelS = pd.DataFrame(np.loadtxt('c2_rho.dat'),
columns=['r', 'c2', 'rho'])
c2_m = modelS['c2']
rho_m = modelS['rho']
modelS.head()
Out[90]:
In [ ]:
def A(n, l, c2_s, rho_s):
kernel = K[n,l]
fx = kernel['c2_m'] * (c2_m - c2_s) / c2_m + \
kernel['rho_m'] * (rho_m - rho_s) / rho_m
return sp.integrate.simps(fx, x=kernel['r'])
def freq_diff(n, l):
idx = nls.index((n,l))
nu_m = nu['nu_m'][idx]
nu_s = nu['nu_s'][idx]
return (nu_m - nu_s) / nu_m
def chi_sq(c2_s, rho_s, F_surf):
return sum(
(freq_diff(n,l) - A(n,l,c2_s,rho_s) - \
F_surf[nls.index((n,l))] / nu['Q'][nls.index((n,l))]
)**2 / nu['sigma'][nls.index((n,l))]
for (n,l) in nls)
def L_2(c2_s, rho_s):
c2 = (c2_m - c2_s) / c2_m
rho = (rho_m - rho_s) / rho_m
d2c2_dr2 = np.diff(c2, n=2) / np.diff(modelS['r'], 2)
d2rho_dr2 = np.diff(rho, n=2) / np.diff(modelS['r'], 2)
return integrate.simps(d2c2_dr2**2 + d2rho_dr2**2, modelS['r'][2:])
In [119]:
A(nls[0][0], nls[0][1], c2_m, rho_m) # should be 0
Out[119]:
In [129]:
chi_sq(c2_m, rho_m, np.zeros(len(nls))) # should be close to 0
Out[129]:
In [148]:
L_2(c2_m, rho_m) # should be 0
Out[148]: