Commit f5a7501927b775d30ec58a0d27b8b508657e8aec

Authored by Thomas Fitoussi
1 parent a44230b7
Exists in master

Rewrite Analysis.py :

> only one power law spectrum index
   > compute results gen by gen and by energy range when it makes sense
   > add observables.py to plot 3D space of arrival parameters (E, dt, theta)
.gitignore 0 โ†’ 100644
... ... @@ -0,0 +1,2 @@
  1 +*.pyc
  2 +*.swp
... ...
Analysis.py
... ... @@ -10,21 +10,18 @@ from Modules.Angle import angle_vs_energy, radial
10 10 from Modules.Timing import timing
11 11 from Modules.Constants import degre
12 12  
13   -def InProgress(i,Nmax):
14   - print " ", (i*100)/Nmax, "% done"
15   -
16 13 if shape(argv)[0] < 2:
17 14 print "not enough arguments (at least 1)"
18 15 exit()
19 16  
20   -PowerSpectrum=[1,1.5,2,2.5]
  17 +powerlaw_index=2
21 18  
22 19 for fileId in argv[1:]:
23   - print "#=============================================================================#"
24   - print "# Analysis of", fileId
25   - print "#=============================================================================#"
  20 + print "#===============================================#"
  21 + print "# Analysis of", fileId
  22 + print "#===============================================#"
26 23 # read files
27   - print "# 1. Reading data"
  24 + print " > Reading data"
28 25 time = ReadTime(fileId)
29 26 energy = ReadEnergy(fileId)
30 27 weightini, generation, theta_arrival, Esource, dir_source = ReadExtraFile(fileId,[2,3,4,5,6])
... ... @@ -39,228 +36,135 @@ for fileId in argv[1:]:
39 36 theta = thetaDir - thetaPos
40 37 phi = phiDir -phiPos
41 38  
42   - Gen_contrib = []
43   - Gen_cont = zeros((int(max(generation))+1))
44   - Source = []
45   - Spectrum = []
46   - Timing = []
47   - Angle_Energy = []
48   - Radial = []
49   -
50   - print "# 2. Computing powerlaw spectrum"
51   - #=============================================================================#
52   - # VERSUS SOURCE SPECTRUM
53   - #=============================================================================#
54   - for powerlaw_index in PowerSpectrum:
55   - # apply source spectrum
56   - weight_source = (Esource/min(Esource))**(1-powerlaw_index)
57   - weight = weightini* weight_source
58   -
59   - # GENERATION CONTRIBUTION ====================================================#
60   - NbTotEvents = sum(weight)
61   - if Gen_contrib==[]:
62   - Gen_contrib = arange(0,max(generation)+1,1)[:,newaxis]
63   -
64   - for gen in list(set(generation)):
65   - Gen_cont[int(gen)] = sum(weight[generation==gen])/NbTotEvents *100
66   - Gen_contrib = append(Gen_contrib,Gen_cont[:,newaxis],axis=1)
67   -
68   - # SPECTRUM (SOURCE AND MEASURED) ============================================#
69   - nbBins = 100
70   - # draw source spectrum
71   - Es=array(list(set(Esource)))
72   - Ws= (Es/min(Es))**(1-powerlaw_index) / ratio
73   - Es,Fs = spectrum(Es,Ws,nbBins=nbBins)
74   - Es=Es[:,newaxis]
75   - Fs=Fs[:,newaxis]
76   - if Source==[]:
77   - Source = Es
78   - Source = append(Source,Fs,axis=1)
79   - else:
80   - Source = append(Source,Fs,axis=1)
81   -
82   - # primary gamma-rays contribution and full spectrum
83   - ener,flux,flux_0 = spectrum(energy,weight,generation,nbBins)
84   - ener=ener[:,newaxis]
85   - flux=flux[:,newaxis]
86   - flux_0=flux_0[:,newaxis]
87   - if Spectrum==[]:
88   - Spectrum = ener
89   - Spectrum = append(Spectrum,flux,axis=1)
90   - Spectrum = append(Spectrum,flux_0,axis=1)
91   - else:
92   - Spectrum = append(Spectrum,flux,axis=1)
93   - Spectrum = append(Spectrum,flux_0,axis=1)
94   -
95   - # IMAGING, RADIAL DISTRIBUTION AND ANGLE VERSUS ENERGY ======================#
96   - nbBins = 50
97   - cond = energy>1e-3
98   - ener,angle = angle_vs_energy(theta_arrival[cond],energy[cond],weight[cond],nbBins)
99   - theta2,dndtheta2 = radial(theta[cond],weight[cond],nbBins)
100   - theta2=theta2[:,newaxis]
101   - dndtheta2=dndtheta2[:,newaxis]
102   - ener=ener[:,newaxis]
103   - angle=angle[:,newaxis]
104   -
105   - if Radial==[]:
106   - Radial = theta2
107   - Radial = append(Radial,dndtheta2,axis=1)
108   - Angle_Energy = ener
109   - Angle_Energy = append(Angle_Energy,angle,axis=1)
110   - else:
111   - Radial = append(Radial,dndtheta2,axis=1)
112   - Angle_Energy = append(Angle_Energy,angle,axis=1)
113   -
114   -
115   - # TIME DISTRIBUTION AND TIME DELAY VERSUS ANGLE =============================#
116   - nbBins = 100
117   - delta_t,dNdt = timing(time,weight,nbBins)
118   - delta_t=delta_t[:,newaxis]
119   - dNdt=dNdt[:,newaxis]
120   - if Timing==[]:
121   - Timing = delta_t
122   - Timing = append(Timing,dNdt,axis=1)
123   - else:
124   - Timing = append(Timing,dNdt,axis=1)
125   -
126   - InProgress(PowerSpectrum.index(powerlaw_index)+1,shape(PowerSpectrum)[0])
  39 + powerlaw_index = 2
127 40  
128 41 #=============================================================================#
129   - # VERSUS JET OPENING ANGLE
  42 + # NO SELECTION
