Ejemplo n.º 1
0
def run( *arguments, **DarkOptions ):
	if len(arguments) <2:
		raise DarkAgesError("There are too few arguments passed. I expected at least 1")
	sampling_mass = float(arguments[1])
	if sampling_mass < 5 or sampling_mass > 5e3:
		raise DarkAgesError("The mass-parameter sholud be in the range [5 GeV, 5 TeV]")

	with open(os.path.join(model_dir, '{}.obj'.format(model_name)),'rb') as dump_file:
		dump_dict = dill.load(dump_file)

	primaries = dump_dict.get('channels')
	tmp_shape = dump_dict.get('spec_interp_{:s}'.format(primaries[0]))._shape
	total_spec = np.zeros(shape=tmp_shape, dtype=np.float64)
	tot_frac = 0.
	for primary in primaries:
		fraction = dump_dict.get('frac_interp_{:s}'.format(primary)).__call__(sampling_mass)
		#fraction = dump_dict.get('frac_interp_{:s}_loglin'.format(primary)).__call__(sampling_mass)
		spectra =  dump_dict.get('spec_interp_{:s}'.format(primary)).__call__(sampling_mass)
		if np.any(spectra > 0.0):
			total_spec += fraction * spectra
			tot_frac += fraction
	if tot_frac > 0.:
		total_spec /= tot_frac
	else:
		total_spec = np.zeros_like(total_spec)

	history = DarkOptions.get('injection_history','annihilation')
	if history == 'decay':
		tdec = DarkOptions.get('t_dec')
		full_model = decaying_model(total_spec[0], total_spec[1], total_spec[2], 1e9*sampling_mass, tdec)
	else:
		full_model = annihilating_model(total_spec[0], total_spec[1], total_spec[2], 1e9*sampling_mass)
	#####

	##### To finish the calculation, calculate f(z) for each deposition channel
	## and print the CLASS-output with the finalize()-method
	#####
	f_functions = np.zeros((len(channel_dict),len(redshift)))
	for channel in channel_dict:
		idx = channel_dict[channel]
		f_functions[idx,:] = full_model.calc_f(transfer_functions[idx])[-1]

	finalize(redshift,
             f_functions[channel_dict['Heat']],
             f_functions[channel_dict['Ly-A']],
             f_functions[channel_dict['H-Ion']],
             f_functions[channel_dict['He-Ion']],
             f_functions[channel_dict['LowE']],
			 **DarkOptions)
Ejemplo n.º 2
0
def run( *arguments, **DarkOptions ):
	if len(arguments) <3:
		raise DarkAgesError("There are too few arguments passed. I expected at least 2")
	#sampling_mass = float(arguments[1])
	sampling_mass = 5*(10**float(arguments[1]))
	if sampling_mass < 50 or sampling_mass > 500:
		raise DarkAgesError("The mass-parameter shsould be in the range [50 GeV, 500 GeV]")
	idx_primary = int(arguments[2])
	if idx_primary != 1 and idx_primary != 0:
		raise DarkAgesError("The mode '{:d}' is not recognized. Please enter a valid mode. The choices are: 0 for 'onlyZ', and 1 for 'WandZ'.".format(idx_primary))

	model_dir = os.path.split(os.path.realpath(__file__))[0]
	model_name =  model_dir.split('/')[-1]

	with open(os.path.join(model_dir, '{}.obj'.format(model_name)),'rb') as dump_file:
		dump_dict = dill.load(dump_file)
		if idx_primary == 0:
			spec_interp = dump_dict.get('spec_interp_right_onlyZ')
		elif idx_primary == 1:
			spec_interp = dump_dict.get('spec_interp_right_WandZ')

	total_spec = spec_interp.__call__(sampling_mass)
	#print total_spec

	history = DarkOptions.get('injection_history','annihilation')
	if history == 'decay':
		tdec = DarkOptions.get('t_dec')
		full_model = decaying_model(total_spec[0], total_spec[1], total_spec[2], 1e9*sampling_mass, tdec)
	else:
		full_model = annihilating_model(total_spec[0], total_spec[1], total_spec[2], 1e9*sampling_mass)

	f_functions = np.zeros((len(channel_dict),len(redshift)))
	for channel in channel_dict:
		idx = channel_dict[channel]
		f_functions[idx,:] = full_model.calc_f(transfer_functions[idx])[-1]

	finalize(redshift,
             f_functions[channel_dict['Heat']],
             f_functions[channel_dict['Ly-A']],
             f_functions[channel_dict['H-Ion']],
             f_functions[channel_dict['He-Ion']],
             f_functions[channel_dict['LowE']])
