Exemplo n.º 1
0
# only consider TALYS cross sections for A >= 12
idx = (data['Z'] + data['N']) >= 12
data = data[idx]

# factor out the principal scaling given by the TRK formula: sigma_int ~ Z*N/A
data['xs'] /= (data['Z'] * data['N'] / (data['Z'] + data['N']))[:, np.newaxis]

# pad cross sections to next larger 2^n + 1 tabulation points for Romberg integration
eps = iR.romb_pad_logspaced(eps, 513)
xs = np.array([iR.romb_pad_zero(x, 513) for x in data['xs']]) * 1e-31

for field in fields:
    print(field.name)

    # calculate the interaction rate, averaged over all isotopes
    rate = np.mean([iR.calc_rate_eps(eps, x, gamma, field) for x in xs],
                   axis=0)
    fname = folder + '/rate_%s.txt' % field.name.split('_')[0]
    try:
        git_hash = gh.get_git_revision_hash()
        header = (
            "Average interaction rate for elastic scattering of %s photons off nuclei\n"
            % field.info + "Produced with crpropa-data version: " + git_hash +
            "\n" +
            "Scale with Z*N/A for nuclei\n1/lambda [1/Mpc] for log10(gamma) = 6-14 in 201 steps"
        )
    except:
        header = (
            "Average interaction rate for elastic scattering of %s photons off nuclei\n"
            "Scale with Z*N/A for nuclei\n1/lambda [1/Mpc] for log10(gamma) = 6-14 in 201 steps"
            % field.info)
Exemplo n.º 2
0
fields = [
    photonField.CMB(),
    photonField.EBL_Kneiske04(),
    photonField.EBL_Stecker05(),
    photonField.EBL_Franceschini08(),
    photonField.EBL_Finke10(),
    photonField.EBL_Dominguez11(),
    photonField.EBL_Gilmore12()
    ]

# calculate interaction rates at z=0, default option
for field in fields:
    print field

    r1 = interactionRate.calc_rate_eps(eps1, xs1, gamma, field)
    r2 = interactionRate.calc_rate_eps(eps2, xs2, gamma, field)

    fname = 'data/ppp_%s.txt' % field.name
    data  = c_[lgamma, r1, r2]
    fmt   = '%.2f\t%.6e\t%.6e'
    header = ("Photo-pion interaction rate with the %s\nlog10(gamma)"
              "\t1/lambda_proton [1/Mpc]\t1/lambda_neutron [1/Mpc]"%field.info)
    savetxt(fname, data, fmt=fmt, header=header)

# calculate redshift dependent interaction rates
for field in fields:
    print field
    redshifts = field.redshift

    if redshifts is None:

fields = [
    photonField.CMB(),
    photonField.EBL_Kneiske04(),
    photonField.EBL_Stecker05(),
    photonField.EBL_Franceschini08(),
    photonField.EBL_Finke10(),
    photonField.EBL_Dominguez11(),
    photonField.EBL_Gilmore12()]

for field in fields:
    print (field.name)

    # Calculate total interaction rates
    R1 = array([interactionRate.calc_rate_eps(eps1, x, gamma, field) for x in xs1sum])
    R2 = array([interactionRate.calc_rate_eps(eps2, x, gamma, field) for x in xs2sum])

    savetxt('data/pd_%s.txt' % field.name,
        r_[c_[d1sum['Z'], d1sum['N'], R1], c_[d2sum['Z'], d2sum['N'], R2]],
        fmt='%i\t%i' + '\t%g'*201,
        header='Photodisintegration by the %s\nZ, N, 1/lambda [1/Mpc] for log10(gamma) = 6-14 in 201 steps' % field.info)

    # Calculate branching ratios from exclusive interaction rates
    B1 = array([interactionRate.calc_rate_eps(eps1, x, gamma, field) for x in xs1exc])
    B2 = array([interactionRate.calc_rate_eps(eps2, x, gamma, field) for x in xs2exc])
    for (Z, N, A) in isotopes1:
        s = (d1exc['Z'] == Z) * (d1exc['N'] == N)
        B1[s] /= sum(B1[s], axis=0)
    for (Z, N, A) in isotopes2:
        s = (d2exc['Z'] == Z) * (d2exc['N'] == N)
idx = (data['Z'] + data['N']) >= 12
data = data[idx]

# Factor out the principal scaling given by the TRK formula: sigma_int ~ Z*N/A
data['xs'] /= ( data['Z'] * data['N'] / (data['Z'] + data['N']) )[:,newaxis]

# Pad cross sections to next larger 2^n + 1 tabulation points for Romberg integration
eps = iR.romb_pad_logspaced(eps, 513)
xs  = array([iR.romb_pad_zero(x, 513) for x in data['xs']]) * 1e-31


