/
cos_corr.pro
7101 lines (6433 loc) · 282 KB
/
cos_corr.pro
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
; docformat = 'rst'
;
;+
;
; Plot correlations.
;
; :Categories:
; COSQUEST
;
; :Returns:
; Postscript plots.
;
; :Params:
;
; :Keywords:
;
; :Author:
; David S. N. Rupke::
; Rhodes College
; Department of Physics
; 2000 N. Parkway
; Memphis, TN 38104
; drupke@gmail.com
;
; :History:
; ChangeHistory::
; 2016aug02, DSNR, created
;
; :Copyright:
; Copyright (C) 2016--2021 David S. N. Rupke
;
; This program is free software: you can redistribute it and/or
; modify it under the terms of the GNU General Public License as
; published by the Free Software Foundation, either version 3 of
; the License or any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see
; http://www.gnu.org/licenses/.
;
;-
; Routine from E. Cameron 2011, PASP
; z = DINDGEN(10000)*0.0001d
function betaprob,c,k,n,z
Beta = IBETA(k+1,n-k+1,z)
ill = VALUE_LOCATE(Beta,(1-c)/2)
iul = VALUE_LOCATE(Beta,1-(1-c)/2)
plower = z[ill]
pupper = z[iul]
return,[plower,pupper]
end
;;;
pro cos_corr
bad = 1d99
fwhm2sig = 2d*sqrt(2d*alog(2d))
lsun_ergps = 3.839d33 ; L_Sun in erg/s
llsun_ergps = alog10(lsun_ergps)
c_cms = 2.99792458d10
c_kms = 2.99792458d5
spy = 3600d*24d*365.25d
msun_g = 1.989d33
eddfac = 1.26d38 ; 4 Pi G m_p c / sigma_T, in erg/s/M_sun
; linmix_err iterations
lm_miniter = 7894L ; 15787 is 4sigma, and miniter typically gets doubled
lm_maxiter = 315740L ; 20 x 15787
; Threshold pval for marking as significant in output regression table
tpval = 0.05
qsotab='/Users/drupke/Box Sync/qsos/qsos.csv'
cosdir='/Users/drupke/Box Sync/cosquest/'
fitdir=cosdir+'fits/'
plotdir=cosdir+'plots/correlations/'
tabdir=cosdir+'tables/'
specdir=cosdir+'spectra/'
linelist = ifsf_linelist(['OVI1031','OVI1037','NV1238','NV1242',$
'PV1117','PV1128'],vacuum=1b)
; for tables
lerr0 = '$_{-'
lerr1 = '}^{+'
lerr2 = '}$'
amp = '&'
dslash = '\\'
ndat = '\nodata'
lineofdashes = strjoin(replicate('-',62))
; Read table
rows=[3,85]
gal = read_csvcol(qsotab,'A',rows=rows,sep=',',type='string')
sgal = read_csvcol(qsotab,'C',rows=rows,sep=',',type='string')
z = read_csvcol(qsotab,'D',rows=rows,sep=',',junk=bad)
lir = read_csvcol(qsotab,'F',rows=rows,sep=',',junk=bad)
lbol = read_csvcol(qsotab,'G',rows=rows,sep=',',junk=bad)
agnfrac = read_csvcol(qsotab,'H',rows=rows,sep=',',junk=bad)
agnfraclb = read_csvcol(qsotab,'I',rows=rows,sep=',',junk=bad)
agnfracub = read_csvcol(qsotab,'J',rows=rows,sep=',',junk=bad)
mbh_phot = read_csvcol(qsotab,'M',rows=rows,sep=',',junk=bad)
lmbh_rev = read_csvcol(qsotab,'N',rows=rows,sep=',',junk=bad)
lmbh_rev_errhi = read_csvcol(qsotab,'O',rows=rows,sep=',',junk=bad)
lmbh_rev_errlo = read_csvcol(qsotab,'P',rows=rows,sep=',',junk=bad)
lmbh_rev_type = read_csvcol(qsotab,'Q',rows=rows,sep=',',type='string')
cossamp = read_csvcol(qsotab,'AD',rows=rows,sep=',',type='string')
nvstatus = read_csvcol(qsotab,'AE',rows=rows,sep=',',type='string')
ovistatus = read_csvcol(qsotab,'AF',rows=rows,sep=',',type='string')
gamxray = read_csvcol(qsotab,'AR',rows=rows,sep=',',junk=bad)
gamxray_errlo = read_csvcol(qsotab,'AS',rows=rows,sep=',',junk=bad)
gamxray_errhi = read_csvcol(qsotab,'AT',rows=rows,sep=',',junk=bad)
nhxray = read_csvcol(qsotab,'AU',rows=rows,sep=',',junk=bad)
nhxray_errlo = read_csvcol(qsotab,'AV',rows=rows,sep=',',junk=bad)
nhxray_errhi = read_csvcol(qsotab,'AW',rows=rows,sep=',',junk=bad)
fsoftxray = read_csvcol(qsotab,'AX',rows=rows,sep=',',junk=bad)
fsoftxray_errlo = read_csvcol(qsotab,'AY',rows=rows,sep=',',junk=bad)
fsoftxray_errhi = read_csvcol(qsotab,'AZ',rows=rows,sep=',',junk=bad)
fhardxray = read_csvcol(qsotab,'BA',rows=rows,sep=',',junk=bad)
fhardxray_errlo = read_csvcol(qsotab,'BB',rows=rows,sep=',',junk=bad)
fhardxray_errhi = read_csvcol(qsotab,'BC',rows=rows,sep=',',junk=bad)
lsoftxray = read_csvcol(qsotab,'BD',rows=rows,sep=',',junk=bad)
lhardxray = read_csvcol(qsotab,'BE',rows=rows,sep=',',junk=bad)
alphaox = read_csvcol(qsotab,'BL',rows=rows,sep=',',junk=bad)
lfir = read_csvcol(qsotab,'BN',rows=rows,sep=',',junk=bad)
ebvgal = read_csvcol(qsotab,'BS',rows=rows,sep=',',junk=bad)
; Get flam1125
readcol,tabdir+'tab_specvals.txt',spgal,flam1125,skip=4,/silent,format='(A,D,X)'
; Parse table data
icos = where(cossamp eq 'V18',ncos)
nlines = n_elements(gal)
tabdat = orderedhash()
tabdat['gal'] = gal[icos]
tabdat['sgal'] = sgal[icos]
tabdat['z'] = z[icos]
tabdat['lir'] = lir[icos]
tabdat['lfir'] = lfir[icos]
tabdat['lbol'] = lbol[icos]
tabdat['agnfrac'] = agnfrac[icos]
tabdat['agnfraclb'] = agnfraclb[icos]
tabdat['agnfracub'] = agnfracub[icos]
tabdat['mbh_phot'] = mbh_phot[icos]
tabdat['lmbh_rev'] = lmbh_rev[icos]
tabdat['lmbh_rev_errlo'] = lmbh_rev_errlo[icos]
tabdat['lmbh_rev_errhi'] = lmbh_rev_errhi[icos]
tabdat['lmbh_rev_type'] = lmbh_rev_type[icos]
tabdat['nvstatus'] = nvstatus[icos]
tabdat['ovistatus'] = ovistatus[icos]
tabdat['alphaox'] = alphaox[icos]
tabdat['ebvgal'] = ebvgal[icos]
tabdat['flam1125'] = flam1125
; Correct cosmologies
; To convert cosmologies, back out -2 log(d_L)_old and add 2 log(d_L)_new
tabdat['lbol'] = tabdat['lbol'] - $
2d*(alog10(lumdist(tabdat['z'],H0=70d,Om=0.3d,Lam=0.7d)) - $
alog10(lumdist(tabdat['z'],H0=69.3d,Om=0.287d,Lam=0.713d)))
tabdat['lir'] = tabdat['lir'] - $
2d*(alog10(lumdist(tabdat['z'],H0=67.8d,Om=0.308d,Lam=0.692d)) - $
alog10(lumdist(tabdat['z'],H0=69.3d,Om=0.287d,Lam=0.713d)))
; output table for x-ray quantities for Table 1
openw,lun_tmp,tabdir+'tab_table1quants_xray.tex',/get_lun
printf,lun_tmp,'#Col 2: log[L(0.5-2keV)/10^44 erg/s]_error_low^error_hi
printf,lun_tmp,'#Col 3: log[L(2-10keV)/10^44 erg/s]_error_low^error_hi
; X-ray data requires special handling because of multiple measurements
tabdat['n_xray'] = dblarr(ncos)
tabdat['gamxray'] = dblarr(ncos,6)+bad
tabdat['gamxray_errlo'] = dblarr(ncos,6)
tabdat['gamxray_errhi'] = dblarr(ncos,6)
tabdat['nhxray'] = dblarr(ncos,6)+bad
tabdat['nhxray_errlo'] = dblarr(ncos,6)
tabdat['nhxray_errhi'] = dblarr(ncos,6)
tabdat['nhxray_lim'] = dblarr(ncos,6)+bad
tabdat['fsoftxray'] = dblarr(ncos,6)+bad
tabdat['fsoftxray_errlo'] = dblarr(ncos,6)
tabdat['fsoftxray_errhi'] = dblarr(ncos,6)
tabdat['fhardxray'] = dblarr(ncos,6)+bad
tabdat['fhardxray_errlo'] = dblarr(ncos,6)
tabdat['fhardxray_errhi'] = dblarr(ncos,6)
tabdat['lsoftxray'] = dblarr(ncos,6)+bad
tabdat['lsoftxray_errlo'] = dblarr(ncos,6)
tabdat['lsoftxray_errhi'] = dblarr(ncos,6)
tabdat['lhardxray'] = dblarr(ncos,6)+bad
tabdat['lhardxray_errlo'] = dblarr(ncos,6)
tabdat['lhardxray_errhi'] = dblarr(ncos,6)
tabdat['ltotxray'] = dblarr(ncos,6)+bad
tabdat['ltotxray_errlo'] = dblarr(ncos,6)
tabdat['ltotxray_errhi'] = dblarr(ncos,6)
tabdat['lsoftratxray'] = dblarr(ncos,6)+bad
tabdat['lsoftratxray_err'] = dblarr(ncos,6)+bad
tabdat['lxlbol'] = dblarr(ncos,6)+bad
tabdat['lxlbol_errlo'] = dblarr(ncos,6)+bad
tabdat['lxlbol_errhi'] = dblarr(ncos,6)+bad
j = -1 ; galaxy index
k = 0 ; zero x-ray component index
for i=0,nlines-1 do begin
if gal[i] ne '' AND cossamp[i] eq 'V18' then begin
j++ ; increment galaxy index
hardstring=''
softstring=''
if gamxray[i] ne bad then begin
k = 0 ; re-zero x-ray component index
; record first x-ray measurement
tabdat['n_xray',j] = k+1
tabdat['gamxray',j,k] = gamxray[i]
tabdat['gamxray_errlo',j,k] = gamxray_errlo[i]
tabdat['gamxray_errhi',j,k] = gamxray_errhi[i]
if nhxray[i] eq 0d then begin
if nhxray_errhi[i] ne 0d then $
tabdat['nhxray_lim',j,k] = alog10(nhxray_errhi[i]) + 22d $
else $
tabdat['nhxray_lim',j,k] = 21d
endif else begin
tabdat['nhxray',j,k] = alog10(nhxray[i])+22d
tabdat['nhxray_errlo',j,k] = $
alog10(nhxray[i]) - alog10(nhxray[i] - nhxray_errlo[i])
tabdat['nhxray_errhi',j,k] = $
alog10(nhxray[i] + nhxray_errhi[i]) - alog10(nhxray[i])
endelse
if lsoftxray[i] ne bad then begin
tabdat['lsoftxray',j,k] = alog10(lsoftxray[i])+44d
softstring = $
string(tabdat['lsoftxray',j,k],format='(D0.2)')
if fsoftxray[i] ne bad then begin
tabdat['fsoftxray',j,k] = alog10(fsoftxray[i]) - 12d
if fsoftxray_errlo[i] ne 0d AND $
fsoftxray_errlo[i] ne bad then begin
; compute flux errors in log space
tabdat['fsoftxray_errlo',j,k] = $
alog10(fsoftxray[i]) - $
alog10(fsoftxray[i] - fsoftxray_errlo[i])
tabdat['fsoftxray_errhi',j,k] = $
alog10(fsoftxray[i] + fsoftxray_errhi[i]) - $
alog10(fsoftxray[i])
fsoftxray_err = (fsoftxray_errlo[i] + fsoftxray_errhi[i])/2d
; Compute luminosity errors from flux errors
tabdat['lsoftxray_errlo',j,k] = $
alog10(lsoftxray[i]) - $
alog10(lsoftxray[i] - lsoftxray[i] * $
fsoftxray_errlo[i] / fsoftxray[i])
tabdat['lsoftxray_errhi',j,k] = $
alog10(lsoftxray[i] + lsoftxray[i] * $
fsoftxray_errhi[i] / fsoftxray[i]) - $
alog10(lsoftxray[i])
if tabdat['lsoftxray_errlo',j,k] lt 0.0095 OR $
tabdat['lsoftxray_errhi',j,k] lt 0.0095 then $
fstring = '(D0.3,A0,D0.3,A0,D0.3,A0)' $
else fstring = '(D0.2,A0,D0.2,A0,D0.2,A0)'
softstring = $
string(tabdat['lsoftxray',j,k],'$_{-',$
tabdat['lsoftxray_errlo',j,k],'}^{+',$
tabdat['lsoftxray_errhi',j,k],'}$',$
format=fstring)
; case of no flux errors; assume 10%
endif else begin
tabdat['fsoftxray_errlo',j,k] = $
alog10(fsoftxray[i]) - alog10(0.9d * fsoftxray[i])
tabdat['fsoftxray_errhi',j,k] = $
alog10(1.1d * fsoftxray[i]) - alog10(fsoftxray[i])
tabdat['lsoftxray_errlo',j,k] = $
alog10(lsoftxray[i]) - alog10(0.9d * lsoftxray[i])
tabdat['lsoftxray_errhi',j,k] = $
alog10(1.1d * lsoftxray[i]) - alog10(lsoftxray[i])
fsoftxray_err = 0.1d * fsoftxray[i]
endelse
endif
endif
if lhardxray[i] ne bad then begin
tabdat['lhardxray',j,k] = alog10(lhardxray[i])+44d
hardstring = $
string(tabdat['lhardxray',j,k],format='(D0.2)')
if fhardxray[i] ne bad then begin
tabdat['fhardxray',j,k] = alog10(fhardxray[i]) - 12d
if fhardxray_errlo[i] ne 0d AND $
fhardxray_errlo[i] ne bad then begin
; compute flux errors in log space
tabdat['fhardxray_errlo',j,k] = $
alog10(fhardxray[i]) - $
alog10(fhardxray[i] - fhardxray_errlo[i])
tabdat['fhardxray_errhi',j,k] = $
alog10(fhardxray[i] + fhardxray_errhi[i]) - $
alog10(fhardxray[i])
tabdat['lhardxray_errlo',j,k] = $
alog10(lhardxray[i]) - $
alog10(lhardxray[i] - lhardxray[i] * $
fhardxray_errlo[i] / fhardxray[i])
fhardxray_err = (fhardxray_errlo[i] + fhardxray_errhi[i])/2d
; Compute luminosity errors from flux errors
tabdat['lhardxray_errhi',j,k] = $
alog10(lhardxray[i] + lhardxray[i] * $
fhardxray_errhi[i] / fhardxray[i]) - $
alog10(lhardxray[i])
if tabdat['lhardxray_errlo',j,k] lt 0.0095 OR $
tabdat['lhardxray_errhi',j,k] lt 0.0095 then $
fstring = '(D0.3,A0,D0.3,A0,D0.3,A0)' $
else fstring = '(D0.2,A0,D0.2,A0,D0.2,A0)'
hardstring = $
string(tabdat['lhardxray',j,k],'$_{-',$
tabdat['lhardxray_errlo',j,k],'}^{+',$
tabdat['lhardxray_errhi',j,k],'}$',$
format=fstring)
; case of no flux errors; assume 10%
endif else begin
tabdat['fhardxray_errlo',j,k] = $
alog10(fhardxray[i]) - alog10(0.9d * fhardxray[i])
tabdat['fhardxray_errhi',j,k] = $
alog10(1.1d * fhardxray[i]) - alog10(fhardxray[i])
tabdat['lhardxray_errlo',j,k] = $
alog10(lhardxray[i]) - alog10(0.9d * lhardxray[i])
tabdat['lhardxray_errhi',j,k] = $
alog10(1.1d * lhardxray[i]) - alog10(lhardxray[i])
fhardxray_err = 0.1d * fhardxray[i]
endelse
endif
endif
if lhardxray[i] ne bad AND lsoftxray[i] ne bad AND $
lsoftxray[i] ne 0d then begin
tabdat['ltotxray',j,k] = alog10(lsoftxray[i] + lhardxray[i])+44d
totxray = lsoftxray[i] + lhardxray[i]
tabdat['ltotxray_errlo',j,k] = $
sqrt(tabdat['lsoftxray_errlo',j,k]^2d + $
tabdat['lhardxray_errlo',j,k]^2d)
tabdat['ltotxray_errhi',j,k] = $
sqrt(tabdat['lsoftxray_errhi',j,k]^2d + $
tabdat['lhardxray_errhi',j,k]^2d)
tabdat['lsoftratxray',j,k] = $
tabdat['lsoftxray',j,k] - tabdat['ltotxray',j,k]
tabdat['lsoftratxray_err',j,k] = $
sqrt(fsoftxray[i]^2d * fhardxray_err^2d + $
fhardxray[i]^2d * fsoftxray_err^2d) / $
(fsoftxray[i]+fhardxray[i])^2d
tabdat['lxlbol',j,k] = tabdat['ltotxray',j,k] - $
llsun_ergps - tabdat['lbol',j]
tabdat['lxlbol_errlo',j,k] = tabdat['ltotxray_errlo',j,k]
tabdat['lxlbol_errhi',j,k] = tabdat['ltotxray_errhi',j,k]
endif
printf,lun_tmp,gal[i],softstring,hardstring,$
format='(A-12,2A27)'
k++
endif else begin
tabdat['n_xray',j] = 0 ; record number of x-ray components
k = 0 ; re-zero x-ray component index
endelse
endif else if gal[i] eq '' then begin
if k gt 0 then begin
hardstring=''
softstring=''
if gamxray[i] ne bad then begin
tabdat['n_xray',j] = k+1
tabdat['gamxray',j,k] = gamxray[i]
tabdat['gamxray_errlo',j,k] = gamxray_errlo[i]
tabdat['gamxray_errhi',j,k] = gamxray_errhi[i]
if nhxray[i] eq 0d then begin
if nhxray_errhi[i] ne 0d then $
tabdat['nhxray_lim',j,k] = alog10(nhxray_errhi[i]) + 22d $
else $
tabdat['nhxray_lim',j,k] = 21d
endif else begin
tabdat['nhxray',j,k] = alog10(nhxray[i])+22d
tabdat['nhxray_errlo',j,k] = $
alog10(nhxray[i]) - alog10(nhxray[i] - nhxray_errlo[i])
tabdat['nhxray_errhi',j,k] = $
alog10(nhxray[i] + nhxray_errhi[i]) - alog10(nhxray[i])
endelse
if lsoftxray[i] ne bad then begin
tabdat['lsoftxray',j,k] = alog10(lsoftxray[i])+44d
softstring = $
string(tabdat['lsoftxray',j,k],format='(D0.2)')
if fsoftxray[i] ne bad then begin
tabdat['fsoftxray',j,k] = alog10(fsoftxray[i]) - 12d
if fsoftxray_errlo[i] ne 0d AND $
fsoftxray_errlo[i] ne bad then begin
; compute flux errors in log space
tabdat['fsoftxray_errlo',j,k] = $
alog10(fsoftxray[i]) - $
alog10(fsoftxray[i] - fsoftxray_errlo[i])
tabdat['fsoftxray_errhi',j,k] = $
alog10(fsoftxray[i] + fsoftxray_errhi[i]) - $
alog10(fsoftxray[i])
fsoftxray_err = (fsoftxray_errlo[i] + fsoftxray_errhi[i])/2d
; Compute luminosity errors from flux errors
tabdat['lsoftxray_errlo',j,k] = $
alog10(lsoftxray[i]) - $
alog10(lsoftxray[i] - lsoftxray[i] * $
fsoftxray_errlo[i] / fsoftxray[i])
tabdat['lsoftxray_errhi',j,k] = $
alog10(lsoftxray[i] + lsoftxray[i] * $
fsoftxray_errhi[i] / fsoftxray[i]) - $
alog10(lsoftxray[i])
if tabdat['lsoftxray_errlo',j,k] lt 0.0095 OR $
tabdat['lsoftxray_errhi',j,k] lt 0.0095 then $
fstring = '(D0.3,A0,D0.3,A0,D0.3,A0)' $
else fstring ='(D0.2,A0,D0.2,A0,D0.2,A0)'
softstring = $
string(tabdat['lsoftxray',j,k],'$_{-',$
tabdat['lsoftxray_errlo',j,k],'}^{+',$
tabdat['lsoftxray_errhi',j,k],'}$',$
format=fstring)
; case of no flux errors; assume 10%
endif else begin
tabdat['fsoftxray_errlo',j,k] = $
alog10(fsoftxray[i]) - alog10(0.9d * fsoftxray[i])
tabdat['fsoftxray_errhi',j,k] = $
alog10(1.1d * fsoftxray[i]) - alog10(fsoftxray[i])
tabdat['lsoftxray_errlo',j,k] = $
alog10(lsoftxray[i]) - alog10(0.9d * lsoftxray[i])
tabdat['lsoftxray_errhi',j,k] = $
alog10(1.1d * lsoftxray[i]) - alog10(lsoftxray[i])
fsoftxray_err = 0.1d * fsoftxray[i]
endelse
endif
endif
if lhardxray[i] ne bad then begin
tabdat['lhardxray',j,k] = alog10(lhardxray[i])+44d
hardstring = $
string(tabdat['lhardxray',j,k],format='(D0.2)')
if fhardxray[i] ne bad then begin
tabdat['fhardxray',j,k] = alog10(fhardxray[i]) - 12d
if fhardxray_errlo[i] ne 0d AND $
fhardxray_errlo[i] ne bad then begin
; compute flux errors in log space
tabdat['fhardxray_errlo',j,k] = $
alog10(fhardxray[i]) - $
alog10(fhardxray[i] - fhardxray_errlo[i])
tabdat['fhardxray_errhi',j,k] = $
alog10(fhardxray[i] + fhardxray_errhi[i]) - $
alog10(fhardxray[i])
tabdat['lhardxray_errlo',j,k] = $
alog10(lhardxray[i]) - $
alog10(lhardxray[i] - lhardxray[i] * $
fhardxray_errlo[i] / fhardxray[i])
fhardxray_err = (fhardxray_errlo[i] + fhardxray_errhi[i])/2d
; Compute luminosity errors from flux errors
tabdat['lhardxray_errhi',j,k] = $
alog10(lhardxray[i] + lhardxray[i] * $
fhardxray_errhi[i] / fhardxray[i]) - $
alog10(lhardxray[i])
if tabdat['lhardxray_errlo',j,k] lt 0.0095 OR $
tabdat['lhardxray_errhi',j,k] lt 0.0095 then $
fstring ='(D0.3,A0,D0.3,A0,D0.3,A0)' $
else fstring = '(D0.2,A0,D0.2,A0,D0.2,A0)'
hardstring = $
string(tabdat['lhardxray',j,k],'$_{-',$
tabdat['lhardxray_errlo',j,k],'}^{+',$
tabdat['lhardxray_errhi',j,k],'}$',$
format=fstring)
; case of no flux errors; assume 10%
endif else begin
tabdat['fhardxray_errlo',j,k] = $
alog10(fhardxray[i]) - alog10(0.9d * fhardxray[i])
tabdat['fhardxray_errhi',j,k] = $
alog10(1.1d * fhardxray[i]) - alog10(fhardxray[i])
tabdat['lhardxray_errlo',j,k] = $
alog10(lhardxray[i]) - alog10(0.9d * lhardxray[i])
tabdat['lhardxray_errhi',j,k] = $
alog10(1.1d * lhardxray[i]) - alog10(lhardxray[i])
fhardxray_err = 0.1d * fhardxray[i]
endelse
endif
endif
if lhardxray[i] ne bad AND lsoftxray[i] ne bad $
AND lsoftxray[i] ne 0d then begin
tabdat['ltotxray',j,k] = alog10(lsoftxray[i] + lhardxray[i])+44d
totxray = lsoftxray[i] + lhardxray[i]
tabdat['ltotxray_errlo',j,k] = $
sqrt(tabdat['lsoftxray_errlo',j,k]^2d + $
tabdat['lhardxray_errlo',j,k]^2d)
tabdat['ltotxray_errhi',j,k] = $
sqrt(tabdat['lsoftxray_errhi',j,k]^2d + $
tabdat['lhardxray_errhi',j,k]^2d)
tabdat['lsoftratxray',j,k] = $
tabdat['lsoftxray',j,k] - tabdat['ltotxray',j,k]
tabdat['lsoftratxray_err',j,k] = $
sqrt(fsoftxray[i]^2d * fhardxray_err^2d + $
fhardxray[i]^2d * fsoftxray_err^2d) / $
(fsoftxray[i]+fhardxray[i])^2d
tabdat['lxlbol',j,k] = tabdat['ltotxray',j,k] - $
llsun_ergps - tabdat['lbol',j]
tabdat['lxlbol_errlo',j,k] = tabdat['ltotxray_errlo',j,k]
tabdat['lxlbol_errhi',j,k] = tabdat['ltotxray_errhi',j,k]
endif
printf,lun_tmp,gal[i],softstring,hardstring,$
format='(A-12,2A27)'
k++
endif else begin
k = 0 ; re-zero x-ray component index
endelse
endif
endif else begin
k = 0 ; re-zero x-ray component index
endelse
endfor
free_lun,lun_tmp
; Compute physical quantities
; Median alpha_ox
igdalphaox = where(tabdat['alphaox'] ne bad)
print,'Median alpha_ox: ',median(tabdat['alphaox',igdalphaox]),format='(A0,D0.2)'
; Set AGN fraction to 1 if we don't have a measurement ... but save original values first for table later
tabdatagnfrac = tabdat['agnfrac']
tabdatagnfraclb = tabdat['agnfraclb']
tabdatagnfracub = tabdat['agnfracub']
ibdagnfrac = where(tabdat['agnfrac'] eq bad,ctbdagnfrac)
if ctbdagnfrac gt 0 then begin
tabdat['agnfrac',ibdagnfrac] = 1d
tabdat['agnfraclb',ibdagnfrac] = 1d
tabdat['agnfracub',ibdagnfrac] = 1d
endif
; Compute L_(F)IR/L_bol
lirlbol = dblarr(ncos)+bad
lfirlbol = dblarr(ncos)+bad
igdlirlbol = where(tabdat['lbol'] ne bad and tabdat['lir'] ne bad)
igdlfirlbol = where(tabdat['lbol'] ne bad and tabdat['lfir'] ne bad)
lirlbol[igdlirlbol] = tabdat['lir',igdlirlbol] - tabdat['lbol',igdlirlbol]
lfirlbol[igdlfirlbol] = tabdat['lfir',igdlfirlbol] - tabdat['lbol',igdlfirlbol]
; Compute L_AGN
lagn = dblarr(ncos)+bad
lagnlb = dblarr(ncos)+bad
lagnub = dblarr(ncos)+bad
lagn_errlo = dblarr(ncos)+bad
lagn_errhi = dblarr(ncos)+bad
igdlbol = where(tabdat['lbol'] ne bad)
lagn[igdlbol] = tabdat['lbol',igdlbol] + $
alog10(tabdat['agnfrac',igdlbol])
lagnlb[igdlbol] = tabdat['lbol',igdlbol] + $
alog10(tabdat['agnfraclb',igdlbol])
lagnub[igdlbol] = tabdat['lbol',igdlbol] + $
alog10(tabdat['agnfracub',igdlbol])
lagn_errlo[igdlbol] = lagn[igdlbol] - lagnlb[igdlbol]
lagn_errhi[igdlbol] = lagnub[igdlbol] - lagn[igdlbol]
; Black hole masses
lmbh = dblarr(ncos)+bad
lmbh_errlo = dblarr(ncos)+bad
lmbh_errhi = dblarr(ncos)+bad
igdrev = where(tabdat['lmbh_rev'] ne bad)
igdrevrm = where(tabdat['lmbh_rev'] ne bad AND $
tabdat['lmbh_rev_type'] eq 'RM')
igdrevse = where(tabdat['lmbh_rev'] ne bad AND $
tabdat['lmbh_rev_type'] eq 'SE')
igdoth = where(tabdat['lmbh_rev'] ne bad AND $
tabdat['lmbh_rev_type'] eq 'GRAVITY')
ibdrev = where(tabdat['lmbh_rev'] eq bad AND $
tabdat['mbh_phot'] ne bad,ctbdrev)
lmbh[igdrev] = tabdat['lmbh_rev',igdrev]
lmbh_errlo[igdrevrm] = $
sqrt(tabdat['lmbh_rev_errlo',igdrevrm]^2d + 0.43d^2d)
lmbh_errhi[igdrevrm] = $
sqrt(tabdat['lmbh_rev_errhi',igdrevrm]^2d + 0.43d^2d)
lmbh_errlo[igdrevse] = $
sqrt(tabdat['lmbh_rev_errlo',igdrevse]^2d + 2d*0.43d^2d)
lmbh_errhi[igdrevse] = $
sqrt(tabdat['lmbh_rev_errhi',igdrevse]^2d + 2d*0.43d^2d)
lmbh_errlo[igdoth] = -tabdat['lmbh_rev_errlo',igdoth]
lmbh_errhi[igdoth] = tabdat['lmbh_rev_errhi',igdoth]
if ctbdrev gt 0 then begin
lmbh[ibdrev] = alog10(tabdat['mbh_phot',ibdrev])
lmbh_errlo[ibdrev] = 0.5d
lmbh_errhi[ibdrev] = 0.5d
endif
;
; Compute Eddington ratio: L_bol/L_Edd = dMdt,acc / dM/dt,Edd
; L_Edd = eddfac * M_BH
eddrat = dblarr(ncos)+bad
leddrat = dblarr(ncos)+bad
leddrat_errlo = dblarr(ncos)
leddrat_errhi = dblarr(ncos)
igd_eddrat = where(lmbh ne bad)
eddrat[igd_eddrat] = $
10d^(lagn[igd_eddrat]+llsun_ergps)/$
(eddfac * 10d^lmbh[igd_eddrat])
leddrat[igd_eddrat] = alog10(eddrat[igd_eddrat])
leddrat_errlo[igd_eddrat] = $
sqrt((lagn[igd_eddrat]-lagnlb[igd_eddrat])^2d + $
lmbh_errhi[igd_eddrat]^2d)
leddrat_errhi[igd_eddrat] = $
sqrt((lagnub[igd_eddrat]-lagn[igd_eddrat])^2d + $
lmbh_errlo[igd_eddrat]^2d)
; lamLlam1125
ldist = lumdist(tabdat['z'],H0=69.3d,Omega_M=0.287d,Lambda0=0.713d,/silent)
Mpc2cm = IDLUNIT('1d6 pc -> cm')
fm_unred,1125d*(1d + tabdat['z']),flam1125,tabdat['ebvgal'],flam1125unred
print,'flam1125 correction for Gal. dust: '
print,' median: ',$
median(flam1125unred/flam1125),format='(A0,D0.2)'
print,' max: ',$
max(flam1125unred/flam1125),format='(A0,D0.2)'
; factor of 1e-14 is flux unit in table
; doing computation in observed frame, since flam still in observed frame
lamLlam1125 = alog10(flam1125unred*4d*!DPi)+2d*alog10(ldist) - 14d + $
2d*alog10(Mpc2cm.quantity) + alog10(1125d*(tabdat['z']+1d))
tabdat['luv'] = lamLlam1125
print,'Median lamLlam1125: ',median(lamLlam1125),format='(A0,D0.2)'
; Get components
maxncomp = 15
nv = orderedhash()
nv['ncomp'] = intarr(ncos)
nv['weq'] = dblarr(ncos,3)
nv['weq_lim'] = dblarr(ncos) + bad ;,3)
nv['weq_A'] = dblarr(ncos,3)
nv['weq_lim_A'] = dblarr(ncos) + bad ;,3)
nv['weq',*,0] = bad
;nv['weq_lim',*,0] = bad
nv['weq_A',*,0] = bad
;nv['weq_lim_A',*,0] = bad
nv['vwtavg'] = dblarr(ncos,3)
nv['vwtrms'] = dblarr(ncos,3)
nv['vwtavg',*,0] = bad
nv['vwtrms',*,0] = bad
nv['v50'] = dblarr(ncos,maxncomp)+bad
nv['cf'] = dblarr(ncos,maxncomp)+bad
nv['tau'] = dblarr(ncos,maxncomp)+bad
nv['sig'] = dblarr(ncos,maxncomp)+bad
ovi = orderedhash()
ovi['ncomp'] = intarr(ncos)
ovi['weq'] = dblarr(ncos,3)
ovi['weq_lim'] = dblarr(ncos) + bad ;,3)
ovi['weq_A'] = dblarr(ncos,3)
ovi['weq_lim_A'] = dblarr(ncos) + bad ;,3)
ovi['weq',*,0] = bad
;ovi['weq_lim',*,0] = bad
ovi['weq_A',*,0] = bad
;ovi['weq_lim_A',*,0] = bad
ovi['vwtavg'] = dblarr(ncos,3)
ovi['vwtrms'] = dblarr(ncos,3)
ovi['vwtavg',*,0] = bad
ovi['vwtrms',*,0] = bad
ovi['v50'] = dblarr(ncos,maxncomp)+bad
ovi['cf'] = dblarr(ncos,maxncomp)+bad
ovi['tau'] = dblarr(ncos,maxncomp)+bad
ovi['sig'] = dblarr(ncos,maxncomp)+bad
pv = orderedhash()
pv['ncomp'] = intarr(ncos)
pv['weq'] = dblarr(ncos,3)
pv['weq_A'] = dblarr(ncos,3)
pv['weq',*,0] = bad
pv['weq_A',*,0] = bad
pv['vwtavg'] = dblarr(ncos,3)
pv['vwtrms'] = dblarr(ncos,3)
pv['vwtavg',*,0] = bad
pv['vwtrms',*,0] = bad
pv['v50'] = dblarr(ncos,maxncomp)+bad
pv['cf'] = dblarr(ncos,maxncomp)+bad
pv['tau'] = dblarr(ncos,maxncomp)+bad
pv['sig'] = dblarr(ncos,maxncomp)+bad
for i=0,ncos-1 do begin
fitdir_gal=fitdir+tabdat['sgal',i]+'/'
if file_test(fitdir_gal,/dir) then begin
file_tmp = fitdir_gal+tabdat['sgal',i]+'NVpar_best.txt'
xdr_tmp = fitdir_gal+tabdat['sgal',i]+'NV_fit.xdr'
if file_test(file_tmp) then begin
readcol,file_tmp,ncomp_tmp,/silent,numline=1,skip=3,format='(I0,X)'
; readcol,file_tmp,ncompem_tmp,/silent,numline=1,skip=1,format='(I0,X,X,X,X)'
readcol,file_tmp,totweq_tmp,totweq_errlo_tmp,totweq_errhi_tmp,$
/silent,numline=1,skip=4,format='(D0,D0,D0,X)'
readcol,file_tmp,vwtavg_tmp,vwtavg_errlo_tmp,vwtavg_errhi_tmp,$
/silent,numline=1,skip=5,format='(D0,D0,D0,X)'
readcol,file_tmp,vwtrms_tmp,vwtrms_errlo_tmp,vwtrms_errhi_tmp,$
/silent,numline=1,skip=6,format='(D0,D0,D0,X)'
nv['ncomp',i]=ncomp_tmp[0]
if totweq_tmp[0] gt 0 then begin
nv['weq',i,0]=alog10(totweq_tmp[0])
nv['weq',i,1]=alog10(totweq_tmp[0])-$
alog10(totweq_tmp[0]-totweq_errlo_tmp[0])
nv['weq',i,2]=alog10(totweq_tmp[0]+totweq_errhi_tmp[0])-$
alog10(totweq_tmp[0])
nv['weq_A',i,0]=totweq_tmp[0]
nv['weq_A',i,1]=totweq_errlo_tmp[0]
nv['weq_A',i,2]=totweq_errhi_tmp[0]
endif
nv['vwtavg',i,0] = vwtavg_tmp[0]
nv['vwtavg',i,1] = vwtavg_errlo_tmp[0]
nv['vwtavg',i,2] = vwtavg_errhi_tmp[0]
nv['vwtrms',i,0] = vwtrms_tmp[0]
nv['vwtrms',i,1] = vwtrms_errlo_tmp[0]
nv['vwtrms',i,2] = vwtrms_errhi_tmp[0]
readcol,file_tmp,cf,tau1243,lambda1243,sig,vel,/silent,$
numline=ncomp_tmp[0],skip=10,format='(D,D,D,D,D)'
nv['v50',i,0:ncomp_tmp[0]-1] = vel
nv['cf',i,0:ncomp_tmp[0]-1] = cf
nv['tau',i,0:ncomp_tmp[0]-1] = tau1243
nv['sig',i,0:ncomp_tmp[0]-1] = sig
endif
file_tmp = fitdir_gal+tabdat['sgal',i]+'OVIpar_best.txt'
if file_test(file_tmp) then begin
readcol,file_tmp,ncomp_tmp,/silent,numline=1,skip=3,format='(I0,X)'
; readcol,file_tmp,ncompem_tmp,/silent,numline=1,skip=1,format='(I0,X,X,X,X)'
readcol,file_tmp,totweq_tmp,totweq_errlo_tmp,totweq_errhi_tmp,$
/silent,numline=1,skip=4,format='(D0,D0,D0,X)'
readcol,file_tmp,vwtavg_tmp,vwtavg_errlo_tmp,vwtavg_errhi_tmp,$
/silent,numline=1,skip=5,format='(D0,D0,D0,X)'
readcol,file_tmp,vwtrms_tmp,vwtrms_errlo_tmp,vwtrms_errhi_tmp,$
/silent,numline=1,skip=6,format='(D0,D0,D0,X)'
ovi['ncomp',i]=ncomp_tmp[0]
if totweq_tmp[0] gt 0 then begin
ovi['weq',i,0]=alog10(totweq_tmp[0])
ovi['weq',i,1]=alog10(totweq_tmp[0])-$
alog10(totweq_tmp[0]-totweq_errlo_tmp[0])
ovi['weq',i,2]=alog10(totweq_tmp[0]+totweq_errhi_tmp[0])-$
alog10(totweq_tmp[0])
ovi['weq_A',i,0]=totweq_tmp[0]
ovi['weq_A',i,1]=totweq_errlo_tmp[0]
ovi['weq_A',i,2]=totweq_errhi_tmp[0]
endif
ovi['vwtavg',i,0] = vwtavg_tmp[0]
ovi['vwtavg',i,1] = vwtavg_errlo_tmp[0]
ovi['vwtavg',i,2] = vwtavg_errhi_tmp[0]
ovi['vwtrms',i,0] = vwtrms_tmp[0]
ovi['vwtrms',i,1] = vwtrms_errlo_tmp[0]
ovi['vwtrms',i,2] = vwtrms_errhi_tmp[0]
readcol,file_tmp,cf,tau1038,lambda1038,sig,vel,/silent,$
numline=ncomp_tmp[0],skip=10,format='(D,D,D,D,D)'
ovi['v50',i,0:ncomp_tmp[0]-1] = vel
ovi['cf',i,0:ncomp_tmp[0]-1] = cf
ovi['tau',i,0:ncomp_tmp[0]-1] = tau1038
ovi['sig',i,0:ncomp_tmp[0]-1] = sig
endif
file_tmp = fitdir_gal+tabdat['sgal',i]+'PVpar_best.txt'
if file_test(file_tmp) then begin
readcol,file_tmp,ncomp_tmp,/silent,numline=1,skip=3,format='(I0,X)'
; readcol,file_tmp,ncompem_tmp,/silent,numline=1,skip=1,format='(I0,X,X,X,X)'
readcol,file_tmp,totweq_tmp,totweq_errlo_tmp,totweq_errhi_tmp,$
/silent,numline=1,skip=4,format='(D0,D0,D0,X)'
readcol,file_tmp,vwtavg_tmp,vwtavg_errlo_tmp,vwtavg_errhi_tmp,$
/silent,numline=1,skip=5,format='(D0,D0,D0,X)'
readcol,file_tmp,vwtrms_tmp,vwtrms_errlo_tmp,vwtrms_errhi_tmp,$
/silent,numline=1,skip=6,format='(D0,D0,D0,X)'
pv['ncomp',i]=ncomp_tmp[0]
if totweq_tmp[0] gt 0 then begin
pv['weq',i,0]=alog10(totweq_tmp[0])
pv['weq',i,1]=alog10(totweq_tmp[0])-$
alog10(totweq_tmp[0]-totweq_errlo_tmp[0])
pv['weq',i,2]=alog10(totweq_tmp[0]+totweq_errhi_tmp[0])-$
alog10(totweq_tmp[0])
pv['weq_A',i,0]=totweq_tmp[0]
pv['weq_A',i,1]=totweq_errlo_tmp[0]
pv['weq_A',i,2]=totweq_errhi_tmp[0]
endif
pv['vwtavg',i,0] = vwtavg_tmp[0]
pv['vwtavg',i,1] = vwtavg_errlo_tmp[0]
pv['vwtavg',i,2] = vwtavg_errhi_tmp[0]
pv['vwtrms',i,0] = vwtrms_tmp[0]
pv['vwtrms',i,1] = vwtrms_errlo_tmp[0]
pv['vwtrms',i,2] = vwtrms_errhi_tmp[0]
readcol,file_tmp,cf,tau1128,lambda1128,sig,vel,/silent,$
numline=ncomp_tmp[0],skip=10,format='(D,D,D,D,D)'
pv['v50',i,0:ncomp_tmp[0]-1] = vel
pv['cf',i,0:ncomp_tmp[0]-1] = cf
pv['tau',i,0:ncomp_tmp[0]-1] = tau1128
pv['sig',i,0:ncomp_tmp[0]-1] = sig
endif
endif
; compute upper limits
iwin_A = 0.5d ; half-width of window in which to compute stats
ispec_A = 2.5d ; half-width of window in which to compute spectrum
modsig = 50d ; sigma for upper limit model
if nv['ncomp',i] eq 0 OR ovi['ncomp',i] eq 0 then begin
readcol,specdir+tabdat['sgal',i]+'.txt',lam,fx,err,format='(D,D,D)',$
/silent
npts = n_elements(lam)
disp = median(lam[1:npts-1]-lam[0:npts-2])
iwin_p = round(iwin_A / disp)
ispec_p = round(ispec_A / disp)
lovi1032 = (1d + tabdat['z',i])*linelist['OVI1031']
lovi1038 = (1d + tabdat['z',i])*linelist['OVI1037']
lnv1238 = (1d + tabdat['z',i])*linelist['NV1238']
lnv1242 = (1d + tabdat['z',i])*linelist['NV1242']
; to avoid strong Galactic absorption for this case
if tabdat['sgal',i] eq 'pg0157' then begin
lovi1032 -= 2d
lovi1038 -= 2d
endif
iovi1032 = value_locate(lam,lovi1032)
iovi1038 = value_locate(lam,lovi1038)
inv1238 = value_locate(lam,lnv1238)
inv1242 = value_locate(lam,lnv1242)
; note we remove PG1501 b/c no data in NV region
if nv['ncomp',i] eq 0 AND inv1238 ne -1 AND inv1238 ne npts-1 AND $
inv1242 ne -1 AND inv1242 ne npts-1 AND $
tabdat['sgal',i] ne 'pg1501'then begin
medfx = median([fx[inv1238-iwin_p:inv1238+iwin_p],$
fx[inv1242-iwin_p:inv1242+iwin_p]])
mederr = median([err[inv1238-iwin_p:inv1238+iwin_p],$
err[inv1242-iwin_p:inv1242+iwin_p]])
rmsfx = stddev([fx[inv1238-iwin_p:inv1238+iwin_p],$
fx[inv1242-iwin_p:inv1242+iwin_p]])
mederrnorm = mederr / medfx
rmsfxnorm = rmsfx / medfx
nvmodweq = 1b
;nvmodweqlo = 1b
;nvmodweqhi = 1b
; model is: cf = rmsfxnorm/2 (divide by 2 b/c two lines!)
; tau = 5
; rest wave
; median measured sig
nvmod = ifsf_doubletfcn(lam[inv1238-ispec_p:inv1242+ispec_p],$
[1,0,rmsfxnorm/2d,5d,lnv1242,modsig],doubletname='NV',$
weq=nvmodweq)
;nvmodlo = ifsf_doubletfcn(lam[inv1238-ispec_p:inv1242+ispec_p],$
; [1,0,rmsfxnorm/4d,5d,lnv1242,modsig],doubletname='NV',$
; weq=nvmodweqlo)
;nvmodhi = ifsf_doubletfcn(lam[inv1238-ispec_p:inv1242+ispec_p],$
; [1,0,rmsfxnorm,5d,lnv1242,modsig],doubletname='NV',$
; weq=nvmodweqhi)
nv['weq_lim',i] = alog10(nvmodweq.abs[0])
;nv['weq_lim',i,0] = alog10(nvmodweq.abs[0])
;nv['weq_lim',i,1] = alog10(nvmodweq.abs[0]) - $
; alog10(nvmodweqlo.abs[0])
;nv['weq_lim',i,2] = alog10(nvmodweqhi.abs[0]) - $
; alog10(nvmodweq.abs[0])
nv['weq_lim_A',i] = nvmodweq.abs[0]
;nv['weq_lim_A',i,0] = nvmodweq.abs[0]
;nv['weq_lim_A',i,1] = nvmodweq.abs[0] - nvmodweqlo.abs[0]
;nv['weq_lim_A',i,2] = nvmodweqhi.abs[0] - nvmodweq.abs[0]
; Examine model spectra cf actual spectra
;set_plot,'x'
;cgplot,lam[inv1238-ispec_p:inv1242+ispec_p],nvmod,yran=[0,1.5]
;cgoplot,lam[inv1238-ispec_p:inv1242+ispec_p],fx[inv1238-ispec_p:inv1242+ispec_p]/medfx
;print,tabdat['sgal',i],mederrnorm,nvmodweq.abs[0]
endif
; note we remove PG2349 b/c geocoronal Lyalpha
if ovi['ncomp',i] eq 0 AND iovi1032 ne -1 AND iovi1032 ne npts-1 AND $
iovi1038 ne -1 AND iovi1038 ne npts-1 AND $
tabdat['sgal',i] ne 'pg2349' then begin
medfx = median([fx[iovi1032-iwin_p:iovi1032+iwin_p],$
fx[iovi1038-iwin_p:iovi1038+iwin_p]])
mederr = median([err[iovi1032-iwin_p:iovi1032+iwin_p],$
err[iovi1038-iwin_p:iovi1038+iwin_p]])
rmsfx = stddev([fx[iovi1032-iwin_p:iovi1032+iwin_p],$
fx[iovi1038-iwin_p:iovi1038+iwin_p]])
mederrnorm = mederr / medfx
rmsfxnorm = rmsfx / medfx
ovimodweq = 1b
;ovimodweqlo = 1b
;ovimodweqhi = 1b
; model is: cf = rmsfxnorm/2 (divide by 2 b/c two lines!)
; tau = 5
; rest wave
; median measured sig
ovimod = ifsf_doubletfcn(lam[iovi1032-ispec_p:iovi1038+ispec_p],$
[1,0,rmsfxnorm/2d,5d,lovi1038,modsig],doubletname='OVI',$
weq=ovimodweq)
;ovimodlo = ifsf_doubletfcn(lam[iovi1032-ispec_p:iovi1038+ispec_p],$
; [1,0,rmsfxnorm/4d,5d,lovi1038,modsig],doubletname='OVI',$
; weq=ovimodweqlo)
;ovimodhi = ifsf_doubletfcn(lam[iovi1032-ispec_p:iovi1038+ispec_p],$
; [1,0,rmsfxnorm,5d,lovi1038,modsig],doubletname='OVI',$
; weq=ovimodweqhi)
ovi['weq_lim',i] = alog10(ovimodweq.abs[0])
;ovi['weq_lim',i,0] = alog10(ovimodweq.abs[0])
;ovi['weq_lim',i,1] = alog10(ovimodweq.abs[0]) - $
; alog10(ovimodweqlo.abs[0])
;ovi['weq_lim',i,2] = alog10(ovimodweqhi.abs[0]) - $
; alog10(ovimodweq.abs[0])
ovi['weq_lim_A',i] = ovimodweq.abs[0]
;ovi['weq_lim_A',i,0] = ovimodweq.abs[0]
;ovi['weq_lim_A',i,1] = ovimodweq.abs[0] - ovimodweqlo.abs[0]
;ovi['weq_lim_A',i,2] = ovimodweqhi.abs[0] - ovimodweq.abs[0]
; Examine model spectra cf actual spectra
;set_plot,'x'
;cgplot,lam[iovi1032-ispec_p:iovi1038+ispec_p],ovimod,yran=[0,1.5]
;cgoplot,lam[iovi1032-ispec_p:iovi1038+ispec_p],fx[iovi1032-ispec_p:iovi1038+ispec_p]/medfx
;print,tabdat['sgal',i],mederrnorm,ovimodweq.abs[0]
endif
endif
endfor
igd_nv_comp = where(nv['v50'] ne bad,ctnvcomp)
igd_ovi_comp = where(ovi['v50'] ne bad,ctovicomp)
nverr = nv['vwtrms']
ibdnverr = where(nverr eq bad,ctbd)
if ctbd gt 0 then nverr[ibdnverr] = 0d
ovierr = ovi['vwtrms']
ibdovierr = where(ovierr eq bad,ctbd)
if ctbd gt 0 then ovierr[ibdovierr] = 0d
; Plots
; Colors
tvlct,[[27],[158],[119]],100
tvlct,[[217],[95],[2]],101
tvlct,[[117],[112],[179]],102
tvlct,[[231],[41],[138]],103
tvlct,[[102],[166],[30]],104
tvlct,[[230],[171],[2]],105
tvlct,[[166],[118],[29]],106
tvlct,[[102],[102],[102]],107
tvlct,[[0],[0],[0]],108
; Arrays for non-detection plots
inv_nd = where(tabdat['nvstatus'] eq 'U',ctnv_nd)
iovi_nd = where(tabdat['ovistatus'] eq 'U',ctovi_nd)
tmpy_nv = dblarr(ctnv_nd)+1d99
tmpy_ovi = dblarr(ctovi_nd)+1d99
for i=0,ctnv_nd-1 do tmpy_nv[i] *= randomu(seed)+0.5d
for i=0,ctovi_nd-1 do tmpy_ovi[i] *= randomu(seed)+0.5d
; output table for regressions
; Threshold pval for marking as significant in output regression table
tpval = 0.05
openw,lun_stat,tabdir+'tab_regressions.txt',/get_lun
printf,lun_stat,'#Col 1: x-axis quantity'
printf,lun_stat,'#Col 2: y-axis quantity'
printf,lun_stat,'#Col 3-4: p, lower limit flag'
printf,lun_stat,'#Col 6-8: r, -/+ error'
printf,lun_stat,'#Col 9: no. of points'
statform = '(A10,A10,D7.3,I2,3D6.2,I3)'
openw,lun_reg_tex,tabdir+'tab_regressions.tex',/get_lun
tweq = '$W_{\rm eq}$'
tvel = ['$v_{\rm wtavg}$','$\sigma_{\rm rms}$']
regtexform = '(A20,A3,A70,A3,I3,A3,D7.3,A3,'+$
'D6.2,A0,D-4.2,A0,D-4.2,A0,A3)'
bregtexform = '(A20,A3,A11,A58,A1,A3,I3,A3,D7.3,A3,'+$
'D6.2,A0,D-4.2,A0,D-4.2,A0,A3)'
regtexform_pvallim = '(A20,A3,A70,A3,I3,A3,A3,D-5.3,A2,'+$
'D6.2,A0,D-4.2,A0,D-4.2,A0,A3)'
bregtexform_pvallim = '(A20,A3,A11,A58,A1,A3,I3,A3,A3,D-5.3,A2,'+$
'D6.2,A0,D-4.2,A0,D-4.2,A0,A3)'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
xlab = 'z'
xtit = 'Redshift'
xran = [0d,0.399d]
ylab = 'lbol'
ytit = 'log(L$\downbol$/L$\sun$)'
yran = [11.2,13.2]
cgps_open,plotdir+ylab+'_vs_'+xlab+'.eps',/encap,/inches,xsiz=7.5,ysize=7.5,/nomatch,$
charsize=2,default=4,/quiet
cgplot,tabdat[xlab],tabdat[ylab],xran=xran,yran=yran,$
psym=9,symsize=1.5,color='Black',xtit=xtit,ytit=ytit,position=[0.18,0.18,0.99,0.99]
cgps_close
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; v50 vs.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
xlab = 'lbol'
xtit = 'log(L$\downbol$/L$\sun$)'
xran = [11.2,13.2]
ylab = 'v50'
ytit = 'v$\down50$ (km/s)'
yran = [-8000,1000]
xrebin = rebin(tabdat[xlab],ncos,maxncomp)
cgps_open,plotdir+ylab+'_vs_'+xlab+'.eps',/encap,/inches,xsiz=7.5,ysize=7.5,/nomatch,$
charsize=chars,default=4,/quiet
cgplot,xrebin[igd_nv_comp],nv[ylab,igd_nv_comp],xran=xran,yran=yran,$
psym=15,symsize=1,color='Red',xtit=xtit,ytit=ytit
; err_ylo=nv['sig',igd_nv_comp]*fwhm2sig/2d,$
; err_yhi=nv['sig',igd_nv_comp]*fwhm2sig/2d
cgoplot,xrebin[igd_ovi_comp],ovi[ylab,igd_ovi_comp],psym=9,symsize=1.5,$
color='Blue'
; err_ylo=ovi['sig',igd_ovi_comp]*fwhm2sig/2d,$
; err_yhi=ovi['sig',igd_ovi_comp]*fwhm2sig/2d
cgps_close
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
xlab = 'luv'
xtit = 'log[ $\lambda$L$\down\\lambda$ (1125 $\Angstrom$)/erg s$\up-1$]'
xran = [42.5d,47d]
ylab = 'v50'
ytit = 'v$\down50$ (km/s)'
yran = [-8000,1000]
xrebin = rebin(tabdat[xlab],ncos,maxncomp)