forked from ctrendafilova/FisherLens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassWrapTools.py
1039 lines (895 loc) · 48.1 KB
/
classWrapTools.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 os
import numpy as np
#import cambWrapTools
import subprocess as sp
import platform
DEBUG_CLASS_DELENS_INI = False
NONLINEAR = True
INTERNAL_SCATTER_CL = True
TCMB = 2.7255 ## CMB temperature in K
def start_class_subproc(ini_path, cwd, version='class_scatter_nl_dl' if NONLINEAR else 'class_scatter_dl'):
"""Version should be class_delens, class_scatter_dl"""
os = platform.system()
print(' '.join(['wsl', './'+cwd+version, ini_path]))
try:
if os == 'Windows':
return sp.run(['wsl', './'+cwd+version, ini_path], check=True, capture_output=True)
elif os == 'Darwin':
return sp.run(['./'+cwd+version, ini_path], check=True, capture_output=True)
elif os == 'Linux':
return sp.run(['./'+cwd+version, ini_path], check=True, capture_output=True)
else:
raise OSError('I have no idea what OS you\'re running!')
except sp.CalledProcessError as e:
raise Exception(e.stdout.decode())
def class_generate_data(cosmo,
rootName = 'testing',
cmbNoise = None,
noiseLevel = 1.,
beamSizeArcmin = 1.,
deflectionNoise = None,
externalUnlensedCMBSpectra = None,
externalLensedCMBSpectra = None,
externalLensingSpectra = None,
classExecDir = os.path.dirname(os.path.abspath(__file__)) + '/CLASS_delens/',
classDataDir = os.path.dirname(os.path.abspath(__file__)) + '/CLASS_delens/',
calculateDerivatives = False,
includeUnlensedSpectraDerivatives = False,
outputAllReconstructions = False,
reconstructionMask = None,
lmax = 5000,
backgroundOnly = False,
extraParams = dict()
):
if not os.path.exists(classDataDir + 'input/'):
os.makedirs(classDataDir + 'input/')
if not os.path.exists(classDataDir + 'output/'):
os.makedirs(classDataDir + 'output/')
SCATTER = 'omega_dmeff' in cosmo.keys()
#if SCATTER:
#print('scattering!')
########################################################
## Convert cosmological parameters to CLASS format ##
########################################################
cosmoclass = dict()
# SCATTERING MODIFICATION
if SCATTER:
cosmoclass['omega_cdm'] = 1.e-15
if NONLINEAR:
cosmoclass.update({
'non linear': 'PT',
'IR resummation': 'Yes',
'Bias tracers': 'Yes',
'cb': 'No',
'RSD': 'Yes',
'AP': 'Yes',
'Omfid': '0.31',
'k_pivot': '0.05',
})
for k in ('omega_dmeff', 'omega_b', 'm_dmeff', 'log10sigma_dmeff', 'sigma_dmeff', 'log10m_dmeff'):
if k in cosmo.keys():
cosmoclass[k] = cosmo[k]
else:
cosmoclass['omega_b'] = cosmo['omega_b_h2']
cosmoclass['omega_cdm'] = cosmo['omega_c_h2']
# PANN MODIFICATION
if 'pann' in cosmo.keys():
cosmoclass['DM_annihilation_efficiency'] = cosmo['pann']
if 'DM_decay_Gamma' in cosmo.keys():
cosmoclass['DM_decay_Gamma'] = cosmo['DM_decay_Gamma']
if 'H0' in list(cosmo.keys()):
cosmoclass['H0'] = cosmo['H0']
elif 'h' in list(cosmo.keys()):
cosmoclass['h'] = cosmo['h']
elif 'theta_s' in list(cosmo.keys()):
cosmoclass['100*theta_s']= 100.*cosmo['theta_s']
if 'A_s' in list(cosmo.keys()):
cosmoclass['A_s'] = cosmo['A_s']
elif 'logA' in list(cosmo.keys()):
cosmoclass['ln10^{10}A_s'] = cosmo['logA']
cosmoclass['n_s'] = cosmo['n_s']
cosmoclass['tau_reio'] = cosmo['tau']
#omega_k
if 'omk' in list(cosmo.keys()):
cosmoclass['Omega_k'] = cosmo['omk']
## CLASS treats 'ur' species differently from 'ncdm' species
## With one massive neutrino eigenstate, 'N_ur' is 2.0328 to make N_eff 3.046
## Subtract off the difference to give consistent N_eff
cosmoclass['N_ur'] = cosmo['N_eff']-(3.046 - 2.0328) if 'mnu' in list(cosmo.keys()) else cosmo['N_eff'] if 'N_eff' in list(cosmo.keys()) else 3.046
## Setup massive neutrinos with a single massive species
if 'mnu' in list(cosmo.keys()):
cosmoclass['N_ncdm'] = 1
cosmoclass['T_ncdm'] = 0.71611
cosmoclass['m_ncdm'] = cosmo['mnu']
if 'Yhe' in list(cosmo.keys()):
cosmoclass['YHe'] = cosmo['Yhe']
if 'r' in list(cosmo.keys()) and cosmo['r'] != 0.:
cosmoclass['r'] = cosmo['r']
if 'n_t' in list(cosmo.keys()):
cosmoclass['n_t'] = cosmo['n_t']
## spectral running
if 'alpha_s' in list(cosmo.keys()):
cosmoclass['alpha_s'] = cosmo['alpha_s']
## isocurvature parameters
if 'f_bi' in list(cosmo.keys()):
cosmoclass['f_bi'] = cosmo['f_bi']
if 'n_bi' in list(cosmo.keys()):
cosmoclass['n_bi'] = cosmo['n_bi']
if 'alpha_bi' in list(cosmo.keys()):
cosmoclass['alpha_bi'] = cosmo['alpha_bi']
if 'f_cdi' in list(cosmo.keys()):
cosmoclass['f_cdi'] = cosmo['f_cdi']
if 'n_cdi' in list(cosmo.keys()):
cosmoclass['n_cdi'] = cosmo['n_cdi']
if 'alpha_cdi' in list(cosmo.keys()):
cosmoclass['alpha_cdi'] = cosmo['alpha_cdi']
if 'f_nid' in list(cosmo.keys()):
cosmoclass['f_nid'] = cosmo['f_nid']
if 'n_nid' in list(cosmo.keys()):
cosmoclass['n_nid'] = cosmo['n_nid']
if 'alpha_nid' in list(cosmo.keys()):
cosmoclass['alpha_nid'] = cosmo['alpha_nid']
if 'f_niv' in list(cosmo.keys()):
cosmoclass['f_niv'] = cosmo['f_niv']
if 'n_niv' in list(cosmo.keys()):
cosmoclass['n_niv'] = cosmo['n_niv']
if 'alpha_niv' in list(cosmo.keys()):
cosmoclass['alpha_niv'] = cosmo['alpha_niv']
## isocurvature covariances
if 'c_ad_bi' in list(cosmo.keys()):
cosmoclass['c_ad_bi'] = cosmo['c_ad_bi']
if 'n_ad_bi' in list(cosmo.keys()):
cosmoclass['n_ad_bi'] = cosmo['n_ad_bi']
if 'alpha_ad_bi' in list(cosmo.keys()):
cosmoclass['alpha_ad_bi'] = cosmo['alpha_ad_bi']
if 'c_ad_cdi' in list(cosmo.keys()):
cosmoclass['c_ad_cdi'] = cosmo['c_ad_cdi']
if 'n_ad_cdi' in list(cosmo.keys()):
cosmoclass['n_ad_cdi'] = cosmo['n_ad_cdi']
if 'alpha_ad_cdi' in list(cosmo.keys()):
cosmoclass['alpha_ad_cdi'] = cosmo['alpha_ad_cdi']
if 'c_ad_nid' in list(cosmo.keys()):
cosmoclass['c_ad_nid'] = cosmo['c_ad_nid']
if 'n_ad_nid' in list(cosmo.keys()):
cosmoclass['n_ad_nid'] = cosmo['n_ad_nid']
if 'alpha_ad_nid' in list(cosmo.keys()):
cosmoclass['alpha_ad_nid'] = cosmo['alpha_ad_nid']
if 'c_ad_niv' in list(cosmo.keys()):
cosmoclass['c_ad_niv'] = cosmo['c_ad_niv']
if 'n_ad_niv' in list(cosmo.keys()):
cosmoclass['n_ad_niv'] = cosmo['n_ad_niv']
if 'alpha_ad_niv' in list(cosmo.keys()):
cosmoclass['alpha_ad_niv'] = cosmo['alpha_ad_niv']
if 'c_bi_cdi' in list(cosmo.keys()):
cosmoclass['c_bi_cdi'] = cosmo['c_bi_cdi']
if 'n_bi_cdi' in list(cosmo.keys()):
cosmoclass['n_bi_cdi'] = cosmo['n_bi_cdi']
if 'alpha_bi_cdi' in list(cosmo.keys()):
cosmoclass['alpha_bi_cdi'] = cosmo['alpha_bi_cdi']
if 'c_bi_nid' in list(cosmo.keys()):
cosmoclass['c_bi_nid'] = cosmo['c_bi_nid']
if 'n_bi_nid' in list(cosmo.keys()):
cosmoclass['n_bi_nid'] = cosmo['n_bi_nid']
if 'alpha_bi_nid' in list(cosmo.keys()):
cosmoclass['alpha_bi_nid'] = cosmo['alpha_bi_nid']
if 'c_bi_niv' in list(cosmo.keys()):
cosmoclass['c_bi_niv'] = cosmo['c_bi_niv']
if 'n_bi_niv' in list(cosmo.keys()):
cosmoclass['n_bi_niv'] = cosmo['n_bi_niv']
if 'alpha_bi_nid' in list(cosmo.keys()):
cosmoclass['alpha_bi_niv'] = cosmo['alpha_bi_niv']
if 'c_cdi_nid' in list(cosmo.keys()):
cosmoclass['c_cdi_nid'] = cosmo['c_cdi_nid']
if 'n_cdi_nid' in list(cosmo.keys()):
cosmoclass['n_cdi_nid'] = cosmo['n_cdi_nid']
if 'alpha_cdi_nid' in list(cosmo.keys()):
cosmoclass['alpha_cdi_nid'] = cosmo['alpha_cdi_nid']
if 'c_cdi_niv' in list(cosmo.keys()):
cosmoclass['c_cdi_niv'] = cosmo['c_cdi_niv']
if 'n_cdi_niv' in list(cosmo.keys()):
cosmoclass['n_cdi_niv'] = cosmo['n_cdi_niv']
if 'alpha_cdi_niv' in list(cosmo.keys()):
cosmoclass['alpha_cdi_niv'] = cosmo['alpha_cdi_niv']
if 'c_nid_niv' in list(cosmo.keys()):
cosmoclass['c_nid_niv'] = cosmo['c_nid_niv']
if 'n_nid_niv' in list(cosmo.keys()):
cosmoclass['n_nid_niv'] = cosmo['n_nid_niv']
if 'alpha_nid_niv' in list(cosmo.keys()):
cosmoclass['alpha_nid_niv'] = cosmo['alpha_nid_niv']
## varying fundamental constants
if 'varying_transition_redshift' in list(cosmo.keys()):
cosmoclass['varying_fundamental_constants'] = 'instantaneous'
cosmoclass['varying_transition_redshift'] = cosmo['varying_transition_redshift']
if 'varying_alpha' in list(cosmo.keys()):
cosmoclass['varying_fundamental_constants'] = 'instantaneous'
cosmoclass['varying_alpha'] = cosmo['varying_alpha']
if 'varying_me' in list(cosmo.keys()):
cosmoclass['varying_fundamental_constants'] = 'instantaneous'
cosmoclass['varying_me'] = cosmo['varying_me']
if 'bbn_alpha_sensitivity' in list(cosmo.keys()):
cosmoclass['varying_fundamental_constants'] = 'instantaneous'
cosmoclass['bbn_alpha_sensitivity'] = cosmo['bbn_alpha_sensitivity']
## EDE-edit
if 'f_scf' in list(cosmo.keys()):
cosmoclass['f_scf'] = cosmo['f_scf']
cosmoclass['Omega_Lambda'] = 0
cosmoclass['Omega_fld'] = 0
cosmoclass['Omega_scf'] = -1
cosmoclass['scf_parameters'] = '1, 1, 1, 1, 1, 0.0'
cosmoclass['CC_scf'] = 1
cosmoclass['n_scf'] = 3
cosmoclass['scf_tuning_index'] = 3
cosmoclass['attractor_ic_scf'] = 'no'
if 'log10f_scf' in list(cosmo.keys()):
cosmoclass['log10f_scf'] = cosmo['log10f_scf']
cosmoclass['Omega_Lambda'] = 0
cosmoclass['Omega_fld'] = 0
cosmoclass['Omega_scf'] = -1
cosmoclass['scf_parameters'] = '1, 1, 1, 1, 1, 0.0'
cosmoclass['CC_scf'] = 1
cosmoclass['n_scf'] = 3
cosmoclass['scf_tuning_index'] = 3
cosmoclass['attractor_ic_scf'] = 'no'
if 'm_scf' in list(cosmo.keys()):
cosmoclass['m_scf'] = cosmo['m_scf']
cosmoclass['Omega_Lambda'] = 0
cosmoclass['Omega_fld'] = 0
cosmoclass['Omega_scf'] = -1
cosmoclass['scf_parameters'] = '1, 1, 1, 1, 1, 0.0'
cosmoclass['CC_scf'] = 1
cosmoclass['n_scf'] = 3
cosmoclass['scf_tuning_index'] = 3
cosmoclass['attractor_ic_scf'] = 'no'
if 'log10m_scf' in list(cosmo.keys()):
cosmoclass['log10m_scf'] = cosmo['log10m_scf']
cosmoclass['Omega_Lambda'] = 0
cosmoclass['Omega_fld'] = 0
cosmoclass['Omega_scf'] = -1
cosmoclass['scf_parameters'] = '1, 1, 1, 1, 1, 0.0'
cosmoclass['CC_scf'] = 1
cosmoclass['n_scf'] = 3
cosmoclass['scf_tuning_index'] = 3
cosmoclass['attractor_ic_scf'] = 'no'
if 'fEDE' in list(cosmo.keys()):
cosmoclass['fEDE'] = cosmo['fEDE']
cosmoclass['Omega_Lambda'] = 0
cosmoclass['Omega_fld'] = 0
cosmoclass['Omega_scf'] = -1
cosmoclass['scf_parameters'] = '1, 1, 1, 1, 1, 0.0'
cosmoclass['CC_scf'] = 1
cosmoclass['n_scf'] = 3
cosmoclass['scf_tuning_index'] = 3
cosmoclass['attractor_ic_scf'] = 'no'
if 'log10z_c' in list(cosmo.keys()):
cosmoclass['log10z_c'] = cosmo['log10z_c']
cosmoclass['Omega_Lambda'] = 0
cosmoclass['Omega_fld'] = 0
cosmoclass['Omega_scf'] = -1
cosmoclass['scf_parameters'] = '1, 1, 1, 1, 1, 0.0'
cosmoclass['CC_scf'] = 1
cosmoclass['n_scf'] = 3
cosmoclass['scf_tuning_index'] = 3
cosmoclass['attractor_ic_scf'] = 'no'
if 'thetai_scf' in list(cosmo.keys()):
cosmoclass['thetai_scf'] = cosmo['thetai_scf']
cosmoclass['Omega_Lambda'] = 0
cosmoclass['Omega_fld'] = 0
cosmoclass['Omega_scf'] = -1
cosmoclass['scf_parameters'] = '1, 1, 1, 1, 1, 0.0'
cosmoclass['CC_scf'] = 1
cosmoclass['n_scf'] = 3
cosmoclass['scf_tuning_index'] = 3
cosmoclass['attractor_ic_scf'] = 'no'
## Dark radiation (7.2.2)
if 'N_idr' in list(cosmo.keys()):
cosmoclass['N_idr'] = cosmo['N_idr']
if 'f_idm' in list(cosmo.keys()):
cosmoclass['f_idm'] = cosmo['f_idm']
if 'Gamma_0_nadm' in list(cosmo.keys()):
cosmoclass['Gamma_0_nadm'] = cosmo['Gamma_0_nadm']
########################################################
## the relevant CLASS commands to call delensing code ##
########################################################
dcode = dict()
dcode['root'] = classDataDir + 'output/' + rootName #+ '_'
if SCATTER and NONLINEAR:
dcode['output'] = 'tCl,pCl,lCl,dlCl,mPk'
else:
dcode['output'] = 'tCl,pCl,lCl,dlCl'
dcode['modes'] = 's'
dcode['lensing'] = 'yes'
if not NONLINEAR:
dcode['non linear'] = 'hmcode'
if dcode['non linear'] == 'hmcode' and 'eta_0' in list(cosmo.keys()):
cosmoclass['eta_0'] = cosmo['eta_0']
if dcode['non linear'] == 'hmcode' and 'c_min' in list(cosmo.keys()):
cosmoclass['c_min'] = cosmo['c_min']
dcode['l_max_scalars'] = lmax
dcode['delta_l_max'] = 500
dcode['delta_dl_max'] = 0
dcode['format'] = 'class_delens'
dcode['accurate_lensing'] = 1
dcode['headers'] = 'yes'
dcode['output_spectra_noise'] = 'yes'
dcode['delensing_verbose'] = 0
dcode['write parameters'] = 'yes'
dcode['delensing derivatives'] = 'no'
dcode['output_derivatives'] = 'no'
dcode['overwrite_root'] = 'yes'
dcode['delensing_verbose'] = 3
dcode['ic'] = 'ad'
if 'r' in list(cosmo.keys()) and cosmo['r'] != 0.:
dcode['modes']+=',t'
dcode['l_max_tensors'] = 1000
## adding isocurvature modes to initial conditions
if 'f_bi' in list(cosmo.keys()) and cosmo['f_bi'] != 0.:
dcode['ic']+=',bi'
if 'f_cdi' in list(cosmo.keys()) and cosmo['f_cdi'] != 0.:
dcode['ic']+=',cdi'
if 'f_nid' in list(cosmo.keys()) and cosmo['f_nid'] != 0.:
dcode['ic']+=',nid'
if 'f_niv' in list(cosmo.keys()) and cosmo['f_niv'] != 0.:
dcode['ic']+=',niv'
if cmbNoise is None:
## If T and P noise are not provided, use analytic noise model
dcode['temperature noise spectra type'] = 'idealized'
dcode['polarization noise spectra type'] = 'idealized'
dcode['delta_noise'] = noiseLevel / 60. / 180. * np.pi ## Convert uK-arcmin to uK-rad
dcode['sigma_beam'] = beamSizeArcmin / 60. / 180. * np.pi ## Convert arcmin to rad
else:
if cmbNoise['l'][-1]<dcode['l_max_scalars']+dcode['delta_l_max']+dcode['delta_dl_max']:
print('You must provde external CMB noise at least up to l=' +str(dcode['l_max_scalars']+dcode['delta_l_max']+dcode['delta_dl_max']))
stop
dcode['temperature noise spectra type'] = 'external'
dcode['polarization noise spectra type'] = 'external'
np.savetxt(classDataDir + 'input/' + rootName + '_temp_noise.dat', np.column_stack((cmbNoise['l'], cmbNoise['cl_TT'])) )
np.savetxt(classDataDir + 'input/' + rootName + '_pol_noise.dat', np.column_stack((cmbNoise['l'], cmbNoise['cl_EE'])) )
dcode['command_for_temperature_noise_spec'] = 'cat ' + classDataDir + 'input/' + rootName + '_temp_noise.dat'
dcode['command_for_polarization_noise_spec'] = 'cat ' + classDataDir + 'input/' + rootName + '_pol_noise.dat'
if deflectionNoise is None:
## If deflection noise is not provided, use iterative delensing
dcode['delensing'] = 'no' # iterative
dcode['lensing reconstruction noise spectra type'] = 'internal'
dcode['noise_iteration_type'] = 'diag'
dcode['min_varr_type'] = 'diag'
dcode['convergence type'] = 'total'
dcode['convergence_criterion_itr'] = '1e-5'
if reconstructionMask is not None:
dcode['recon_mask_lmin_T'] = reconstructionMask['lmin_T'] if 'lmin_T' in reconstructionMask.keys() else 0
dcode['recon_mask_lmax_T'] = reconstructionMask['lmax_T'] if 'lmax_T' in reconstructionMask.keys() else 30000
dcode['recon_mask_lmin_E'] = reconstructionMask['lmin_E'] if 'lmin_E' in reconstructionMask.keys() else 0
dcode['recon_mask_lmax_E'] = reconstructionMask['lmax_E'] if 'lmax_E' in reconstructionMask.keys() else 30000
dcode['recon_mask_lmin_B'] = reconstructionMask['lmin_B'] if 'lmin_B' in reconstructionMask.keys() else 0
dcode['recon_mask_lmax_B'] = reconstructionMask['lmax_B'] if 'lmax_B' in reconstructionMask.keys() else 30000
else:
dcode['delensing'] = 'no' # yes
dcode['lensing reconstruction noise spectra type'] = 'external'
## Write file containing deflection noise, assuming deflectionNoise is array of NLdd at every L starting from 2
np.savetxt(classDataDir + 'input/' + rootName + '_defl_noise.dat', np.column_stack((np.arange(len(deflectionNoise))+2, deflectionNoise)) )
dcode['command_for_lens_recon_noise_spec'] = 'cat ' + classDataDir + 'input/' + rootName + '_defl_noise.dat'
# UNLENSED
if SCATTER:
if INTERNAL_SCATTER_CL:
dcode['cmb spectra type'] = 'internal'
#print('internal delensing with scatter_dl')
else:
dcode['cmb spectra type'] = 'external'
dcode['command_for_external_cmb_spectra'] = 'cat ' + classDataDir + 'output/' + rootName + '_cl_reorder.dat'
print('Shoving scattering spectra into CLASS_delens from', classDataDir + 'output/' + rootName + '_cl_reorder.dat')
elif externalUnlensedCMBSpectra is None:
## If unlensed spectra are not provided, calculate spectra with CLASS
dcode['cmb spectra type'] = 'internal'
else:
## If unlensed spectra are provided, read them in
if externalLensingSpectra is None:
print('Need to supply lensing spectrum to use external unlensed spectra')
stop
## Need unlensed spectra and lensing spectra to higher l than lmax
if dcode['l_max_scalars'] + (dcode['delta_l_max']+dcode['delta_dl_max']) > np.shape(externalUnlensedCMBSpectra['l'])[0]:
print(('Need to supply unlensed spectrum to lmax >= ' + str( dcode['l_max_scalars'] + (dcode['delta_l_max']+dcode['delta_dl_max'])+1 ) + \
' in order to compute delensed spectrum to lmax = ' + str( lmax ) ))
stop
if dcode['l_max_scalars'] + (dcode['delta_l_max']+dcode['delta_dl_max']) > np.shape(externalLensingSpectra['cl_phiphi'])[0]:
print(('Need to supply lensing spectrum to lmax >= ' + str( dcode['l_max_scalars'] + (dcode['delta_l_max']+dcode['delta_dl_max'])+1 ) + \
' in order to compute delensed spectrum to lmax = ' + str( lmax ) ))
stop
dcode['cmb spectra type'] = 'external'
np.savetxt(classDataDir + 'input/' + rootName + '_unlensed_input_spectra.dat', \
np.column_stack(
(externalUnlensedCMBSpectra['l'], externalUnlensedCMBSpectra['cl_TT'], \
externalUnlensedCMBSpectra['cl_TE'], externalUnlensedCMBSpectra['cl_EE'], \
externalUnlensedCMBSpectra['cl_BB'], externalLensingSpectra['cl_phiphi'] )) )
dcode['command_for_external_cmb_spectra'] = 'cat ' + classDataDir + 'input/' + rootName + '_unlensed_input_spectra.dat'
# LENSED
if SCATTER:
# according to kim, passing lensed cl is not necessary, so please do not uncomment this unless you have a reason to
#dcode['lensed cmb spectra type'] = 'external'
#dcode['command_for_external_lensed_cmb_spectra'] = 'cat ' + classDataDir + 'output/' + rootName + '_cl_lensed_reorder.dat'
pass
elif externalLensedCMBSpectra is None:
## If lensed spectra are not provided, calculate spectra with CLASS
dcode['lensed cmb spectra type'] = 'internal'
else:
print('External lensed spectra not currently working, pass only external unlensed spectra.')
stop
## If lensed spectra are provided, read them in
if externalLensingSpectra is None:
print('Need to supply lensing spectrum to use external lensed spectra')
stop
## Need lensed spectra and lensing spectra to higher l than lmax
if dcode['l_max_scalars'] + (dcode['delta_l_max']+dcode['delta_dl_max']) > np.shape(externalLensedCMBSpectra['l'])[0]:
print(('Need to supply lensed spectrum to lmax >= ' + str( dcode['l_max_scalars'] + (dcode['delta_l_max']+dcode['delta_dl_max'])+1 ) + \
' in order to compute delensed spectrum to lmax = ' + str( lmax ) ))
stop
if dcode['l_max_scalars'] + (dcode['delta_l_max']+dcode['delta_dl_max']) > np.shape(externalLensingSpectra['cl_phiphi'])[0]:
print(('Need to supply lensing spectrum to lmax >= ' + str( dcode['l_max_scalars'] + (dcode['delta_l_max']+dcode['delta_dl_max'])+1 ) + \
' in order to compute delensed spectrum to lmax = ' + str( lmax ) ))
stop
dcode['lensed cmb spectra type'] = 'external'
np.savetxt(classDataDir + 'input/' + rootName + '_lensed_input_spectra.dat', \
np.column_stack((externalLensedCMBSpectra['l'], externalLensedCMBSpectra['cl_TT'], \
externalLensedCMBSpectra['cl_TE'], externalLensedCMBSpectra['cl_EE'], \
externalLensedCMBSpectra['cl_BB'], externalLensingSpectra['cl_phiphi'] )) )
dcode['command_for_external_lensed_cmb_spectra'] = 'cat ' + classDataDir + 'input/' + rootName + '_lensed_input_spectra.dat'
########################################################
## CLASS code calculates most of the relevant data, ##
## including the spectra, reconstruction noise and ##
## derivatives. It is important to give the correct ##
## input file and with appropriate options included ##
########################################################
if calculateDerivatives is not False:
dcode['delensing derivatives'] = 'yes'
dcode['output_derivatives'] = 'yes'
dcode['derv_binedges'] = '1'
dervtype = calculateDerivatives
dcode['derivative type'] = dervtype
if includeUnlensedSpectraDerivatives is not False:
dcode['calculate_derviaties_wrt_unlensed'] = 'yes'
dcode['unlensed derivative type'] = dervtype
## extraParams is dictionary allowing for arbitrary additional specifications in CLASS format
## e.g. extraParams['tol_ncdm'] = 1.e-3 sets a precision parameter associated with ncdm
## extraParams will overwrite any previously set parameters
if backgroundOnly is True:
cosmoclass['write_background'] = 'yes'
cosmoclass['write_thermodynamics'] = 'yes'
cosmoclass['thermodynamics_verbose'] = 1
dcode['output'] = ''
dcode['lensing'] = 'no'
dcode['non linear'] = ''
calculateDerivatives = False
dcode.update(extraParams)
########################################################
## Running the CLASS code to write the spectra inside ##
## specific files, as well as their derivatives, and ##
## the CMB and lensing noise used to create these. ##
########################################################
if SCATTER:
with open(classDataDir + 'input/' + rootName + "_class_scatter.ini", "w") as f:
f.write('\n'.join(['%s = %s' % (k, v) for k, v in cosmoclass.items()]))
f.write('\n')
if INTERNAL_SCATTER_CL:
f.write('\n'.join(['%s = %s' % (k, v) for k, v in dcode.items()]))
else:
# this section should not trigger post-merge
f.write("""
# THIS IS WHAT THE SCATTERING CODE TAKES IN
output = tCl,pCl,lCl
modes = s
lensing = yes
root = CLASS_delens/data/Node_0/output/scatter_
overwrite_root = yes
l_max_scalars = 5000
""")
with open(classDataDir + 'input/' + rootName + "_class_delens.ini", "w") as f:
f.write('\n'.join(['%s = %s' % (k, v) for k, v in dcode.items()]))
if DEBUG_CLASS_DELENS_INI:
input(rootName + '_class_scatter.ini ready. Please check it and press enter to continue.')
#print('Starting scatter...')
scatter_proc = start_class_subproc(classDataDir + 'input/' + rootName + "_class_scatter.ini", cwd=classExecDir)
# REORDER LENSED SPECTRA (we will not input lensed spectra, it will be internal (?), cmd+f LOC37377)
"""spectra = np.loadtxt(classDataDir + 'output/' + rootName + '_cl_lensed.dat')
np.savetxt(classDataDir + 'output/' + rootName + '_cl_lensed_reorder.dat',
np.column_stack(
(spectra[:, 0], spectra[:, 1], spectra[:, 3], spectra[:, 2], spectra[:, 4], spectra[:, 5])))"""
if not INTERNAL_SCATTER_CL:
# REORDER UNLENSED SPECTRA
spectra = np.loadtxt(classDataDir + 'output/' + rootName + '__cl.dat')
np.savetxt(classDataDir + 'output/' + rootName + '_cl_reorder.dat',
np.column_stack(
(spectra[:, 0], spectra[:, 1], spectra[:, 3], spectra[:, 2], spectra[:, 4], spectra[:, 5])
))
print('Starting delens...')
if DEBUG_CLASS_DELENS_INI:
raise Exception(f'Yovel - Stopping so you can look at what just happened. Run [./class_delens /Users/yovel/Desktop/fisher_test/FisherLens/CLASS_delens/data/Node_0/input/scatter_class_delens.ini]. Check input/{rootName}_class_delens.ini and output/{rootName}_defl_noise.dat')
delens_proc = start_class_subproc(classDataDir + 'input/' + rootName + "_class_delens.ini", cwd=classExecDir)
#delens_proc = sp.run(['./class_delens', classDataDir + 'input/' + rootName + "_class_delens.ini"], cwd=classExecDir, stdout=sp.PIPE, stderr=sp.PIPE, check=True)
else: # ann or decay, both work
with open(classDataDir + 'input/' + rootName + ".ini", "w") as f:
f.write( '\n'.join(['%s = %s' % (k, v) for k, v in cosmoclass.items()])
+'\n'
+'\n'.join(['%s = %s' % (k, v) for k, v in dcode.items()]))
ann_or_decay_proc = start_class_subproc(classDataDir + 'input/' + rootName + ".ini", classExecDir, version='class_delens')
#os.system("cd " + classExecDir + " ; ./class_delens " + classDataDir + 'input/' + rootName + ".ini")
########################################################
## Filling the spectra into specific CLASS dict()s. ##
########################################################
if calculateDerivatives is False and backgroundOnly is False:
########################################################
## the calculated spectra to be filled in whats below ##
########################################################
cspec = dict()
cspec['cl_unlensed'] = None # To be filled with unlensed CMB spectra
cspec['cl_lensed'] = None # To be filled with lensed CMB spectra
cspec['cl_delensed'] = None # To be filled with delensed CMB spectra
cspec['nl_lensing'] = None # To be filled with lensing reconstruction noise
cspec['nl_cmb'] = None # To be filled with CMB spectra noise
cspec['cl_unlensed'] = np.loadtxt(classDataDir + "output/" + rootName + "_cl.dat")
cspec['cl_lensed'] = np.loadtxt(classDataDir + "output/" + rootName + "_cl_lensed.dat")
cspec['cl_delensed'] = np.loadtxt(classDataDir + "output/" + rootName + "_cl_delensed.dat")
cspec['nl_cmb'] = np.loadtxt(classDataDir + "output/" + rootName + "_spectra_noise.dat")
if deflectionNoise is None:
cspec['nl_lensing'] = np.loadtxt(classDataDir + "output/" + rootName + "_lensing_noise_rcn.dat")
lvec = cspec['cl_lensed'][:,0]
nElls = len(lvec)
########################################################
## Filling dict()s in a way similar to the JM wrapper ##
########################################################
dl_TT = cspec['cl_unlensed'][:nElls,1]*(TCMB*1.e6)**2
dl_EE = cspec['cl_unlensed'][:nElls,2]*(TCMB*1.e6)**2
dl_TE = cspec['cl_unlensed'][:nElls,3]*(TCMB*1.e6)**2
dl_BB = cspec['cl_unlensed'][:nElls,4]*(TCMB*1.e6)**2
cl_TT = cspec['cl_unlensed'][:nElls,1]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
cl_EE = cspec['cl_unlensed'][:nElls,2]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
cl_TE = cspec['cl_unlensed'][:nElls,3]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
cl_BB = cspec['cl_unlensed'][:nElls,4]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
unlensed = {'l' : cspec['cl_unlensed'][:nElls,0],
'cl_TT' : cl_TT,
'cl_EE' : cl_EE,
'cl_TE' : cl_TE,
'cl_BB' : cl_BB,
'dl_TT' : dl_TT,
'dl_EE' : dl_EE,
'dl_TE' : dl_TE,
'dl_BB' : dl_BB
}
dl_TT_lensed = cspec['cl_lensed'][:nElls,1]*(TCMB*1.e6)**2
dl_EE_lensed = cspec['cl_lensed'][:nElls,2]*(TCMB*1.e6)**2
dl_TE_lensed = cspec['cl_lensed'][:nElls,3]*(TCMB*1.e6)**2
dl_BB_lensed = cspec['cl_lensed'][:nElls,4]*(TCMB*1.e6)**2
cl_TT_lensed = cspec['cl_lensed'][:nElls,1]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
cl_EE_lensed = cspec['cl_lensed'][:nElls,2]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
cl_TE_lensed = cspec['cl_lensed'][:nElls,3]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
cl_BB_lensed = cspec['cl_lensed'][:nElls,4]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
lensed = {'l' : cspec['cl_lensed'][:nElls,0],
'cl_TT' : cl_TT_lensed,
'cl_EE' : cl_EE_lensed,
'cl_TE' : cl_TE_lensed,
'cl_BB' : cl_BB_lensed,
'dl_TT' : dl_TT_lensed,
'dl_EE' : dl_EE_lensed,
'dl_TE' : dl_TE_lensed,
'dl_BB' : dl_BB_lensed
}
dl_TT_delensed = cspec['cl_delensed'][:nElls,1]*(TCMB*1.e6)**2
dl_EE_delensed = cspec['cl_delensed'][:nElls,2]*(TCMB*1.e6)**2
dl_TE_delensed = cspec['cl_delensed'][:nElls,3]*(TCMB*1.e6)**2
dl_BB_delensed = cspec['cl_delensed'][:nElls,4]*(TCMB*1.e6)**2
cl_TT_delensed = cspec['cl_delensed'][:nElls,1]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
cl_EE_delensed = cspec['cl_delensed'][:nElls,2]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
cl_TE_delensed = cspec['cl_delensed'][:nElls,3]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
cl_BB_delensed = cspec['cl_delensed'][:nElls,4]*2*np.pi/(lvec*(lvec+1))*(TCMB*1.e6)**2
delensed = {'l' : cspec['cl_delensed'][:nElls,0],
'cl_TT' : cl_TT_delensed,
'cl_EE' : cl_EE_delensed,
'cl_TE' : cl_TE_delensed,
'cl_BB' : cl_BB_delensed,
'dl_TT' : dl_TT_delensed,
'dl_EE' : dl_EE_delensed,
'dl_TE' : dl_TE_delensed,
'dl_BB' : dl_BB_delensed
}
cl_TT_noise = cspec['nl_cmb'][:nElls,1]
cl_EE_noise = cspec['nl_cmb'][:nElls,2]
cl_TE_noise = np.empty(nElls)
cl_TE_noise.fill(0.)
cl_BB_noise = cspec['nl_cmb'][:nElls,2]
dl_TT_noise = cl_TT_noise*(lvec*(lvec+1))/(2*np.pi)
dl_EE_noise = cl_EE_noise*(lvec*(lvec+1))/(2*np.pi)
dl_TE_noise = cl_TE_noise*(lvec*(lvec+1))/(2*np.pi)
dl_BB_noise = cl_BB_noise*(lvec*(lvec+1))/(2*np.pi)
cmbNoiseSpectra = {'l' : cspec['nl_cmb'][:nElls,0],
'cl_TT' : cl_TT_noise,
'cl_EE' : cl_EE_noise,
'cl_TE' : cl_TE_noise,
'cl_BB' : cl_BB_noise,
'dl_TT' : dl_TT_noise,
'dl_EE' : dl_EE_noise,
'dl_TE' : dl_TE_noise,
'dl_BB' : dl_BB_noise
}
cl_phiphi = cspec['cl_unlensed'][:nElls,5]*2*np.pi/(lvec*(lvec+1))
cl_dd = cl_phiphi*(lvec*(lvec+1))
cl_kk = cl_phiphi*(lvec*(lvec+1))*(lvec*(lvec+1))/4.
lensing = {'l' : cspec['cl_unlensed'][:nElls,0],
'cl_phiphi' : cl_phiphi,
'cl_dd' : cl_dd,
'cl_kk' : cl_kk
}
powers=dict()
powers['unlensed'] = unlensed
powers['lensed'] = lensed
powers['lensing'] = lensing
powers['delensed'] = delensed
## These lines are used to avoid error when not computing deflection noise
deflection_noise = dict()
deflection_noise['MV'] = None
if deflectionNoise is None:
if dcode['min_varr_type'] == 'diag':
nl_dd_MV = cspec['nl_lensing'][:nElls,1]*2.*np.pi
nl_dd_TT = cspec['nl_lensing'][:nElls,2]*2.*np.pi
nl_dd_TE = cspec['nl_lensing'][:nElls,3]*2.*np.pi
nl_dd_EE = cspec['nl_lensing'][:nElls,4]*2.*np.pi
nl_dd_BB = cspec['nl_lensing'][:nElls,5]*2.*np.pi
nl_dd_EB = cspec['nl_lensing'][:nElls,6]*2.*np.pi
nl_dd_TB = cspec['nl_lensing'][:nElls,7]*2.*np.pi
deflection_noise = {'l' :cspec['nl_lensing'][:nElls,0],
'MV' : nl_dd_MV,
'TT' : nl_dd_TT,
'TE' : nl_dd_TE,
'EE' : nl_dd_EE,
'BB' : nl_dd_BB,
'EB' : nl_dd_EB,
'TB' : nl_dd_TB
}
elif dcode['min_varr_type'] == 'eb':
nl_dd_MV = cspec['nl_lensing'][:nElls,1]*2.*np.pi
nl_dd_EB = cspec['nl_lensing'][:nElls,2]*2.*np.pi
deflection_noise = {'l' :cspec['nl_lensing'][:nElls,0],
'MV' : nl_dd_MV,
'EB' : nl_dd_EB
}
if outputAllReconstructions is False:
reconstructionOutput = deflection_noise['MV']
if outputAllReconstructions is True:
reconstructionOutput = deflection_noise
if calculateDerivatives is not False:
########################################################
## Calculate the derivatives of the CMB spectra. ##
########################################################
dCldCLd = loadLensingDerivatives(rootName = rootName,
classDataDir = classDataDir,
dervtype = dervtype)
if includeUnlensedSpectraDerivatives is not False:
dCldCLu = loadUnlensedSpectraDerivatives(rootName = rootName,
classDataDir = classDataDir,
dervtype = dervtype)
if backgroundOnly is True:
# returns rs/dV for desired redshifts
background = np.loadtxt(classDataDir + "output/" + rootName + "_background.dat")
thermo = np.loadtxt(classDataDir + "output/" + rootName + "_thermodynamics.dat")
thermo_summary = np.loadtxt(classDataDir + "output/" + rootName + "_thermodynamics_summary.dat")
output_data = {'background' : background,
'thermo' : thermo,
'thermo_summary' : thermo_summary}
output = output_data
elif calculateDerivatives is False:
output = [powers, reconstructionOutput]
else:
if includeUnlensedSpectraDerivatives is not False:
output = [dCldCLd, dCldCLu]
else:
output = dCldCLd
return output
# CST
def camb_class_generate_data(cosmo,
rootName = 'testing',
cmbNoise = None,
noiseLevel = 1.,
beamSizeArcmin = 1.,
deflectionNoise = None,
externalUnlensedCMBSpectra = None,
externalLensedCMBSpectra = None,
externalLensingSpectra = None,
classExecDir = os.path.dirname(os.path.abspath(__file__)) + '/CLASS_delens/',
classDataDir = os.path.dirname(os.path.abspath(__file__)) + '/CLASS_delens/',
calculateDerivatives = False,
includeUnlensedSpectraDerivatives = False,
outputAllReconstructions = False,
reconstructionMask = None,
lmax = 5000,
extraParams = dict(),
accuracy = 2,
doLensedWithCAMB = False):
cambPowerSpectra = cambWrapTools.getPyCambPowerSpectra(cosmo = cosmo, \
accuracy = accuracy, \
lmaxToWrite = lmax+3000)
if calculateDerivatives == False:
powersFid, deflectionNoises = class_generate_data(cosmo = cosmo,
rootName = rootName,
cmbNoise = cmbNoise,
noiseLevel = noiseLevel,
beamSizeArcmin = beamSizeArcmin,
deflectionNoise = deflectionNoise,
externalUnlensedCMBSpectra = cambPowerSpectra['unlensed'],
externalLensedCMBSpectra = externalLensedCMBSpectra,
externalLensingSpectra = cambPowerSpectra['lensing'],
classExecDir = classExecDir,
classDataDir = classDataDir,
calculateDerivatives = calculateDerivatives,
includeUnlensedSpectraDerivatives = includeUnlensedSpectraDerivatives,
outputAllReconstructions = outputAllReconstructions,
reconstructionMask = reconstructionMask,
lmax = lmax,
extraParams = extraParams)
powersFid['unlensed'] = cambPowerSpectra['unlensed']
## If you want to use the lensed spectra from CAMB
if doLensedWithCAMB == True:
powersFid['lensed'] = cambPowerSpectra['lensed']
powersFid['lensing'] = cambPowerSpectra['lensing']
return powersFid, deflectionNoises
else:
return class_generate_data(cosmo = cosmo,
rootName = rootName,
cmbNoise = cmbNoise,
noiseLevel = noiseLevel,
beamSizeArcmin = beamSizeArcmin,
deflectionNoise = deflectionNoise,
externalUnlensedCMBSpectra = cambPowerSpectra['unlensed'],
externalLensedCMBSpectra = externalLensedCMBSpectra,
externalLensingSpectra = cambPowerSpectra['lensing'],
classExecDir = classExecDir,
classDataDir = classDataDir,
calculateDerivatives = calculateDerivatives,
includeUnlensedSpectraDerivatives = includeUnlensedSpectraDerivatives,
outputAllReconstructions = outputAllReconstructions,
reconstructionMask = reconstructionMask,
lmax = lmax,
extraParams = extraParams)
def generate_data(cosmo,
rootName = 'testing',
cmbNoise = None,
noiseLevel = 1.,
beamSizeArcmin = 1.,
deflectionNoise = None,
externalUnlensedCMBSpectra = None,
externalLensedCMBSpectra = None,
externalLensingSpectra = None,
classExecDir = os.path.dirname(os.path.abspath(__file__)) + '/CLASS_delens/',
classDataDir = os.path.dirname(os.path.abspath(__file__)) + '/CLASS_delens/',
calculateDerivatives = False,
includeUnlensedSpectraDerivatives = False,
outputAllReconstructions = False,
reconstructionMask = None,
lmax = 5000,
extraParams = dict(),
accuracy = 2,
useClass = True,
doLensedWithCAMB = False):
if useClass == True:
return class_generate_data(cosmo,
rootName = rootName,
cmbNoise = cmbNoise,
noiseLevel = noiseLevel,
beamSizeArcmin = beamSizeArcmin,
deflectionNoise = deflectionNoise,
externalUnlensedCMBSpectra = externalUnlensedCMBSpectra,
externalLensedCMBSpectra = externalLensedCMBSpectra,
externalLensingSpectra = externalLensingSpectra,
classExecDir = classExecDir,
classDataDir = classDataDir,
calculateDerivatives = calculateDerivatives,
includeUnlensedSpectraDerivatives = includeUnlensedSpectraDerivatives,
outputAllReconstructions = outputAllReconstructions,
reconstructionMask = reconstructionMask,
lmax = lmax,
extraParams = extraParams
)
elif useClass == False:
return camb_class_generate_data(cosmo,
rootName = rootName,
cmbNoise = cmbNoise,
noiseLevel = noiseLevel,
beamSizeArcmin = beamSizeArcmin,
deflectionNoise = deflectionNoise,
externalUnlensedCMBSpectra = externalUnlensedCMBSpectra,
externalLensedCMBSpectra = externalLensedCMBSpectra,
externalLensingSpectra = externalLensingSpectra,
classExecDir = classExecDir,
classDataDir = classDataDir,
calculateDerivatives = calculateDerivatives,
includeUnlensedSpectraDerivatives = includeUnlensedSpectraDerivatives,
outputAllReconstructions = outputAllReconstructions,
reconstructionMask = reconstructionMask,
lmax = lmax,
extraParams = extraParams,
accuracy = accuracy,
doLensedWithCAMB = doLensedWithCAMB
)
def loadLensingDerivatives(rootName = 'testing',
classDataDir = os.path.dirname(os.path.abspath(__file__)) + '/../../CLASS_delens/',
dervtype = 'lensed'):
## Loads dCldCLd from files as computed by class_generate_data and returns dictionary with zero padding as used by Fisher code ##
dCldCLd = dict()
dCldCLd['cl_TT'] = np.pad(np.loadtxt(classDataDir + "output/" + rootName + "_dClTTdCldd_"+dervtype+".dat"), ((2,0),), 'constant')
dCldCLd['cl_EE'] = np.pad(np.loadtxt(classDataDir + "output/" + rootName + "_dClEEdCldd_"+dervtype+".dat"), ((2,0),), 'constant')
dCldCLd['cl_TE'] = np.pad(np.loadtxt(classDataDir + "output/" + rootName + "_dClTEdCldd_"+dervtype+".dat"), ((2,0),), 'constant')
dCldCLd['cl_BB'] = np.pad(np.loadtxt(classDataDir + "output/" + rootName + "_dClBBdCldd_"+dervtype+".dat"), ((2,0),), 'constant')
return dCldCLd
def loadUnlensedSpectraDerivatives(rootName = 'testing',
classDataDir = os.path.dirname(os.path.abspath(__file__)) + '/../../CLASS_delens/',
dervtype = 'lensed'):
## Loads dCldCLu from files as computed by class_generate_data and returns dictionary with zero padding as used by Fisher code ##
dCldCLu = dict()
dCldCLu['cl_TT_cl_TT'] = np.pad(np.loadtxt(classDataDir + "output/" + rootName + "_dClTTdClTT_"+dervtype+".dat"), ((2,0),), 'constant')
dCldCLu['cl_TE_cl_TE'] = np.pad(np.loadtxt(classDataDir + "output/" + rootName + "_dClTEdClTE_"+dervtype+".dat"), ((2,0),), 'constant')
dCldCLu['cl_EE_cl_EE'] = np.pad(np.loadtxt(classDataDir + "output/" + rootName + "_dClEEdClEE_"+dervtype+".dat"), ((2,0),), 'constant')
dCldCLu['cl_EE_cl_BB'] = np.pad(np.loadtxt(classDataDir + "output/" + rootName + "_dClEEdClBB_"+dervtype+".dat"), ((2,0),), 'constant')
dCldCLu['cl_BB_cl_EE'] = np.pad(np.loadtxt(classDataDir + "output/" + rootName + "_dClBBdClEE_"+dervtype+".dat"), ((2,0),), 'constant')
dCldCLu['cl_BB_cl_BB'] = np.pad(np.loadtxt(classDataDir + "output/" + rootName + "_dClBBdClBB_"+dervtype+".dat"), ((2,0),), 'constant')
return dCldCLu
###########################
## Copied from biasespol ##
###########################
def noiseSpectra(l, noiseLevelT, useSqrt2 = True, beamArcmin = 1.4, beamFile = None, noiseLevelP = None):
#make a full set of noise spectra.
if beamFile == None:
beam_sigma_radians = (beamArcmin * np.pi / (180. * 60.)) / np.sqrt(8. * np.log(2) )
beamPower = np.exp(l * (l+1) * beam_sigma_radians**2)
else:
beamVals = np.loadtxt(beamFile)
beamValsOnL = (scipy.interpolate.interp1d(beamVals[:,0], beamVals[:,1], bounds_error = False))(l)
beamPower = 1/(beamValsOnL**2)
noise_ster = (np.pi / (180. * 60))**2 * noiseLevelT**2
nl = len(l)
cl_TT = np.empty(nl)
cl_TT.fill(noise_ster)
cl_TT *= beamPower
cl_EE = np.empty(nl)
if useSqrt2:
cl_EE.fill(noise_ster * 2.)
else:
noise_sterP = (np.pi / (180. * 60))**2 * noiseLevelP**2
cl_EE.fill(noise_sterP)
cl_EE *= beamPower
cl_BB = np.empty(nl)
if useSqrt2:
cl_BB.fill(noise_ster * 2.)
else:
noise_sterP = (np.pi / (180. * 60))**2 * noiseLevelP**2
cl_BB.fill(noise_sterP)
cl_BB *= beamPower
cl_TE = np.empty(nl)
cl_TE.fill(0.)
output = {'l' : l,\
'cl_TT' : cl_TT,\
'cl_EE' : cl_EE,\