def runTest(self):

        outputFile = tempfile.NamedTemporaryFile()

        sim = crp.ModuleList()

        # photon fields
        CMB = crp.CMB()
        IRB = crp.IRB_Kneiske04()

        sim.add(crp.SimplePropagation(1 * crp.kpc, 1 * crp.Mpc))
        sim.add(crp.Redshift())
        sim.add(crp.PhotoPionProduction(CMB))
        sim.add(crp.PhotoPionProduction(IRB))
        sim.add(crp.PhotoDisintegration(CMB))
        sim.add(crp.PhotoDisintegration(IRB))
        sim.add(crp.NuclearDecay())
        sim.add(crp.ElectronPairProduction(CMB))
        sim.add(crp.ElectronPairProduction(IRB))
        sim.add(crp.MinimumEnergy(1 * crp.EeV))
        sim.add(crp.EMCascade())

        # observer
        obs = crp.Observer()
        obs.add(crp.ObserverPoint())
        sim.add(obs)

        # output
        output = crp.TextOutput(outputFile.name)
        output.set1D(True)
        obs.onDetection(output)

        # source
        source = crp.Source()
        source.add(crp.SourceUniform1D(1 * crp.Mpc, 1000 * crp.Mpc))
        source.add(crp.SourceRedshift1D())

        # power law spectrum with charge dependent maximum energy Z*100 EeV
        # elements: H, He, N, Fe with equal abundances at constant energy per
        # nucleon
        composition = crp.SourceComposition(1 * crp.EeV, 100 * crp.EeV, -1)
        composition.add(1,  1,  1)  # H
        composition.add(4,  2,  1)  # He-4
        composition.add(14, 7,  1)  # N-14
        composition.add(56, 26, 1)  # Fe-56
        source.add(composition)

        # run simulation
        sim.run(source, 1)

        outputFile.close()
Exemplo n.º 2
0
 def testDisablingOfKwargs(self):
     with self.assertRaises(
             Exception,
             msg=
             "This is likely due to a swig bug. Please try to disable the builtin option by compiling crpropa with cmake .. -DENABLE_SWIG_BUILTIN=OFF"
     ):
         p = crp.PhotoDisintegration(photonField=crp.IRB_Dominguez11)
Exemplo n.º 3
0
 def testExceptionOnNonExistingArguemnt(self):
     with self.assertRaises(
             Exception,
             msg=
             "This is likely due to a swig bug. Please try to disable the builtin option by compiling crpropa with cmake .. -DENABLE_SWIG_BUILTIN=OFF"
     ):
         p = crp.PhotoDisintegration(
             nonExistingKeywordArguemntShouldRaiseException=True)
Exemplo n.º 4
0
pid = -crp.nucleusId(1, 1)
sun = crp.Vector3d(-8.5, 0, 0) * crp.kpc

E = E * crp.EeV
nhat = hp.dir2vec(lon, lat, lonlat=True)
direc = crp.Vector3d()
direc.setXYZ(nhat[0], nhat[1], nhat[2])

ps = crp.ParticleState(pid, E, sun, direc)
cr = crp.Candidate(ps)
sim = crp.ModuleList()
sim.add(crp.Redshift())
sim.add(crp.PhotoPionProduction(crp.CMB))
sim.add(crp.PhotoPionProduction(crp.IRB))
sim.add(crp.PhotoDisintegration(crp.CMB))
sim.add(crp.PhotoDisintegration(crp.IRB))
sim.add(crp.NuclearDecay())
sim.add(crp.ElectronPairProduction(crp.CMB))
sim.add(crp.ElectronPairProduction(crp.IRB))
np.random.seed(s1)
p1 = ss.truncnorm.rvs(a1, b1, 18.25, 2.75, size=1)[0]
p2 = ss.truncnorm.rvs(a2, b2, 0.2, 0.12, size=1)[0]
p3 = ss.truncnorm.rvs(a3, b3, 10.97, 3.80, size=1)[0]
p4 = ss.truncnorm.rvs(a4, b4, 2.84, 1.30, size=1)[0]
Bfield = crp.JF12Field(s1, p1, p2, p3, p4)
Bfield.randomStriated(s2)
Bfield.randomTurbulent(s3)
sim.add(crp.PropagationCK(Bfield, 1e-8, 0.5 * crp.parsec, 15 * crp.parsec))
sim.add(crp.SphericalBoundary(crp.Vector3d(0), 20 * crp.kpc))
sim.run(cr)