Commit 49a0fe942494fb53065d7e98f23c24c248dae50f
1 parent
6633967c
Exists in
master
Add direct printing of the maps in Analysis.py
Showing
7 changed files
with
91 additions
and
86 deletions
Show diff stats
Analysis.py
... | ... | @@ -3,12 +3,15 @@ |
3 | 3 | from sys import argv |
4 | 4 | from numpy import append, savetxt, shape, array, newaxis, zeros, arange |
5 | 5 | from Modules.Read import ReadEnergy, ReadTime, ReadExtraFile, ReadProfile |
6 | +from Modules.Read import ReadMomentumAngle, ReadPositionAngle, resultDirectory | |
6 | 7 | from Modules.Spectrum import spectrum |
8 | +from Modules.Map import printMap, isotrop | |
7 | 9 | from Modules.Angle import radial, angle_vs_energy |
8 | 10 | from Modules.Timing import timing |
11 | +from Modules.Constants import degre | |
9 | 12 | |
10 | -def InProgress(fileId,i,Nmax): | |
11 | - print "Work on ", fileId, ": ", (i*100)/Nmax, "% done" | |
13 | +def InProgress(fileId,step,i,Nmax): | |
14 | + print "Work on ", fileId, "(step "+ step +": ", (i*100)/Nmax, "% done" | |
12 | 15 | |
13 | 16 | if shape(argv)[0] < 2: |
14 | 17 | print "not enough arguments (at least 1)" |
... | ... | @@ -17,8 +20,10 @@ if shape(argv)[0] < 2: |
17 | 20 | #================================================================# |
18 | 21 | # Parameters |
19 | 22 | #================================================================# |
20 | -folder = "Results/" | |
21 | 23 | PowerSpectrum=[1,1.5,2,2.5] |
24 | +powerlaw_index = 2 | |
25 | +Elim = 1e-1 # GeV | |
26 | +thetalim = 20 # degre | |
22 | 27 | |
23 | 28 | for fileId in argv[1:]: |
24 | 29 | # read files |
... | ... | @@ -27,16 +32,24 @@ for fileId in argv[1:]: |
27 | 32 | weightini, generation, theta_arrival, Esource = ReadExtraFile(fileId,[2,3,4,5]) |
28 | 33 | nbPhotonsEmitted=ReadProfile(fileId,[3]) |
29 | 34 | |
30 | - lim =100000 | |
31 | - time=time[:lim] | |
32 | - energy=energy[:lim] | |
33 | - weightini=weightini[:lim] | |
34 | - generation = generation[:lim] | |
35 | - theta_arrival = theta_arrival[:lim] | |
36 | - Esource=Esource[:lim] | |
37 | - | |
38 | - cond = (generation==0) | |
39 | - test=energy[cond]/Esource[cond] | |
35 | + #=============================================================================# | |
36 | + # IMAGING | |
37 | + #=============================================================================# | |
38 | + thetaDir,phiDir = ReadMomentumAngle(fileId)*degre | |
39 | + thetaPos,phiPos = ReadPositionAngle(fileId)*degre | |
40 | + theta = thetaDir - thetaPos | |
41 | + phi = phiDir -phiPos | |
42 | + | |
43 | + # apply source spectrum | |
44 | + weight_source = (Esource/min(Esource))**(1-powerlaw_index) | |
45 | + weight = weightini* weight_source | |
46 | + | |
47 | + # apply selection | |
48 | + cond=(energy>Elim) & (abs(theta)<thetalim) & (abs(phi)<thetalim) | |
49 | + weight=weight[cond] | |
50 | + theta=theta[cond] | |
51 | + phi=phi[cond] | |
52 | + printMap(theta,phi,weight,fileId,source=isotrop(),borne=[thetalim,thetalim]) | |
40 | 53 | |
41 | 54 | Gen_contrib = [] |
42 | 55 | Gen_cont = zeros((int(max(generation))+1)) |
... | ... | @@ -48,14 +61,9 @@ for fileId in argv[1:]: |
48 | 61 | |
49 | 62 | for powerlaw_index in PowerSpectrum: |
50 | 63 | # apply source spectrum |
51 | - weight_source = Esource**(1-powerlaw_index) | |
64 | + weight_source = (Esource/min(Esource))**(1-powerlaw_index) | |
52 | 65 | weight = weightini* weight_source |
53 | 66 | |
54 | - print "%e" %(max(weight_source)/min(weight_source)) | |
55 | - | |
56 | - #cond = (energy>95) & (energy<105) & (generation==0) | |
57 | - #print weightini[cond], weight[cond] | |
58 | - | |
59 | 67 | #=============================================================================# |
60 | 68 | # GENERATION CONTRIBUTION |
61 | 69 | #=============================================================================# |
... | ... | @@ -73,8 +81,7 @@ for fileId in argv[1:]: |
73 | 81 | nbBins = 100 |
74 | 82 | # draw source spectrum |
75 | 83 | Es=array(list(set(Esource))) |
76 | - print shape(Es) | |
77 | - Ws= (Es)**(1-powerlaw_index) | |
84 | + Ws= (Es/min(Es))**(1-powerlaw_index) | |
78 | 85 | Es,Fs = spectrum(Es,Ws,nbBins=nbBins) |
79 | 86 | Es=Es[:,newaxis] |
80 | 87 | Fs=Fs[:,newaxis] |
... | ... | @@ -132,11 +139,11 @@ for fileId in argv[1:]: |
132 | 139 | else: |
133 | 140 | Timing = append(Timing,dNdt,axis=1) |
134 | 141 | |
135 | - InProgress(fileId,PowerSpectrum.index(powerlaw_index)+1,shape(PowerSpectrum)[0]) | |
142 | + InProgress(fileId,"1",PowerSpectrum.index(powerlaw_index)+1,shape(PowerSpectrum)[0]) | |
136 | 143 | |
137 | - savetxt(folder+fileId+"/Generation.txt",Gen_contrib) | |
138 | - savetxt(folder+fileId+"/Spectrum.txt",Spectrum) | |
139 | - savetxt(folder+fileId+"/Source_spectrum.txt",Source) | |
140 | - savetxt(folder+fileId+"/Angle_vs_Energy.txt",Angle_Energy) | |
141 | - savetxt(folder+fileId+"/Radial_distribution.txt",Radial) | |
142 | - savetxt(folder+fileId+"/Timing.txt",Timing) | |
144 | + savetxt(resultDirectory+fileId+"/Generation.txt",Gen_contrib) | |
145 | + savetxt(resultDirectory+fileId+"/Spectrum.txt",Spectrum) | |
146 | + savetxt(resultDirectory+fileId+"/Source_spectrum.txt",Source) | |
147 | + savetxt(resultDirectory+fileId+"/Angle_vs_Energy.txt",Angle_Energy) | |
148 | + savetxt(resultDirectory+fileId+"/Radial_distribution.txt",Radial) | |
149 | + savetxt(resultDirectory+fileId+"/Timing.txt",Timing) | ... | ... |
EBL-spectrums.py
... | ... | @@ -5,8 +5,8 @@ from scipy.optimize import curve_fit |
5 | 5 | import matplotlib.pyplot as plt |
6 | 6 | from Modules.Constants import * |
7 | 7 | |
8 | -fig = plt.figure() | |
9 | -ax = fig.add_subplot(111) | |
8 | +fig1 = plt.figure() | |
9 | +ax = fig1.add_subplot(111) | |
10 | 10 | |
11 | 11 | z=2 |
12 | 12 | |
... | ... | @@ -16,11 +16,11 @@ lamb,lambdaI = np.loadtxt("EBL_files/lambdaI_Dominguez.dat",unpack=True,usecols= |
16 | 16 | hv = h*c/(lamb*1e-4) # erg |
17 | 17 | density = 1e-6*(4*pi/c)*lambdaI/(hv**2) /(erg_to_GeV*1e9) *(1+z)**3 |
18 | 18 | hv = hv *(erg_to_GeV*1e9) |
19 | -ax.plot(hv,density*hv**2,"--b",label="Dominguez and Al") | |
19 | +ax.plot(hv,density*hv**2,"--b",label="Dominguez et Al") | |
20 | 20 | |
21 | 21 | # ==== Kneiske and Doll - "best fit" ==== |
22 | 22 | hv,density = np.loadtxt("EBL_files/n_bestfit10.dat",unpack=True,usecols=[0,1]) |
23 | -ax.plot(hv,density*hv**2,"--r",label="Kneiske and Doll - 'best fit'") | |
23 | +ax.plot(hv,density*hv**2,"--r",label="Kneiske et Doll - 'best fit'") | |
24 | 24 | |
25 | 25 | # ==== Kneiske and Doll - "lower limit" ==== |
26 | 26 | hv,density = np.loadtxt("EBL_files/n_lowerlimit10.dat",unpack=True,usecols=[0,179]) |
... | ... | @@ -38,28 +38,50 @@ ax.plot(hv,density*hv**2,"--c",label="Fraceschini") |
38 | 38 | hv,density = np.loadtxt("EBL_files/n_Finke.dat",unpack=True,usecols=[0,201]) |
39 | 39 | #hv,density = np.loadtxt("EBL_files/n_Finke.dat",unpack=True,usecols=[0,1]) |
40 | 40 | density=density*(1+z)**3 |
41 | -ax.plot(hv,density*hv**2,"--m",label="Finke and Al") | |
41 | +ax.plot(hv,density*hv**2,"--m",label="Finke et Al") | |
42 | 42 | |
43 | 43 | # ==== Gilmore ==== |
44 | 44 | hv,density = np.loadtxt("EBL_files/n_Gil.dat",unpack=True,usecols=[0,14]) |
45 | 45 | #hv,density = np.loadtxt("EBL_files/n_Gil.dat",unpack=True,usecols=[0,1]) |
46 | -ax.plot(hv,density*hv**2,"--y",label="Gilmore and Al") | |
46 | +ax.plot(hv,density*hv**2,"--y",label="Gilmore et Al") | |
47 | 47 | |
48 | 48 | #==== CMB ==== |
49 | -def nCMB(E): | |
49 | +def nCMB(E,z): | |
50 | 50 | kTcmb = k*Tcmb*erg_to_GeV*1e9*(1+z) |
51 | 51 | theta = E/kTcmb |
52 | 52 | nCMB=(hb*c*erg_to_GeV*1e9)**(-3) *(E/np.pi)**2 /(np.exp(theta)-1) |
53 | 53 | return nCMB |
54 | 54 | |
55 | 55 | hv = np.logspace(-4,-1,1000) |
56 | -ax.plot(hv,nCMB(hv)*hv**2,"-k",label="CMB") | |
56 | +ax.plot(hv,nCMB(hv,z)*hv**2,"-k",label="CMB") | |
57 | 57 | |
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",title="z = %.0f"%z) | |
61 | +ax.legend(loc="best",frameon=False,framealpha=0.5) | |
62 | 62 | ax.set_xlabel("energy [eV]") |
63 | -ax.set_ylabel("$n_{EBL}$ [photon.eV.cm$^{-3}$]") | |
63 | +ax.set_ylabel("$n$ [photon.eV.cm$^{-3}$]") | |
64 | + | |
65 | +#==== Dominguez vs redshift ================================================================== | |
66 | +fig2 = plt.figure() | |
67 | +ax2 = fig2.add_subplot(111) | |
68 | + | |
69 | +z = np.loadtxt("EBL_files/z_Dominguez.dat",unpack=True,usecols=[0]) | |
70 | +for z_index in [1,9,12,15,17]: | |
71 | + lamb,lambdaI = np.loadtxt("EBL_files/lambdaI_Dominguez.dat",unpack=True,usecols=[0,z_index]) | |
72 | + hv = h*c/(lamb*1e-4) # erg | |
73 | + density = 1e-6*(4*pi/c)*lambdaI/(hv**2) /(erg_to_GeV*1e9) *(1+z[z_index])**3 | |
74 | + hv = hv *(erg_to_GeV*1e9) | |
75 | + p=ax2.plot(hv,density*hv**2,"--") | |
76 | + # CMB | |
77 | + hv = np.logspace(-4,-1,1000) | |
78 | + ax2.plot(hv,nCMB(hv,z[z_index])*hv**2,color=p[0].get_color(),linestyle='-',label="z="+str(z[z_index-1])) | |
79 | + | |
80 | +ax2.set_xscale('log') | |
81 | +ax2.set_yscale('log') | |
82 | +ax2.grid(b=True,which='major') | |
83 | +ax2.legend(loc="best",frameon=False,framealpha=0.5) | |
84 | +ax2.set_xlabel("energy [eV]") | |
85 | +ax2.set_ylabel("$n$ [photon.eV.cm$^{-3}$]") | |
64 | 86 | |
65 | 87 | plt.show() | ... | ... |
Modules/Map.py
1 | 1 | from numpy import shape, pi, histogram2d, arange, newaxis, exp, log, array, sin, cos |
2 | 2 | from scipy.signal import convolve2d |
3 | -from matplotlib.pyplot import figure, show, matshow | |
3 | +from matplotlib.pyplot import figure, show, matshow, savefig | |
4 | 4 | from matplotlib.colors import LogNorm |
5 | -from Read import ReadEnergy, ReadExtraFile, ReadMomentumAngle, ReadPositionAngle, ReadProfile | |
5 | +from Read import resultDirectory | |
6 | 6 | from Constants import degre |
7 | 7 | |
8 | 8 | thetalim = 180 |
... | ... | @@ -14,15 +14,15 @@ thetalim=float(thetalim) |
14 | 14 | limits = [[-thetalim,thetalim],[-philim,philim]] |
15 | 15 | |
16 | 16 | def isotrop(): |
17 | - return array([[1]]) | |
17 | + return array([[1]]), "isotropic" | |
18 | 18 | |
19 | 19 | def Gaussian2D(center=[0,0],fwhm=0.01): |
20 | 20 | x = arange(-thetalim,thetalim+step,step) |
21 | 21 | y = arange(-philim,philim+step,step) |
22 | 22 | y = y[:,newaxis] |
23 | - return exp(-4*log(2) * ((x-center[0])**2 + (y+center[1])**2) / fwhm**2) | |
23 | + return exp(-4*log(2) * ((x-center[0])**2 + (y+center[1])**2) / fwhm**2), "jet_"+str(fwhm) | |
24 | 24 | |
25 | -def drawMap(files,Elim=0.1,source=isotrop(),borne=[180,180]): | |
25 | +def printMap(theta,phi,weight,fileId,source=isotrop(),borne=[180,180]): | |
26 | 26 | ''' |
27 | 27 | Plot 2D histogram of arrival direction of the photons with energy upper than Elim |
28 | 28 | Input: list of directories |
... | ... | @@ -31,47 +31,23 @@ def drawMap(files,Elim=0.1,source=isotrop(),borne=[180,180]): |
31 | 31 | Input (optional): limits on theta, phi |
32 | 32 | Output: 2D histogram of theta cos(phi), theta sin(phi) |
33 | 33 | ''' |
34 | - print "Cut at", Elim, "GeV" | |
35 | 34 | fig = figure() |
36 | - nbplots = len(files) | |
37 | 35 | |
38 | - ind=1 | |
39 | - for fileId in files: | |
40 | - thetaDir,phiDir = ReadMomentumAngle(fileId)*degre | |
41 | - thetaPos,phiPos = ReadPositionAngle(fileId)*degre | |
42 | - theta = thetaDir - thetaPos | |
43 | - phi = phiDir -phiPos | |
44 | - | |
45 | - energy = ReadEnergy(fileId) | |
46 | - weightini, Esource = ReadExtraFile(fileId,[2,5]) | |
47 | - | |
48 | - zsource, Dsource, nbPhotonsEmitted, EGMF = ReadProfile(fileId,[1,2,3,4]) | |
49 | - # apply source spectrum | |
50 | - powerlaw_index = 2 | |
51 | - weight = weightini*(Esource/min(Esource))**(1-powerlaw_index) | |
52 | - | |
53 | - cond=(energy>Elim) & (abs(theta)<thetalim) & (abs(phi)<philim) | |
54 | - energy = energy[cond] | |
55 | - weight=weight[cond]/nbPhotonsEmitted | |
56 | - theta=theta[cond] | |
57 | - phi=phi[cond] | |
58 | - | |
59 | - H,xedges,yedges = histogram2d(theta*cos(phi),theta*sin(phi),nbBins,weights=weight,range=limits) | |
60 | - conv=convolve2d(H,source,boundary="wrap",mode="same") | |
61 | - | |
62 | - ax = fig.add_subplot(100+nbplots*10+ind) | |
63 | - im = ax.matshow(conv,norm=LogNorm(),aspect='auto', | |
64 | - extent=[xedges[0],xedges[-1],yedges[0],yedges[-1]]) | |
65 | - #H,xedges,yedges,im = ax.hist2d(theta,phi,nbBins,weights=weight,norm=LogNorm()) | |
66 | - cbar=fig.colorbar(im, ax=ax) | |
67 | - cbar.ax.set_ylabel("counts normalize to 1 photon emitted") | |
68 | - ax.set_xlim((-borne[0],borne[0])) | |
69 | - ax.set_ylim((-borne[1],borne[1])) | |
70 | - ax.set_xlabel("$\\theta$ $\\cos(\\phi)$ [deg]") | |
71 | - ax.set_ylabel("$\\theta$ $\\sin(\\phi)$ [deg]") | |
72 | - ax.grid(b=True,which='major') | |
73 | - ax.set_title("source at %.0f"%Dsource+"Mpc (z=%.4f"%zsource+"): EGMF="+str(EGMF)+" Gauss" ) | |
74 | - | |
75 | - ind=ind+1 | |
76 | - | |
77 | - show() | |
36 | + H,xedges,yedges = histogram2d(theta*cos(phi),theta*sin(phi),nbBins,weights=weight,range=limits) | |
37 | + conv=convolve2d(H,source[0],boundary="wrap",mode="same") | |
38 | + | |
39 | + ax = fig.add_subplot(111) | |
40 | + im = ax.matshow(conv,norm=LogNorm(),aspect='auto', | |
41 | + extent=[xedges[0],xedges[-1],yedges[0],yedges[-1]]) | |
42 | + #H,xedges,yedges,im = ax.hist2d(theta,phi,nbBins,weights=weight,norm=LogNorm()) | |
43 | + cbar=fig.colorbar(im, ax=ax) | |
44 | + cbar.ax.set_ylabel("counts") | |
45 | + ax.set_xlim((-borne[0],borne[0])) | |
46 | + ax.set_ylim((-borne[1],borne[1])) | |
47 | + ax.set_xlabel("$\\theta$ $\\cos(\\phi)$ [deg]") | |
48 | + ax.set_ylabel("$\\theta$ $\\sin(\\phi)$ [deg]") | |
49 | + ax.grid(b=True,which='major') | |
50 | + ax.set_title(fileId+" - "+source[1]) | |
51 | + | |
52 | + savefig(resultDirectory+fileId+"/map_"+source[1]+".png") | |
53 | + #show() | ... | ... |
Modules/Map.pyc
No preview for this file type
Modules/Read.pyc
No preview for this file type
Modules/Spectrum.py
... | ... | @@ -51,7 +51,7 @@ def drawSpectrum(files,PlotAnalytic=False): |
51 | 51 | for powerlaw_index in [1,1.5,2,2.5]: |
52 | 52 | # read files |
53 | 53 | Es,Fs = ReadSourceSpectrum(fileId,[0,i]) |
54 | - p = ax1.plot(Es,Fs,drawstyle='.') | |
54 | + p = ax1.plot(Es,Fs,linestyle=':') | |
55 | 55 | # draw full spectrum |
56 | 56 | ener,flux,flux_0 = ReadSpectrum(fileId,[0,j,j+1]) |
57 | 57 | ax1.plot(ener,flux,color=p[0].get_color(),drawstyle='steps-mid',label="p=%.1f"%powerlaw_index) | ... | ... |
Modules/Spectrum.pyc
No preview for this file type