130 43 #=============================================================================#
131   - Jet_Opening=[180,60,30] # degre (180 <=> isotrop)
132   - powerlaw_index = 2
133   - Elim = 1e-1 # GeV
134   - thetalim = 20 # degre
135   -
136   - # apply source spectrum
  44 + print " > No selection of events ..."
  45 + # SPECTRUM (SOURCE) =========================================================#
137 46 weight_source = (Esource/min(Esource))**(1-powerlaw_index)
138 47 weight = weightini* weight_source
139   -
140   - print "# 3. compute images and radial distribution"
141   - for jet_opening_angle in Jet_Opening:
142   - # apply selection ( /!\ USE DECREASING VALUES OF jet_opening_angle )
143   - cond = (dir_source*degre <= jet_opening_angle) #& (energy>Elim) #& (abs(theta)<thetalim) & (abs(phi)<thetalim)
144   - dir_source = dir_source[cond]
145   - theta_arrival = theta_arrival[cond]
146   - theta = theta[cond]
147   - phi = phi[cond]
148   - weight = weight[cond]
149   - energy = energy[cond]
150   - time = time[cond]
151   - generation = generation[cond]
152   -
153   - # GENERATION CONTRIBUTION ====================================================#
154   - NbTotEvents = sum(weight)
155   - if Gen_contrib==[]:
156   - Gen_contrib = arange(0,max(generation)+1,1)[:,newaxis]
157   -
158   - for gen in list(set(generation)):
159   - Gen_cont[int(gen)] = sum(weight[generation==gen])/NbTotEvents *100
160   - Gen_contrib = append(Gen_contrib,Gen_cont[:,newaxis],axis=1)
161   -
162   - # SPECTRUM (SOURCE AND MEASURED) ============================================#
163   - nbBins = 100
164   - # draw source spectrum
165   - Es=array(list(set(Esource)))
166   - Ws= (Es/min(Es))**(1-powerlaw_index) / ratio
167   - Es,Fs = spectrum(Es,Ws,nbBins=nbBins)
168   - Es=Es[:,newaxis]
169   - Fs=Fs[:,newaxis]
170   - if Source==[]:
171   - Source = Es
172   - Source = append(Source,Fs,axis=1)
173   - else:
174   - Source = append(Source,Fs,axis=1)
175   -
176   - # primary gamma-rays contribution and full spectrum
177   - ener,flux,flux_0 = spectrum(energy,weight,generation,nbBins)
178   - ener=ener[:,newaxis]
179   - flux=flux[:,newaxis]
180   - flux_0=flux_0[:,newaxis]
181   - if Spectrum==[]:
182   - Spectrum = ener
183   - Spectrum = append(Spectrum,flux,axis=1)
184   - Spectrum = append(Spectrum,flux_0,axis=1)
185   - else:
186   - Spectrum = append(Spectrum,flux,axis=1)
187   - Spectrum = append(Spectrum,flux_0,axis=1)
188   -
189   - # IMAGING, RADIAL DISTRIBUTION AND ANGLE VERSUS ENERGY ======================#
190   - nbBins = 50
191   - computeMap(theta,phi,weight,energy,fileId,jet_opening_angle,nbBins,borne=[thetalim,thetalim])
192   - ener,angle = angle_vs_energy(theta_arrival,energy,weight,nbBins)
193   - theta2,dndtheta2 = radial(theta_arrival,weight,nbBins)
194   - theta2=theta2[:,newaxis]
195   - dndtheta2=dndtheta2[:,newaxis]
196   - ener=ener[:,newaxis]
197   - angle=angle[:,newaxis]
198   -
199   - if Radial==[]:
200   - Radial = theta2
201   - Radial = append(Radial,dndtheta2,axis=1)
202   - Angle_Energy = ener
203   - Angle_Energy = append(Angle_Energy,angle,axis=1)
204   - else:
205   - Radial = append(Radial,dndtheta2,axis=1)
206   - Angle_Energy = append(Angle_Energy,angle,axis=1)
207   -
208   - # TIME DISTRIBUTION AND TIME DELAY VERSUS ANGLE =============================#
209   - nbBins = 100
210   - delta_t,dNdt = timing(time,weight,nbBins)
211   - delta_t=delta_t[:,newaxis]
212   - dNdt=dNdt[:,newaxis]
213   - Timing = append(Timing,dNdt,axis=1)
214   -
215   - InProgress(Jet_Opening.index(jet_opening_angle)+1,shape(Jet_Opening)[0])
  48 + nbBins = 100
  49 + Es=array(list(set(Esource)))
  50 + Ws= (Es/min(Es))**(1-powerlaw_index) / ratio
  51 + Es,Fs = spectrum(Es,Ws,nbBins=nbBins)
  52 + Es=Es[:,newaxis]
  53 + Fs=Fs[:,newaxis]
  54 + Source = Es
  55 + Source = append(Source,Fs,axis=1)
  56 +
  57 + # IMAGING ===================================================================#
  58 + print " ... Computing image"
  59 + nbBins = 50
  60 + thetalim = 20
  61 + computeMap(theta,phi,weight,energy,fileId,nbBins,borne=[thetalim,thetalim])
  62 +
  63 + # SPECTRUM (MEASURED) =======================================================#
  64 + print " ... Computing spectrum"
  65 + nbBins = 100
  66 + ener,flux = spectrum(energy,weight,nbBins)
  67 + ener=ener[:,newaxis]
  68 + flux=flux[:,newaxis]
  69 + Spectrum = ener
  70 + Spectrum = append(Spectrum,flux,axis=1)
  71 +
  72 + # ANGLE VERSUS ENERGY =======================================================#
  73 + print " ... Computing arrival angle versus energy"
  74 + nbBins = 100
  75 + ener,angle = angle_vs_energy(theta_arrival,energy,weight,nbBins)
  76 + ener=ener[:,newaxis]
  77 + angle=angle[:,newaxis]
  78 + Angle_Energy = ener
  79 + Angle_Energy = append(Angle_Energy,angle,axis=1)
  80 +
  81 + # RADIAL ====================================================================#
  82 + print " ... Computing radial distribution"
  83 + nbBins = 100
  84 + theta2,dndtheta = radial(theta,weight,nbBins)
  85 + theta2=theta2[:,newaxis]
  86 + dndtheta=dndtheta[:,newaxis]
  87 + Radial = theta2
  88 + Radial = append(Radial,dndtheta,axis=1)
  89 +
  90 + # TIME DISTRIBUTION AND TIME DELAY VERSUS ANGLE =============================#
  91 + print " ... Computing time distribution"
  92 + nbBins = 100
  93 + delta_t,dNdt = timing(time,weight,nbBins)
  94 + delta_t=delta_t[:,newaxis]
  95 + dNdt=dNdt[:,newaxis]
  96 + Timing = delta_t
  97 + Timing = append(Timing,dNdt,axis=1)
