def plot_spectral_models(self): for component in self.get_components(tags=['pwn', 'composite']): fig, ax = plt.subplots() table = component['table'] tag = component['tag'] vals = [] idx = 0 energies = Energy.equal_log_spacing(emin=0.02, emax=100, unit='TeV', nbins=40) for row in table: idx += 1 if (idx < 100): spec = LogParabola( amplitude=row['spec_norm'] * u.Unit('MeV-1 s-1 cm-2'), alpha=row['spec_alpha'], reference=1 * u.TeV, beta=row['spec_beta'], ) fluxes = [] e2dnde = [] for energy in energies: dnde = spec.evaluate( energy=energy, amplitude=row['spec_norm'] * u.Unit('MeV-1 s-1 cm-2'), alpha=row['spec_alpha'], reference=1 * u.TeV, beta=row['spec_beta'], ) fluxes.append(dnde.value) e2dnde.append( ((energy**2 * dnde).to('erg cm-2 s-1')).value) ax.plot(energies.value, e2dnde, color='black', alpha=0.2, lw=2) else: break ax.set_title('{} spectra'.format(component['tag'])) ax.loglog() ax.set_xlabel('Energy (TeV)') ax.set_ylabel('e2dnde (erg cm-2 s-1)') ax.set_ylim(2e-18, 5e-10) fig.tight_layout() filename = 'ctadc_skymodel_gps_sources_spectra_{}.png'.format( component['tag']) log.info('Writing {}'.format(filename)) fig.savefig(filename) plt.close(fig)
neb_model = LogParabola(amplitude=amplitude, reference=reference, alpha=alphapar, beta=beta) ###MAGIC HESSII elif spectype == 'ExponentialCutoffPowerLaw': neb_model = ExponentialCutoffPowerLaw(index=index, amplitude=amplitude, reference=reference, lambda_=lambda_) ## HESS elif spectype == 'PowerLaw': neb_model = PowerLaw(index=index, amplitude=amplitude, reference=reference) ### HEGRA else: raise ValueError('Spectra Model must be either "LogParabola", "PowerLaw", or "ExponentialCutoffPowerLaw"') energy_array = np.linspace(emin.value, emax.value, 300) * u.TeV flare_plus_neb_model = np.zeros(len(energy_array)) * u.Unit('cm-2 s-1 TeV-1') for i in range(len(energy_array)): flare_plus_neb_model.value[i] = (neb_model.evaluate(energy_array[i], amplitude=amplitude, reference=reference, alpha=alphapar, beta=beta).value + flare_model.evaluate(energy_array[i], index = flare_index, amplitude = flare_amplitude, reference = flare_reference,lambda_ = lambda_flare).value) * 1e11 #print flare_plus_neb_model sum_model = TableModel(energy_array,flare_plus_neb_model,scale=1.0e-11) # No EBL model needed target = Target(name='Crab', model=sum_model) #events = np.zeros(N_simul) * u.ct cnts_specs = [] # Simulation t_start = time.clock()