Commit e6f5876a4993ab1f206ae66d3d26ec5d8d4a6e01

Authored by Thomas Fitoussi
1 parent 374f3d52
Exists in master

Map: convolution of the results from mono-directional source

-> source isotrop
   -> gaussian
Analysis.py
... ... @@ -6,7 +6,7 @@ from Modules.Spectrum import drawSpectrum, drawSpectrum_normaLepton
6 6 from Modules.Angle import drawAngle, drawRadial
7 7 from Modules.Timing import drawTiming
8 8 from Modules.Generation import drawGeneration
9   -from Modules.Map import drawMap, drawMapHisto
  9 +from Modules.Map import drawMap
10 10  
11 11 def error(error_type):
12 12 print error_type
... ... @@ -43,9 +43,6 @@ elif argv[1] == "timing":
43 43 elif argv[1] == "generation":
44 44 drawGeneration(argv[2:])
45 45  
46   -elif argv[1] == "maphisto":
47   - drawMapHisto(argv[2:])
48   -
49 46 elif argv[1] == "map":
50 47 drawMap(argv[2:])
51 48  
... ...
Modules/Angle.py
... ... @@ -83,6 +83,8 @@ def radial(fileName):
83 83 thetacenter=(angle[1:nbBins+1]+angle[0:nbBins])/2
84 84 dtheta=angle[1:nbBins+1]-angle[0:nbBins]
85 85 dndtheta2=dn/dtheta
  86 + maxflux = ReadNphot_source(fileName)
  87 + dndtheta2 /= maxflux
86 88  
87 89 return thetacenter, dndtheta2
88 90  
... ... @@ -92,8 +94,7 @@ def drawRadial(files):
92 94  
93 95 for fileId in files:
94 96 theta,dndtheta2=radial(fileId)
95   - Nmax=ReadNphot_source(fileId) # Nb photons emitted by the source
96   - ax.plot(theta,dndtheta2/Nmax,drawstyle='steps-mid',label=fileId)
  97 + ax.plot(theta,dndtheta2,drawstyle='steps-mid',label=fileId)
97 98  
98 99 ax.legend(loc="best",title="%3d - %3d GeV"%(Eliminf,Elimsup))
99 100 ax.set_yscale('log')
... ...
Modules/Angle.pyc
No preview for this file type
Modules/Map.py
1   -from numpy import shape, pi
2   -from matplotlib.pyplot import figure, show
  1 +from numpy import shape, pi, histogram2d, arange, newaxis, exp, log, array
  2 +from scipy.signal import convolve2d
  3 +from matplotlib.pyplot import figure, show, matshow
3 4 from matplotlib.colors import LogNorm
4 5 from Read import ReadEnergy, ReadWeight, ReadMomentumAngle, ReadPositionAngle, ReadNphot_source
5 6 from Read import ReadD_source, Readz_source, ReadEGMF
6 7 from Constants import degre
7 8  
8   -Elim=1e-1 # GeV
9   -borne=5 # degree
10   -nbBins = 100
  9 +thetalim = 180
  10 +philim = 90
  11 +step = 1 #deg
  12 +nbBins = array([int(2*philim/step)+1,int(2*thetalim/step)+1])
  13 +philim=float(philim)
  14 +thetalim=float(thetalim)
  15 +limits = [[-thetalim,thetalim],[-philim,philim]]
11 16  
12   -def thetaphi(fileId):
  17 +def thetaphi(fileId,Elim=0.1):
13 18 energy = ReadEnergy(fileId)
14 19 weight = ReadWeight(fileId)
15 20 thetaDir,phiDir = ReadMomentumAngle(fileId)*degre
16 21 thetaPos,phiPos = ReadPositionAngle(fileId)*degre
  22 + Nmax=ReadNphot_source(fileId) # Nb photons emitted by the source
17 23  
18 24 theta = thetaDir - thetaPos
19 25 phi = phiDir -phiPos
20 26  
21   - cond=(energy>Elim) & (abs(theta)<borne) & (abs(phi)<borne)
  27 + cond=(energy>Elim) & (abs(theta)<thetalim) & (abs(phi)<philim)
22 28 energy = energy[cond]
23   - weight=weight[cond]
  29 + weight=weight[cond]/Nmax