216 98  
217 99 #=============================================================================#
218 100 # BY ENERGY RANGE
219 101 #=============================================================================#
220   - print "# 3. By energy range"
221   - powerlaw_index = 2
222   - weight_source = (Esource/min(Esource))**(1-powerlaw_index)
223   - weight = weightini* weight_source
224   -
  102 + print " > Selection by energy range ..."
225 103 Emin = [1e-3,1e0,1e3] #GeV
226 104 Emax = [1e0,1e3,1e5] #GeV
  105 +
227 106 for n in arange(0,3,1):
228 107 cond= (energy>Emin[n]) & (energy<Emax[n])
229 108  
230   - # TIME DISTRIBUTION AND TIME DELAY VERSUS ANGLE =============================#
  109 + # RADIAL =================================================================#
  110 + nbBins = 100
  111 + theta2,dndtheta = radial(theta[cond],weight[cond],nbBins)
  112 + dndtheta=dndtheta[:,newaxis]
  113 + Radial = append(Radial,dndtheta,axis=1)
  114 +
  115 + # TIME DISTRIBUTION AND TIME DELAY VERSUS ANGLE ==========================#
231 116 nbBins = 100
232 117 delta_t,dNdt = timing(time[cond],weight[cond],nbBins)
233   - delta_t=delta_t[:,newaxis]
234 118 dNdt=dNdt[:,newaxis]
235 119 Timing = append(Timing,dNdt,axis=1)
236 120  
  121 + print " ... ", ((n+1)*100)/3,"% done"
  122 +
237 123 #=============================================================================#
238 124 # BY GENERATION
239 125 #=============================================================================#
240   - print "# 3. By generation"
  126 + print " > Selection by generation ..."
  127 + NbTotEvents = sum(weight)
241 128 gen_tab =list(set(generation))
242   - powerlaw_index = 2
243   - weight_source = (Esource/min(Esource))**(1-powerlaw_index)
244   - weight = weightini* weight_source
245   -
  129 + Gen_cont = zeros([shape(gen_tab)[0],2])
246 130 for gen in gen_tab:
247 131 cond = generation==gen
248   - print shape(time[cond])
  132 + contrib =sum(weight[cond])/NbTotEvents*100
  133 + i = gen_tab.index(gen)
  134 + Gen_cont[i,0]=int(gen)
  135 + Gen_cont[i,1]=contrib
  136 + print " ... gen=",int(gen),"-> contribution:",int(contrib),"%"
  137 +
  138 + # SPECTRUM (MEASURED) ====================================================#
  139 + nbBins = 100
  140 + ener,flux = spectrum(energy[cond],weight[cond],nbBins)
  141 + flux=flux[:,newaxis]
  142 + Spectrum = append(Spectrum,flux,axis=1)
249 143  
250   - # TIME DISTRIBUTION AND TIME DELAY VERSUS ANGLE =============================#
  144 + # ANGLE VERSUS ENERGY ====================================================#
  145 + nbBins = 100
  146 + ener,angle = angle_vs_energy(theta_arrival[cond],energy[cond],weight[cond],nbBins)
  147 + angle=angle[:,newaxis]
  148 + Angle_Energy = append(Angle_Energy,angle,axis=1)
  149 +
  150 + # RADIAL =================================================================#
  151 + nbBins = 100
  152 + theta2,dndtheta = radial(theta[cond],weight[cond],nbBins)
  153 + dndtheta=dndtheta[:,newaxis]
  154 + Radial = append(Radial,dndtheta,axis=1)
  155 +
  156 + # TIME DISTRIBUTION AND TIME DELAY VERSUS ANGLE ==========================#
251 157 nbBins = 100
252 158 delta_t,dNdt = timing(time[cond],weight[cond],nbBins)
253   - delta_t=delta_t[:,newaxis]
254 159 dNdt=dNdt[:,newaxis]
255 160 Timing = append(Timing,dNdt,axis=1)
256 161  
257 162 #=============================================================================#
258   - print "# 4. writing files"
259   - savetxt(resultDirectory+fileId+"/Generation.txt",Gen_contrib)
  163 + print " > writing files"
260 164 savetxt(resultDirectory+fileId+"/Spectrum.txt",Spectrum)
261 165 savetxt(resultDirectory+fileId+"/Source_spectrum.txt",Source)
262 166 savetxt(resultDirectory+fileId+"/Angle_vs_Energy.txt",Angle_Energy)
263 167 savetxt(resultDirectory+fileId+"/Radial_distribution.txt",Radial)
264 168 savetxt(resultDirectory+fileId+"/Timing.txt",Timing)
265   - print "#=============================================================================#"
266   -
  169 + savetxt(resultDirectory+fileId+"/Generation.txt",Gen_cont)
  170 + print "#===============================================#"
... ...
EBL-spectrums.py
... ... @@ -58,7 +58,7 @@ ax.plot(hv,nCMB(hv,z)*hv**2,&quot;-k&quot;,label=&quot;CMB&quot;)
58 58 ax.set_xscale('log')
59 59 ax.set_yscale('log')
60 60 ax.grid(b=True,which='major')
61   -ax.legend(loc="best",frameon=False,framealpha=0.5)
  61 +ax.legend(loc="best")#,frameon=False,framealpha=0.5)
