示例#1
0
from photoion import effCrossSection
from photoion.units import c__AA_s, h__erg_s, Rsun__cm, parsec__cm
import numpy as np
import matplotlib.pyplot as plt

# Load spectrum, convert to frequency
# F_nu * d nu = F_lambda * d lambda
# F_nu = c * F_lambda / lambda^2 
spectrumFile = '../data/k35000-4.dat'
spec = np.genfromtxt(spectrumFile, names=['wl', 'flux']) # [AA, erg/cm^2/s/AA]
_spec = spec[::-1] # invert index to account the minus sign in (d nu / d lambda)
nu = c__AA_s / _spec['wl'] # Hz
F_nu = _spec['flux'] * c__AA_s / _spec['wl'] ** 2 # erg/cm^2/s/Hz

a_nu = effCrossSection('H0', nu, E_units='Hz')

# T = 20000 K
alpha_B = 2.59e-13

r_star = 10.0 * Rsun__cm
r = np.linspace(r_star, 50.0 * parsec__cm, 1000)
N_H = 10.0 * np.ones_like(r) # cm^-3
x = np.zeros_like(r)

for i_r, _r in enumerate(r):
    if i_r == 0.0:
        tau_nu = 0.0
    else:
#         tau_nu = N_H * a_nu * np.trapz((1 - x[:i_r - 1]), r[:i_r - 1])
        tau_nu = a_nu * np.trapz(N_H[:i_r - 1], r[:i_r - 1])
# else:
#     print 'unknown temperature %s' % sys.argv[1]

spectrumFile = '../data/k35000-4.dat'
    
     
# Load spectrum, convert to frequency
# F_nu * d nu = F_lambda * d lambda
# F_nu = c * F_lambda / lambda^2 
spec = np.genfromtxt(spectrumFile, names=['wl', 'flux']) # [AA, erg/cm^2/s/AA]
_spec = spec[::-1] # invert index to account the minus sign in (d nu / d lambda)
nu = c__AA_s / _spec['wl'] # Hz
F_nu = _spec['flux'] * _spec['wl'] ** 2 / c__AA_s # erg/cm^2/s/Hz

# Recombination cross sections
a_nu_H = effCrossSection('H0', nu, E_units='Hz')
a_nu_He = effCrossSection('He0', nu, E_units='Hz')

# Masks to integrate tau_nu
nu_0_H = ionizationEnergy('H0') / h__eV_s
nu_0_He = ionizationEnergy('He0') / h__eV_s
mask_tau_H = nu >= nu_0_H
mask_tau_He = nu >= nu_0_He

# Recombination coefficients
# T = 10000 K
alpha_B_H = 2.59e-13
alpha_B_He = 2.73e-13
alpha_1_He = 1.59e-13
alpha_A_He = alpha_B_He + alpha_1_He