24 30 theta=theta[cond]
25 31 phi=phi[cond]
26 32  
27 33 print "file", fileId, "->", shape(energy)[0], "events"
28 34 return energy, theta, phi, weight
29 35  
30   -def drawMap(files):
31   - print "Cut at", Elim, "GeV"
32   - fig = figure()
33   - nbplots = len(files)
  36 +def isotrop():
  37 + return array([[1]])
34 38  
35   - ind=1
36   - for fileId in files:
37   - energy, theta, phi, weight = thetaphi(fileId)
  39 +def Gaussian2D(center=[0,0],fwhm=0.01):
  40 + x = arange(-thetalim,thetalim+step,step)
  41 + y = arange(-philim,philim+step,step)
  42 + y = y[:,newaxis]
  43 + return exp(-4*log(2) * ((x-center[0])**2 + (y+center[1])**2) / fwhm**2)
38 44  
39   - ax = fig.add_subplot(100+nbplots*10+ind)
40   -
41   - Emax = max(energy)
42   - Emin = min(energy)
43   - colors = energy/Emax
44   - area = pi * (15 * colors)**2 +15
45   - sax = ax.scatter(theta, phi, c=colors, s=area, alpha=0.3, marker='o')
46   -
47   - if Emin < 1e-3:
48   - liminf = "%.0f"%(Emin*1e6)+"keV"
49   - elif Emin < 1:
50   - liminf = "%.0f"%(Emin*1e3)+"MeV"
51   - else:
52   - liminf = "%.0f"%(Emin)+"GeV"
53   - limsup = "%.0f"%(Emax*1e-3)+"TeV"
54   - cbar = fig.colorbar(sax, ticks=[0.01,1])
55   - cbar.ax.set_yticklabels([liminf,limsup])
56   -
57   - ax.set_xlim((-borne,borne))
58   - ax.set_ylim((-borne,borne))
59   - ax.set_xlabel("$\\theta$ [deg]")
60   - ax.set_ylabel("$\\phi$ [deg]")
61   - zsource=Readz_source(fileId)
62   - Dsource=ReadD_source(fileId)
63   - EGMF=ReadEGMF(fileId)
64   - ax.set_title("source at %.0f"%Dsource+"Mpc (z=%.4f"%zsource+"): EGMF="+str(EGMF)+" Gauss" )
65   -
66   - ind=ind+1
67   -
68   - show()
69   -
70   -def drawMapHisto(files):
  45 +def drawMap(files,Elim=0.1,source=isotrop(),borne=[180,90]):
71 46 print "Cut at", Elim, "GeV"
72 47 fig = figure()
73 48 nbplots = len(files)
74 49  
75 50 ind=1
76 51 for fileId in files:
77   - energy, theta, phi, weight = thetaphi(fileId)
78   - Nmax=ReadNphot_source(fileId) # Nb photons emitted by the source
  52 + energy, theta, phi, weight = thetaphi(fileId,Elim)
  53 +
  54 + H,xedges,yedges = histogram2d(phi,theta,nbBins,weights=weight,range=limits)
  55 + conv=convolve2d(H,source,boundary="wrap",mode="same")
79 56  
80 57 ax = fig.add_subplot(100+nbplots*10+ind)
81   - H,xedges,yedges,im = ax.hist2d(theta,phi,nbBins,range=[[-borne,borne],[-borne,borne]],weights=weight/Nmax,norm=LogNorm())
82   - extent = [yedges[0], yedges[-1], xedges[0], xedges[-1]]
  58 + im = ax.matshow(conv,norm=LogNorm(),aspect='auto',
  59 + extent=[xedges[0],xedges[-1],yedges[0],yedges[-1]])
  60 + #H,xedges,yedges,im = ax.hist2d(theta,phi,nbBins,weights=weight,norm=LogNorm())
83 61 cbar=fig.colorbar(im, ax=ax)
84 62 cbar.ax.set_ylabel("counts normalize to 1 photon emitted")
85   - ax.set_xlim((-borne,borne))
86   - ax.set_ylim((-borne,borne))
  63 + ax.set_xlim((-borne[0],borne[0]))
  64 + ax.set_ylim((-borne[1],borne[1]))
87 65 ax.set_xlabel("$\\theta$ [deg]")
88 66 ax.set_ylabel("$\\phi$ [deg]")
  67 + ax.grid(b=True,which='major')
