def test_AddThermalTargetPhotons(self): fr = gp.Radiation() t = 2.7 e_dens = 0.25*gp.eV_to_erg fr.AddThermalTargetPhotons(2.7,0.25*gp.eV_to_erg) g_1 = np.array(fr.GetTargetPhotons()) g_2 = self.grey_body(g_1[:,0],t,e_dens) dg = np.sqrt(np.sum((g_2-g_1[:,1])**2)) / np.sum(g_2) self.assertTrue(dg < 1e-4)
def test_ImportTargetPhotonsFromFile(self): fr = gp.Radiation() t = 2.7 e_dens = 0.25*gp.eV_to_erg fr.AddThermalTargetPhotons(2.7,0.25*gp.eV_to_erg,1000) g_a = np.array(fr.GetTargetPhotons(0)) self.write_grey_body(g_a[:,0],t,e_dens) fr.ImportTargetPhotonsFromFile("rad_temp.dat") g_2 = self.grey_body(g_a[:,0],t,e_dens) # print g_2 g_b = np.array(fr.GetTargetPhotons(1)) g_1 = np.interp(g_a[:,0],g_b[:,0],g_b[:,1]) dg = np.sqrt(np.sum((g_2-g_1)**2)) / np.sum(g_2) self.assertTrue(dg < 1e-4)
def particle_spectrum_start(tmin, tmax, p_spectrum, lt0, lt1, b0, b1, emax0, emax1, r0, r1, v0, v1, dens, Tfir, Ufir, Tnir, Unir): """ GAMERA computation of the particle spectrum (for the first two time bins) http://libgamera.github.io/GAMERA/docs/time_dependent_modeling.html Procedure to do at the first two time steps in the calculation of the PWN Radius (seems that GAMERA needs at least three time steps to solve the advective equation) Returns ------- sed : array-like Array with the evolved particle spectrum (erg/cm**2/s vs TeV) at the last step energy : float Total particle energy content (in erg) """ t = np.linspace(tmin, tmax, 3) b = np.linspace(b0, b1, 3) lt = np.linspace(lt0, lt1, 3) emax = np.linspace(emax0, emax1, 3) r = np.linspace(r0, r1, 3) v = np.linspace(v0, v1, 3) fp = gp.Particles() fp.SetCustomInjectionSpectrum(p_spectrum) fp.SetLuminosity(list(zip(t, lt))) fp.SetBField(list(zip(t, b))) fp.SetEmax(list(zip(t, emax))) fp.SetRadius(list(zip(t, r))) fp.SetExpansionVelocity(list(zip(t, v))) fp.SetAmbientDensity(dens) fp.AddThermalTargetPhotons(2.7, 0.25 * gp.eV_to_erg) #CMB fp.AddThermalTargetPhotons(Tfir, Ufir) #FIR photon field fp.AddThermalTargetPhotons(Tnir, Unir) #NIR photon field fp.SetTmin(tmin) erad = np.logspace( -21, 4., 250 ) * gp.TeV_to_erg # energies(in ergs) where radiation will be calculated fr = gp.Radiation() fr.AddThermalTargetPhotons(2.7, 0.25 * gp.eV_to_erg) #CMB fr.AddThermalTargetPhotons(Tfir, Ufir) #FIR photon field fr.AddThermalTargetPhotons(Tnir, Unir) #NIR photon field fr.SetAmbientDensity(dens) fp.SetAge(tmax) fp.ToggleQuietMode() fp.CalculateElectronSpectrum() sed = np.array(fp.GetParticleSED()) energy = fp.GetParticleEnergyContent() * gp.TeV_to_erg return sed, energy
def particle_spectrum(tmin, tmax, tt, p_spectrum, lt, b, emax, r, v, dens, Tfir, Ufir, Tnir, Unir, no_escape): """ GAMERA computation of the particle spectrum http://libgamera.github.io/GAMERA/docs/time_dependent_modeling.html Procedure to do at each time step in the calculation of the PWN Radius Returns ------- sed : array-like Array with the evolved particle spectrum (erg/cm**2/s vs TeV) at the last step energy : float Total particle energy content (in erg) """ fp = gp.Particles() t = tt[tt <= tmax] fp.SetCustomInjectionSpectrum(p_spectrum) if no_escape == False: e = np.logspace(np.log10(gp.m_e), np.log10(3 * np.max(emax)), 100) #particle escape t_m, e_m = np.meshgrid(t, e) #particle escape fp.SetTimeAndEnergyDependentEscapeTime(t, e, t_esc(e_m, t_m, b, r)) #particle escape fp.SetLuminosity(list(zip(t, lt))) fp.SetBField(list(zip(t, b))) fp.SetEmax(list(zip(t, emax))) fp.SetRadius(list(zip(t, r))) fp.SetExpansionVelocity(list(zip(t, v))) fp.SetAmbientDensity(dens) fp.AddThermalTargetPhotons(2.7, 0.25 * gp.eV_to_erg) #CMB fp.AddThermalTargetPhotons(Tfir, Ufir) #FIR photon field fp.AddThermalTargetPhotons(Tnir, Unir) #NIR photon field fp.SetTmin(tmin) erad = np.logspace( -21, 4., 250 ) * gp.TeV_to_erg # energies(in ergs) where radiation will be calculated fr = gp.Radiation() fr.AddThermalTargetPhotons(2.7, 0.25 * gp.eV_to_erg) #CMB fr.AddThermalTargetPhotons(Tfir, Ufir) #FIR photon field fr.AddThermalTargetPhotons(Tnir, Unir) #NIR photon field fr.SetAmbientDensity(dens) fp.SetAge(tmax) fp.ToggleQuietMode() fp.CalculateElectronSpectrum() sed = np.array(fp.GetParticleSED()) energy = fp.GetParticleEnergyContent() * gp.TeV_to_erg return sed, energy
def test_AddArbitraryTargetPhotons(self): fr = gp.Radiation() t = 2.7 e_dens = 0.25*gp.eV_to_erg fr.AddThermalTargetPhotons(2.7,0.25*gp.eV_to_erg) g_a = np.array(fr.GetTargetPhotons(0)) g_2 = self.grey_body(g_a[:,0],t,e_dens) fr.AddArbitraryTargetPhotons(list(zip(g_a[:,0],g_2))) g_b = np.array(fr.GetTargetPhotons(1)) g_1 = np.interp(g_a[:,0],g_b[:,0],g_b[:,1]) dg = np.sqrt(np.sum((g_2-g_1)**2)) / np.sum(g_2) self.assertTrue(dg < 1e-4)
configParser = ConfigParser.RawConfigParser() configParser.read(configFile) lum = float(configParser.get('Parameters', 'Luminosity')) age = float(configParser.get('Parameters', 'Age')) dist = float(configParser.get('Parameters', 'Distance')) dens = float(configParser.get('Parameters', 'AmbientDensity')) bfield = float(configParser.get('Parameters', 'BField')) t = float(configParser.get('Parameters', 'tRAD')) e = gp.eV_to_erg * float(configParser.get('Parameters', 'edensRAD')) ebins = float(configParser.get('Parameters', 'Ebins')) emax = gp.TeV_to_erg * float(configParser.get('Parameters', 'Emax')) emin = gp.TeV_to_erg * float(configParser.get('Parameters', 'Emin')) spind = float(configParser.get('Parameters', 'SpectralIndex')) outfile = configParser.get('Files', 'outfile') fr = gp.Radiation() fp = gp.Particles() fu = gp.Utils() fu.DrawGamera() # set particle stuff fp.SetLuminosity(lum) fp.SetBField(bfield) fp.SetEmax(emax) fp.SetEmin(emin) fp.SetSpectralIndex(spind) fp.SetEnergyBins(ebins) fp.SetAmbientDensity(dens) fp.SetAge(age) # set radiation stuff fr.SetDistance(dist)
def final_spectrum(t, age, LT, B, EMAX, R, V, dens, dist, Tfir, Ufir, Tnir, Unir, binss, tmin, ebreak, alpha1, alpha2, no_escape): """ GAMERA computation of the particle spectrum (for the extraction of the photon sed at the end of the evolution of the PWN) http://libgamera.github.io/GAMERA/docs/time_dependent_modeling.html Returns ------- sed : array-like Array with the evolved particle spectrum (erg/cm**2/s vs TeV) at the last step tot : array-like Array with the total photon spectrum (erg/cm**2/s vs TeV) ic : array-like Array with the inverse compton photon spectrum (erg/cm**2/s vs TeV) ic : array-like Array with the inverse compton contribution to the total photon spectrum (erg/cm**2/s vs TeV) ic_cmb : array-like Array with the cmb inverse compton contribution to the total photon spectrum (erg/cm**2/s vs TeV) ic_fir : array-like Array with the fir inverse compton contribution to the total photon spectrum (erg/cm**2/s vs TeV) ic_nir : array-like Array with the nir inverse compton contribution to the total photon spectrum (erg/cm**2/s vs TeV) ic_ssc : array-like Array with the self-synchrotron compton contribution to the total photon spectrum (erg/cm**2/s vs TeV) ic_synch : array-like Array with the synchrotron contribution to the total photon spectrum (erg/cm**2/s vs TeV) """ fp = gp.Particles() p_spectrum = broken_powerlaw(ebreak,alpha1,alpha2,EMAX, 500) if no_escape == False: e = np.logspace(np.log10(gp.m_e),np.log10(3*np.max(EMAX)),100) #particle escape t_m, e_m = np.meshgrid(t, e) #particle escape fp.SetTimeAndEnergyDependentEscapeTime(t, e, t_esc(e_m, t_m, B, R)) #particle escape fp.SetCustomInjectionSpectrum(p_spectrum) fp.SetLuminosity(list(zip(t,LT))) fp.SetBField(list(zip(t,B))) fp.SetEmax(list(zip(t,EMAX))) fp.SetRadius(list(zip(t,R))) fp.SetExpansionVelocity(list(zip(t,V))) fp.SetAmbientDensity(dens) fp.AddThermalTargetPhotons(2.7,0.25*gp.eV_to_erg) fp.AddThermalTargetPhotons(Tfir, Ufir) fp.AddThermalTargetPhotons(Tnir, Unir) fp.SetTmin(tmin) erad = np.logspace(-2,4.,binss) * gp.TeV_to_erg # energies(in ergs) where radiation will be calculated fr = gp.Radiation() fr.SetDistance(dist) fr.AddThermalTargetPhotons(2.7,0.25*gp.eV_to_erg) fr.AddThermalTargetPhotons(Tfir, Ufir) fr.AddThermalTargetPhotons(Tnir, Unir) fr.SetAmbientDensity(dens) fp.SetAge(age) fp.ToggleQuietMode() fp.CalculateElectronSpectrum(binss) sed = np.array(fp.GetParticleSED()) sp = np.array(fp.GetParticleSpectrum()) fr.SetElectrons(sp[:]) fr.SetBField(fp.GetBField()) fr.AddSSCTargetPhotons(fp.GetRadius()) fr.ToggleQuietMode() fr.CalculateDifferentialPhotonSpectrum(erad) tot = np.array(fr.GetTotalSED()) return sed, tot