62 62 ax.set_xlabel("energy [eV]")
63 63 ax.set_ylabel("$n$ [photon.eV.cm$^{-3}$]")
64 64  
... ... @@ -80,7 +80,7 @@ for z_index in [1,9,12,15,17]:
80 80 ax2.set_xscale('log')
81 81 ax2.set_yscale('log')
82 82 ax2.grid(b=True,which='major')
83   -ax2.legend(loc="best",frameon=False,framealpha=0.5)
  83 +ax2.legend(loc="best")#,frameon=False,framealpha=0.5)
84 84 ax2.set_xlabel("energy [eV]")
85 85 ax2.set_ylabel("$n$ [photon.eV.cm$^{-3}$]")
86 86  
... ...
Modules/Analytic.pyc deleted
No preview for this file type
Modules/Angle.py
1   -from numpy import log10, histogram
  1 +from numpy import log10, histogram, arange
2 2 from matplotlib.pyplot import figure, show
3 3 from matplotlib import gridspec
4   -from Read import ReadRadial, ReadAngleVsEnergy
  4 +from Read import ReadRadial, ReadAngleVsEnergy, ReadGeneration
5 5 from Analytic import Analytic_theta
6 6 from Constants import degre
7 7  
... ... @@ -21,7 +21,7 @@ def angle_vs_energy(theta,energy,weight,nbBins=50):
21 21 return enercenter, angle
22 22  
23 23 def radial(theta,weight,nbBins=50):
24   - cond = theta!=0
  24 + cond = theta>0
25 25 theta = log10(theta[cond])
26 26 weight = weight[cond]
27 27 dn,angle2 = histogram(theta,nbBins,range=[log10(1e-3),log10(25)],weights=weight)
... ... @@ -35,7 +35,7 @@ def radial(theta,weight,nbBins=50):
35 35  
36 36 return thetacenter, dndtheta
37 37  
38   -def drawRadial(files,all_source_spectrum=False,all_jets=False):
  38 +def drawRadial(files,plot_gen=False,plot_energy_range=False):