89 68 zsource=Readz_source(fileId)
90 69 Dsource=ReadD_source(fileId)
91 70 EGMF=ReadEGMF(fileId)
... ... @@ -94,3 +73,43 @@ def drawMapHisto(files):
94 73 ind=ind+1
95 74  
96 75 show()
  76 +
  77 +#def drawMap(files):
  78 +# print "Cut at", Elim, "GeV"
  79 +# fig = figure()
  80 +# nbplots = len(files)
  81 +#
  82 +# ind=1
  83 +# for fileId in files:
  84 +# energy, theta, phi, weight = thetaphi(fileId)
  85 +#
  86 +# ax = fig.add_subplot(100+nbplots*10+ind)
  87 +#
  88 +# Emax = max(energy)
  89 +# Emin = min(energy)
  90 +# colors = energy/Emax
  91 +# area = pi * (15 * colors)**2 +15
  92 +# sax = ax.scatter(theta, phi, c=colors, s=area, alpha=0.3, marker='o')
  93 +#
  94 +# if Emin < 1e-3:
  95 +# liminf = "%.0f"%(Emin*1e6)+"keV"
  96 +# elif Emin < 1:
  97 +# liminf = "%.0f"%(Emin*1e3)+"MeV"
  98 +# else:
  99 +# liminf = "%.0f"%(Emin)+"GeV"
  100 +# limsup = "%.0f"%(Emax*1e-3)+"TeV"
  101 +# cbar = fig.colorbar(sax, ticks=[0.01,1])
  102 +# cbar.ax.set_yticklabels([liminf,limsup])
  103 +#
  104 +# ax.set_xlim((-borne,borne))
  105 +# ax.set_ylim((-borne,borne))
  106 +# ax.set_xlabel("$\\theta$ [deg]")
  107 +# ax.set_ylabel("$\\phi$ [deg]")
  108 +# zsource=Readz_source(fileId)
  109 +# Dsource=ReadD_source(fileId)
  110 +# EGMF=ReadEGMF(fileId)
  111 +# ax.set_title("source at %.0f"%Dsource+"Mpc (z=%.4f"%zsource+"): EGMF="+str(EGMF)+" Gauss" )
  112 +#
  113 +# ind=ind+1
  114 +#
  115 +# show()
... ...
Modules/Map.pyc
No preview for this file type
Modules/Spectrum.py
... ... @@ -47,7 +47,7 @@ def drawSpectrum(files,PlotElmag=False,PlotAnalytic=False):
47 47 ax.plot(energy,flux,"--",color=p[0].get_color(),label="Elmag - "+fileId)
48 48  
49 49 if PlotAnalytic:
50   - alpha=5e3
  50 + alpha=2.8e3
51 51 ax.plot(energy,alpha*sqrt(energy),'--m',linewidth=2)
52 52 ax.plot(energy,energy**(0)*max(flux),'--m',linewidth=2)
53 53 ax.axvline(x=Ethreshold_gg(), ymin=0., ymax = 1., color='r', linewidth=2)
... ...
Modules/Spectrum.pyc
No preview for this file type
Modules/Timing.py
... ... @@ -9,7 +9,7 @@ def timing(fileName):
9 9 time=ReadTime(fileName)
10 10 weight=ReadWeight(fileName)
11 11 prop = float(shape(time[time<0])[0])/shape(time)[0]
12   - print "file", fileName, "->", shape(time)[0], "events", "negative time:", shape(time[time<0]), "~", prop
  12 + print "file", fileName, "->", shape(time)[0], "events", "negative time:", shape(time[time<0])[0], "~", prop
13 13  
14 14 time=time[time>0]
15 15 weight=weight[time>0]
... ... @@ -17,13 +17,15 @@ def timing(fileName):
17 17 nbBins = 100
18 18 zSource = Readz_source(fileName)
19 19 tlim = quad(comobileTime,zSource,0)[0]/yr
20   - time=log10(time/tlim)
  20 + time = log10(time/tlim)
21 21  
22 22 dN,dt=histogram(time,nbBins,weights=weight)
23 23 timecenter=(dt[1:nbBins+1]+dt[0:nbBins])/2
24 24 binSize=dt[1:nbBins+1]-dt[0:nbBins]
25 25 Nmax=ReadNphot_source(fileName) # Nb photons emitted by the source
26 26 dNdt=dN/(Nmax*binSize)
  27 + maxflux = ReadNphot_source(fileName)
  28 + dNdt /= maxflux
27 29  
28 30 return timecenter, dNdt
29 31  
... ...
Modules/Timing.pyc
No preview for this file type