-
Notifications
You must be signed in to change notification settings - Fork 2
/
full_experiment.py
executable file
·328 lines (289 loc) · 12.4 KB
/
full_experiment.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
#!/usr/bin/env python
"""
Calculate Fisher matrix and P(k) constraints for all redshift bins for a given
experiment.
"""
import numpy as np
import pylab as P
import radiofisher as rf
from radiofisher import experiments
from radiofisher.units import *
from mpi4py import MPI
import sys
comm = MPI.COMM_WORLD
myid = comm.Get_rank()
size = comm.Get_size()
################################################################################
# Set-up experiment parameters
################################################################################
# Load cosmology and experimental settings
e = experiments
cosmo = experiments.cosmo
# Label experiments with different settings
#EXPT_LABEL = "_2yr_3pbwedge"
EXPT_LABEL = "_1bin_4000hr" #"_2yr"
#EXPT_LABEL = "_2yr_horizwedge"
#cosmo['A_xi'] = 0.01
#cosmo['logkmg'] = np.log10(0.005)
# A_xi: 0.01 0.1
# logkmg: 0.05, 0.01, 0.005, 0.001
expt_list = [
( 'exptS', e.exptS ), # 0
( 'aexptM', e.exptM ), # 1
( 'exptL', e.exptL ), # 2
( 'iexptL', e.exptL ), # 3
( 'cexptL', e.exptL ), # 4
( 'GBT', e.GBT ), # 5
( 'Parkes', e.Parkes ), # 6
( 'GMRT', e.GMRT ), # 7
( 'WSRT', e.WSRT ), # 8
( 'APERTIF', e.APERTIF ), # 9
( 'VLBA', e.VLBA ), # 10
( 'JVLA', e.JVLA ), # 11
( 'iJVLA', e.JVLA ), # 12
( 'BINGO', e.BINGO ), # 13
( 'iBAOBAB32', e.BAOBAB32 ), # 14
( 'iBAOBAB128', e.BAOBAB128 ), # 15
( 'yCHIME', e.CHIME ), # 16
( 'iAERA3', e.AERA3 ), # 17
( 'iMFAA', e.MFAA ), # 18
( 'yTIANLAIpath', e.TIANLAIpath ), # 19
( 'yTIANLAI', e.TIANLAI ), # 20
( 'yTIANLAIband2', e.TIANLAIband2 ), # 21
( 'FAST', e.FAST ), # 22
( 'KAT7', e.KAT7 ), # 23
( 'iKAT7', e.KAT7 ), # 24
( 'cKAT7', e.KAT7 ), # 25
( 'MeerKATb1', e.MeerKATb1 ), # 26
( 'iMeerKATb1', e.MeerKATb1 ), # 27
( 'cMeerKATb1', e.MeerKATb1 ), # 28
( 'MeerKATb2', e.MeerKATb2 ), # 29
( 'iMeerKATb2', e.MeerKATb2 ), # 30
( 'cMeerKATb2', e.MeerKATb2 ), # 31
( 'ASKAP', e.ASKAP ), # 32
( 'SKA1MIDbase1', e.SKA1MIDbase1 ), # 33
( 'iSKA1MIDbase1', e.SKA1MIDbase1 ), # 34
( 'cSKA1MIDbase1', e.SKA1MIDbase1 ), # 35
( 'SKA1MIDbase2', e.SKA1MIDbase2 ), # 36
( 'iSKA1MIDbase2', e.SKA1MIDbase2 ), # 37
( 'cSKA1MIDbase2', e.SKA1MIDbase2 ), # 38
( 'SKA1MIDfull1', e.SKA1MIDfull1 ), # 39
( 'iSKA1MIDfull1', e.SKA1MIDfull1 ), # 40
( 'cSKA1MIDfull1', e.SKA1MIDfull1 ), # 41
( 'SKA1MIDfull2', e.SKA1MIDfull2 ), # 42
( 'iSKA1MIDfull2', e.SKA1MIDfull2 ), # 43
( 'cSKA1MIDfull2', e.SKA1MIDfull2 ), # 44
( 'fSKA1SURbase1', e.SKA1SURbase1 ), # 45
( 'fSKA1SURbase2', e.SKA1SURbase2 ), # 46
( 'fSKA1SURfull1', e.SKA1SURfull1 ), # 47
( 'fSKA1SURfull2', e.SKA1SURfull2 ), # 48
( 'exptCV', e.exptCV ), # 49
( 'GBTHIM', e.GBTHIM ), # 50
( 'SKA0MID', e.SKA0MID ), # 51
( 'fSKA0SUR', e.SKA0SUR ), # 52
( 'SKA1MID900', e.SKA1MID900 ), # 53
( 'SKA1MID350', e.SKA1MID350 ), # 54
( 'iSKA1MID900', e.SKA1MID900 ), # 55
( 'iSKA1MID350', e.SKA1MID350 ), # 56
( 'fSKA1SUR650', e.SKA1SUR650 ), # 57
( 'fSKA1SUR350', e.SKA1SUR350 ), # 58
( 'aSKA1LOW', e.SKA1LOW ), # 59
( 'SKAMID_PLUS', e.SKAMID_PLUS ), # 60
( 'SKAMID_PLUS2', e.SKAMID_PLUS2 ), # 61
( 'yCHIME_nocut', e.CHIME_nocut ), # 62
( 'yCHIME_avglow', e.CHIME_avglow ), # 63
( 'MID_B1_Base', e.MID_B1_Base ), # 64
( 'MID_B1_Alt', e.MID_B1_Alt ), # 65
( 'MID_B2_Base', e.MID_B2_Base ), # 66
( 'MID_B2_Upd', e.MID_B2_Upd ), # 67
( 'MID_B2_Alt', e.MID_B2_Alt ), # 68
( 'aLOW_Base', e.LOW_Base ), # 69
( 'aLOW_Upd', e.LOW_Upd ), # 70
( 'aLOW_Alt', e.LOW_Alt ), # 71
( 'MID_B2_Alt2', e.MID_B2_Alt2 ), # 72
( 'iMID_B1_Base', e.MID_B1_Base ), # 73
( 'iMID_B1_Alt', e.MID_B1_Alt ), # 74
( 'iMID_B2_Base', e.MID_B2_Base ), # 75
( 'hMID_B1_Rebase', e.MID_B1_Rebase), # 76
( 'hMID_B1_Octave', e.MID_B1_Octave), # 77
( 'hMID_B2_Rebase', e.MID_B2_Rebase), # 78
( 'hMID_B2_Octave', e.MID_B2_Octave), # 79
( 'iCVTEST1', e.CVlimited_z0to3), # 80
( 'iCVTEST2', e.CVlimited_z2to5), # 81
( 'iHIRAX', e.HIRAX), # 82
( 'iCosVis32x32', e.CosVis32x32), # 83
( 'iCosVis32x32_dmin10m', e.CosVis32x32_dmin10m), # 84
( 'iCosVis256x256', e.CosVis256x256), # 85
( 'MID_B1_RedBook', e.MID_B1_RedBook), # 86
( 'MID_B2_RedBook', e.MID_B2_RedBook), # 87
( 'MID_B1_SKAonly_RedBook', e.MID_B1_SKAonly_RedBook), # 88
( 'MID_B1_MK_RedBook', e.MID_B1_MK_RedBook), # 89
( 'MID_B2_MK_RedBook', e.MID_B2_MK_RedBook), # 90
( 'iHIRAX_highz', e.HIRAX_highz), # 91
( 'MeerKATL', e.MeerKAT_Lband), # 92
( 'MeerKATUHF', e.MeerKAT_UHF), # 93
]
names, expts = zip(*expt_list)
names = list(names); expts = list(expts)
################################################################################
# Take command-line argument for which survey to calculate, or set manually
if len(sys.argv) > 1:
k = int(sys.argv[1])
try:
Sarea = float(sys.argv[2])
except:
Sarea = None
pass
else:
raise IndexError("Need to specify ID for experiment.")
names[k] += EXPT_LABEL
if myid == 0:
print("="*50)
print("Survey:", names[k])
print("="*50)
# Tweak settings depending on chosen experiment
cv_limited = False
expts[k]['mode'] = "dish"
if names[k][0] == "i": expts[k]['mode'] = "idish"
if names[k][0] == "c": expts[k]['mode'] = "combined"
if names[k][0] == "y": expts[k]['mode'] = "icyl"
if names[k][0] == "f": expts[k]['mode'] = "paf"
if names[k][0] == "t": expts[k]['mode'] = "ipaf"
if names[k][0] == "a": expts[k]['mode'] = "iaa"
if names[k][0] == "h": expts[k]['mode'] = "hybrid"
expt = expts[k]
if Sarea is None:
survey_name = names[k]
root = "output/" + survey_name
else:
expt['Sarea'] = Sarea * (D2RAD)**2.
survey_name = names[k] + "_" + str(int(Sarea))
root = "output/" + survey_name
# Define redshift bins
expt_zbins = rf.overlapping_expts(expt)
zs, zc = rf.zbins_equal_spaced(expt_zbins, dz=0.1)
#zs, zc = rf.zbins_equal_spaced(expt_zbins, dz=0.25) # 0.2
#zs, zc = rf.zbins_const_dnu(expt_zbins, cosmo, dnu=20.)
#zs, zc = rf.zbins_const_dr(expt_zbins, cosmo, bins=14)
#zs, zc = rf.zbins_const_dnu(expt_zbins, cosmo, dnu=60.)
#zs, zc = rf.zbins_const_dnu(expt_zbins, cosmo, dnu=30.)
#zs = rf.zbins_fixed(expt_zbins, dz=0.1)
# FIXME
#print("FIXME! zbins set to manual")
#zs = np.array([0.25, 0.48])
#zc = 0.5*(zs[1:] + zs[:-1])
# Define kbins (used for output)
kbins = np.logspace(np.log10(0.001), np.log10(1.), 61)
#cosmo['f0_kbins'] = np.array([1e-4, 1e-2, 1e-1, 1e1])
expt['epsilon_fg'] = 1e-14
#expt['ttot'] *= 17520. / 1e4 #8765. / 1e4 # 2 calendar years on-sky
expt['ttot'] *= 4000. / 1e4 #8765. / 1e4
expt['k_nl0'] = 0.2 # = 0.3 h/Mpc
expt['wedge'] = False #'horizon' #'3pb' #False
# Neutrino mass
cosmo['mnu'] = 0.
# Precompute cosmological functions, P(k), massive neutrinos, and T(k) for f_NL
cosmo_fns = rf.background_evolution_splines(cosmo)
if cosmo['mnu'] != 0.:
# Massive neutrinos
mnu_str = "mnu%03d" % (cosmo['mnu']*100.)
fname_pk = "cache_pk_%s.dat" % mnu_str
fname_nu = "cache_%s" % mnu_str
survey_name += mnu_str; root += mnu_str
cosmo = rf.load_power_spectrum(cosmo, fname_pk, comm=comm)
mnu_fn = rf.deriv_neutrinos(cosmo, fname_nu, mnu=cosmo['mnu'], comm=comm)
else:
# Normal operation (no massive neutrinos or non-Gaussianity)
cosmo = rf.load_power_spectrum(cosmo, "cache_pk.dat", comm=comm)
mnu_fn = None
# Non-Gaussianity
#transfer_fn = rf.deriv_transfer(cosmo, "cache_transfer.dat", comm=comm)
transfer_fn = None
# Effective no. neutrinos, N_eff
#Neff_fn = rf.deriv_neutrinos(cosmo, "cache_Neff", Neff=cosmo['N_eff'], comm=comm)
Neff_fn = None
# Optional additional parameters
switches = []
#switches = ['mg', ] #'sdbias']
# Scale-dependent growth
#cosmo['fs8_kbins'] = [0., 1e-2, 1e-1, 1e0, 1e2]
H, r, D, f = cosmo_fns
################################################################################
# Store cosmological functions
################################################################################
# Store values of cosmological functions
if myid == 0:
# Calculate cosmo fns. at redshift bin centroids and save
_H = H(zc)
_dA = r(zc) / (1. + np.array(zc))
_D = D(zc)
_f = f(zc)
np.savetxt(root+"-cosmofns-zc.dat", np.column_stack((zc, _H, _dA, _D, _f)))
# Calculate cosmo fns. as smooth fns. of z and save
zz = np.linspace(0., 1.05*np.max(zc), 1000)
_H = H(zz)
_dA = r(zz) / (1. + zz)
_D = D(zz)
_f = f(zz)
np.savetxt(root+"-cosmofns-smooth.dat", np.column_stack((zz, _H, _dA, _D, _f)) )
# Precompute derivs for all processes
eos_derivs = rf.eos_fisher_matrix_derivs(cosmo, cosmo_fns, fsigma8=True)
"""
# Output all cosmo/instrumental parameters
print "*"*50
for key in cosmo.keys():
print "%20s: %s" % (key, cosmo[key])
print "*"*50
for key in expt.keys():
print "%20s: %s" % (key, expt[key])
print "*"*50
"""
################################################################################
# Loop through redshift bins, assigning them to each process
################################################################################
for i in range(zs.size-1):
if i % size != myid:
continue
print(">>> %2d working on redshift bin %d / %d -- z = %3.3f" \
% (myid, i, zs.size, zc[i]))
# Calculate effective experimental params. in the case of overlapping expts.
Sarea_rad = Sarea*(D2RAD)**2. if Sarea is not None else None
expt_eff = rf.overlapping_expts(expt, zs[i], zs[i+1], Sarea=Sarea_rad)
# Calculate basic Fisher matrix
# (A, bHI, Tb, sigma_NL, sigma8, n_s, f, aperp, apar, [Mnu], [fNL], [pk]*Nkbins)
F_pk, kc, binning_info, paramnames = rf.fisher(
zs[i], zs[i+1], cosmo, expt_eff,
cosmo_fns=cosmo_fns,
transfer_fn=transfer_fn,
massive_nu_fn=mnu_fn,
Neff_fn=Neff_fn,
return_pk=True,
cv_limited=cv_limited,
switches=switches,
kbins=kbins )
# Expand Fisher matrix with EOS parameters
##F_eos = rf.fisher_with_excluded_params(F, [10, 11, 12]) # Exclude P(k)
F_eos, paramnames = rf.expand_fisher_matrix(zc[i], eos_derivs, F_pk,
names=paramnames, exclude=[],
fsigma8=True)
# Expand Fisher matrix for H(z), dA(z)
# Replace aperp with dA(zi), using product rule. aperp(z) = dA(fid,z) / dA(z)
# (And convert dA to Gpc, to help with the numerics)
paramnames[paramnames.index('aperp')] = 'DA'
da = r(zc[i]) / (1. + zc[i]) / 1000. # Gpc
F_eos[7,:] *= -1. / da
F_eos[:,7] *= -1. / da
# Replace apar with H(zi)/100, using product rule. apar(z) = H(z) / H(fid,z)
paramnames[paramnames.index('apar')] = 'H'
F_eos[8,:] *= 1. / H(zc[i]) * 100.
F_eos[:,8] *= 1. / H(zc[i]) * 100.
# Save Fisher matrix and k bins
np.savetxt(root+"-fisher-full-%d.dat" % i, F_eos, header=" ".join(paramnames))
if myid == 0: np.savetxt(root+"-fisher-kc.dat", kc)
# Save P(k) rebinning info
np.savetxt(root+"-rebin-Fbase-%d.dat" % i, np.array(binning_info['F_base']) )
np.savetxt(root+"-rebin-cumul-%d.dat" % i, np.array(binning_info['cumul']) )
np.savetxt(root+"-rebin-kgrid-%d.dat" % i, np.array(binning_info['kgrid']) )
np.savetxt(root+"-rebin-Vfac-%d.dat" % i, np.array([binning_info['Vfac'],]) )
comm.barrier()
if myid == 0: print("Finished.")