Commit 28843f231ae54f8d785b802bf99b14053415b2a4
1 parent
49a0fe94
Exists in
master
Put radial distribution inside the map computation
=> can tke into account the jet opening if so
Showing
7 changed files
with
163 additions
and
118 deletions
Show diff stats
Analysis.py
... | ... | @@ -5,60 +5,40 @@ from numpy import append, savetxt, shape, array, newaxis, zeros, arange |
5 | 5 | from Modules.Read import ReadEnergy, ReadTime, ReadExtraFile, ReadProfile |
6 | 6 | from Modules.Read import ReadMomentumAngle, ReadPositionAngle, resultDirectory |
7 | 7 | from Modules.Spectrum import spectrum |
8 | -from Modules.Map import printMap, isotrop | |
9 | -from Modules.Angle import radial, angle_vs_energy | |
8 | +from Modules.Map import computeMap, isotrop | |
9 | +from Modules.Angle import angle_vs_energy | |
10 | 10 | from Modules.Timing import timing |
11 | 11 | from Modules.Constants import degre |
12 | 12 | |
13 | -def InProgress(fileId,step,i,Nmax): | |
14 | - print "Work on ", fileId, "(step "+ step +": ", (i*100)/Nmax, "% done" | |
13 | +def InProgress(i,Nmax): | |
14 | + print " ", (i*100)/Nmax, "% done" | |
15 | 15 | |
16 | 16 | if shape(argv)[0] < 2: |
17 | 17 | print "not enough arguments (at least 1)" |
18 | 18 | exit() |
19 | 19 | |
20 | -#================================================================# | |
21 | -# Parameters | |
22 | -#================================================================# | |
20 | +#=============================================================================# | |
23 | 21 | PowerSpectrum=[1,1.5,2,2.5] |
24 | -powerlaw_index = 2 | |
25 | -Elim = 1e-1 # GeV | |
26 | -thetalim = 20 # degre | |
27 | 22 | |
28 | 23 | for fileId in argv[1:]: |
24 | + print "#=============================================================================#" | |
25 | + print "# Analysis of", fileId | |
26 | + print "#=============================================================================#" | |
29 | 27 | # read files |
28 | + print "# 1. Reading data" | |
30 | 29 | time = ReadTime(fileId) |
31 | 30 | energy = ReadEnergy(fileId) |
32 | 31 | weightini, generation, theta_arrival, Esource = ReadExtraFile(fileId,[2,3,4,5]) |
33 | 32 | nbPhotonsEmitted=ReadProfile(fileId,[3]) |
34 | 33 | |
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]) | |
53 | - | |
54 | 34 | Gen_contrib = [] |
55 | 35 | Gen_cont = zeros((int(max(generation))+1)) |
56 | 36 | Source = [] |
57 | 37 | Spectrum = [] |
58 | - Radial = [] | |
59 | 38 | Angle_Energy = [] |
60 | 39 | Timing = [] |
61 | 40 | |
41 | + print "# 2. Computing powerlaw spectrum" | |
62 | 42 | for powerlaw_index in PowerSpectrum: |
63 | 43 | # apply source spectrum |
64 | 44 | weight_source = (Esource/min(Esource))**(1-powerlaw_index) |
... | ... | @@ -78,7 +58,7 @@ for fileId in argv[1:]: |
78 | 58 | #=============================================================================# |
79 | 59 | # SPECTRUM (SOURCE AND MEASURED) |
80 | 60 | #=============================================================================# |
81 | - nbBins = 100 | |
61 | + nbBins = 50 | |
82 | 62 | # draw source spectrum |
83 | 63 | Es=array(list(set(Esource))) |
84 | 64 | Ws= (Es/min(Es))**(1-powerlaw_index) |
... | ... | @@ -105,28 +85,6 @@ for fileId in argv[1:]: |
105 | 85 | Spectrum = append(Spectrum,flux_0,axis=1) |
106 | 86 | |
107 | 87 | #=============================================================================# |
108 | - # RADIAL DISTRIBUTION AND ANGLE VERSUS ENERGY | |
109 | - #=============================================================================# | |
110 | - nbBins = 100 | |
111 | - ener,angle = angle_vs_energy(theta_arrival,energy,weight,nbPhotonsEmitted) | |
112 | - ener=ener[:,newaxis] | |
113 | - angle=angle[:,newaxis] | |
114 | - if Angle_Energy==[]: | |
115 | - Angle_Energy = ener | |
116 | - Angle_Energy = append(Angle_Energy,angle,axis=1) | |
117 | - else: | |
118 | - Angle_Energy = append(Angle_Energy,angle,axis=1) | |
119 | - | |
120 | - theta,dndtheta2 = radial(theta_arrival,weight,nbPhotonsEmitted) | |
121 | - theta=theta[:,newaxis] | |
122 | - dndtheta2=dndtheta2[:,newaxis] | |
123 | - if Radial==[]: | |
124 | - Radial = theta | |
125 | - Radial = append(Radial,dndtheta2,axis=1) | |
126 | - else: | |
127 | - Radial = append(Radial,dndtheta2,axis=1) | |
128 | - | |
129 | - #=============================================================================# | |
130 | 88 | # TIME DISTRIBUTION AND TIME DELAY VERSUS ANGLE |
131 | 89 | #=============================================================================# |
132 | 90 | nbBins = 100 |
... | ... | @@ -139,11 +97,57 @@ for fileId in argv[1:]: |
139 | 97 | else: |
140 | 98 | Timing = append(Timing,dNdt,axis=1) |
141 | 99 | |
142 | - InProgress(fileId,"1",PowerSpectrum.index(powerlaw_index)+1,shape(PowerSpectrum)[0]) | |
100 | + InProgress(PowerSpectrum.index(powerlaw_index)+1,shape(PowerSpectrum)[0]) | |
101 | + | |
102 | + #=============================================================================# | |
103 | + # IMAGING, RADIAL DISTRIBUTION AND ANGLE VERSUS ENERGY | |
104 | + #=============================================================================# | |
105 | + print "# 3. compute images and radial distribution" | |
106 | + powerlaw_index = 2 | |
107 | + Elim = 1e-1 # GeV | |
108 | + thetalim = 20 # degre | |
109 | + nbBins = 100 | |
110 | + Radial = [] | |
111 | + | |
112 | + thetaDir,phiDir = ReadMomentumAngle(fileId)*degre | |
113 | + thetaPos,phiPos = ReadPositionAngle(fileId)*degre | |
114 | + theta = thetaDir - thetaPos | |
115 | + phi = phiDir -phiPos | |
116 | + | |
117 | + # apply source spectrum | |
118 | + weight_source = (Esource/min(Esource))**(1-powerlaw_index) | |
119 | + weight = weightini* weight_source | |
143 | 120 | |
121 | + # apply selection | |
122 | + cond=(energy>Elim) #& (abs(theta)<thetalim) & (abs(phi)<thetalim) | |
123 | + theta=theta[cond] | |
124 | + phi=phi[cond] | |
125 | + weight=weight[cond] | |
126 | + energy=energy[cond] | |
127 | + theta2,dndtheta2 = computeMap(theta,phi,weight,energy,fileId,nbBins, | |
128 | + source=isotrop(),borne=[thetalim,thetalim]) | |
129 | + ener,angle = angle_vs_energy(theta,energy,weight,nbBins) | |
130 | + theta2=theta2[:,newaxis] | |
131 | + dndtheta2=dndtheta2[:,newaxis] | |
132 | + ener=ener[:,newaxis] | |
133 | + angle=angle[:,newaxis] | |
134 | + | |
135 | + if Radial==[]: | |
136 | + Radial = theta2 | |
137 | + Radial = append(Radial,dndtheta2,axis=1) | |
138 | + Angle_Energy = ener | |
139 | + Angle_Energy = append(Angle_Energy,angle,axis=1) | |
140 | + else: | |
141 | + Radial = append(Radial,dndtheta2,axis=1) | |
142 | + Angle_Energy = append(Angle_Energy,angle,axis=1) | |
143 | + | |
144 | + #=============================================================================# | |
145 | + print "# 4. writing files" | |
144 | 146 | savetxt(resultDirectory+fileId+"/Generation.txt",Gen_contrib) |
145 | 147 | savetxt(resultDirectory+fileId+"/Spectrum.txt",Spectrum) |
146 | 148 | savetxt(resultDirectory+fileId+"/Source_spectrum.txt",Source) |
147 | 149 | savetxt(resultDirectory+fileId+"/Angle_vs_Energy.txt",Angle_Energy) |
148 | 150 | savetxt(resultDirectory+fileId+"/Radial_distribution.txt",Radial) |
149 | 151 | savetxt(resultDirectory+fileId+"/Timing.txt",Timing) |
152 | + print "#=============================================================================#" | |
153 | + | ... | ... |
Modules/Angle.py
... | ... | @@ -23,24 +23,6 @@ def angle_vs_energy(theta,energy,weight,nbPhotonsEmitted=1,nbBins=40): |
23 | 23 | |
24 | 24 | return enercenter, angle |
25 | 25 | |
26 | -def radial(theta,weight,nbPhotonsEmitted=1,nbBins=50,thetamax=90): | |
27 | - ''' | |
28 | - Compute flux versus arrival angle | |
29 | - Input: directory name | |
30 | - Input (optionnal): maximal angle desired (by default full sky) | |
31 | - Output: arrival angle, flux (dn/dtheta) | |
32 | - ''' | |
33 | - | |
34 | - theta=log10(theta) | |
35 | - dn,angle = histogram(theta,nbBins,range=[log10(1e-6),log10(thetamax)],weights=weight) | |
36 | - angle=10**angle | |
37 | - thetacenter = (angle[1:nbBins+1]+angle[0:nbBins])/2 | |
38 | - dtheta = angle[1:nbBins+1]-angle[0:nbBins] | |
39 | - dndtheta = dn/dtheta*thetacenter | |
40 | - dndtheta /= nbPhotonsEmitted | |
41 | - | |
42 | - return thetacenter, dndtheta | |
43 | - | |
44 | 26 | def drawAngle_vs_energy(files): |
45 | 27 | ''' |
46 | 28 | Plot arrival angle versus energy + analytic expression |
... | ... | @@ -51,11 +33,8 @@ def drawAngle_vs_energy(files): |
51 | 33 | ax1 = fig.add_subplot(111) |
52 | 34 | |
53 | 35 | for fileId in files: |
54 | - i=1 | |
55 | - for powerlaw_index in [1,1.5,2,2.5]: | |
56 | - # apply source spectrum | |
57 | - ener,angle = ReadAngleVsEnergy(fileId,[0,i]) | |
58 | - p=ax1.plot(ener,angle,'-',label="p=%.1f"%powerlaw_index) | |
36 | + ener,angle = ReadAngleVsEnergy(fileId,[0,1]) | |
37 | + p=ax1.plot(ener,angle,drawstyle='steps-mid',label=fileId) | |
59 | 38 | |
60 | 39 | yfit = Analytic_theta(ener,fileId) |
61 | 40 | ax1.plot(ener,yfit,'--',color="m",linewidth=2,label="analytic") |
... | ... | @@ -69,27 +48,3 @@ def drawAngle_vs_energy(files): |
69 | 48 | ax1.set_xlabel("energy [GeV]") |
70 | 49 | |
71 | 50 | show() |
72 | - | |
73 | -def drawRadial(files): | |
74 | - ''' | |
75 | - Plot flux versus arrival angle | |
76 | - Input: list of directories | |
77 | - Output: graph of flux versus angle | |
78 | - ''' | |
79 | - fig = figure() | |
80 | - ax = fig.add_subplot(111) | |
81 | - | |
82 | - for fileId in files: | |
83 | - i=1 | |
84 | - for powerlaw_index in [1,1.5,2,2.5]: | |
85 | - theta,dndtheta2 = ReadRadial(fileId,[0,i]) | |
86 | - ax.plot(theta,dndtheta2,drawstyle='steps-mid',label="p=%.1f"%powerlaw_index) | |
87 | - | |
88 | - ax.legend(loc="best") | |
89 | - ax.set_xscale('log') | |
90 | - ax.set_yscale('log') | |
91 | - ax.grid(b=True,which='major') | |
92 | - ax.set_xlabel("$\\theta$ [rad]") | |
93 | - ax.set_ylabel("$\\theta*dN/d\\theta$") | |
94 | - | |
95 | - show() | ... | ... |
Modules/Angle.pyc
No preview for this file type
Modules/Generation.py
Modules/Map.py
1 | -from numpy import shape, pi, histogram2d, arange, newaxis, exp, log, array, sin, cos | |
1 | +from numpy import shape, histogram2d, arange, newaxis, array, nditer, zeros, histogram | |
2 | +from numpy import sqrt, pi, exp, log, log10, sin, cos, where | |
2 | 3 | from scipy.signal import convolve2d |
3 | -from matplotlib.pyplot import figure, show, matshow, savefig | |
4 | +from matplotlib.pyplot import figure, matshow, savefig, show | |
4 | 5 | from matplotlib.colors import LogNorm |
5 | -from Read import resultDirectory | |
6 | +from Read import resultDirectory, ReadRadial, ReadAngleVsEnergy | |
7 | +from Analytic import Analytic_theta | |
6 | 8 | from Constants import degre |
7 | 9 | |
8 | 10 | thetalim = 180 |
9 | 11 | philim = 180 |
10 | 12 | step = 0.25 #deg |
11 | -nbBins = array([int(2*philim/step)+1,int(2*thetalim/step)+1]) | |
13 | +bining = array([int(2*philim/step)+1,int(2*thetalim/step)+1]) | |
12 | 14 | philim=float(philim) |
13 | 15 | thetalim=float(thetalim) |
14 | 16 | limits = [[-thetalim,thetalim],[-philim,philim]] |
... | ... | @@ -22,7 +24,7 @@ def Gaussian2D(center=[0,0],fwhm=0.01): |
22 | 24 | y = y[:,newaxis] |
23 | 25 | return exp(-4*log(2) * ((x-center[0])**2 + (y+center[1])**2) / fwhm**2), "jet_"+str(fwhm) |
24 | 26 | |
25 | -def printMap(theta,phi,weight,fileId,source=isotrop(),borne=[180,180]): | |
27 | +def computeMap(theta,phi,weight,energy,saveId,nbBins=50,source=isotrop(),borne=[180,180]): | |
26 | 28 | ''' |
27 | 29 | Plot 2D histogram of arrival direction of the photons with energy upper than Elim |
28 | 30 | Input: list of directories |
... | ... | @@ -33,13 +35,18 @@ def printMap(theta,phi,weight,fileId,source=isotrop(),borne=[180,180]): |
33 | 35 | ''' |
34 | 36 | fig = figure() |
35 | 37 | |
36 | - H,xedges,yedges = histogram2d(theta*cos(phi),theta*sin(phi),nbBins,weights=weight,range=limits) | |
38 | + H,xedges,yedges = histogram2d(theta*cos(phi),theta*sin(phi),bining,weights=weight,range=limits) | |
37 | 39 | conv=convolve2d(H,source[0],boundary="wrap",mode="same") |
40 | + #H2,xedges,yedges = histogram2d(theta*cos(phi),theta*sin(phi),bining,weights=energy,range=limits) | |
41 | + #conv2=convolve2d(H2,source[0],boundary="wrap",mode="same") | |
38 | 42 | |
43 | + #===============================================================================================# | |
44 | + # IMAGE | |
45 | + #===============================================================================================# | |
39 | 46 | ax = fig.add_subplot(111) |
40 | 47 | im = ax.matshow(conv,norm=LogNorm(),aspect='auto', |
41 | 48 | extent=[xedges[0],xedges[-1],yedges[0],yedges[-1]]) |
42 | - #H,xedges,yedges,im = ax.hist2d(theta,phi,nbBins,weights=weight,norm=LogNorm()) | |
49 | + #H,xedges,yedges,im = ax.hist2d(theta,phi,bining,weights=weight,norm=LogNorm()) | |
43 | 50 | cbar=fig.colorbar(im, ax=ax) |
44 | 51 | cbar.ax.set_ylabel("counts") |
45 | 52 | ax.set_xlim((-borne[0],borne[0])) |
... | ... | @@ -47,7 +54,70 @@ def printMap(theta,phi,weight,fileId,source=isotrop(),borne=[180,180]): |
47 | 54 | ax.set_xlabel("$\\theta$ $\\cos(\\phi)$ [deg]") |
48 | 55 | ax.set_ylabel("$\\theta$ $\\sin(\\phi)$ [deg]") |
49 | 56 | ax.grid(b=True,which='major') |
50 | - ax.set_title(fileId+" - "+source[1]) | |
57 | + ax.set_title(saveId+" - "+source[1]) | |
51 | 58 | |
52 | - savefig(resultDirectory+fileId+"/map_"+source[1]+".png") | |
53 | - #show() | |
59 | + savefig(resultDirectory+saveId+"/map_"+source[1]+".png") | |
60 | + | |
61 | + #===============================================================================================# | |
62 | + # RADIAL DISTRIBUTION AND ENERGY VERSUS ANGLE | |
63 | + #===============================================================================================# | |
64 | + theta2 = zeros(shape(conv)[0]*shape(conv)[1]) | |
65 | + N_evts = zeros(shape(conv)[0]*shape(conv)[1]) | |
66 | + #E_evts = zeros(shape(conv)[0]*shape(conv)[1]) | |
67 | + theta_cos_phi = xedges[::-1] | |
68 | + theta_sin_phi = yedges[::-1] | |
69 | + it = nditer(conv,flags=["multi_index"]) | |
70 | + #it2 = nditer(conv2,flags=["multi_index"]) | |
71 | + k = 0 | |
72 | + while not it.finished: | |
73 | + i = int(it.multi_index[1]) | |
74 | + j = int(it.multi_index[0]) | |
75 | + theta2[k]= sqrt(theta_cos_phi[i]**2+theta_sin_phi[j]**2) | |
76 | + N_evts[k]= it[0] | |
77 | + #E_evts[k]= it2[0] | |
78 | + k += 1 | |
79 | + it.iternext() | |
80 | + #it2.iternext() | |
81 | + | |
82 | + theta2=log10(theta2) | |
83 | + thetamax=max(borne) | |
84 | + dn,angle = histogram(theta2,nbBins,range=[log10(1e-2),log10(thetamax)],weights=N_evts) | |
85 | + angle=10**angle | |
86 | + thetacenter = (angle[1:nbBins+1]+angle[0:nbBins])/2 | |
87 | + dtheta = angle[1:nbBins+1]-angle[0:nbBins] | |
88 | + dndtheta = dn/dtheta*thetacenter | |
89 | + | |
90 | + #theta2 = 10**theta2 | |
91 | + #E_evts = E_evts[E_evts!=0] | |
92 | + #N_evts = N_evts[N_evts!=0] | |
93 | + #theta2 = theta2[E_evts!=0] | |
94 | + #E_evts =log10(E_evts) | |
95 | + #angle,ener =histogram(E_evts,nbBins,weights=N_evts*theta2) | |
96 | + #nb,ener =histogram(E_evts,nbBins,weights=N_evts) | |
97 | + #ener = 10**ener | |
98 | + #enercenter=(ener[1:nbBins+1]+ener[0:nbBins])/2 | |
99 | + #angle /= nb*degre | |
100 | + | |
101 | + return thetacenter, dndtheta #, enercenter, angle | |
102 | + | |
103 | +def drawRadial(files): | |
104 | + ''' | |
105 | + Plot flux versus arrival angle | |
106 | + Input: list of directories | |
107 | + Output: graph of flux versus angle | |
108 | + ''' | |
109 | + fig = figure() | |
110 | + ax = fig.add_subplot(111) | |
111 | + | |
112 | + for fileId in files: | |
113 | + theta,dndtheta2 = ReadRadial(fileId,[0,1]) | |
114 | + ax.plot(theta,dndtheta2,drawstyle='steps-mid',label=fileId) | |
115 | + | |
116 | + ax.legend(loc="best") | |
117 | + ax.set_xscale('log') | |
118 | + ax.set_yscale('log') | |
119 | + ax.grid(b=True,which='major') | |
120 | + ax.set_xlabel("$\\theta$ [deg]") | |
121 | + ax.set_ylabel("$\\theta*dN/d\\theta$") | |
122 | + | |
123 | + show() | ... | ... |
Modules/Map.pyc
No preview for this file type
README.md
... | ... | @@ -9,16 +9,31 @@ They also requires: |
9 | 9 | |
10 | 10 | Instruction to install it could be found here: http://www.scipy.org/install.html |
11 | 11 | |
12 | -## Principle | |
12 | +## Important remarks | |
13 | 13 | |
14 | -There is interdependancy between modules. Don't copy one and not the others otherwise they will be | |
14 | +There is interdependency between modules. Don't copy one and not the others otherwise they will be | |
15 | 15 | errors. |
16 | 16 | |
17 | -In the same time, the function in each module are written in way being used independantly, just | |
17 | +In the same time, the function in each module are written in way being used independently, just | |
18 | 18 | import it and python will do the rest. For example, to use the spectrum, use just add to your |
19 | 19 | script: "from Modules.Spectrum import spectrum". |
20 | 20 | |
21 | -Few modules are available: | |
21 | +## how-to | |
22 | + | |
23 | +* First create a directory call Results in which will be copy the output directory of the | |
24 | + simulation. You can named the output directory as you wish. It aims to have separately different | |
25 | + simulations and plot them together. | |
26 | + | |
27 | + mkdir Results | |
28 | + | |
29 | +* Since data files can become really huge, the "Analysis.py" script aims to pre-generate the need | |
30 | + files which will be used later to draw figures. | |
31 | + | |
32 | + python Analysis output | |
33 | + or if you want to do more than directory at a time | |
34 | + python Analysis output another_result_directory etc | |
35 | + | |
36 | +* From you draw some figures using the modules available | |
22 | 37 | |
23 | 38 | | Modules | functions | |
24 | 39 | | --------------- | --------------------------------------------------------- | |
... | ... | @@ -29,8 +44,10 @@ Few modules are available: |
29 | 44 | | "Spectrum.py" | extract and plot the spectrum | |
30 | 45 | | "timing.py" | extract and plot delta_t/t | |
31 | 46 | | "Angle.py" | extract and plot theta^2 in histogram or versus energy | |
32 | -| "Map.py" | plot map of the arrival photon, points or histo2d | | |
33 | -| "Generation.py" | plot historgram of the arrival particles generation | | |
47 | +| "Map.py" | plot map of the arrival photons histo2d | | |
48 | +| "Generation.py" | plot histogram of the arrival particles generation | | |
49 | + | |
50 | +or develop yours! | |
34 | 51 | |
35 | 52 | **N.B.:** "draw..." function call a table of files because it allows to plots more than one figure |
36 | 53 | on the same graph, rather than the rest of the function can call only one file at a time. | ... | ... |