-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbBand_evo.pyx
executable file
·166 lines (87 loc) · 2.76 KB
/
bbBand_evo.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#Define the Band function
cimport cython
from scipy.integrate import quad
cdef extern from "math.h":
float exp(float)
cdef extern from "math.h":
float pow(float ,float)
cdef extern from "math.h":
float log(float)
@cython.cdivision(True)
cdef float BlackBody( float x, float A, float kT):
cdef float val
cdef float exponent
exponent = (x/kT) - 1.
val = A * (x**2) / (exp (exponent) )
return val
@cython.cdivision(True)
cpdef float PulseIntegrator(float t, float emin, float emax):
cdef float val
val = float(quad(evo,emin,emax,args=(t))[0])
return val
@cython.cdivision(True)
cdef float Band( float x, float A, float Ep, float alpha, float beta):
cdef float cond = (alpha-beta)*Ep/(2+alpha)
cdef float val
if x < cond:
val = A*( pow(x/100., alpha) * exp(-x*(2+alpha)/Ep) )
else:
val = A* ( pow( (alpha -beta)*Ep/(100.*(2+alpha)),alpha-beta)*exp(beta-alpha)*pow(x/100.,beta))
return val
eMin = 6.
eMax = 50000.
cdef float emin = eMin
cdef float emax = eMax
from scipy.interpolate import interp1d
from numpy import logspace
cdef float alpha = -1.
cdef float beta = -2.2
def pht(float Ep):
cdef float val
b = lambda x: Band(x,1.,Ep,alpha,beta)
val = quad(b,emin,emax)[0]
return val
Ep = logspace(-3.,4.3010299956639813,1000)
flux =[]
for ep in Ep:
flux.append(pht(ep))
interpF = interp1d(Ep,flux)
#### Definition of the KRL Pulse
@cython.cdivision(True)
cdef float KRL(float t, float tmax, float c, float r, float d, float fmax):
cdef float f
f = fmax*pow((((t+c)/(tmax+c))),r)
f/=pow(((d+(r*pow((((t+c)/(tmax+c))),(1+r))))/(d+r)),((d+r)/(1+r)))
return f
def bbPht(kT):
b = lambda x: BlackBody(x,1.,kT)
cdef float val = quad(b,emin,emax)[0]
return val
kT = logspace(-4,4,1000)
flux =[]
for kt in kT:
flux.append(pht(kt))
interpBB = interp1d(kT,flux)
@cython.cdivision(True)
cpdef float evo(float ene, float t):
cdef float A
cdef float indx = -1.
cdef float Ep = 2000.* pow(1.+t,indx)
cdef float maxFlux = 10000.
A = KRL(t,.5,.1, 2.,1.,maxFlux)
cdef float renorm = interpF(Ep) #The interpolated Ep to flux ratio
cdef float val = Band(ene,A,Ep,alpha,beta)/renorm
######BB
cdef float tbreak = 5.
cdef float indx1 = -.66
cdef float indx2 = -.7
cdef float kT
if t<= tbreak:
kT = 80.*pow(1+t,indx1)
else:
kT= 80*pow(tbreak,indx1-indx2)*pow(1+t,indx2)
maxFlux = 1E-0
A = KRL(t,.5,.1, 2.,1.,maxFlux)
renorm = interpBB(kT)
val += BlackBody(ene,A,kT)/renorm
return val