Blame view

Modules/Timing.py 1.33 KB
7030f150   Thomas Fitoussi   Full reorganisati...
1
2
3
from numpy import histogram, log10, shape
from matplotlib.pyplot import figure, show
from scipy.integrate import quad
8011cc96   Thomas Fitoussi   Add profile readi...
4
from Read import ReadTime, ReadWeight, Readz_source, ReadNphot_source
7030f150   Thomas Fitoussi   Full reorganisati...
5
6
7
8
9
10
11
from Constants import yr
from Integrand import comobileTime

def timing(fileName):
   time=ReadTime(fileName)
   weight=ReadWeight(fileName)
   prop = float(shape(time[time<0])[0])/shape(time)[0]
e6f5876a   Thomas Fitoussi   Map: convolution ...
12
   print "file", fileName, "->", shape(time)[0], "events", "negative time:", shape(time[time<0])[0], "~", prop
7030f150   Thomas Fitoussi   Full reorganisati...
13
14
15
16
17

   time=time[time>0]
   weight=weight[time>0]

   nbBins = 100
8011cc96   Thomas Fitoussi   Add profile readi...
18
   zSource = Readz_source(fileName)
7030f150   Thomas Fitoussi   Full reorganisati...
19
   tlim = quad(comobileTime,zSource,0)[0]/yr
e6f5876a   Thomas Fitoussi   Map: convolution ...
20
   time = log10(time/tlim)
7030f150   Thomas Fitoussi   Full reorganisati...
21
22
23
24

   dN,dt=histogram(time,nbBins,weights=weight)
   timecenter=(dt[1:nbBins+1]+dt[0:nbBins])/2
   binSize=dt[1:nbBins+1]-dt[0:nbBins]
8011cc96   Thomas Fitoussi   Add profile readi...
25
   Nmax=ReadNphot_source(fileName) # Nb photons emitted by the source
7030f150   Thomas Fitoussi   Full reorganisati...
26
   dNdt=dN/(Nmax*binSize)
e6f5876a   Thomas Fitoussi   Map: convolution ...
27
28
   maxflux = ReadNphot_source(fileName)
   dNdt /= maxflux
7030f150   Thomas Fitoussi   Full reorganisati...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

   return timecenter, dNdt

def drawTiming(files):
   fig = figure()
   ax = fig.add_subplot(111)
   for fileId in files:
      time,dNdt = timing(fileId) 
      ax.plot(time[dNdt!=0],dNdt[dNdt!=0],linestyle="steps-mid",label=fileId)

   ax.set_yscale('log')
   ax.grid(b=True,which='major')
   ax.legend(loc="best")
   ax.set_xlabel("Time [$\Delta t / t$ log scale]")
   ax.set_ylabel("$t\ dN/dt$")

   show()