for field in [photonField.CMB(), photonField.EBL_Gilmore12()]:
    print (field.name)

    # Calculate the interaction rate, averaged over all isotopes
    rate = mean([iR.calc_rate_eps(eps, x, gamma, field) for x in xs], axis=0)

    savetxt('data/ElasticScattering_%s.txt' % field.name.split('_')[0],
        rate, fmt='%g',
        header='Average interaction rate for elastic scattering of %s photons off nuclei\nScale with Z*N/A for nuclei\n1/lambda [1/Mpc] for log10(gamma) = 6-14 in 201 steps' % field.info)

    # Calculate CDF for background photon energies, averaged over all isotopes
    CDF = zeros((len(gamma), len(eps)))
    for x in xs:
        C = iR.calc_diffrate_eps(eps, x, gamma, field)
        CDF += C / amax(C, axis=1)[:,newaxis]
    CDF /= len(data)
    CDF = nan_to_num(CDF)

    savetxt('data/ElasticScattering_CDF_%s.txt' % field.name.split('_')[0],
        c_[log10(gamma), CDF],
Exemplo n.º 5
0
    photonField.EBL_Gilmore12(),
    photonField.EBL_Stecker16('upper'),
    photonField.EBL_Stecker16('lower')
]

for field in fields:
    print(field.name)

    # output folder
    folder = 'data/Photodisintegration'
    if not os.path.exists(folder):
        os.makedirs(folder)

    # Calculate total interaction rates
    R1 = np.array(
        [interactionRate.calc_rate_eps(eps1, x, gamma, field) for x in xs1sum])
    R2 = np.array(
        [interactionRate.calc_rate_eps(eps2, x, gamma, field) for x in xs2sum])

    np.savetxt(
        folder + '/rate_%s.txt' % field.name,
        np.r_[np.c_[d1sum['Z'], d1sum['N'], R1], np.c_[d2sum['Z'], d2sum['N'],
                                                       R2]],
        fmt='%i\t%i' + '\t%g' * 201,
        header=
        'Photodisintegration by the %s\nZ, N, 1/lambda [1/Mpc] for log10(gamma) = 6-14 in 201 steps'
        % field.info)

    # Calculate branching ratios from exclusive interaction rates
    B1 = np.array(
        [interactionRate.calc_rate_eps(eps1, x, gamma, field) for x in xs1exc])
idx = (data['Z'] + data['N']) >= 12
data = data[idx]

# factor out the principal scaling given by the TRK formula: sigma_int ~ Z*N/A
data['xs'] /= (data['Z'] * data['N'] / (data['Z'] + data['N']))[:, np.newaxis]

# pad cross sections to next larger 2^n + 1 tabulation points for Romberg integration
eps = iR.romb_pad_logspaced(eps, 513)
xs = np.array([iR.romb_pad_zero(x, 513) for x in data['xs']]) * 1e-31


for field in fields:
    print(field.name)

    # calculate the interaction rate, averaged over all isotopes
    rate = np.mean([iR.calc_rate_eps(eps, x, gamma, field) for x in xs], axis=0)
    fname = folder + '/rate_%s.txt' % field.name.split('_')[0]
    header = 'Average interaction rate for elastic scattering of %s photons off nuclei\nScale with Z*N/A for nuclei\n1/lambda [1/Mpc] for log10(gamma) = 6-14 in 201 steps' % field.info
    np.savetxt(fname, rate, fmt='%g', header=header)

    # calculate CDF for background photon energies, averaged over all isotopes
    CDF = np.zeros((len(gamma), len(eps)))
    for x in xs:
        C = iR.calc_rate_eps(eps, x, gamma, field, cdf=True)
        CDF += C / np.max(C, axis=1, keepdims=True)
    CDF /= len(data)
    CDF = np.nan_to_num(CDF)

    fname = folder + '/cdf_%s.txt' % field.name.split('_')[0]
    data = np.c_[np.log10(gamma), CDF]
    fmt = '%g' + '\t%g' * len(eps)
d = np.genfromtxt('tables/PPP/xs_neutron.txt', unpack=True)
eps2 = d[0, :2049] * 1e9 * eV  # [J]
xs2 = d[1, :2049] * 1e-34  # [m^2]

for field in fields:
    print(field.name)

    # output folder
    folder = 'data/PhotoPionProduction'
    if not os.path.exists(folder):
        os.makedirs(folder)

    # ----------------------------------------------------
    # calculate interaction rates at z=0, default option
    # ----------------------------------------------------
    r1 = interactionRate.calc_rate_eps(eps1, xs1, gamma, field)
    r2 = interactionRate.calc_rate_eps(eps2, xs2, gamma, field)

    fname = folder + '/rate_%s.txt' % field.name
    data = np.c_[lgamma, r1, r2]
    fmt = '%.2f\t%.6e\t%.6e'
    try:
        git_hash = gh.get_git_revision_hash()
        header = (
            "Photo-pion interaction rate with the %s\n" % field.info +
            "Produced with crpropa-data version: " + git_hash + "\n" +
            "log10(gamma)\t1/lambda_proton [1/Mpc]\t1/lambda_neutron [1/Mpc]")
    except:
        header = ("Photo-pion interaction rate with the %s\nlog10(gamma)"
                  "\t1/lambda_proton [1/Mpc]\t1/lambda_neutron [1/Mpc]" %
                  field.info)