コード例 #1
0
 def testPlotting(self):
     tm = GlobalAVGKappaTransferMatrix(20, 11, 5, self.constant5000Burstgen, 5.475, [5, 6])
     odir = tempfile.mkdtemp(suffix = "plottest")
     ofl = os.path.join(odir, "plot.png")
     tm.plotToFile(ofl)
     self.assertEqual(os.path.exists(ofl), True)
     shutil.rmtree(odir)
コード例 #2
0
 def testSamplesOutsideRange(self):
     R = numpy.linspace(4.95, 6.05, 22)
     kappa = [ 2. / 3 ] * 22
     weights = [ 1. ] * 22
     tm = DistanceAVGKappaTransferMatrix(20, 11, 200, self.constant5000Burstgen, 5.475, R, kappa, weights, RRange = (5., 6))
     tm.generateMatrix()
     self.assertEqual(tm.RRange[0], 5)
     self.assertEqual(tm.RRange[1], 6)
     self.assertAlmostEqual(tm.getMatrix()[9][5], 1., delta = 0.01)
     tmref = GlobalAVGKappaTransferMatrix(20, 11, 200, self.constant5000Burstgen, 5.475, (5, 6))
     self.assertMatrixAlmostEqual(tm.getMatrix() , tmref.getMatrix(), delta = 0.15)
コード例 #3
0
 def testDistanceAVGLocalKappavsGlobal(self):
     R = numpy.linspace(5.05, 5.95, 20)
     kappa = [ 2. / 3 ] * 20
     weights = [ 1. ] * 20
     tm = DistanceAVGKappaTransferMatrix(20, 11, 5000, self.constant5000Burstgen, 5.475, R, kappa, weights, RRange = (5, 6))
     tm.generateMatrix()
     self.assertEqual(tm.RRange[0], 5)
     self.assertEqual(tm.RRange[1], 6)
     self.assertAlmostEqual(tm.getMatrix()[9][5], 1., delta = 0.01)
     tmref = GlobalAVGKappaTransferMatrix(20, 11, 5000, self.constant5000Burstgen, 5.475, [5, 6])
     self.assertMatrixAlmostEqual(tm.getMatrix(), tmref.getMatrix(), delta = 0.05)
コード例 #4
0
 def testGlobalShotNoise(self):
     for sn, sng in ((5, self.constant5Burstgen), (50, self.constant50Burstgen), (500, self.constant500Burstgen), (5000, self.constant5000Burstgen)):
         tm = GlobalAVGKappaTransferMatrix(20, 11, 1000, sng, 5.475, (5, 6))
         tmx = tm.getMatrix()
         print "Burstsizes %d" % sn
         for _ in range(7):
             mbin = random.choice(range(20))
             binmid = generateBinMid(1, mbin, 20, 5)
             eff = rToEff(binmid, R0 = 5.475)
             print "Testing mbin %d at pos %f with efficiency %f" % (mbin, binmid, eff)
             shotnoise = getShotNoise(eff, 11, 1000, sn)
             tmxvec = tmx[mbin, :]
             tmxvec.shape = (11, 1)
             self.assertAlmostEqual((tmxvec - shotnoise).sum(), 0.0, delta = 0.005)
コード例 #5
0
 def testRandomUncorr(self):
     length = 100000
     startdist = 4
     enddist = 7
     rbins = 10
     ebins = 20
     bursts = 10000
     R0 = 5.475
     bgen = self.constant50Burstgen
     R = numpy.random.random(length) * (enddist - startdist) + startdist
     kappa2 = numpy.array(list(getKappa(genRandomVec(), genRandomVec(), genRandomVec()) ** 2 for _ in range(length)))
     print "Kappa^2 mean is ", kappa2.mean()
     R0mod = modifyR0(R0, kappa2.mean())
     prbs = numpy.ones(length)
     globaltm = GlobalAVGKappaTransferMatrix(rbins, ebins, bursts, bgen, R0mod, (startdist, enddist))
     localtm = DistanceAVGKappaTransferMatrix(rbins, ebins, bursts, bgen, R0, R, kappa2, prbs, RRange = (startdist, enddist))
     self.assertMatrixAlmostEqual(globaltm.getMatrix(), localtm.getMatrix(), delta = 0.10)
コード例 #6
0
 def testGlobal(self):
     tm = GlobalAVGKappaTransferMatrix(20, 11, 5, self.constant5000Burstgen, 5.475, (5, 6))
     self.assertEqual(tm.getMatrix().shape, (20, 11))
     self.assertEqual(tm.RRange[0], 5)
     self.assertEqual(tm.RRange[1], 6)
     self.assertEqual(tm.getMatrix()[9][5], 1.)