39 39 '''
40 40 Plot flux versus arrival angle
41 41 Input: list of directories
... ... @@ -45,21 +45,24 @@ def drawRadial(files,all_source_spectrum=False,all_jets=False):
45 45 ax = fig.add_subplot(111)
46 46  
47 47 for fileId in files:
48   - if all_source_spectrum:
49   - i=1
50   - for powerlaw_index in [1,1.5,2,2.5]:
  48 + theta,dndtheta2 = ReadRadial(fileId,[0,1])
  49 + ax.plot(theta,dndtheta2,drawstyle='steps-mid')
  50 +
  51 + if plot_energy_range:
  52 + labels = ["MeV band","GeV band","TeV band"]
  53 + i = 2
  54 + for n in arange(0,3,1):
51 55 theta,dndtheta2 = ReadRadial(fileId,[0,i])
52   - ax.plot(theta,dndtheta2,drawstyle='steps-mid',label="p=%.1f"%powerlaw_index)
  56 + ax.plot(theta,dndtheta2,drawstyle='steps-mid',label=labels[n])
53 57 i+=1
54   - elif all_jets:
  58 +
  59 + if plot_gen:
  60 + generation = ReadGeneration(fileId,[0])
55 61 i=5
56   - for jet_opening in ["isotrop","60 deg","30 deg"]:
  62 + for gen in generation:
57 63 theta,dndtheta2 = ReadRadial(fileId,[0,i])
58   - ax.plot(theta,dndtheta2,drawstyle='steps-mid',label=jet_opening)
  64 + ax.plot(theta,dndtheta2,drawstyle='steps-mid',label="gen=%.0f"%gen)
59 65 i+=1
60   - else:
61   - theta,dndtheta2 = ReadRadial(fileId,[0,5])
62   - ax.plot(theta,dndtheta2,drawstyle='steps-mid',label=fileId)
63 66  
64 67 ax.legend(loc="best")
65 68 ax.set_xscale('log')
... ... @@ -70,7 +73,7 @@ def drawRadial(files,all_source_spectrum=False,all_jets=False):
70 73  
71 74 show()
72 75  
73   -def drawAngle_vs_energy(files,all_source_spectrum=False,all_jets=False,PlotAnalytic=False):
  76 +def drawAngle_vs_energy(files,plot_gen=False,plot_analytic=False):
74 77 '''
75 78 Plot arrival angle versus energy + analytic expression
76 79 Input: list of directories
... ... @@ -80,21 +83,18 @@ def drawAngle_vs_energy(files,all_source_spectrum=False,all_jets=False,PlotAnaly
80 83 ax1 = fig.add_subplot(111)
81 84  
82 85 for fileId in files:
83   - if all_source_spectrum:
84   - i=1
85   - for powerlaw_index in [1,1.5,2,2.5]:
86   - ener,angle = ReadAngleVsEnergy(fileId,[0,i])
87   - p=ax1.plot(ener,angle,drawstyle='steps-mid',label="p=%.1f"%powerlaw_index)
88   - elif all_jets:
89   - i=5
90   - for jet_opening in ["isotrop","60 deg","30 deg"]:
  86 + ener,angle = ReadAngleVsEnergy(fileId,[0,1])
  87 + p=ax1.plot(ener,angle,drawstyle='steps-mid')
  88 +
  89 + if plot_gen:
  90 + generation = ReadGeneration(fileId,[0])
  91 + i=2
  92 + for gen in generation:
91 93 ener,angle = ReadAngleVsEnergy(fileId,[0,i])
92   - p=ax1.plot(ener,angle,drawstyle='steps-mid',label=jet_opening)
93   - else:
94   - ener,angle = ReadAngleVsEnergy(fileId,[0,1])
95   - p=ax1.plot(ener,angle,drawstyle='steps-mid',label=fileId)
  94 + ax1.plot(ener,angle,drawstyle='steps-mid',label="gen=%.0f"%gen)
  95 + i+=1
96 96  
97   - if PlotAnalytic:
  97 + if plot_analytic:
98 98 yfit = Analytic_theta(ener,fileId)
99 99 ax1.plot(ener,yfit,'--',color=p[0].get_color(),linewidth=2)
100 100  
... ...
Modules/Angle.pyc deleted
No preview for this file type
Modules/Constants.pyc deleted
No preview for this file type
Modules/Generation.pyc deleted
No preview for this file type
Modules/Integrand.pyc deleted
No preview for this file type
Modules/Map.py
... ... @@ -15,7 +15,7 @@ philim=float(philim)
15 15 thetalim=float(thetalim)
16 16 limits = [[-thetalim,thetalim],[-philim,philim]]
17 17  
18   -def computeMap(theta,phi,weight,energy,saveId,jet_opening_angle=180,nbBins=50,borne=[180,180]):
  18 +def computeMap(theta,phi,weight,energy,saveId,nbBins=50,borne=[180,180]):
19 19 '''
20 20 Plot 2D histogram of arrival direction of the photons with energy upper than Elim
21 21 Input: list of directories
... ... @@ -41,12 +41,8 @@ def computeMap(theta,phi,weight,energy,saveId,jet_opening_angle=180,nbBins=50,bo
41 41 ax.set_xlabel("$\\theta$ $\\cos(\\phi)$ [deg]")
42 42 ax.set_ylabel("$\\theta$ $\\sin(\\phi)$ [deg]")
43 43 ax.grid(b=True,which='major')
44   - if jet_opening_angle == 180:
45   - ax.set_title(saveId+" - isotrop")
46   - savefig(resultDirectory+saveId+"/map_isotrop.png")
47   - else:
48   - ax.set_title(saveId+" - jet opening angle: %d degre"%(int(jet_opening_angle)))
49   - savefig(resultDirectory+saveId+"/map_"+str(int(jet_opening_angle))+".png")
  44 + ax.set_title(saveId+" - isotrop")
  45 + savefig(resultDirectory+saveId+"/map_isotrop.png")
50 46  
51 47 #def isotrop():
52 48 # return array([[1]]), "isotropic"
... ...
Modules/Map.pyc deleted
No preview for this file type
Modules/Observables.py 0 โ†’ 100644
... ... @@ -0,0 +1,56 @@
  1 +from numpy import sort, log10
  2 +from matplotlib.pyplot import figure, show
  3 +from mpl_toolkits.mplot3d import Axes3D
  4 +from Modules.Read import ReadEnergy, ReadTime, ReadExtraFile
  5 +from Modules.Constants import degre
  6 +
  7 +def drawObservablesSpace(fileId):
  8 + fig = figure()
  9 + ax = fig.add_subplot(232,projection='3d')
  10 + ax1 = fig.add_subplot(233)
  11 + ax2 = fig.add_subplot(231)
  12 + ax3 = fig.add_subplot(235)
  13 +
  14 + energy = ReadEnergy(fileId)
  15 + delay = ReadTime(fileId)
  16 + generation, theta = ReadExtraFile(fileId,[3,4])
  17 + theta*=degre
  18 +
  19 + colors=['b','g','r','m','c','y']
  20 + i=0
  21 +
  22 + for gen in sort(list(set(generation))):
  23 + cond = (generation==gen) & (delay>0) & (theta>0)
  24 + ax.scatter(log10(energy[cond]),log10(theta[cond]),log10(delay[cond]),color=colors[i],label="gen = %.0f"%gen)
  25 + ax1.scatter(energy[cond],delay[cond],color=colors[i])
  26 + ax2.scatter(theta[cond],delay[cond],color=colors[i])
  27 + ax3.scatter(theta[cond],energy[cond],color=colors[i])
  28 + i+=1
  29 +
  30 + ax.legend(loc="best")
  31 + #ax.set_xscale('log')
  32 + #ax.set_yscale('log')
  33 + #ax.set_zscale('log')
  34 + ax.set_xlabel("energy [GeV]")
  35 + ax.set_ylabel("$\\theta$ [deg]")
  36 + ax.set_zlabel("Time delay [s]")
  37 +
  38 + ax1.grid(b=True,which='major')
  39 + ax1.set_xscale('log')
  40 + ax1.set_yscale('log')
  41 + ax1.set_xlabel("energy [GeV]")
  42 + ax1.set_ylabel("Time delay [s]")
  43 +
  44 + ax2.grid(b=True,which='major')
  45 + ax2.set_xscale('log')
  46 + ax2.set_yscale('log')
  47 + ax2.set_xlabel("$\\theta$ [deg]")
  48 + ax2.set_ylabel("Time delay [s]")
  49 +
  50 + ax3.grid(b=True,which='major')
  51 + ax3.set_xscale('log')
  52 + ax3.set_yscale('log')
  53 + ax3.set_xlabel("$\\theta$ [deg]")
  54 + ax3.set_ylabel("energy [GeV]")
  55 +
  56 + show()
... ...
Modules/Read.py
... ... @@ -60,5 +60,5 @@ def ReadRadial(fileName,cols=[0,1,2,3,4]):
60 60 def ReadTiming(fileName,cols=[0,1,2,3,4]):
61 61 return loadtxt(resultDirectory+fileName+"/Timing.txt",unpack=True,usecols=cols)
62 62  
63   -def ReadGeneration(fileName,cols=[0,1,2,3,4]):
  63 +def ReadGeneration(fileName,cols=[0,1]):
64 64 return loadtxt(resultDirectory+fileName+"/Generation.txt",unpack=True,usecols=cols)
... ...
Modules/Read.pyc deleted
No preview for this file type
Modules/Spectrum.py
1 1 from numpy import histogram, log10, sqrt, array
2 2 from matplotlib.pyplot import figure, show, setp
3 3 from matplotlib import gridspec
4   -from Read import ReadSpectrum, ReadSourceSpectrum
  4 +from Read import ReadSpectrum, ReadSourceSpectrum, ReadGeneration
5 5 from Constants import degre
6   -from Analytic import Ethreshold_gg
  6 +from Analytic import Ethreshold_gg, Analytic_flux, Eic
7 7  
8   -def spectrum(energy,weight,generation=[],nbBins=100):
  8 +def spectrum(energy,weight,nbBins=100):
9 9 '''
10 10 Compute flux versus energy
11 11 Input: events energy and weight (optional: number of bins)
... ... @@ -19,20 +19,9 @@ def spectrum(energy,weight,generation=[],nbBins=100):
19 19 enercenter=(ener[1:nbBins+1]+ener[0:nbBins])/2
20 20 binSize=ener[1:nbBins+1]-ener[0:nbBins]
21 21 flux = enercenter**2 * flux/binSize
  22 + return enercenter,flux
22 23  
23   - if generation == []:
24   - return enercenter,flux
25   - else:
26   - cond=(generation==0)
27   - flux_0,ener_0=histogram(energy[cond],nbBins,range=[log10(Emin),log10(Emax)],weights=weight[cond])
28   - ener_0 = 10**ener_0
29   - enercenter_0=(ener_0[1:nbBins+1]+ener_0[0:nbBins])/2
30   - binSize=ener_0[1:nbBins+1]-ener_0[0:nbBins]
31   - flux_0 = enercenter_0**2 * flux_0/binSize
32   - return enercenter,flux,flux_0
33   -
34   -
35   -def drawSpectrum(files,all_source_spectrum=False,all_jets=False,PlotAnalytic=False):
  24 +def drawSpectrum(files,plot_gen=False,plot_source=False,plot_analytic=False):
36 25 '''
37 26 Plot flux versus energy
38 27 Input: list of directories
... ... @@ -47,59 +36,36 @@ def drawSpectrum(files,all_source_spectrum=False,all_jets=False,PlotAnalytic=Fal
47 36 ax1 = fig.add_subplot(111)
48 37  
49 38 for fileId in files:
50   - if all_source_spectrum:
51   - i=1
52   - j=1
53   - for powerlaw_index in [1,1.5,2,2.5]:
54   - # read files
55   - Es,Fs = ReadSourceSpectrum(fileId,[0,i])
56   - p = ax1.plot(Es,Fs,linestyle=':')
57   - # draw full spectrum
58   - ener,flux,flux_0 = ReadSpectrum(fileId,[0,j,j+1])
59   - ax1.plot(ener,flux,color=p[0].get_color(),drawstyle='steps-mid',label="p=%.1f"%powerlaw_index)
60   - # primary gamma-rays contribution
61   - #ax1.plot(ener,flux_0,color=p[0].get_color(),linestyle='--',drawstyle='steps-mid')
62   - #contrib=flux_0/flux
63   - #ax2.plot(ener,contrib,drawstyle='steps-mid',color=p[0].get_color())
64   - i+=1
65   - j+=2
66   - elif all_jets:
67   - i=5
68   - j=9
69   - for jet_opening in ["isotrop","60 deg","30 deg"]:
  39 + # draw full spectrum
  40 + ener,flux = ReadSpectrum(fileId,[0,1])
  41 + p = ax1.plot(ener,flux,drawstyle='steps-mid')
  42 +
  43 + if plot_gen:
  44 + generation = ReadGeneration(fileId,[0])
  45 + j=2
  46 + for gen in generation:
70 47 # read files
71   - Es,Fs = ReadSourceSpectrum(fileId,[0,i])
72   - p = ax1.plot(Es,Fs,linestyle=':')
73   - # draw full spectrum
74   - ener,flux,flux_0 = ReadSpectrum(fileId,[0,j,j+1])
75   - ax1.plot(ener,flux,color=p[0].get_color(),drawstyle='steps-mid',label=jet_opening)
76   - # primary gamma-rays contribution
77   - #ax1.plot(ener,flux_0,color=p[0].get_color(),linestyle='--',drawstyle='steps-mid')
78   - #contrib=flux_0/flux
79   - #ax2.plot(ener,contrib,drawstyle='steps-mid',color=p[0].get_color())
80   - i+=1
81   - j+=2
  48 + ener,flux = ReadSpectrum(fileId,[0,j])
  49 + ax1.plot(ener,flux,drawstyle='steps-mid',label="gen=%.0f"%gen)
  50 + j+=1
82 51  
83   - else:
84   - # read files
85   - #Es,Fs = ReadSourceSpectrum(fileId,[0,3])
86   - #p = ax1.plot(Es,Fs,linestyle=':')
87   - # draw full spectrum
88   - ener,flux,flux_0 = ReadSpectrum(fileId,[0,5,6])
89   - ax1.plot(ener,flux,drawstyle='steps-mid')
90   - #ax1.plot(ener,flux,color=p[0].get_color(),drawstyle='steps-mid',label=fileId)
91   - # primary gamma-rays contribution
92   - #ax1.plot(ener,flux_0,color=p[0].get_color(),linestyle='--',drawstyle='steps-mid')
93   - #contrib=flux_0/flux
94   - #ax2.plot(ener,contrib,drawstyle='steps-mid',color=p[0].get_color())
  52 + if plot_source:
  53 + Es,Fs = ReadSourceSpectrum(fileId,[0,1])
  54 + ax1.plot(Es,Fs,color=p[0].get_color(),linestyle=':')
95 55  
96   - if PlotAnalytic:
  56 + if plot_analytic:
97 57 minEner=min(ener)
98   - alpha=flux[ener==minEner]/sqrt(minEner)
99   - ax1.plot(ener,alpha*sqrt(ener),'--m',linewidth=2)
100   - ax1.plot(ener,ener**(0)*max(flux)*0.95,'--m',linewidth=2)
101   - ax1.axvline(x=Ethreshold_gg(), ymin=0., ymax = 1., color='r', linewidth=2)
102   - ax1.axvline(x=1e4, ymin=0., ymax = 1., color='g', linewidth=2)
  58 + #alpha=flux[ener==minEner]/sqrt(minEner)
  59 + #ax1.plot(ener,alpha*sqrt(ener/100),'.-g',linewidth=2)
  60 + ax1.plot(ener,2*Analytic_flux(ener),'--g',linewidth=1)
  61 + Elim= Eic(Ethreshold_gg()/2)
  62 + alpha = 2*4.63e3/Elim**(1/4.)
  63 + ax1.plot(ener,alpha*sqrt(ener),'--r',linewidth=1)
  64 + alpha = 2*14.6e3
  65 + ax1.plot(ener,alpha*(ener/100)**(1/4.),'--m',linewidth=1)
  66 + #ax1.plot(ener,ener**(0)*max(flux)*0.95,'--m',linewidth=2)
  67 + #ax1.axvline(x=Ethreshold_gg(), ymin=0., ymax = 1., color='r', linewidth=2)
  68 + #ax1.axvline(x=1e4, ymin=0., ymax = 1., color='g', linewidth=2)
103 69  
104 70 ax1.legend(loc="best")
105 71 ax1.set_xscale('log')
... ...
Modules/Spectrum.pyc deleted
No preview for this file type
Modules/Timing.py
1   -from numpy import histogram, log10, shape, arange, pi, convolve
  1 +from numpy import histogram, log10, shape, arange, pi, convolve, r_
2 2 from matplotlib.pyplot import figure, show
3   -from Read import ReadTime, ReadTiming, ReadExtraFile, ReadProfile, ReadEnergy
  3 +from Read import ReadTime, ReadTiming, ReadExtraFile, ReadProfile, ReadEnergy, ReadGeneration
4 4 from Constants import yr, degre
5 5 from Analytic import Analytic_delay_vs_theta
6 6  
... ... @@ -23,50 +23,35 @@ def timing(time,weight,nbBins=100):
23 23 binSize=dt[1:nbBins+1]-dt[0:nbBins]
24 24 dNdt=dN/binSize *timecenter
25 25  
26   - return timecenter, dNdt
  26 + return timecenter, dNdt#/max(dNdt)
27 27  
28   -def drawTiming(files,plot_case=0):
  28 +def drawTiming(files,plot_gen=False,plot_energy_range=False):
29 29 '''
30 30 Plot flux versus time delay
31 31 Input: list of directories
32   - plot_case: (0) nothing, (1) all source spectrum, (2) all jets, (3) by energy band,
33   - (4) by generation
34 32 Output: graph of flux versus time delay
35 33 '''
36 34 fig = figure()
37 35 ax = fig.add_subplot(111)
38 36 for fileId in files:
39   - if plot_case == 1:
40   - i=1
41   - for powerlaw_index in [1,1.5,2,2.5]:
42   - delta_t,dNdt = ReadTiming(fileId,[0,i])
43   - ax.plot(delta_t,dNdt,linestyle="steps-mid",label="p=%.1f"%powerlaw_index)
44   - i+=1
45   - elif plot_case == 2:
46   - i=5
47   - for jet_opening in ["isotrop","60 degre","30 degre"]:
48   - delta_t,dNdt = ReadTiming(fileId,[0,i])
49   - ax.plot(delta_t,dNdt,linestyle="steps-mid",label=jet_opening)
50   - i+=1
51   - elif plot_case == 3:
52   - i=8
53   - Emin = [1e-3,1e0,1e3] #GeV
54   - Emax = [1e0,1e3,1e5] #GeV
  37 + delta_t,dNdt = ReadTiming(fileId,[0,1])
  38 + p=ax.plot(delta_t,dNdt,linestyle="steps-mid")
  39 +
  40 + if plot_energy_range:
  41 + labels = ["MeV band","GeV band","TeV band"]
  42 + i = 2
55 43 for n in arange(0,3,1):
56   - label = "%1.0e Gev"%Emin[n]+"< $E_\\gamma$ < %1.0e Gev"%Emax[n]
57 44 delta_t,dNdt = ReadTiming(fileId,[0,i])
58   - ax.plot(delta_t,dNdt,linestyle="steps-mid",label=label)
  45 + ax.plot(delta_t,dNdt,linestyle="steps-mid",label=labels[n])
59 46 i+=1
60   - elif plot_case == 4:
61   - i=11
62   - generation = ReadExtraFile(fileId,[3])
63   - for gen in list(set(generation)):
  47 +
  48 + if plot_gen:
  49 + generation = ReadGeneration(fileId,[0])
  50 + i=5
  51 + for gen in generation:
64 52 delta_t,dNdt = ReadTiming(fileId,[0,i])
65 53 ax.plot(delta_t,dNdt,linestyle="steps-mid",label="gen=%.0f"%gen)
66 54 i+=1
67   - else:
68   - delta_t,dNdt = ReadTiming(fileId,[0,3])
69   - ax.plot(delta_t,dNdt,linestyle="steps-mid",label=fileId)
70 55  
71 56 ax.set_xscale('log')
72 57 ax.set_yscale('log')
... ... @@ -81,12 +66,19 @@ def drawConvolveTiming(files):
81 66 fig = figure()
82 67 ax = fig.add_subplot(111)
83 68 for fileId in files:
84   - delta_t,dNdt1 = ReadTiming(fileId,[0,8]) # MeV band
85   - delta_t,dNdt2 = ReadTiming(fileId,[0,9]) # GeV band
86   - delta_t,dNdt3 = ReadTiming(fileId,[0,10]) # TeV band
87   - ax.plot(delta_t,convolve(dNdt1,dNdt2,'same'),linestyle="steps-mid",label="MeV - GeV band")
88   - ax.plot(delta_t,convolve(dNdt2,dNdt3,'same'),linestyle="steps-mid",label="GeV - TeV band")
89   - ax.plot(delta_t,convolve(dNdt1,dNdt3,'same'),linestyle="steps-mid",label="MeV - TeV band")
  69 + delta_t,dNdt1 = ReadTiming(fileId,[0,2]) # MeV band
  70 + delta_t,dNdt2 = ReadTiming(fileId,[0,3]) # GeV band
  71 + delta_t,dNdt3 = ReadTiming(fileId,[0,4]) # TeV band
  72 + conv1 = convolve(dNdt1,dNdt2,'same')
  73 + conv2 = convolve(dNdt2,dNdt3,'same')
  74 + conv3 = convolve(dNdt1,dNdt3,'same')
  75 + ax.plot(delta_t,conv1/max(conv1),linestyle="steps-mid",label="MeV - GeV band")
  76 + ax.plot(delta_t,conv2/max(conv2),linestyle="steps-mid",label="GeV - TeV band")
  77 + ax.plot(delta_t,conv3/max(conv3),linestyle="steps-mid",label="MeV - TeV band")
  78 + print fileId, " ====================================="
  79 + print " MeV - GeV band: ",delta_t[r_[True, conv1[1:] > conv1[:-1]] & r_[conv1[:-1] > conv1[1:], True]]
  80 + print " GeV - TeV band: ",delta_t[r_[True, conv2[1:] > conv2[:-1]] & r_[conv2[:-1] > conv2[1:], True]]
  81 + print " MeV - TeV band: ",delta_t[r_[True, conv3[1:] > conv3[:-1]] & r_[conv3[:-1] > conv3[1:], True]]
90 82  
91 83 ax.set_xscale('log')
92 84 ax.set_yscale('log')
... ... @@ -117,21 +109,26 @@ def drawDelay_vs_angle(fileId):
117 109 ax = fig.add_subplot(111)
118 110 nbBins = 100
119 111  
120   - theta = ReadExtraFile(fileId,[4])*degre
  112 + generation, theta = ReadExtraFile(fileId,cols=[3,4])
  113 + theta *= degre
121 114 energy = ReadEnergy(fileId)
122 115 delay = ReadTime(fileId)
123 116  
124 117 Emin = [1e-3,1e0,1e3] #GeV
125 118 Emax = [1e0,1e3,1e5] #GeV
126   - for n in arange(0,3,1):
127   - cond= (energy>Emin[n]) & (energy<Emax[n])
128   - if Emin[n]==1e-3:
129   - label="MeV band"
130   - if Emin[n]==1e0:
131   - label="GeV band"
132   - if Emin[n]==1e3:
133   - label="TeV band"
134   - ax.plot(theta[cond],delay[cond],".",label=label)
  119 +
  120 + for gen in list(set(generation)):
  121 + cond = generation==gen
  122 + ax.plot(theta[cond],delay[cond],",",label="gen = %.0f"%gen)
  123 + #for n in arange(0,3,1):
  124 + # cond= (energy>Emin[n]) & (energy<Emax[n])
  125 + # if Emin[n]==1e-3:
  126 + # label="MeV band"
  127 + # if Emin[n]==1e0:
  128 + # label="GeV band"
  129 + # if Emin[n]==1e3:
  130 + # label="TeV band"
  131 + # ax.plot(theta[cond],delay[cond],".",label=label)
135 132  
136 133 dt,angle=delay_vs_theta(theta,delay,nbBins)
137 134 ax.plot(angle,dt,color='m',linestyle="steps-mid",linewidth=2)
... ...
Modules/Timing.pyc deleted
No preview for this file type
Modules/Weight.pyc deleted
No preview for this file type
Modules/__init__.py
... ... @@ -0,0 +1 @@
  1 +from Constants import *
... ...
Modules/__init__.pyc deleted
No preview for this file type
Results/.gitignore 0 โ†’ 100644
... ... @@ -0,0 +1,2 @@
  1 +*
  2 +!.gitignore
... ...
lambda_gg.py 0 โ†’ 100755
... ... @@ -0,0 +1,57 @@
  1 +#!/usr/bin/python
  2 +
  3 +from sys import argv
  4 +import matplotlib.pyplot as plt
  5 +from matplotlib import gridspec
  6 +from numpy import *
  7 +from scipy.integrate import quad
  8 +from Modules.Analytic import Ethreshold_gg
  9 +
  10 +c=2.99792458e10 # cm.s-1
  11 +Mpc=(3.0856776e+16)*1e8 # Mpc to cm
  12 +H0=67.8*1e5/(Mpc) # s-1
  13 +omegaM = 0.3
  14 +omegaK = 0
  15 +omegaL = 0.7
  16 +zlim=-0.
  17 +def properIntegrand(z):
  18 + return -c/(H0*(1+z)*sqrt(omegaM*(1+z)**3+omegaK*(1+z)**2+omegaL))
  19 +def comobileIntegrand(z):
  20 + return -c/(H0*sqrt(omegaM*(1+z)**3+omegaK*(1+z)**2+omegaL))
  21 +
  22 +color=['b','r','g','m','c','y']
  23 +
  24 +# Proper distance figure
  25 +#========================
  26 +fig1 = plt.figure()
  27 +ax11 = fig1.add_subplot(111)
  28 +
  29 +labels=["0","0.5","1","2","3"]
  30 +theory=[1,2,3,4,5]
  31 +ind=0
  32 +for lab in labels:
  33 + # theoritical curve ===================================================
  34 + # f: without cosmo
  35 + # g: with cosmo
  36 + e,f,g=loadtxt('lambda_e.dat',unpack=True,usecols=[0,int(theory[ind]),int(theory[ind])+5])
  37 + e = e*511.e3/1.e9 #GeV
  38 + cond= (e>100) & (e<1e5)
  39 + e=e[cond]
  40 + g=g[cond]
  41 + f=f[cond]
  42 + p = ax11.plot(e,g,"-"+color[ind],label="z = "+lab)
  43 + ax11.plot(e,f,color=p[0].get_color(),linestyle='--')
  44 +
  45 + ind=ind+1
  46 +
  47 +ax11.axvline(x=Ethreshold_gg(), ymin=0., ymax = 1., color='r', linewidth=2)
  48 +
  49 +ax11.legend(loc="best")
  50 +ax11.grid(b=True,which='major')
  51 +ax11.set_ylim([1e-4,1e4])
  52 +ax11.set_xscale('log')
  53 +ax11.set_yscale('log')
  54 +ax11.set_xlabel("energy [GeV]")
  55 +ax11.set_ylabel("$\lambda_{\gamma\gamma}$ [Mpc]")
  56 +
  57 +plt.show()
... ...