Blame view

Modules/Angle.py 2.67 KB
65135318   Thomas Fitoussi   Reset modules
1
2
from numpy import log10, histogram
from matplotlib.pyplot import figure, show
7030f150   Thomas Fitoussi   Full reorganisati...
3
from matplotlib import gridspec
074c1729   Thomas Fitoussi   Analysis.py used ...
4
from Read import ReadRadial, ReadAngleVsEnergy
7030f150   Thomas Fitoussi   Full reorganisati...
5
from Analytic import Analytic_theta
7030f150   Thomas Fitoussi   Full reorganisati...
6
7
8
9
10
from Constants import degre

Eliminf = 1e0 #GeV
Elimsup = 1e5 #GeV

65135318   Thomas Fitoussi   Reset modules
11
def angle_vs_energy(theta,energy,weight,nbPhotonsEmitted=1,nbBins=40):
f4246390   Thomas Fitoussi   Improve angular d...
12
13
14
15
16
   '''
      Compute arrival angle versus energy
      Input: directory name
      Output: energy, arrival angle
   '''
7030f150   Thomas Fitoussi   Full reorganisati...
17
   energy =log10(energy)
65135318   Thomas Fitoussi   Reset modules
18
   angle,ener =histogram(energy,nbBins,weights=weight*theta)
f4246390   Thomas Fitoussi   Improve angular d...
19
   nb,ener =histogram(energy,nbBins,weights=weight)
7030f150   Thomas Fitoussi   Full reorganisati...
20
21
   ener = 10**ener
   enercenter=(ener[1:nbBins+1]+ener[0:nbBins])/2
65135318   Thomas Fitoussi   Reset modules
22
   angle /= nb * nbPhotonsEmitted
7030f150   Thomas Fitoussi   Full reorganisati...
23
24
25

   return enercenter, angle

074c1729   Thomas Fitoussi   Analysis.py used ...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def radial(theta,weight,nbPhotonsEmitted=1,nbBins=50,thetamax=90):
   '''
      Compute flux versus arrival angle
      Input: directory name
      Input (optionnal): maximal angle desired (by default full sky)
      Output: arrival angle, flux (dn/dtheta)
   '''

   theta=log10(theta)
   dn,angle = histogram(theta,nbBins,range=[log10(1e-6),log10(thetamax)],weights=weight)
   angle=10**angle
   thetacenter = (angle[1:nbBins+1]+angle[0:nbBins])/2
   dtheta = angle[1:nbBins+1]-angle[0:nbBins]
   dndtheta = dn/dtheta*thetacenter
   dndtheta /= nbPhotonsEmitted

   return thetacenter, dndtheta

65135318   Thomas Fitoussi   Reset modules
44
def drawAngle_vs_energy(files):
f4246390   Thomas Fitoussi   Improve angular d...
45
46
47
48
49
   '''
      Plot arrival angle versus energy + analytic expression
      Input: list of directories
      Output: graph of arrival angle versus energy
   '''
7030f150   Thomas Fitoussi   Full reorganisati...
50
   fig = figure()
65135318   Thomas Fitoussi   Reset modules
51
   ax1 = fig.add_subplot(111)
7030f150   Thomas Fitoussi   Full reorganisati...
52
53

   for fileId in files:
074c1729   Thomas Fitoussi   Analysis.py used ...
54
55
56
57
58
      i=1
      for powerlaw_index in [1,1.5,2,2.5]: 
         # apply source spectrum
         ener,angle = ReadAngleVsEnergy(fileId,[0,i])
         p=ax1.plot(ener,angle,'-',label="p=%.1f"%powerlaw_index)
65135318   Thomas Fitoussi   Reset modules
59
60
61

      yfit = Analytic_theta(ener,fileId)
      ax1.plot(ener,yfit,'--',color="m",linewidth=2,label="analytic")
7030f150   Thomas Fitoussi   Full reorganisati...
62
63
64
65
66
67

   ax1.legend(loc="best")
   ax1.set_xscale('log')
   ax1.set_yscale('log')
   ax1.set_ylim([0,180])
   ax1.grid(b=True,which='major')
65135318   Thomas Fitoussi   Reset modules
68
69
   ax1.set_ylabel("$\\theta$ [rad]")
   ax1.set_xlabel("energy [GeV]")
7030f150   Thomas Fitoussi   Full reorganisati...
70
71
72

   show()

074c1729   Thomas Fitoussi   Analysis.py used ...
73
def drawRadial(files):
f4246390   Thomas Fitoussi   Improve angular d...
74
75
76
   '''
      Plot flux versus arrival angle
      Input: list of directories
f4246390   Thomas Fitoussi   Improve angular d...
77
78
      Output: graph of flux versus angle
   '''
7030f150   Thomas Fitoussi   Full reorganisati...
79
80
81
82
   fig = figure()
   ax = fig.add_subplot(111)

   for fileId in files:
074c1729   Thomas Fitoussi   Analysis.py used ...
83
84
85
      i=1
      for powerlaw_index in [1,1.5,2,2.5]: 
         theta,dndtheta2 = ReadRadial(fileId,[0,i])
65135318   Thomas Fitoussi   Reset modules
86
         ax.plot(theta,dndtheta2,drawstyle='steps-mid',label="p=%.1f"%powerlaw_index)
7030f150   Thomas Fitoussi   Full reorganisati...
87

f4246390   Thomas Fitoussi   Improve angular d...
88
89
   ax.legend(loc="best")
   ax.set_xscale('log')
7030f150   Thomas Fitoussi   Full reorganisati...
90
91
   ax.set_yscale('log')
   ax.grid(b=True,which='major')
65135318   Thomas Fitoussi   Reset modules
92
93
   ax.set_xlabel("$\\theta$ [rad]")
   ax.set_ylabel("$\\theta*dN/d\\theta$")
7030f150   Thomas Fitoussi   Full reorganisati...
94
95
   
   show()