Commit d33c0bebaf2f4da5754804f4f2f4581cd810efbb
1 parent
5bbd0e5c
Exists in
master
Add time distribution script
- dN/dt versus t
Showing
3 changed files
with
76 additions
and
0 deletions
Show diff stats
Constantes.py
Constantes.pyc
No preview for this file type
... | ... | @@ -0,0 +1,75 @@ |
1 | +#!/usr/bin/python | |
2 | + | |
3 | +from sys import argv | |
4 | +import os.path | |
5 | +import numpy as np | |
6 | +from scipy.optimize import curve_fit | |
7 | +import matplotlib.pyplot as plt | |
8 | +from Constantes import s_to_yr | |
9 | + | |
10 | +if argv[1] == "EGMF": | |
11 | + fileName="Results_EGMF" | |
12 | +elif argv[1] == "EBL": | |
13 | + fileName="Results_EBL" | |
14 | + B=10**(-15) | |
15 | + Model=["Kneiske and Doll - 'best fit'","Kneiske and Doll - 'lower limit'", | |
16 | + "Franceschini","Finke and Al","Gilmore and Al","Dominguez and Al"] | |
17 | +else: | |
18 | + print "Used: ./Energy_distribution.py arg1 ind1 ind2 ..." | |
19 | + print " arg1 = EGMF or EBL " | |
20 | + print " ind1 = file number \n" | |
21 | + print "Examples: " | |
22 | + print " to study EGMF14: ./Energy_distribution.py EGMF 14 " | |
23 | + print " to study EBL1 and EBL2: ./Energy_distribution.py EBL 1 2 \n" | |
24 | + exit() | |
25 | + | |
26 | +# figure: energy distribution | |
27 | +#============================= | |
28 | +nbBins = 200 | |
29 | +convert= 180/np.pi | |
30 | +color=['b','r','g','c','m','y'] | |
31 | + | |
32 | +fig = plt.figure() | |
33 | +ax = fig.add_subplot(111) | |
34 | + | |
35 | +time= np.loadtxt(fileName+argv[2]+"/Results_position",unpack=True,usecols=[0]) | |
36 | +tmax = max(time) | |
37 | +tmin = min(time) | |
38 | +print tmin, tmax | |
39 | + | |
40 | +ind = 0 | |
41 | +for fileId in argv[2:]: | |
42 | + time= np.loadtxt(fileName+fileId+"/Results_position",unpack=True,usecols=[0]) | |
43 | + weight,gen=np.loadtxt(fileName+fileId+"/Results_extra",unpack=True,usecols=[2,3]) | |
44 | + | |
45 | + cond=(gen<8) | |
46 | + time=time[cond] | |
47 | + weight=weight[cond] | |
48 | + | |
49 | + print "data shape",fileName+fileId,":", np.shape(time) | |
50 | + | |
51 | + dN,dt=np.histogram(time,nbBins,range=(tmin,tmax),weights=weight) | |
52 | + timecenter=(dt[1:nbBins+1]+dt[0:nbBins])/2 | |
53 | + binSize=dt[1:nbBins+1]-dt[0:nbBins] | |
54 | + dNdt=dN/binSize | |
55 | + | |
56 | + if argv[1] == "EGMF": | |
57 | + #ax.hist(time,nbBins,weights=weight,range=(tmin,tmax),log=1,facecolor=color[ind],alpha=.5, | |
58 | + # label="$10^{-%.0f"%float(fileId)+"}$Gauss") | |
59 | + ax.plot(timecenter[dNdt!=0],dNdt[dNdt!=0],"-"+color[ind], | |
60 | + label="$10^{-%.0f"%float(fileId)+"}$Gauss") | |
61 | + elif argv[1] == "EBL": | |
62 | + #plt.hist(time,nbBins,weights=weight,range=(tmin,tmax),log=1,facecolor=color[ind],alpha=.5, | |
63 | + ax.plot(timecenter,dNdt,"."+color[ind], | |
64 | + label=Model[int(fileId)-1]) | |
65 | + | |
66 | + ind=ind+1 | |
67 | + | |
68 | +#ax.set_xscale('log') | |
69 | +#ax.set_yscale('log') | |
70 | +ax.grid(b=True,which='major') | |
71 | +ax.legend(loc="best") | |
72 | +ax.set_xlabel("Time [yr]") | |
73 | +ax.set_ylabel("$dN/dt$ [yr$^{-1}$]") | |
74 | + | |
75 | +plt.show() | ... | ... |