-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetdist_chainplot_utils.py
More file actions
4947 lines (4316 loc) · 201 KB
/
getdist_chainplot_utils.py
File metadata and controls
4947 lines (4316 loc) · 201 KB
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
"""
Adapting the chain plotter from Y3 extensions for use in Y6.
It's basically just a wrapper for getdist plotting, with some added
functionality for reading in cosmosis chains, adding derived parameters,
computing summary statistics.
To use, import this script into your plotting script or notebook as a module.
If you want to do this for a script that's in a directory other
than where this one is, you can do this:
import sys
chainplotdir = os.environ['Y6METHODSDIR']+"/y6_fiducial/plot_chains"
sys.path.insert(0,chainplotdir)
cpu = __import__('getdist_chainplot_utils')
Contact jessie muir with questions
"""
import os, sys
import numpy as np
import scipy as sp
import matplotlib
import matplotlib.pyplot as plt
#import pandas as pd
import math, copy
import getdist as gd
import getdist.plots as gdplots
from getdist.mcsamples import MCSamples
#from anesthetic import NestedSamples
from scipy.stats import chi2
from scipy.special import erfinv, erfcinv
from scipy.interpolate import interp1d
from matplotlib import rcParams
rcParams['font.family'] = 'serif'
from matplotlib import rc
import colorsys
rc('text',usetex=True)
from matplotlib.ticker import FormatStrFormatter
default_callfrom = ''
# light blue, dark blue, l green, d green, peach, red
DEFAULT_COLORS = ['#a6cee3',\
'#1f78b4',\
'#b2df8a',\
'#33a02c',\
'#fb9a99',\
'#e31a1c',\
'#fdbf6f',\
'#ff7f00',\
'#cab2d6',\
'#6a3d9a',\
'#ffff99',\
'#b15928']
# ^ just grabbed the 12 class qualitative color ist from colorbrewer2.org
# colors used in Y3ext paper
lightblue='#a6cee3'
midblue = '#1f78b4'
darkblue = '#03538A'
lightgreen = '#b2df8a'
midgreen = '#33a02c'
pink='#fb9a99'
red='#e31a1c'
lightred='#f6baba'#'#ee7576' # for filled planck results
darkred='#710d0e'
lightorange='#fdbf6f'
orange='#ff7f00'
lightpurple='#cab2d6'
purple='#6a3d9a'
darkpurple='#4E049F'
yellow='#ffed6f'
brown='#b15928'
salmon='#fc8d62'
beige1='#f7f5eb' #beige
beige2='#e8e6df'
beige3='#deddd9'
#==================================================================
# Defaults for convenience.
#==================================================================
OMNUH2_TO_MNU_FACTOR = 93.14 # for active neutrinos
# TO DO CHECK AGAINST Y6 SETUP
DEFAULT_FILE_PREFIX = 'chain'
DEFAULT_FILE_SUFFIX = '.txt'
# TO DO, add TATT params
# tex labels
DEFAULT_PLABELS = {\
'cosmological_parameters--omega_m':r'$\Omega_{\rm m}$',\
'cosmological_parameters--w':r'$w_0$',\
'cosmological_parameters--wa':r'$w_a$',\
'cosmological_parameters--wp':r'$w_{\rm p}$',\
'a_pivot':r'$a_{\rm p}$',\
'z_pivot':r'$z_{\rm p}$',\
'cosmological_parameters--omega_k':r'$\Omega_k$',\
'cosmological_parameters--omega_c':r'$\Omega_{\rm c}$',\
'COSMOLOGICAL_PARAMETERS--SIGMA_8':r'$\sigma_8$',\
'cosmological_parameters--sigma_8':r'$\sigma_8$',\
'S8':r'$S_8$',\
'cosmological_parameters--s_8':r'$S_8$',\
'cosmological_parameters--h0':r'$h$',\
'cosmological_parameters--omega_b':r'$\Omega_b$',\
'cosmological_parameters--n_s':r'$n_s$',\
'cosmological_parameters--a_s':r'$A_s$',\
'cosmological_parameters--a_s_1e9':r'$A_s*10^9$',\
'cosmological_parameters--omnuh2':r'$\Omega_{\nu}h^2$',\
'cosmological_parameters--ommh2':r'$\Omega_{\rm m}h^2$',\
'cosmological_parameters--ombh2':r'$\Omega_{\rm b}h^2$',\
'cosmological_parameters--omch2':r'$\Omega_{\rm c}h^2$',\
'cosmological_parameters--alens':r'$A_{\rm L}$',\
'cosmological_parameters--tau':r'$\tau$',\
'summnu':r'$\sum m_{\nu}\,[{\rm eV}]$',\
'cosmological_parameters--mnu':r'$\sum m_{\nu}\,[{\rm eV}]$',\
'supernova_params--m':r'$M_{\rm SN}$',\
'bin_bias--b1':r'$b^{[1]}$',\
'bin_bias--b2':r'$b^{[2]}$',\
'bin_bias--b3':r'$b^{[3]}$',\
'bin_bias--b4':r'$b^{[4]}$',\
'bin_bias--b5':r'$b^{[5]}$',\
'bin_bias--b6':r'$b^{[6]}$',\
'bias_lens--b1':r'$b^{[1]}$',\
'bias_lens--b2':r'$b^{[2]}$',\
'bias_lens--b3':r'$b^{[3]}$',\
'bias_lens--b4':r'$b^{[4]}$',\
'bias_lens--b5':r'$b^{[5]}$',\
'bias_lens--b6':r'$b^{[6]}$',\
'bias_lens--b1wt_bin1':r'$b^{[1]}}$',\
'bias_lens--b1wt_bin2':r'$b^{[2]}$',\
'bias_lens--b1wt_bin3':r'$b^{[3]}$',\
'bias_lens--b1wt_bin4':r'$b^{[4]}$',\
'bias_lens--b1wt_bin5':r'$b^{[5]}$',\
'bias_lens--b1wt_bin6':r'$b^{[6]}$',\
'bias_lens--b1e_bin1':r'$b_1^{[1]}$',\
'bias_lens--b1e_bin2':r'$b_1^{[2]}$',\
'bias_lens--b1e_bin3':r'$b_1^{[3]}$',\
'bias_lens--b1e_bin4':r'$b_1^{[4]}$',\
'bias_lens--b1e_bin5':r'$b_1^{[5]}$',\
'bias_lens--b1e_bin6':r'$b_1^{[6]}$',\
'bias_lens--b2e_bin1':r'$b_2^{[1]}$',\
'bias_lens--b2e_bin2':r'$b_2^{[2]}$',\
'bias_lens--b2e_bin3':r'$b_2^{[3]}$',\
'bias_lens--b2e_bin4':r'$b_2^{[4]}$',\
'bias_lens--b2e_bin5':r'$b_2^{[5]}$',\
'bias_lens--b2e_bin6':r'$b_2^{[6]}$',\
'bias_lens--b1e_sig8_bin1':r'$b_1^{[1]}\sigma_8$',\
'bias_lens--b1e_sig8_bin2':r'$b_1^{[2]}\sigma_8$',\
'bias_lens--b1e_sig8_bin3':r'$b_1^{[3]}\sigma_8$',\
'bias_lens--b1e_sig8_bin4':r'$b_1^{[4]}\sigma_8$',\
'bias_lens--b1e_sig8_bin5':r'$b_1^{[5]}\sigma_8$',\
'bias_lens--b1e_sig8_bin6':r'$b_1^{[6]}\sigma_8$',\
'bias_lens--b2e_sig8sq_bin1':r'$b_2^{[1]}\sigma_8^2$',\
'bias_lens--b2e_sig8sq_bin2':r'$b_2^{[2]}\sigma_8^2$',\
'bias_lens--b2e_sig8sq_bin3':r'$b_2^{[3]}\sigma_8^2$',\
'bias_lens--b2e_sig8sq_bin4':r'$b_2^{[4]}\sigma_8^2$',\
'bias_lens--b2e_sig8sq_bin5':r'$b_2^{[5]}\sigma_8^2$',\
'bias_lens--b2e_sig8sq_bin6':r'$b_2^{[6]}\sigma_8^2$',\
'bias_lens--rmean_bin':r'$X_{\rm lens}$',\
'shear_calibration_parameters--m1':R'$m_1$',\
'shear_calibration_parameters--m2':r'$m_2$',\
'shear_calibration_parameters--m3':r'$m_3$',\
'shear_calibration_parameters--m4':r'$m_4$',\
'shear_calibration_parameters--m5':r'$m_5$',\
'intrinsic_alignment_parameters--a':R'$A_{\rm IA}$',\
'intrinsic_alignment_parameters--alpha':R'$\alpha_{\rm IA}$',\
'wl_photoz_errors--bias_1':r'$\Delta z_{s}^1$',\
'wl_photoz_errors--bias_2':r'$\Delta z_{s}^2$',\
'wl_photoz_errors--bias_3':r'$\Delta z_{s}^3$',\
'wl_photoz_errors--bias_4':r'$\Delta z_{s}^4$',\
'wl_photoz_errors--bias_5':r'$\Delta z_{s}^5$',\
'wl_photoz_errors--bias_6':r'$\Delta z_{s}^6$',\
'lens_photoz_errors--bias_1':r'$\Delta z_{l}^1$',\
'lens_photoz_errors--bias_2':r'$\Delta z_{l}^2$',\
'lens_photoz_errors--bias_3':r'$\Delta z_{l}^3$',\
'lens_photoz_errors--bias_4':r'$\Delta z_{l}^4$',\
'lens_photoz_errors--bias_5':r'$\Delta z_{l}^5$',\
'lens_photoz_errors--bias_6':r'$\Delta z_{l}^6$',\
'lens_photoz_errors--width_1':r'$W_{l}^1$',\
'lens_photoz_errors--width_2':r'$W_{l}^2$',\
'lens_photoz_errors--width_3':r'$W_{l}^3$',\
'lens_photoz_errors--width_4':r'$W_{l}^4$',\
'lens_photoz_errors--width_5':r'$W_{l}^5$',\
'lens_photoz_errors--width_6':r'$W_{l}^6$',\
'intrinsic_alignment_parameters--a':r'$a_{\rm TATT}$',\
'intrinsic_alignment_parameters--alpha':r'$\alpha_{\rm TATT}$',\
'intrinsic_alignment_parameters--z_piv':r'$z_{\rm piv}^{\rm TATT}$',\
'intrinsic_alignment_parameters--a1':r'$A_1^{\rm TATT}$',\
'intrinsic_alignment_parameters--a2':r'$A_2^{\rm TATT}$',\
'intrinsic_alignment_parameters--adel':r'$A_{\rm del}^{\rm TATT}$',\
'intrinsic_alignment_parameters--alpha1':r'$\alpha_1^{\rm TATT}$',\
'intrinsic_alignment_parameters--alpha2':r'$\alpha_2^{\rm TATT}$',\
'intrinsic_alignment_parameters--alphadel':r'$\alpha_{\rm del}^{\rm TATT}$',\
'intrinsic_alignment_parameters--bias_ta':r'$b_{\rm ta}$',\
'intrinsic_alignment_parameters--bias_tt':r'$b_{\rm tt}$',\
'shear_calibration_parameters--m1_uncorr':'$m^{1}_{uncorr.}$',
'shear_calibration_parameters--m2_uncorr':'$m^{2}_{uncorr.}$',
'shear_calibration_parameters--m3_uncorr':'$m^{3}_{uncorr.}$',
'shear_calibration_parameters--m4_uncorr':'$m^{4}_{uncorr.}$',
'source_photoz_u--u_0_uncorr':'$u^{1}_{s, uncorr.}$',
'source_photoz_u--u_1_uncorr':'$u^{2}_{s, uncorr.}$',
'source_photoz_u--u_2_uncorr':'$u^{3}_{s, uncorr.}$',
'source_photoz_u--u_3_uncorr':'$u^{4}_{s, uncorr.}$',
'source_photoz_u--u_4_uncorr':'$u^{5}_{s, uncorr.}$',
'source_photoz_u--u_5_uncorr':'$u^{6}_{s, uncorr.}$',
'source_photoz_u--u_6_uncorr':'$u^{7}_{s, uncorr.}$',
'source_photoz_u--u_7_uncorr':'$u^{8}_{s, uncorr.}$',
'source_photoz_u--u_8_uncorr':'$u^{9}_{s, uncorr.}$',
'lens_photoz_u--u_0_0':'$u^{0,0}_{l}$',
'lens_photoz_u--u_0_1':'$u^{0,1}_{l}$',
'lens_photoz_u--u_0_2':'$u^{0,2}_{l}$',
'lens_photoz_u--u_0_3':'$u^{0,3}_{l}$',
'lens_photoz_u--u_1_0':'$u^{1,0}_{l}$',
'lens_photoz_u--u_1_1':'$u^{1,1}_{l}$',
'lens_photoz_u--u_1_2':'$u^{1,2}_{l}$',
'lens_photoz_u--u_1_3':'$u^{1,3}_{l}$',
'lens_photoz_u--u_2_0':'$u^{2,0}_{l}$',
'lens_photoz_u--u_2_1':'$u^{2,1}_{l}$',
'lens_photoz_u--u_2_2':'$u^{2,2}_{l}$',
'lens_photoz_u--u_2_3':'$u^{2,3}_{l}$',
'lens_photoz_u--u_3_0':'$u^{3,0}_{l}$',
'lens_photoz_u--u_3_1':'$u^{3,1}_{l}$',
'lens_photoz_u--u_3_2':'$u^{3,2}_{l}$',
'lens_photoz_u--u_3_3':'$u^{3,3}_{l}$',
'lens_photoz_u--u_4_0':'$u^{4,0}_{l}$',
'lens_photoz_u--u_4_1':'$u^{4,1}_{l}$',
'lens_photoz_u--u_4_2':'$u^{4,2}_{l}$',
'lens_photoz_u--u_4_3':'$u^{4,3}_{l}$',
'lens_photoz_u--u_5_0':'$u^{5,0}_{l}$',
'lens_photoz_u--u_5_1':'$u^{5,1}_{l}$',
'lens_photoz_u--u_5_2':'$u^{5,2}_{l}$',
'lens_photoz_u--u_5_3':'$u^{5,3}_{l}$',
'SHEAR_CALIBRATION_PARAMETERS--M1':'$m^{1}$',
'SHEAR_CALIBRATION_PARAMETERS--M2':'$m^{2}$',
'SHEAR_CALIBRATION_PARAMETERS--M3':'$m^{3}$',
'SHEAR_CALIBRATION_PARAMETERS--M4':'$m^{4}$',
'SOURCE_PHOTOZ_U--U_0':'$u^{1}_{s}$',
'SOURCE_PHOTOZ_U--U_1':'$u^{2}_{s}$',
'SOURCE_PHOTOZ_U--U_2':'$u^{3}_{s}$',
'SOURCE_PHOTOZ_U--U_3':'$u^{4}_{s}$',
'SOURCE_PHOTOZ_U--U_4':'$u^{5}_{s}$',
'SOURCE_PHOTOZ_U--U_5':'$u^{6}_{s}$',
'SOURCE_PHOTOZ_U--U_6':'$u^{7}_{s}$',
'SOURCE_PHOTOZ_U--U_7':'$u^{8}_{s}$',
'SOURCE_PHOTOZ_U--U_8':'$u^{9}_{s}$',
'source_photoz_u--u_0':'$u^{1}_{s}$',
'source_photoz_u--u_1':'$u^{2}_{s}$',
'source_photoz_u--u_2':'$u^{3}_{s}$',
'source_photoz_u--u_3':'$u^{4}_{s}$',
'source_photoz_u--u_4':'$u^{5}_{s}$',
'source_photoz_u--u_5':'$u^{6}_{s}$',
'source_photoz_u--u_6':'$u^{7}_{s}$',
'source_photoz_u--u_7':'$u^{8}_{s}$',
'source_photoz_u--u_8':'$u^{9}_{s}$',
'mag_alpha_lens--alpha_1':r'$\alpha_1$',\
'mag_alpha_lens--alpha_2':r'$\alpha_2$',\
'mag_alpha_lens--alpha_3':r'$\alpha_3$',\
'mag_alpha_lens--alpha_4':r'$\alpha_4$',\
'mag_alpha_lens--alpha_5':r'$\alpha_5$',\
'mag_alpha_lens--alpha_6':r'$\alpha_6$',\
'delta_neff':r'$\Delta N_{\rm eff}$',\
'ranks--rank_hyperparm_1':r'$\mathcal{H}_1$',\
'ranks--rank_hyperparm_2':r'$\mathcal{H}_2$',\
'ranks--rank_hyperparm_3':r'$\mathcal{H}_3$',\
'RANKS--REALISATION_ID':"\mathrm{ HR~rlzn \#}",\
'ranks--realisation_id':"\mathrm{ HR~rlzn \#}",\
'cosmological_parameters--tau':r'$\tau$',\
'planck--a_planck':r'$A_{\rm planck}$',\
'cosmological_parameters--yhe':r'$Y_{\rm He}$',
'xlens--xlens_all':r'$X_{\rm lens}$',
}
# providing some parameter fid val and range dicts for convenience
# but use with caution; probably better to just read in an values ini
# fid values used for extensions, where sim DV had NLA IA model
Y3FIDVALDICT = {
'cosmological_parameters--w':-1. ,\
'cosmological_parameters--wa':0.0,\
'cosmological_parameters--wp':-1. ,\
'cosmological_parameters--omega_k':0.0,\
'modified_gravity--sigma0':0.0,\
'modified_gravity--mu0':0.0,\
'cosmological_parameters--h0':.69,\
'cosmological_parameters--n_s': .97,\
'COSMOLOGICAL_PARAMETERS--SIGMA_8':0.82594,\
'cosmological_parameters--sigma_8':0.82594,\
'S8':0.82594,\
'cosmological_parameters--a_s':2.19e-9,\
'cosmological_parameters--tau':0.08,\
'asx1.e9':2.19,\
'cosmological_parameters--alens':1.,\
'cosmological_parameters--omega_b':0.048,\
'cosmological_parameters--omega_m':0.3, \
'cosmological_parameters--omnuh2':0.00083 ,\
'cosmological_parameters--ommh2':.69*.69*.3,\
'cosmological_parameters--ombh2': .69*.69*0.048,\
'cosmological_parameters--log10_fr0':-6.0,\
'summnu':0.00083*OMNUH2_TO_MNU_FACTOR ,\
'intrinsic_alignment_parameters--z_piv' : 0.62,\
'intrinsic_alignment_parameters--a1' : 0.7,\
'intrinsic_alignment_parameters--a2' : 0. ,\
'intrinsic_alignment_parameters--alpha1': -1.7,\
'intrinsic_alignment_parameters--alpha2': 0.,\
'intrinsic_alignment_parameters--bias_ta': 0.,\
'shear_calibration_parameters--m1':0.,\
'shear_calibration_parameters--m2':0.,\
'shear_calibration_parameters--m3':0.,\
'shear_calibration_parameters--m4':0.,\
'wl_photoz_errors--bias_1':0.,\
'wl_photoz_errors--bias_2':0.,\
'wl_photoz_errors--bias_3':0.,\
'wl_photoz_errors--bias_4':0.,\
'lens_photoz_errors--bias_1':0.,\
'lens_photoz_errors--bias_2':0.,\
'lens_photoz_errors--bias_3':0.,\
'lens_photoz_errors--bias_4':0.,\
'lens_photoz_errors--bias_5':0.,\
'lens_photoz_errors--bias_6':0.,\
'lens_photoz_errors--width_1':1.,\
'lens_photoz_errors--width_2':1.,\
'lens_photoz_errors--width_3':1.,\
'lens_photoz_errors--width_4':1.,\
'lens_photoz_errors--width_5':1.,\
'lens_photoz_errors--width_6':1.,\
'mag_alpha_lens--alpha_1' : 1.21,\
'mag_alpha_lens--alpha_2' : 1.15,\
'mag_alpha_lens--alpha_3' : 1.88,\
'mag_alpha_lens--alpha_4' : 1.97,\
'mag_alpha_lens--alpha_5' : 1.78,\
'mag_alpha_lens--alpha_6' : 2.48,\
'bias_lens--b1': 1.5,\
'bias_lens--b2': 1.8,\
'bias_lens--b3': 1.8,\
'bias_lens--b4': 1.9,\
'bias_lens--b5': 2.3,\
'bias_lens--b6': 2.3,\
'bias_lens--b1wt_bin1': 1.5,\
'bias_lens--b1wt_bin2': 1.8,\
'bias_lens--b1wt_bin3': 1.8,\
'bias_lens--b1wt_bin4': 1.9,\
'bias_lens--b1wt_bin5': 2.3,\
'bias_lens--b1wt_bin6': 2.3,\
'bias_lens--rmean_bin':1.0,\
'ranks--rank_hyperparm_1':0.5,\
'ranks--rank_hyperparm_2':0.5,\
'ranks--rank_hyperparm_3':0.5,\
'npg_parameters--a1':1.,\
'npg_parameters--a2':1.,\
'npg_parameters--a3':1.,\
'npg_parameters--a4':1.,\
'npg_parameters--a5':1.,\
'npg_parameters--a_cmb':1.,\
'supernova_params--m':-19.,\
'modified_gravity--b0':0.1,\
'cosmological_parameters--neff':3.046,\
'cosmological_parameters--meffsterile':0.0,\
'cosmological_parameters--delta_neff':0.0,\
'shear_calibration_parameters--m1_uncorr':0.0,\
'shear_calibration_parameters--m2_uncorr':0.0,\
'shear_calibration_parameters--m3_uncorr':0.0,\
'shear_calibration_parameters--m4_uncorr':0.0,\
'source_photoz_u--u_0_uncorr':0.0,\
'source_photoz_u--u_1_uncorr':0.0,\
'source_photoz_u--u_2_uncorr':0.0,\
'source_photoz_u--u_3_uncorr':0.0,\
'source_photoz_u--u_4_uncorr':0.0,\
'source_photoz_u--u_5_uncorr':0.0,\
'source_photoz_u--u_6_uncorr':0.0,\
'source_photoz_u--u_7_uncorr':0.0,\
'source_photoz_u--u_8_uncorr':0.0,\
'lens_photoz_u--u_0_0':0.0,\
'lens_photoz_u--u_0_1':0.0,\
'lens_photoz_u--u_0_2':0.0,\
'lens_photoz_u--u_1_0':0.0,\
'lens_photoz_u--u_1_1':0.0,\
'lens_photoz_u--u_1_2':0.0,\
'lens_photoz_u--u_2_0':0.0,\
'lens_photoz_u--u_2_1':0.0,\
'lens_photoz_u--u_2_2':0.0,\
'lens_photoz_u--u_3_0':0.0,\
'lens_photoz_u--u_3_1':0.0,\
'lens_photoz_u--u_3_2':0.0,\
'lens_photoz_u--u_4_0':0.0,\
'lens_photoz_u--u_4_1':0.0,\
'lens_photoz_u--u_4_2':0.0,\
'lens_photoz_u--u_5_0':0.0,\
'lens_photoz_u--u_5_1':0.0,\
'lens_photoz_u--u_5_2':0.0,\
'SHEAR_CALIBRATION_PARAMETERS--M1':-0.00339767,\
'SHEAR_CALIBRATION_PARAMETERS--M2':0.0064552,\
'SHEAR_CALIBRATION_PARAMETERS--M3':0.01593935,\
'SHEAR_CALIBRATION_PARAMETERS--M4':0.00169811,\
'SOURCE_PHOTOZ_U--U_0''source_photoz_u--u_0_uncorr':0.0,
'SOURCE_PHOTOZ_U--U_1''source_photoz_u--u_1_uncorr':0.0,
'SOURCE_PHOTOZ_U--U_2''source_photoz_u--u_2_uncorr':0.0,
'SOURCE_PHOTOZ_U--U_3''source_photoz_u--u_3_uncorr':0.0,
'SOURCE_PHOTOZ_U--U_4''source_photoz_u--u_4_uncorr':0.0,
'SOURCE_PHOTOZ_U--U_5''source_photoz_u--u_5_uncorr':0.0,
'SOURCE_PHOTOZ_U--U_6''source_photoz_u--u_6_uncorr':0.0,
'SOURCE_PHOTOZ_U--U_7''source_photoz_u--u_7_uncorr':0.0,
'SOURCE_PHOTOZ_U--U_8''source_photoz_u--u_8_uncorr':0.0,
}
# These were used for extensions, which used NLA model
Y3RANGES = {'cosmological_parameters--h0':[.55,.91],\
'cosmological_parameters--n_s':[.87,1.07] ,\
'bin_bias--b4':[0.8,3.0],\
'bin_bias--b1':[0.8,3.0], \
'bin_bias--b2':[0.8,3.0],\
'bin_bias--b3':[0.8,3.0],\
'bias_lens--b1':[0.8,3.0],\
'bias_lens--b2':[0.8,3.0],\
'bias_lens--b3':[0.8,3.0],\
'bias_lens--b4':[0.8,3.0],\
'bias_lens--b1wt_bin1':[0.8,3.0],\
'bias_lens--b1wt_bin2':[0.8,3.0],\
'bias_lens--b1wt_bin3':[0.8,3.0],\
'bias_lens--b1wt_bin4':[0.8,3.0],\
'bias_lens--rmean_bin':[0.6,1.4],\
'shear_calibration_parameters--m1':[-.1,.1],\
'shear_calibration_parameters--m2':[-.1,.1],\
'shear_calibration_parameters--m3':[-.1,.1],\
'shear_calibration_parameters--m4':[-.1,.1],\
'COSMOLOGICAL_PARAMETERS--SIGMA_8':[.5,1.],\
'S8':[None,None],\
'cosmological_parameters--a_s':[.5e-9,5.e-9],\
'cosmological_parameters--omega_b':[0.03,0.07],\
'cosmological_parameters--omega_m':[.1,.9], \
'cosmological_parameters--w':[-3.,-.3333], \
'cosmological_parameters--tau':[0.01,0.8], \
'cosmological_parameters--log10_fr0':[-8.,-2.],\
'supernova_params--m':[-20,-18.], \
'intrinsic_alignment_parameters--a':[-5.,5.],\
'intrinsic_alignment_parameters--alpha':[-5.,5.],\
'intrinsic_alignment_parameters--a1' : [-5.,5.],\
'intrinsic_alignment_parameters--a2' : [-5.,5.],\
'intrinsic_alignment_parameters--alpha1': [-5.,5.],\
'intrinsic_alignment_parameters--alpha2': [-5.,5.],\
'intrinsic_alignment_parameters--bias_ta': [0.,2],\
'cosmological_parameters--omnuh2':[.0006, 0.00644],\
'summnu':[.0006*OMNUH2_TO_MNU_FACTOR ,0.00644*OMNUH2_TO_MNU_FACTOR ],\
'wl_photoz_errors--bias_1':[-.1,.1],\
'wl_photoz_errors--bias_2':[-.1,.1],\
'wl_photoz_errors--bias_3':[-.1,.1],\
'wl_photoz_errors--bias_4':[-.1,.1],\
'lens_photoz_errors--bias_1':[-.05,.05],\
'lens_photoz_errors--bias_2':[-.05,.05],\
'lens_photoz_errors--bias_3':[-.05,.05],\
'lens_photoz_errors--bias_4':[-.05,.05],\
'lens_photoz_errors--width_1':[0.1,1.9],\
'lens_photoz_errors--width_2':[0.1,1.9],\
'lens_photoz_errors--width_3':[0.1,1.9],\
'lens_photoz_errors--width_4':[0.1,1.9],\
'cosmological_parameters--alens':[0.,10],\
}
#=================================================================
# Functions for handling filenames and labels
#=================================================================
def get_sampler_from_chain(chainfile):
'''Get the sampler used in the chain.
It assumes the second line of a chain always starts with #sampler=
and it reads the following string.
'''
with open(chainfile, 'r') as fp:
for i, line in enumerate(fp):
if i == 1:
sampler = line.strip()
elif i > 1:
break
return sampler[9:]
def get_param_label(p,texdict = DEFAULT_PLABELS,forgetdist=True):
if p in texdict.keys():
label= texdict[p]
else:
label= p
if forgetdist: #get dist adds text formatting automatically
outlabel = label.replace('$','')
else:
outlabel = label
return outlabel
def get_label(m,mdict):
if m in mdict.keys():
return mdict[m]
else:
return m
def get_fidval(p,valdict):
"""
This will be used to get values to center ellipses on.
If we haven't set up a parameter's fiducial value in the
dictionary, just center on zero.
"""
if p in valdict.keys():
return valdict[p]
else:
return 0.
def get_pscaling(p):
"""
for certain parameters (mostly a_s), to handle plotting, need to rescale
"""
if p=='cosmological_parameters--a_s':
return 1.e9
else:
return 1.
def parse_truthvals(truthvals,pkeys):
"""
Given list of parameter keys inpkeys, and truthvals, which is either string or dictionary, return list of defaults (nan if not in dictionary)
"""
outtruth = []
for k in pkeys:
if k in truthvals.keys():
outtruth.append(truthvals[k])
else:
outtruth.append(np.nan)
return outtruth
#==================================================================
# Functions for reading in values files, generating fid and range dicts
#==================================================================
def get_bashvars_fromshfile(shfile,force_testsampler=True,callfrom='.'):
"""
given sh file where environment variables for extensions chains
are set, reads that file and sets environment variables in a way
this script can use.
Will only parse lines in the sh file that start with either
export or %include.
"""
if callfrom not in shfile:
f = open(os.path.join(callfrom,shfile),'r')
else:
f = open(shfile,'r')
for line in f:
line = os.path.expandvars(line)
if line.startswith('export'):
# get rid of white space, export, everything after commment character
cleaned = line.replace('export','').replace('"','').split("#")[0].strip()
key,value = cleaned.split("=")
if key=='SAMPLER' and force_testsampler:
os.environ[key]='test'
else:
os.environ[key]=value
if line.startswith('source'):
# read in another file to set more variables
fname = line.split()[1]
get_bashvars_fromshfile(fname,force_testsampler)
f.close()
return 0
def get_bashvars_fromshfile(shfile,force_testsampler=True,callfrom='.'):
"""
given sh file where environment variables for extensions chains
are set, reads that file and sets environment variables in a way
this script can use.
Will only parse lines in the sh file that start with either
export or %include.
"""
if callfrom not in shfile:
f = open(os.path.join(callfrom,shfile),'r')
else:
f = open(shfile,'r')
for line in f:
line = os.path.expandvars(line)
if line.startswith('export'):
# get rid of white space, export, everything after commment character
cleaned = line.replace('export','').replace('"','').split("#")[0].strip()
key,value = cleaned.split("=")
if key=='SAMPLER' and force_testsampler:
os.environ[key]='test'
else:
os.environ[key]=value
if line.startswith('source'):
# read in another file to set more variables
fname = line.split()[1]
get_bashvars_fromshfile(fname,force_testsampler)
f.close()
return 0
def get_valuesini_from_paramsini(paramsini,callfrom=default_callfrom, bashvarf = None):
"""
Check whether params vile sets values file. If it does, return values name.
Note that this function won't dig through
"""
if bashvarf is not None:
# get bash variables set up
get_bashvars_fromshfile(bashvarf)
inpipelinesec =False
valuesf = None
#print("opening:",paramsini)
f = open(paramsini)
#print(' success')
for line in f:
line = line.strip()
if not line: # empty line
continue
line = os.path.expandvars(line)
if line.startswith('%include'): #include line
incfile = os.path.join(callfrom,line.replace('%include ',''))
# call recursively include that other ini, but don't reset bash vars
tempvaluesf = get_valuesini_from_paramsini(incfile,callfrom)
if tempvaluesf is not None: # overwriting previous value
valuesf = tempvaluesf
elif line.startswith(';') or line.startswith('#'): #comment
continue
elif line.startswith('['): #section header
section = line.replace('[','').replace(']','')
inpipelinesec = section=='pipeline'
#print( 'section=',section, inpipelinesec)
elif not inpipelinesec: # variable, but not in [pipeline]
continue
else: #variable in [pipeline]
items = line.replace('=','').split()
var = items[0]
#print(' >',items,var,var=='values')
if var=='values':
valuesf = items[1]
#print(" >> valuesf=",valuesf)
f.close()
return valuesf
def read_values_ini(valuesini,callfrom=default_callfrom, vardict={}, bashvarf = None):
"""
Given path to values file ini, reads in that values file and relevant %includes
and return parameter info in dictionary
vardict - dictionary containing parameter info
valuesini - path of values ini file we want to read
callfrom - string path that cosmosis will be called from, used to find %included files
bashvarf - name of sh job file defining bash variables that might be used in ini
"""
if bashvarf is not None:
# get bash variables set up
if not os.path.isfile(bashvarf):
print("Can't find bash file, skipping:",bashvarf)
return None
get_bashvars_fromshfile(bashvarf)
if not os.path.isfile(valuesini):
print("Can't find values.ini file, skipping:",valuesini)
return None
# keys will be (section, paramname)
# values will be lists of 3 numbers; second and third will be nan if param fixed
section=None
#print(">>>>>>READING",valuesini)
f = open(valuesini)
for line in f:
line = line.strip()
if not line: # empty line
continue
line = os.path.expandvars(line)
if line.startswith('%include'): #include line
incfile = os.path.join(callfrom,line.replace('%include ',''))
# call recursively include that other ini, but don't reset bash vars
read_values_ini(incfile,callfrom, vardict, None)
elif line.startswith(';') or line.startswith('#'): #comment
continue
elif line.startswith('['): #section header
section = line.replace('[','').replace(']','')
# cosmosis isn't case sensitive, switch everything to lowercase
section = section.lower()
else: # variable!
# remove any comment stuff
line = line.split(';')[0]
line = line.split('#')[0]
# now get the info
items = line.replace('=','').split()
var = items[0].lower()
valsin = [float(x) for x in items[1:]]
nvals = len(valsin)
vals = np.nan*np.ones(3)
vals[:nvals] = np.array(valsin)
#print(' ',var,valsin,nvals,vals)
vardict[(section,var)] = vals
f.close()
#for k in vardict.keys():
# print(' ',k,vardict[k])
return vardict
#--------------------------------------------------
def get_fidvals_and_ranges_from_values_ini(valuesini,callfrom=default_callfrom, bashvarf = None):
vardict = read_values_ini(valuesini, callfrom, bashvarf =bashvarf)
fidvals = {}
ranges = {}
#print('>>>>>>>>>>>')
for key in vardict.keys():
sec = key[0]
var = key[1]
vals = vardict[key]
savekey = sec+'--'+var
if np.isnan(vals[1]): #fixed param, just one number
fidvals[savekey] = vals[0]
else:
fidvals[savekey] = vals[1]
ranges[savekey] = [vals[0],vals[2]]
#print(' ',savekey,vals,vals[1],np.isnan(vals[1]),fidvals[savekey])
return fidvals, ranges
#==================================================================
# Functions for reading in chains
#==================================================================
def get_chain_fname(runname,datadir = '.',suffix = DEFAULT_FILE_SUFFIX,prefix=DEFAULT_FILE_PREFIX,fname=None,alt4file = {},infitsfile=None, scalecutfile = None, joinchar = '.', modelsubdirs = False, y3style=True):
"""
If you pass in fname, will look in [datadir]/fname for chain data.
If fname is None (default), will use datastr, modelstr, suffix and prefix to
construct filename.
if y3style == False:
filename is datadir/prefix_runname_suffix (underscores adjusted if suffix is just .txt)
if y3stulle == True:
datadir/prefix_infitsfile.scalecutfile.runname.txt (.txt as chain suffix), periods = joinchar
returns string name of file containin chain data
For some cases, a run name might need to look in a different file;
-- e.g. for BAO ggsplit, there are only geometric params, so
the model b_l is equivalent to b_l-sOm, so when this function gets b_l-sOm it just load b_l
To handle this, you should pass a dict alt4file which has these run name translations
"""
if fname is not None:
return os.path.join(datadir,fname)
if modelsubdirs: #separate subdis for l, w, ok, base models
model = runname.split('_')[1]
mbase = model.split('-')[0]
lookindir = os.path.join(datadir,mbase)
else:
lookindir = datadir
if y3style:
if runname in alt4file.keys():
userun=alt4file[runname]
else:
userun = runname
prefixstr = ''
suffixstr = ''
if prefix and (prefix[-1] not in ('_','-')):
prefixstr = prefix+'_'
else:
prefixstr = prefix
if suffix and ((suffix!='.txt') and (suffix[0] not in ('_','-'))):
suffixstr = '_'+suffix
else:
suffixstr = suffix
fnamebase = lookindir +prefixstr+joinchar.join([infitsfile,scalecutfile,runname])+suffixstr
fname = os.path.join(lookindir,fnamebase)
return fname
else:
if runname in alt4file.keys():
userun=alt4file[runname]
else:
userun = runname
prefixstr = ''
suffixstr = ''
if prefix:
prefixstr = prefix+'_'
if suffix and (suffix!='.txt'):
suffixstr = '_'+suffix
else:
suffixstr = suffix
fnamebase = ''.join([prefixstr,userun,suffixstr])
return os.path.join(datadir,fnamebase)
#--------------------------------------------------
def get_nsample(filename):
"""
For multinest or polychord files, the last line tells you how many lines
to keep. This function pulls that info from th file.
"""
nsamples=None
fi = open(filename,"r")
for ln in fi:
if (ln.startswith("nsample=")) or (ln.startswith('#nsample=')):
nsamples = int(ln.replace('nsample=','').replace('#',''))
break
fi.close()
return nsamples
#--------------------------------------------------
def get_nlive(filename,useboost=False):
"""
for mn or pc files, get live points out of file header
if useboost==True, will also look for the boosted_posterior setting,
will return Nlive_boosted=Nlive*(1+boost_posterior)
"""
if not os.path.isfile(filename):
return None
fi = open(filename,"r")
# use "#live_points=" rather than "## live_points ="
# the latter might be there just from a pc module def
# single comment and no spaces means what was actually used to run
lines = fi.readlines()
nlive = None
boost=None
for ln in lines:
if ln.startswith("#live_points="):
nlive = int(ln.replace("#live_points=",''))
if (not useboost) or (boost is not None):
# we have everything we need
break
elif ln.startswith("#boost_posteriors="):
boost = float(ln.replace("#boost_posteriors=",""))
if nlive is not None: # have both pieces of info
break
fi.close()
print("nlive=",nlive,useboost,'boost',boost)
if useboost:
return nlive*(1.+boost)
else:
return nlive
#--------------------------------------------------
def get_logz(filename):
lastone=False
fi = open(filename,"r")
for ln in fi:
if lastone:
logz_error= float(ln.replace('#log_z_error=',''))
break
if ln.startswith("#log_z="):
logz = float(ln.replace('#log_z=',''))
lastone=True
fi.close()
return logz,logz_error
#--------------------------------------------------
def get_paramdict(filename,getlist=False):
"""
Reads in first line of chain file to make dictionary
to translate parameter names to column indices.
"""
#print("Getting parameter->index dictionary from ",filename)
f = open(filename,'r')
firstline = f.readline().split()
#print(firstline)
f.close()
pdict = {}
plist = []
userightmost=['weight','post','like','prior', 'old_weight','old_post', 'log_weight']
for i in range(len(firstline)):
s = firstline[i].replace('#','')
plist.append(s)
if s.lower() not in pdict.keys():
# if we ran with IS and a parameter is saved as extra output
# for both original and IS run, it'll appear twice.
# we want to use the leftmost one (that's the one that uses the IS calcs
# the original extra output and samplter output goes to the right of that
# thanks to Noah and Otavio for catching this
pdict[s] = i
pdict[s.lower()]=i
elif s in userightmost:
# for specific list of columns, use rightmost
# for sampled and derived params, want to use leftmost version
# but for sampler output want rightmost
# (there will only be one copy though so this doesn't really matter)
pdict[s] = i
pdict[s.lower()]=i
if getlist:
return pdict, plist
else:
return pdict
#--------------------------------------------------
def get_ranges_from_chainheader(filename,chaindir=''):
"""
Read through cosmosis chain header to get hard prior boundaries
so that getdist can correct for these.
"""
ranges = {}
try:
f = open(os.path.join(chaindir,filename),'r')
except:
return None
invalues=False
for line in f:
if 'END_OF_VALUES_INI' in line:
invalues = False
# done reading values, stop reading the file
break
if 'START_OF_VALUES_INI' in line:
invalues=True
# we're entering the part of the header with values info
continue
if invalues:
line = line.replace('##','').strip()
if not line: #empty line
continue
elif line.startswith('['): # section header
valsect = line.replace(']','').replace('[','')
else:
linesplit = line.replace('=','').split()
if len(linesplit)==4:
paramkey = valsect+'--'+linesplit[0]
minval = float(linesplit[1])
maxval = float(linesplit[3])
ranges[paramkey]=(minval,maxval)
else:
# if there are less than 4 entries (name bound start bound)
# parameter is fixed, don't count it
continue
f.close()
return ranges
#--------------------------------------------------
def rangedict_from_gdchain(gdchain):
bounds = gdchain.ranges
rangedict = {}
for name in bounds.names:
lowerval = bounds.getLower(name)
upperval = bounds.getUpper(name)
rangedict[name]=(lowerval,upperval)
return rangedict
#--------------------------------------------------
def get_Nparams(filename):
"""
Given chain file, read through header to get number of parameters sampled over
"""
params = []
f = open(filename,'r')
invalues=False
for line in f:
if 'END_OF_VALUES_INI' in line:
invalues=False
break
if 'START_OF_VALUES_INI' in line:
invalues=True
continue
if invalues:
line = line.replace('##','').strip()
if line.startswith('[') or not line:
continue
else:
linesplit = line.split()
if len(linesplit)==5:
params.append(linesplit[0])
else:
# if there are less than 5 entries (name = bound start bound)
# parameter is fixed, don't count it
continue
f.close()
return len(params),params
#--------------------------------------------------
def prep_chain(chainfname,chainlabel,kdesmooth=.5, paramlabels = DEFAULT_PLABELS, rangedict=None, chaindir=''):
"""
Read in chain, add some derived parameters that we're likely to want
May want to add/remove things here
Note that these add_x() functions will just do nothing if necessary
sampled parameters aren't in the chain
If rangedict is None, will find hard prior boundaries in chain header
and automatically pass them to getdist (recommended)
"""
if rangedict is None:
rangedict = get_ranges_from_chainheader(chainfname,chaindir)
gdchain = get_gdchain(chainfname,flabel=chainlabel,\
kdesmooth=kdesmooth ,indatdir = chaindir,\
paramlabels = paramlabels, rangedict = rangedict)
#print('>>>',chainfname,gdchain)
if gdchain is not None:
add_S8(gdchain)