forked from gkulkarni/QLF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtg2.py
1669 lines (1160 loc) · 43.7 KB
/
rtg2.py
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
mpl.rcParams['text.usetex'] = True
mpl.rcParams['font.family'] = 'serif'
mpl.rcParams['font.serif'] = 'cm'
mpl.rcParams['font.size'] = '22'
import matplotlib.pyplot as plt
from scipy.integrate import quad
from scipy.interpolate import RectBivariateSpline
import sys
import gammapi
from gammapi import get_gammapi_percentiles
import matplotlib.patches as mpatches
# These npz files generated by rhoqso_fit2.py.
data = np.load('e1450_18.npz')
z18 = data['z']
median18 = data['median']
up18 = data['up']
down18 = data['down']
print 'median18=', median18[:10]
data = np.load('e1450_21.npz')
z21 = data['z']
median21 = data['median']
up21 = data['up']
down21 = data['down']
print 'median21=', median21[:10]
# z18 = data['z']
# medianbright18 = data['medianbright']
# medianfaint18 = data['medianfaint']
# downbright18 = data['downbright']
# upbright18 = data['upbright']
# downfaint18 = data['downfaint']
# upfaint18 = data['upfaint']
# data = np.load('e1450_21_2.npz')
# z21 = data['z']
# medianbright21 = data['medianbright']
# medianfaint21 = data['medianfaint']
# downbright21 = data['downbright']
# upbright21 = data['upbright']
# downfaint21 = data['downfaint']
# upfaint21 = data['upfaint']
# data = np.load('e912_18_2.npz')
# z18_912 = data['z']
# median18_912 = data['median']
# down18_912 = data['down']
# up18_912 = data['up']
# data = np.load('e912_21_2.npz')
# z21_912 = data['z']
# median21_912 = data['median']
# down21_912 = data['down']
# up21_912 = data['up']
print 'data loaded'
z_HM12 = np.loadtxt('z_HM12.txt')
data_HM12 = np.loadtxt('hm12.txt')
w_HM12 = data_HM12[:,0]
e_HM12 = data_HM12[:,1:]
# kx=1 and ky=1 required here to get good interpolation at the Lyman
# break. Also remember that you will most likely need the
# 'grid=False' option while invoking emissivity_HM12.
emissivity_HM12 = RectBivariateSpline(w_HM12, z_HM12, e_HM12, kx=1, ky=1)
jdata_HM12 = np.loadtxt('j_HM12.txt')
w_j_HM12 = jdata_HM12[:,0]
# Remove lines with same wavelength so that RectBivariateSpline can
# work. Not sure why these lines occur in HM12 tables.
w_j_HM12, idx = np.unique(w_j_HM12, return_index=True)
j_HM12 = jdata_HM12[idx, 1:]
bkgintens_HM12 = RectBivariateSpline(w_j_HM12, z_HM12, j_HM12, kx=1, ky=1)
yrbys = 3.154e7
cmbympc = 3.24077928965e-25
c_mpcPerYr = 2.998e10*yrbys*cmbympc # Mpc/yr
c_angPerSec = 2.998e18
nu0 = 3.288e15 # threshold freq for H I ionization; s^-1 (Hz)
hplanck = 6.626069e-27 # erg s
omega_lambda = 0.7
omega_nr = 0.3
h = 0.7
def qso_emissivity_hm12(nu, z):
"""HM12 qso comoving emissivity.
This is given by equations (37) and (38) of HM12.
"""
w = c_angPerSec/nu
nu_912 = c_angPerSec/912.0
nu_1300 = c_angPerSec/1300.0
a = 10.0**24.6 * (1.0+z)**4.68 * np.exp(-0.28*z)/(np.exp(1.77*z)+26.3)
b = a * (nu_1300/nu_912)**-1.57
if w > 1300.0:
e = b*(nu/nu_1300)**-0.44
else:
e = a*(nu/nu_912)**-1.57
return e
vqso_emissivity_hm12 = np.vectorize(qso_emissivity_hm12, otypes=[np.float])
def qso_emissivity_mh15(nu, z):
"""HM12 qso comoving emissivity.
This is given by equations (37) and (38) of HM12.
"""
w = c_angPerSec/nu
nu_912 = c_angPerSec/912.0
nu_1300 = c_angPerSec/1300.0
loge = 25.15*np.exp(-0.0026*z) - 1.5*np.exp(-1.3*z)
a = 10.0**loge
if w > 912.0:
e = a*(nu/nu_912)**-0.61
else:
e = a*(nu/nu_912)**-1.70
return e
vqso_emissivity_mh15 = np.vectorize(qso_emissivity_mh15, otypes=[np.float])
def H(z):
H0 = 1.023e-10*h
hubp = H0*np.sqrt(omega_nr*(1+z)**3+omega_lambda) # yr^-1
return hubp
def dzdt(z):
return -(1.0+z)*H(z) # yr^-1
def dtdz(z):
return 1.0/dzdt(z) # yr
def f(N_HI, z):
"""
HI column density distribution. This parameterisation, and the
best-fit values of the parameters, is taken from Becker and Bolton
2013 (MNRAS 436 1023), Equation (5).
"""
A = 0.93
beta_N = 1.33
beta_z = 1.92
N_LL = 10.0**17.2 # cm^-2
return (A/N_LL) * ((N_HI/N_LL)**(-beta_N)) * (((1.0+z)/4.5)**beta_z) # cm^2
def f_HM12(N_HI, z):
"""HI column density distribution from HM12.
See their Table 1 and Section 3.
"""
log10NHI = np.log10(N_HI)
if z < 1.56:
if 11.0 <= log10NHI < 15.0:
a = 1.729816e8
b = 1.5
g = 0.16
elif 15.0 <= log10NHI < 17.5:
a = 5.495409e15
b = 2.0
g = 0.16
elif 17.5 <= log10NHI < 19.0:
f17p5 = 5.495409e15 * (1+z)**0.16 * (10.0**17.5)**-2.0
f19 = 1.279381 * (1+z)**0.16 * (10.0**19)**-1.05
b = np.log10(f17p5/f19)/1.5
a = f17p5 * (10.0**17.5)**b
return a * N_HI**-b
elif 19.0 <= log10NHI < 20.3:
a = 1.279381
b = 1.05
g = 0.16
elif 20.3 <= log10NHI:
a = 2.471724e19
b = 2.0
g = 0.16
return a * (1+z)**g * N_HI**-b
elif 1.56 <= z < 5.5:
if 11.0 <= log10NHI < 15.0:
a = 1.199499e7
b = 1.5
g = 3.0
elif 15.0 <= log10NHI < 17.5:
a = 3.801894e14
b = 2.0
g = 3.0
elif 17.5 <= log10NHI < 19.0:
f17p5 = 3.801894e14 * (1+z)**3.0 * (10.0**17.5)**-2.0
f19 = 0.449780 * (1+z)**1.27 * (10.0**19)**-1.05
b = np.log10(f17p5/f19)/1.5
a = f17p5 * (10.0**17.5)**b
return a * N_HI**-b
elif 19.0 <= log10NHI < 20.3:
a = 0.449780
b = 1.05
g = 1.27
elif 20.3 <= log10NHI:
a = 8.709636e18
b = 2.0
g = 1.27
return a * (1+z)**g * N_HI**-b
elif 5.5 <= z:
if 11.0 <= log10NHI < 15.0:
a = 29.512092
b = 1.5
g = 9.9
elif 15.0 <= log10NHI < 17.5:
a = 9.332543e8
b = 2.0
g = 9.9
elif 17.5 <= log10NHI < 19.0:
f17p5 = 9.332543e8 * (1+z)**9.9 * (10.0**17.5)**-2.0
f19 = 0.449780 * (1+z)**1.27 * (10.0**19)**-1.05
b = np.log10(f17p5/f19)/1.5
a = f17p5 * (10.0**17.5)**b
return a * N_HI**-b
elif 19.0 <= log10NHI < 20.3:
a = 0.449780
b = 1.05
g = 1.27
elif 20.3 <= log10NHI:
a = 8.709636e18
b = 2.0
g = 1.27
return a * (1+z)**g * N_HI**-b
return 0.0
vf_HM12 = np.vectorize(f_HM12, otypes=[np.float])
def sigma_HI(nu):
"""Calculate the HI ionization cross-section.
This parameterisation is taken from Osterbrock and Ferland 2006
(Sausalito, California: University Science Books), Equation (2.4).
"""
a0 = 6.3e-18 # cm^2
if nu < nu0:
return 0.0
elif nu/nu0-1.0 == 0.0:
return a0*(nu0/nu)**4
else:
eps = np.sqrt(nu/nu0-1.0)
return (a0 * (nu0/nu)**4 * np.exp(4.0-4.0*np.arctan(eps)/eps) /
(1.0-np.exp(-2.0*np.pi/eps)))
def tau_eff(nu, z):
"""Calculate the effective opacity between redshifts z0 and z.
There are two magic numbers: N_HI_min, N_HI_max. These should
ideally be 0 and infinity, but I have chosen to avoid improper
integrals here.
"""
N_HI_min = 1.0e11
N_HI_max = 10.0**21.55 # Limit taken in HM12 Table 1.
n = np.logspace(np.log(N_HI_min), np.log(N_HI_max), num=50, base=np.e)
fn = n * vf_HM12(n, z) * (1.0-np.exp(-n*sigma_HI(nu)))
return np.trapz(fn, x=np.log(n))
def luminosity(M):
return 10.0**((51.60-M)/2.5) # ergs s^-1 Hz^-1
def fnu(nu, M):
L = luminosity(M)
w = c_angPerSec / nu
nu_912 = c_angPerSec / 912.0
nu_1450 = c_angPerSec / 1450.0
a = L
b = a * (912.0/1450.0)**0.61
if w > 912.0:
e = a*(w/1450.0)**0.61
else:
if M < -23.0:
e = b*(w/912.0)**1.70
else:
e = b*(w/912.0)**0.56
return e
vfnu = np.vectorize(fnu, excluded=['M'], otypes=[np.float])
def fnu_bright(nu):
"""Only the frequency term for M < -23.
"""
w = c_angPerSec / nu
nu_912 = c_angPerSec / 912.0
nu_1450 = c_angPerSec / 1450.0
a = 1.0
b = a * (912.0/1450.0)**0.61
if w > 912.0:
e = a*(w/1450.0)**0.61
else:
e = b*(w/912.0)**1.7
return e
vfnu_bright = np.vectorize(fnu_bright, otypes=[np.float])
def fnu_faint(nu):
"""Only the frequency term for M > -23.
"""
w = c_angPerSec / nu
nu_912 = c_angPerSec / 912.0
nu_1450 = c_angPerSec / 1450.0
a = 1.0
b = a * (912.0/1450.0)**0.61
if w > 912.0:
e = a*(w/1450.0)**0.61
else:
e = b*(w/912.0)**1.7
return e
vfnu_faint = np.vectorize(fnu_faint, otypes=[np.float])
def emissivity(w, z, loglf, theta, mbright=-30, mfaint=-18):
m = np.linspace(mbright, mfaint, num=100)
nu = c_angPerSec/w
farr = np.array([10.0**loglf(theta, x, z)*vfnu(nu, x) for x in m])
return np.trapz(farr, m, axis=0) # erg s^-1 Hz^-1 Mpc^-3
def emissivity_18(w, z):
nu = c_angPerSec/w
e1 = np.interp(z, z18, median18)
e = e1*vfnu_faint(nu)
return e # erg s^-1 Hz^-1 Mpc^-3
def emissivity_18_down(w, z):
nu = c_angPerSec/w
e1 = np.interp(z, z18, down18)
e = e1*vfnu_faint(nu)
return e # erg s^-1 Hz^-1 Mpc^-3
def emissivity_18_up(w, z):
nu = c_angPerSec/w
e1 = np.interp(z, z18, up18)
e = e1*vfnu_faint(nu)
return e # erg s^-1 Hz^-1 Mpc^-3
def emissivity_21(w, z):
nu = c_angPerSec/w
e1 = np.interp(z, z21, median21)
e = e1*vfnu_faint(nu)
return e # erg s^-1 Hz^-1 Mpc^-3
def emissivity_21_down(w, z):
nu = c_angPerSec/w
e1 = np.interp(z, z21, down21)
e = e1*vfnu_faint(nu)
return e # erg s^-1 Hz^-1 Mpc^-3
def emissivity_21_up(w, z):
nu = c_angPerSec/w
e1 = np.interp(z, z21, up21)
e = e1*vfnu_faint(nu)
return e # erg s^-1 Hz^-1 Mpc^-3
def g_lsa(z, loglf, theta):
"""Photoionisation rate with Local Source Approx.
"""
w = 912.0
em = emissivity(w, z, loglf, theta, mbright=-30.0, mfaint=-23.0)
alpha_EUV = -1.7
part1 = 4.6e-13 * (em/1.0e24) * ((1.0+z)/5.0)**(-2.4) / (1.5-alpha_EUV) # s^-1
em = emissivity(w, z, loglf, theta, mbright=-23.0, mfaint=-18.0)
alpha_EUV = -0.56
part2 = 4.6e-13 * (em/1.0e24) * ((1.0+z)/5.0)**(-2.4) / (1.5-alpha_EUV) # s^-1
return part1 + part2
def gs_lsa(lfg, dz=0.1, zmax=7.0):
zmin = 0.0
n = (zmax-zmin)/dz+1
zs = np.linspace(zmax, zmin, num=n)
theta = np.median(lfg.samples, axis=0)
gs = np.array([g_lsa(x, lfg.log10phi, theta) for x in zs])
return zs, gs
def j(emodel, loglf=None, theta=None, dz=0.1, n_ws=200, n_ws_int=100, zmax=7.0):
"""Calculate the mean specific intensity.
Actually, directly outputs a redshift, photoionisation rate, pair.
Needs a model for emissivity. From my tests, I have found that dz
= 0.01, n_ws = 600, n_ws_int = 400, and zmax = 9 is necessary for
convergence.
"""
ws = np.logspace(0.0, 5.0, num=n_ws)
nu = c_angPerSec/ws
j = np.zeros_like(nu)
zmin = 0.0
n = (zmax-zmin)/dz+1
zs = np.linspace(zmax, zmin, num=n)
gs = []
for z in zs:
if loglf is not None:
e = emodel(ws/(1.0+z), z, loglf, theta)
else:
e = emodel(ws/(1.0+z), z)
# [j] = erg s^-1 Hz^-1 cm^-2 sr^-1
j = j + (e*c_mpcPerYr*np.abs(dtdz(z))*dz*cmbympc**2)/(4.0*np.pi)
nu_rest = c_angPerSec*(1.0+z)/ws
t = np.array([tau_eff(x, z) for x in nu_rest])
j = j*np.exp(-t*dz)
n = 4.0*np.pi*j*(1.0+z)**3/(hplanck*nu_rest)
nu_int = np.logspace(np.log10(nu0), 18, num=n_ws_int)
n_int = np.interp(nu_int, nu_rest[::-1], n[::-1])
s = np.array([sigma_HI(x) for x in nu_int])
g = np.trapz(n_int*s, x=nu_int) # s^-1
gs.append(g)
gs = np.array(gs)
return zs, gs
def em_hm12(w, z):
"""HM12 Galaxies+QSO emissivity."""
return emissivity_HM12(w, z*np.ones_like(w), grid=False)
def em_qso_hm12(w, z):
"""HM12 QSOs-only emissivity."""
return vqso_emissivity_hm12(c_angPerSec/w, z)
def em_qso_mh15(w, z):
"""HM12 QSOs-only emissivity."""
return vqso_emissivity_mh15(c_angPerSec/w, z)
def calverley(ax):
zm, gm, gm_sigma = np.loadtxt('Data/calverley.dat',unpack=True)
gm += 12.0
gml = 10.0**gm
gml_up = 10.0**(gm+gm_sigma)-10.0**gm
gml_low = 10.0**gm - 10.0**(gm-gm_sigma)
ax.scatter(zm, gml, c='k', edgecolor='None',
label='Calverley et al.\ 2011', s=64, marker='v')
ax.errorbar(zm, gml, ecolor='k', capsize=5,
elinewidth=1.5, capthick=1.5,
yerr=np.vstack((gml_low, gml_up)),
fmt='None', zorder=1, mfc='darkorange',
mec='darkorange', markeredgewidth=1, ms=5)
return
def wyithe11(ax):
zm, gm, gm_u, gm_l = np.loadtxt('Data_new/wyithe11_gammaHI.txt',
unpack=True)
gml = gm
gml_up = gm_u
gml_low = gm_l
ax.scatter(zm, gml, c='k', edgecolor='None',
label='Wyithe \& Bolton 2011', s=64, marker='^')
ax.errorbar(zm, gml, ecolor='k', capsize=5,
elinewidth=1.5, capthick=1.5,
yerr=np.vstack((gml_low, gml_up)),
fmt='None', zorder=1, mfc='darkorange',
mec='darkorange', markeredgewidth=1, ms=5)
return
def daloisio18(ax):
zmin, zmax, gm, gm_u, gm_l = np.loadtxt('Data_new/daloisio18_gammaHI.txt',
unpack=True)
zm = (zmin+zmax)/2.0
gml = gm
gml_up = gm_u
gml_low = gm_l
ax.scatter(zm, gml, c='dodgerblue', edgecolor='None',
label="D'Aloisio et al.\ 2018", s=64, marker='h')
ax.errorbar(zm, gml, ecolor='dodgerblue', capsize=5,
elinewidth=1.5, capthick=1.5,
yerr=np.vstack((gml_low, gml_up)),
fmt='None', zorder=1, mfc='darkorange',
mec='darkorange', markeredgewidth=1, ms=5)
return
def davies17(ax):
zmin, zmax, gm, gm_u, gm_l = np.loadtxt('Data_new/davies17_gammaHI.txt',
unpack=True)
gm += 12.0
zmin = zmin[(gm_u!=0.0)]
zmax = zmax[(gm_u!=0.0)]
gm = gm[(gm_u!=0.0)]
gm_l = gm_l[(gm_u!=0.0)]
gm_u = gm_u[(gm_u!=0.0)]
zm = (zmin+zmax)/2.0
gml = 10.0**gm
gml_up = 10.0**(gm+gm_u)-10.0**gm
gml_low = 10.0**gm - 10.0**(gm-gm_l)
ax.scatter(zm, gml, c='g', edgecolor='None',
label="Davies et al.\ 2018", s=64, marker='s')
ax.errorbar(zm, gml, ecolor='g', capsize=5,
elinewidth=1.5, capthick=1.5,
yerr=np.vstack((gml_low, gml_up)),
fmt='None', zorder=1, mfc='darkorange',
mec='darkorange', markeredgewidth=1, ms=5)
zmin, zmax, gm, gm_u, gm_l = np.loadtxt('Data_new/davies17_gammaHI.txt',
unpack=True)
gm += 12.0
zmin = zmin[(gm_u==0.0)]
zmax = zmax[(gm_u==0.0)]
gm = gm[(gm_u==0.0)]
zm = (zmin+zmax)/2.0
gml = 10.0**gm
ax.scatter(zm, gml, c='g', edgecolor='None',
s=64, marker='s')
ax.errorbar(zm, gml, yerr=0.05, ecolor='g', capsize=5, uplims=True,
elinewidth=1.5, capthick=1.5,
fmt='None', zorder=1, mfc='darkorange',
mec='darkorange', markeredgewidth=1, ms=5)
return
def bb13(ax, puc=False):
zm, gm, gm_up, gm_low = np.loadtxt('Data/BeckerBolton.dat', unpack=True)
gml = 10.0**gm
gml_up = 10.0**(gm+gm_up)-10.0**gm
gml_low = 10.0**gm - 10.0**(gm-np.abs(gm_low))
if puc:
ax.scatter(1+zm, gml, c='k', edgecolor='None', marker='v',
label='Becker \& Bolton 2013', s=64, zorder=10)
ax.errorbar(1+zm, gml, ecolor='k', capsize=5,
elinewidth=2, capthick=3,
yerr=np.vstack((gml_low, gml_up)),
fmt='None', zorder=10, mfc='k', mec='k',
markeredgewidth=1.5, ms=5)
return
ax.scatter(zm, gml, c='k', edgecolor='None',
label='Becker \& Bolton 2013', s=64, zorder=10)
ax.errorbar(zm, gml, ecolor='k', capsize=5,
elinewidth=2, capthick=3,
yerr=np.vstack((gml_low, gml_up)),
fmt='None', zorder=10, mfc='k', mec='k',
markeredgewidth=1.5, ms=5)
return
def g_hm12_total(ax, puc=False):
zs = np.linspace(0.0, 7.0, num=200)
nu = np.logspace(np.log10(nu0), 18, num=100)
g_hm12 = []
for r in zs:
j_hm12 = bkgintens_HM12(c_angPerSec/nu, r*np.ones_like(nu), grid=False)
n = 4.0*np.pi*j_hm12/(hplanck*nu)
s = np.array([sigma_HI(x) for x in nu])
g_hm12.append(np.trapz(n*s, x=nu)) # s^-1
if puc:
ax.plot(1+zs, np.array(g_hm12)/1.0e-12, c='brown', lw=1, dashes=[1,1],
label='Haardt \& Madau 2012', zorder=2)
return
ax.plot(zs, np.array(g_hm12)/1.0e-12, c='brown', lw=1, dashes=[1,1],
label='Haardt \& Madau 2012')
return
def lfis(individuals, ax):
for x in individuals:
get_gammapi_percentiles(x, x.z.mean())
reject = [0, 1, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
m = np.ones(len(individuals), dtype=bool)
m[reject] = False
minv = np.logical_not(m)
individuals_good = [x for i, x in enumerate(individuals)
if i not in set(reject)]
individuals_bad = [x for i, x in enumerate(individuals)
if i in set(reject)]
c = np.array([x.gammapi[2]+12.0 for x in individuals_good])
u = np.array([x.gammapi[0]+12.0 for x in individuals_good])
l = np.array([x.gammapi[1]+12.0 for x in individuals_good])
gml = 10.0**c
gml_up = 10.0**u-10.0**c
gml_low = 10.0**c - 10.0**l
zs = np.array([x.z.mean() for x in individuals_good])
uz = np.array([x.z.max() for x in individuals_good])
lz = np.array([x.z.min() for x in individuals_good])
uz = np.array([x.zlims[0] for x in individuals_good])
lz = np.array([x.zlims[1] for x in individuals_good])
uzerr = uz-zs
lzerr = zs-lz
ax.scatter(zs, gml, c='k', edgecolor='k',
label='Individual fits (accepted; $M<-18$)',
s=44, zorder=4, linewidths=1.5)
ax.errorbar(zs, gml, ecolor='k', capsize=0, fmt='None', elinewidth=1.5,
yerr=np.vstack((gml_low,gml_up)),
xerr=np.vstack((lzerr,uzerr)),
mfc='#ffffff', mec='#404040', zorder=3, mew=1,
ms=5)
c = np.array([x.gammapi[2]+12.0 for x in individuals_bad])
u = np.array([x.gammapi[0]+12.0 for x in individuals_bad])
l = np.array([x.gammapi[1]+12.0 for x in individuals_bad])
gml = 10.0**c
gml_up = 10.0**u-10.0**c
gml_low = 10.0**c - 10.0**l
zs = np.array([x.z.mean() for x in individuals_bad])
uz = np.array([x.z.max() for x in individuals_bad])
lz = np.array([x.z.min() for x in individuals_bad])
uz = np.array([x.zlims[0] for x in individuals_bad])
lz = np.array([x.zlims[1] for x in individuals_bad])
uzerr = uz-zs
lzerr = zs-lz
ax.scatter(zs, gml, c='#ffffff', edgecolor='k',
label='Individual fits (rejected; $M<-18$)',
s=44, zorder=4, linewidths=1.5)
ax.errorbar(zs, gml, ecolor='k', capsize=0, fmt='None', elinewidth=1.5,
yerr=np.vstack((gml_low,gml_up)),
xerr=np.vstack((lzerr,uzerr)),
mfc='#ffffff', mec='#404040', zorder=3, mew=1,
ms=5)
return
def Gamma_HI(em, z):
"""Taken from Equation 11 of Lusso et al. 2015.
"""
alpha_EUV = -0.56
g = 4.6e-13 * (em/1.0e24) * ((1.0+z)/5.0)**(-2.4) / (1.5-alpha_EUV) # s^-1
return g
def gamma_HI_Manti17(z):
"""Manti et al. 2017 (MNRAS 466 1160) Equation (9).
"""
logg = - 11.66 - 0.081*z - 0.00014*z**2 + 0.0033*z**3 - 0.0013*z**4
return 10.0**logg # s^-1
def kollmeier(ax, puc=False):
"""Plot Kollmeier's Gamma_HI values.
These are from 2014 ApJ 789 L32. Adjusted by Gabor to our 373
cosmology. See his note for details.
"""
z = 0.1
g = 2.2e-13 # s^-1
if puc:
ax.scatter(1+z, g*1.0e12, c='k', edgecolor='None',
label='Kollmeier et al.\ 2014', s=64, marker='p')
else:
ax.scatter(z, g*1.0e12, c='k', edgecolor='None',
label='Kollmeier et al.\ 2014', s=64)
return
def bolton17(ax):
"""Plot Sherwood Gamma_HI value.
These are from 2017 MNRAS 464 897. Adjusted by Gabor to our 373
cosmology. See his note for details. We only show the z = 2
value on the PUC plot.
"""
z = 2.0
g = 1.87e-12 # s^-1
ax.scatter(1+z, g*1.0e12, c='k', edgecolor='None',
label='Bolton et al.\ 2017', s=64, marker='s')
return
def shull(ax, puc=False):
"""Plot Shull's Gamma_HI values.
These are from 2015 ApJ 811 3. Adjusted by Gabor to our 373
cosmology. See his note for details.
"""
if puc:
z = np.linspace(0, 0.47)
g = 5.0e-14 * (1.0+z)**4.4 # s^-1
ax.plot(1+z, g*1.0e12, lw=2, c='k', label='Shull et al.\ 2015',
dashes=[7,2], zorder=5)
return
z = np.linspace(0, 0.47)
g = 5.0e-14 * (1.0+z)**4.4 # s^-1
ax.plot(z, g*1.0e12, lw=4, c='#8c564b', label='Shull et al.\ 2015')
return
def khaire(ax, puc=False):
"""Plot Khaire's Gamma_HI values.
These are from 2015 MNRAS 451 L30. They correspond to Khaire's
fesc=0 model. Obtained from Khaire by email.
"""
z, g = np.loadtxt('Data_new/khaire15_gammaHI.dat',
usecols=(0,1), unpack=True)
if puc:
ax.plot(1+z, g*1.0e12, lw=2, c='peru',
label='Khaire \& Srianand 2015 QSOs',
zorder=2, dashes=[5,2])
return
ax.plot(z, g*1.0e12, lw=2, c='peru',
label='Khaire \& Srianand 2015 QSOs',
zorder=2, dashes=[5,2])
return
def puchwein(ax, puc=False):
"""Plot Puchwein's Gamma_HI values.
These are from https://arxiv.org/src/1801.04931v1/anc/rates_fiducial.txt
"""
z, g = np.loadtxt('Data_new/puchwein18_gammaHI.dat',
usecols=(0,1), unpack=True)
if puc:
ax.plot(1+z, g*1.0e12, lw=2, c='brown',
label='Puchwein et al.\ 2018',
dashes=[7,2], zorder=2)
return
ax.plot(z, g*1.0e12, lw=2, c='grey',
label='Puchwein et al.\ 2018',
dashes=[7,2], zorder=2)
return
def bolton(ax):
"""Plot Bolton's Gamma_HI values.
These are from MNRAS 2017 464 897, as rescaled by Gabor.
"""
z = np.array([2.0, 3.0, 4.0, 5.0])
g = np.array([1.87e-12, 9.15e-13, 8.83e-13, 7.55e-13]) # s^-1
ax.plot(z, g*1.0e12, lw=2, c='#9467bd', label='Bolton et al.\ 2017')
return
def onorbe(ax, puc=False):
"""Plot Onorbe's Gamma_HI values.
These are from ApJ 2017 837 106, Table 3.
"""
log1pz, g = np.loadtxt('Data_new/onorbe17_gammaHI.dat',
usecols=(0,1), unpack=True)
z = 10.0**log1pz - 1.0
if puc:
ax.plot(1+z, g*1.0e12, c='grey', lw=2,
label='O\~norbe et al.\ 2017',
dashes=[2,2], zorder=2)
return
ax.plot(z, g*1.0e12, c='grey', lw=2,
label='O\~norbe et al.\ 2017',
dashes=[2,2], zorder=2)
return
def viel(ax, puc=False):
"""Plot Viel's Gamma_HI values.
These are from MNRAS 2017 467 L86.
"""
z = 0.1
g = 0.071e-12 # s^-1
if puc:
zmin = 1.09
emin = 0.05
zmax = 1.11
emax = 0.1
dz = zmax - zmin
de = emax - emin
rect = mpatches.Rectangle((zmin, emin), dz, de,
ec='k', color='#ffffff',
lw=2, zorder=10,
label='Viel et al.\ 2017')
ax.add_patch(rect)
return
return
def gaikwad_a(ax):
"""Plot Gaikwad's Gamma_HI values.
These are from his Paper I (MNRAS 2017 466 838) rescaled to our cosmology by Gabor.
"""
z = np.array([0.1125, 0.2, 0.3, 0.4])
zmin = np.array([0.075, 0.15, 0.25, 0.35])
zmax = np.array([0.15, 0.25, 0.35, 0.45])
uzerr = zmax - z
lzerr = z - zmin
g = np.array([7.095e-14, 1.075e-13, 1.559e-13, 2.258e-13])
gerr = np.array([1.613e-14, 2.258e-14, 3.978e-14, 5.590e-14])
ax.scatter(z, g*1.0e12, c='#d62728', edgecolor='None',
label='Gaikwad et al.\ 2017a',
s=64, zorder=10, linewidths=1.5)
ax.errorbar(z, g*1.0e12, ecolor='#d62728', capsize=0,
fmt='None', elinewidth=1.5, zorder=10,
xerr=np.vstack((lzerr, uzerr)),
yerr=gerr*1.0e12)