def compute_ck2004_ldcoeffs(self, plot_diagnostics=False):
if 'ck2004_all' not in self.content:
print('Castelli & Kurucz (2004) intensities are not computed yet. Please compute those first.')
return None
self._ck2004_ld_energy_grid = np.nan*np.ones((len(self._ck2004_intensity_axes[0]), len(self._ck2004_intensity_axes[1]), len(self._ck2004_intensity_axes[2]), 11))
self._ck2004_ld_photon_grid = np.nan*np.ones((len(self._ck2004_intensity_axes[0]), len(self._ck2004_intensity_axes[1]), len(self._ck2004_intensity_axes[2]), 11))
mus = self._ck2004_intensity_axes[3]
for Tindex in range(len(self._ck2004_intensity_axes[0])):
for lindex in range(len(self._ck2004_intensity_axes[1])):
for mindex in range(len(self._ck2004_intensity_axes[2])):
IsE = 10**self._ck2004_Imu_energy_grid[Tindex,lindex,mindex,:].flatten()
fEmask = np.isfinite(IsE)
if len(IsE[fEmask]) <= 1:
continue
IsE /= IsE[fEmask][-1]
IsP = 10**self._ck2004_Imu_photon_grid[Tindex,lindex,mindex,:].flatten()
fPmask = np.isfinite(IsP)
IsP /= IsP[fPmask][-1]
cElin, pcov = cfit(self._ldlaw_lin, mus[fEmask], IsE[fEmask], p0=[0.5])
cElog, pcov = cfit(self._ldlaw_log, mus[fEmask], IsE[fEmask], p0=[0.5, 0.5])
cEsqrt, pcov = cfit(self._ldlaw_sqrt, mus[fEmask], IsE[fEmask], p0=[0.5, 0.5])
cEquad, pcov = cfit(self._ldlaw_quad, mus[fEmask], IsE[fEmask], p0=[0.5, 0.5])
cEnlin, pcov = cfit(self._ldlaw_nonlin, mus[fEmask], IsE[fEmask], p0=[0.5, 0.5, 0.5, 0.5])
self._ck2004_ld_energy_grid[Tindex, lindex, mindex] = np.hstack((cElin, cElog, cEsqrt, cEquad, cEnlin))
cPlin, pcov = cfit(self._ldlaw_lin, mus[fPmask], IsP[fPmask], p0=[0.5])
cPlog, pcov = cfit(self._ldlaw_log, mus[fPmask], IsP[fPmask], p0=[0.5, 0.5])
cPsqrt, pcov = cfit(self._ldlaw_sqrt, mus[fPmask], IsP[fPmask], p0=[0.5, 0.5])
cPquad, pcov = cfit(self._ldlaw_quad, mus[fPmask], IsP[fPmask], p0=[0.5, 0.5])
cPnlin, pcov = cfit(self._ldlaw_nonlin, mus[fPmask], IsP[fPmask], p0=[0.5, 0.5, 0.5, 0.5])
self._ck2004_ld_photon_grid[Tindex, lindex, mindex] = np.hstack((cPlin, cPlog, cPsqrt, cPquad, cPnlin))
if plot_diagnostics:
if Tindex == 10 and lindex == 9 and mindex == 5:
print self._ck2004_intensity_axes[0][Tindex], self._ck2004_intensity_axes[1][lindex], self._ck2004_intensity_axes[2][mindex]
print mus, IsE
print cElin, cElog, cEsqrt
import matplotlib.pyplot as plt
plt.plot(mus[fEmask], IsE[fEmask], 'bo')
plt.plot(mus[fEmask], self._ldlaw_lin(mus[fEmask], *cElin), 'r-')
plt.plot(mus[fEmask], self._ldlaw_log(mus[fEmask], *cElog), 'g-')
plt.plot(mus[fEmask], self._ldlaw_sqrt(mus[fEmask], *cEsqrt), 'y-')
plt.plot(mus[fEmask], self._ldlaw_quad(mus[fEmask], *cEquad), 'm-')
plt.plot(mus[fEmask], self._ldlaw_nonlin(mus[fEmask], *cEnlin), 'k-')
plt.show()
self.content.append('ck2004_ld')
评论列表
文章目录