Ejemplo n.º 3
0
# spectrum of 'dN/dE'-type
spec_data = np.genfromtxt(specfile, unpack=True, usecols=(0,1,2,3,4), skip_header=1, dtype=np.float64)
masses = np.unique(spec_data[0])
try:
	assert len(masses) == 1
	mass = masses[0]
except AssertionError:
	raise DarkAgesError('It seems that the file {:s} contains spectra for several masses. (Found {:d} different masses)'.format(specfile,len(masses)))

logEnergies = get_logEnergies()
redshift = get_redshift()

spec_el, spec_ph, spec_oth = sample_spectrum(spec_data[2], spec_data[3], spec_data[4], spec_data[1], mass, logEnergies, **DarkOptions)
example_model = model(spec_el, spec_ph, spec_oth, 1e9*mass, logEnergies,redshift)

f_function = np.zeros( shape=(5,len(redshift)), dtype=np.float64 )
for channel in channel_dict:
	idx = channel_dict[channel]
	f_function[idx,:] = example_model.calc_f(transfer_functions[idx])[-1]

### Finalize (Print the output to be read by CLASS) ###

finalize(redshift,
         f_function[channel_dict['Heat']],
         f_function[channel_dict['Ly-A']],
         f_function[channel_dict['H-Ion']],
         f_function[channel_dict['He-Ion']],
         f_function[channel_dict['LowE']],
         **DarkOptions)
Ejemplo n.º 4
0
def run(*arguments, **DarkOptions):
    ##### In this block the external parameters in arguments[1:] (sys.argv[1:]) are read and translated into
    ## the parameters you like. In the given example case study the parameters are the DM mass at which the
    ## spectra should be sampled and the relative contribbution of muons to the total spectrum.
    ## If the input is not useful (mass outside the considered range, mixing not in [0,1]) an error is raised.
    #####
    if len(arguments) < 3:
        raise DarkAgesError(
            "There are too few arguments passed. I expected at least 2")
    sampling_mass = float(arguments[1])
    if sampling_mass < 50 or sampling_mass > 100:
        raise DarkAgesError(
            "The mass-parameter should be in the range [50 GeV, 100 GeV]. Your input was '{0}'"
            .format(sampling_mass))
    mixing = float(arguments[2])
    if mixing < 0 or mixing > 1:
        raise DarkAgesError(
            "The mixing-parameter should be in the range [0,1]. Your input was '{0}'"
            .format(mixing))
    #####

    ##### In this block we read in the the prepared 'interpolation'-objects
    #####
    model_dir = os.path.split(os.path.realpath(__file__))[0]
    model_name = model_dir.split('/')[-1]

    with open(os.path.join(model_dir, '{}.obj'.format(model_name)),
              'rb') as dump_file:
        dump_dict = dill.load(dump_file)
        spec_interp_muon = dump_dict.get('spec_interp_muon')
        spec_interp_bottom = dump_dict.get('spec_interp_bottom')
    ####

    #### In this block the spectra are sampled and the total spectra are calculated
    #####
    temp_spec_muon = spec_interp_muon.__call__(sampling_mass)
    temp_spec_bottom = spec_interp_bottom.__call__(sampling_mass)

    total_spec = mixing * temp_spec_muon + (1. - mixing) * temp_spec_bottom
    #####

    ##### In this block the 'model' object is created given the spectra
    ## (This function could also take logEnergies and redshift as additional
    ## arguments. But since we do not give them here. The global default values
    ## are taken)
    #####
    full_model = annihilating_model(total_spec[0], total_spec[1],
                                    total_spec[2], 1e9 * sampling_mass)
    #####

    ##### To finish the calculation, calculate f(z) for each deposition channel
    ## and print the CLASS-output with the finalize()-method
    ## for that we need for the first time the redshift array
    ## which we access by the get_redshift of DarkAges.__init__
    #####
    redshift = get_redshift()
    f_functions = np.zeros((len(channel_dict), len(redshift)))
    for channel in channel_dict:
        idx = channel_dict[channel]
        f_functions[idx, :] = full_model.calc_f(transfer_functions[idx])[-1]

    finalize(redshift, f_functions[channel_dict['Heat']],
             f_functions[channel_dict['Ly-A']],
             f_functions[channel_dict['H-Ion']],
             f_functions[channel_dict['He-Ion']],
             f_functions[channel_dict['LowE']], **DarkOptions)