Blame view

modules/maps.py 2.16 KB
28843f23   Thomas Fitoussi   Put radial distri...
1
2
from numpy import shape, histogram2d, arange, newaxis, array, nditer, zeros, histogram
from numpy import sqrt, pi, exp, log, log10, sin, cos, where
28843f23   Thomas Fitoussi   Put radial distri...
3
from matplotlib.pyplot import figure, matshow, savefig, show
7030f150   Thomas Fitoussi   Full reorganisati...
4
from matplotlib.colors import LogNorm
138898c8   Thomas Fitoussi   Computation of ra...
5
#from scipy.signal import convolve2d
30f3bf5d   Thomas Fitoussi   Adapt reading of ...
6
7
from read import  ReadRadial, ReadAngleVsEnergy
from constants import degre
7030f150   Thomas Fitoussi   Full reorganisati...
8

e6f5876a   Thomas Fitoussi   Map: convolution ...
9
thetalim = 180
f4246390   Thomas Fitoussi   Improve angular d...
10
11
philim = 180
step = 0.25 #deg
28843f23   Thomas Fitoussi   Put radial distri...
12
bining = array([int(2*philim/step)+1,int(2*thetalim/step)+1])
e6f5876a   Thomas Fitoussi   Map: convolution ...
13
14
15
philim=float(philim)
thetalim=float(thetalim)
limits = [[-thetalim,thetalim],[-philim,philim]]
7030f150   Thomas Fitoussi   Full reorganisati...
16

f5a75019   Thomas Fitoussi   Rewrite Analysis....
17
def computeMap(theta,phi,weight,energy,saveId,nbBins=50,borne=[180,180]):
f4246390   Thomas Fitoussi   Improve angular d...
18
19
20
21
22
23
24
25
   '''
      Plot 2D histogram of arrival direction of the photons with energy upper than Elim
      Input: list of directories
      Input (optional): lower energy limit (in GeV (default = 100MeV)
      Input (optional): nature of the source (default isotrop) 
      Input (optional): limits on theta, phi 
      Output: 2D histogram of theta cos(phi), theta sin(phi)
   '''
0b56ded5   Thomas Fitoussi   take into account...
26
   fig = figure()
49a0fe94   Thomas Fitoussi   Add direct printi...
27

28843f23   Thomas Fitoussi   Put radial distri...
28
29
30
   #===============================================================================================#
   #  IMAGE
   #===============================================================================================#
49a0fe94   Thomas Fitoussi   Add direct printi...
31
   ax = fig.add_subplot(111)
138898c8   Thomas Fitoussi   Computation of ra...
32
33
   #H,xedges,yedges = histogram2d(theta*cos(phi),theta*sin(phi),bining,weights=weight,range=limits)
   #conv=convolve2d(H,source[0],boundary="wrap",mode="same")
0b56ded5   Thomas Fitoussi   take into account...
34
35
   H,xedges,yedges,im = ax.hist2d(theta*cos(phi),theta*sin(phi),bining,weights=weight,
         norm=LogNorm(),range=limits)
49a0fe94   Thomas Fitoussi   Add direct printi...
36
37
38
39
40
41
42
   cbar=fig.colorbar(im, ax=ax)
   cbar.ax.set_ylabel("counts")
   ax.set_xlim((-borne[0],borne[0]))
   ax.set_ylim((-borne[1],borne[1]))
   ax.set_xlabel("$\\theta$ $\\cos(\\phi)$ [deg]")
   ax.set_ylabel("$\\theta$ $\\sin(\\phi)$ [deg]")
   ax.grid(b=True,which='major')
f5a75019   Thomas Fitoussi   Rewrite Analysis....
43
   ax.set_title(saveId+" - isotrop")
30f3bf5d   Thomas Fitoussi   Adapt reading of ...
44
   savefig(saveId+"/map_isotrop.png")
28843f23   Thomas Fitoussi   Put radial distri...
45

138898c8   Thomas Fitoussi   Computation of ra...
46
47
48
49
50
51
52
53
#def isotrop():
#   return array([[1]]), "isotropic"
#
#def Gaussian2D(center=[0,0],fwhm=0.01):
#   x = arange(-thetalim,thetalim+step,step)
#   y = arange(-philim,philim+step,step)
#   y = y[:,newaxis]
#   return exp(-4*log(2) * ((x-center[0])**2 + (y+center[1])**2) / fwhm**2), "jet_"+str(fwhm)