-
Notifications
You must be signed in to change notification settings - Fork 0
/
params_prosp_fsps.py
384 lines (313 loc) · 16.7 KB
/
params_prosp_fsps.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
import sys, os
import numpy as np
from astropy.cosmology import WMAP9 as cosmo
from prospect.models import priors, transforms
def params_fsps_phisfh(obs=None, free_gas_logu=False, **extra):
'''mass + metallicity + sfh priors from p-beta
'''
from prospect.models import priors_beta as PZ
if free_gas_logu:
fit_order = ['nzsfh',
'dust2', 'dust_index', 'dust1_fraction',
'log_fagn', 'log_agn_tau', 'gas_logz',
'duste_qpah', 'duste_umin', 'log_duste_gamma',
'gas_logu']
else:
fit_order = ['nzsfh',
'dust2', 'dust_index', 'dust1_fraction',
'log_fagn', 'log_agn_tau', 'gas_logz',
'duste_qpah', 'duste_umin', 'log_duste_gamma']
# -------------
# MODEL_PARAMS
model_params = {}
# --- BASIC PARAMETERS ---
model_params['nzsfh'] = {'N': 9,
'isfree': True,
'init': np.array([0.5,8,0.0, 0,0,0,0,0,0]),
'prior': PZ.PhiSFH(zred_mini=1e-3, zred_maxi=20.0,
mass_mini=6.0, mass_maxi=12.5,
z_mini=-1.98, z_maxi=0.19,
logsfr_ratio_mini=-5.0, logsfr_ratio_maxi=5.0,
logsfr_ratio_tscale=0.3, nbins_sfh=7,
const_phi=True)}
model_params['zred'] = {'N': 1, 'isfree': False,
'depends_on': transforms.nzsfh_to_zred,
'init': 0.5,
'prior': priors.Uniform(mini=1e-3, maxi=20.0)}
model_params['logmass'] = {'N': 1, 'isfree': False,
'depends_on': transforms.nzsfh_to_logmass,
'init': 8.0,
'units': 'Msun',
'prior': priors.Uniform(mini=6.0, maxi=12.5)}
model_params['logzsol'] = {'N': 1, 'isfree': False,
'init': -0.5,
'depends_on': transforms.nzsfh_to_logzsol,
'units': r'$\log (Z/Z_\odot)$',
'prior': priors.Uniform(mini=-1.98, maxi=0.19)}
model_params['imf_type'] = {'N': 1, 'isfree': False,
'init': 1, #1 = chabrier
'units': "FSPS index",
'prior': None}
model_params['add_igm_absorption'] = {'N': 1, 'isfree': False, 'init': True}
model_params["add_agb_dust_model"] = {'N': 1, 'isfree': False, 'init': True}
model_params["pmetals"] = {'N': 1, 'isfree': False, 'init': -99}
# --- SFH ---
nbins_sfh = 7
model_params["sfh"] = {'N': 1, 'isfree': False, 'init': 3}
model_params['logsfr_ratios'] = {'N': nbins_sfh-1, 'isfree': False,
'init': 0.0,
'depends_on': transforms.nzsfh_to_logsfr_ratios,
'prior': priors.StudentT(mean=np.full(nbins_sfh-1,0.0),
scale=np.full(nbins_sfh-1,0.3),
df=np.full(nbins_sfh-1,2))}
model_params["mass"] = {'N': 7,
'isfree': False,
'init': 1e6,
'units': r'M$_\odot$',
'depends_on': logsfr_ratios_to_masses}
model_params['agebins'] = {'N': 7, 'isfree': False,
'init': zred_to_agebins(np.atleast_1d(0.5)),
'prior': None,
'depends_on': zred_to_agebins}
# --- Dust Absorption ---
model_params['dust_type'] = {"N": 1, "isfree": False, "init": 4, "units": "FSPS index"}
model_params['dust1_fraction'] = {'N': 1, 'isfree': True,
'init': 1.0,
'prior': priors.ClippedNormal(mini=0.0, maxi=2.0, mean=1.0, sigma=0.3),
}
model_params['dust2'] = {'N': 1, 'isfree': True,
'init': 0.0,
'units': '',
'prior': priors.ClippedNormal(mini=0.0, maxi=4.0, mean=0.3, sigma=1.0),
}
model_params['dust1'] = {"N": 1,
"isfree": False,
'depends_on': to_dust1,
"init": 0.0, "units": "optical depth towards young stars",
"prior": None}
model_params['dust_index'] = {'N': 1, 'isfree': True,
'init': 0.7,
'units': '',
'prior': priors.Uniform(mini=-1.0, maxi=0.4)}
# --- Nebular Emission ---
model_params['add_neb_emission'] = {'N': 1, 'isfree': False, 'init': True}
model_params['add_neb_continuum'] = {'N': 1, 'isfree': False, 'init': True}
model_params['gas_logz'] = {'N': 1, 'isfree': True,
'init': -0.5,
'units': r'log Z/Z_\odot',
'prior': priors.Uniform(mini=-2.0, maxi=0.5)}
if free_gas_logu:
model_params['gas_logu'] = {"N": 1, 'isfree': True,
'init': -1.0, 'units': r"Q_H/N_H",
'prior': priors.Uniform(mini=-4, maxi=-1)}
else:
model_params['gas_logu'] = {"N": 1, 'isfree': False,
'init': -1.0, 'units': r"Q_H/N_H",
'prior': priors.Uniform(mini=-4, maxi=-1)}
# --- AGN dust ---
model_params['add_agn_dust'] = {"N": 1, "isfree": False, "init": True}
model_params['log_fagn'] = {'N': 1, 'isfree': True,
'init': -7.0e-5,
'prior': priors.Uniform(mini=-5.0, maxi=np.log10(3.0))}
model_params['fagn'] = {"N": 1, "isfree": False, "init": 0, "depends_on": to_fagn}
model_params['log_agn_tau'] = {'N': 1, 'isfree': True,
'init': np.log10(20.0),
'prior': priors.Uniform(mini=np.log10(5.0), maxi=np.log10(150.0))}
model_params['agn_tau'] = {"N": 1, "isfree": False, "init": 0, "depends_on": to_agn_tau}
# --- Dust Emission ---
model_params['duste_qpah'] = {'N':1, 'isfree':True,
'init': 2.0,
'prior': priors.ClippedNormal(mini=0.0, maxi=7.0, mean=2.0, sigma=2.0)}
model_params['duste_umin'] = {'N':1, 'isfree':True,
'init': 1.0,
'prior': priors.ClippedNormal(mini=0.1, maxi=25.0, mean=1.0, sigma=10.0)}
model_params['log_duste_gamma'] = {'N':1, 'isfree':True,
'init': -2.0,
'prior': priors.ClippedNormal(mini=-4.0, maxi=0.0, mean=-2.0, sigma=1.0)}
model_params['duste_gamma'] = {"N": 1, "isfree": False, "init": 0, "depends_on": to_duste_gamma}
#---- Units ----
model_params['peraa'] = {'N': 1, 'isfree': False, 'init': False}
model_params['mass_units'] = {'N': 1, 'isfree': False, 'init': 'mformed'}
model_params['sigma_smooth'] = {'N': 1, 'isfree': False, 'init': 0.0}
extra = [k for k in model_params.keys() if k not in fit_order]
fit_order = fit_order + list(extra)
tparams = {}
for i in fit_order:
tparams[i] = model_params[i]
for i in list(model_params.keys()):
if i not in fit_order:
tparams[i] = model_params[i]
model_params = tparams
return (model_params, fit_order)
def params_fsps_alpha(obs=None, free_gas_logu=False, **extra):
'''p-alpha priors
'''
if free_gas_logu:
fit_order = ['zred', 'logmass', 'logzsol', 'logsfr_ratios',
'dust2', 'dust_index', 'dust1_fraction',
'log_fagn', 'log_agn_tau', 'gas_logz',
'duste_qpah', 'duste_umin', 'log_duste_gamma', 'gas_logu']
else:
fit_order = ['zred', 'logmass', 'logzsol', 'logsfr_ratios',
'dust2', 'dust_index', 'dust1_fraction',
'log_fagn', 'log_agn_tau', 'gas_logz',
'duste_qpah', 'duste_umin', 'log_duste_gamma']
# -------------
# MODEL_PARAMS
model_params = {}
# --- BASIC PARAMETERS ---
model_params['zred'] = {'N': 1, 'isfree': True,
'init': 0.5,
'prior': priors.Uniform(mini=1e-3, maxi=20.0)}
model_params['logmass'] = {'N': 1, 'isfree': True,
'init': 8.0,
'units': 'Msun',
'prior': priors.Uniform(mini=6.0, maxi=12.5)}
model_params['logzsol'] = {'N': 1, 'isfree': True,
'init': -0.5,
'units': r'$\log (Z/Z_\odot)$',
'prior': priors.Uniform(mini=-1.98, maxi=0.19)}
model_params['imf_type'] = {'N': 1,
'isfree': False,
'init': 1, #1 = chabrier
'units': None,
'prior': None}
model_params['add_igm_absorption'] = {'N': 1, 'isfree': False, 'init': True}
model_params["add_agb_dust_model"] = {'N': 1, 'isfree': False, 'init': True}
model_params["pmetals"] = {'N': 1, 'isfree': False, 'init': -99}
# --- SFH ---
nbins_sfh = 7
model_params["sfh"] = {'N': 1, 'isfree': False, 'init': 3}
model_params['logsfr_ratios'] = {'N': nbins_sfh-1, 'isfree': True,
'init': 0.0,
'prior': priors.StudentT(mean=np.full(nbins_sfh-1,0.0),
scale=np.full(nbins_sfh-1,0.3),
df=np.full(nbins_sfh-1,2))}
model_params["mass"] = {'N': 7,
'isfree': False,
'init': 1e6,
'units': r'M$_\odot$',
'depends_on': logsfr_ratios_to_masses}
model_params['agebins'] = {'N': 7, 'isfree': False,
'init': zred_to_agebins(np.atleast_1d(0.5)),
'prior': None,
'depends_on': zred_to_agebins}
# --- Dust Absorption ---
model_params['dust_type'] = {"N": 1, "isfree": False, "init": 4, "units": "FSPS index"}
model_params['dust1_fraction'] = {'N': 1, 'isfree': True,
'init': 1.0,
'prior': priors.ClippedNormal(mini=0.0, maxi=2.0, mean=1.0, sigma=0.3)}
model_params['dust2'] = {'N': 1, 'isfree': True,
'init': 0.3,
'units': '',
'prior': priors.ClippedNormal(mini=0.0, maxi=4.0, mean=0.3, sigma=1.0)}
model_params['dust1'] = {"N": 1,
"isfree": False,
'depends_on': to_dust1,
"init": 0.0, "units": "optical depth towards young stars",
"prior": None}
model_params['dust_index'] = {'N': 1, 'isfree': True,
'init': -0.3,
'units': '',
'prior': priors.Uniform(mini=-1.0, maxi=0.4)}
# --- Nebular Emission ---
model_params['add_neb_emission'] = {'N': 1, 'isfree': False, 'init': True}
model_params['add_neb_continuum'] = {'N': 1, 'isfree': False, 'init': True}
model_params['gas_logz'] = {'N': 1, 'isfree': True,
'init': -0.5,
'units': r'log Z/Z_\odot',
'prior': priors.Uniform(mini=-2.0, maxi=0.5)}
model_params['gas_logu'] = {"N": 1, 'isfree': False,
'init': -1.0, 'units': r"Q_H/N_H",
'prior': priors.Uniform(mini=-4.0, maxi=-1.0)}
if free_gas_logu:
model_params['gas_logu'] = {"N": 1, 'isfree': True,
'init': -1.0, 'units': r"Q_H/N_H",
'prior': priors.Uniform(mini=-4.0, maxi=-1.0)}
# --- AGN dust ---
model_params['add_agn_dust'] = {"N": 1, "isfree": False, "init": True}
model_params['log_fagn'] = {'N': 1, 'isfree': True,
'init': -7.0e-5,
'prior': priors.Uniform(mini=-5.0, maxi=np.log10(3.0))}
model_params['fagn'] = {"N": 1, "isfree": False, "init": 0, "depends_on": to_fagn}
model_params['log_agn_tau'] = {'N': 1, 'isfree': True,
'init': np.log10(20.0),
'prior': priors.Uniform(mini=np.log10(5.0), maxi=np.log10(150.0))}
model_params['agn_tau'] = {"N": 1, "isfree": False, "init": 0, "depends_on": to_agn_tau}
# --- Dust Emission ---
model_params['duste_qpah'] = {'N':1, 'isfree':True,
'init': 2.0,
'prior': priors.ClippedNormal(mini=0.0, maxi=7.0, mean=2.0, sigma=2.0)}
model_params['duste_umin'] = {'N':1, 'isfree':True,
'init': 1.0,
'prior': priors.ClippedNormal(mini=0.1, maxi=25.0, mean=1.0, sigma=10.0)}
model_params['log_duste_gamma'] = {'N':1, 'isfree':True,
'init': -2.0,
'prior': priors.ClippedNormal(mini=-4.0, maxi=0.0, mean=-2.0, sigma=1.0)}
model_params['duste_gamma'] = {"N": 1, "isfree": False, "init": 0, "depends_on": to_duste_gamma}
#---- Units ----
model_params['peraa'] = {'N': 1, 'isfree': False, 'init': False}
model_params['mass_units'] = {'N': 1, 'isfree': False, 'init': 'mformed'}
model_params['sigma_smooth'] = {'N': 1, 'isfree': False, 'init': 0.0}
extra = [k for k in model_params.keys() if k not in fit_order]
fit_order = fit_order + list(extra)
tparams = {}
for i in fit_order:
tparams[i] = model_params[i]
for i in list(model_params.keys()):
if i not in fit_order:
tparams[i] = model_params[i]
model_params = tparams
return (model_params, fit_order)
def zred_to_agebins(zred=None,**extras):
"""parrot v3 and after
Set the nonparameteric SFH age bins depending on the age of the universe
at ``zred``. The first bin is not altered and the last bin is always 10% of
the upper edge of the oldest bin, but the intervening bins are evenly
spaced in log(age).
Parameters
----------
zred : float
Cosmological redshift. This sets the age of the universe.
agebins : ndarray of shape ``(nbin, 2)``
The SFH bin edges in log10(years).
Returns
-------
agebins : ndarray of shape ``(nbin, 2)``
The new SFH bin edges.
"""
amin = 7.1295
nbins_sfh = 7
tuniv = cosmo.age(zred)[0].value*1e9 # because input zred is atleast_1d
tbinmax = (tuniv*0.9)
if (zred <= 3.):
agelims = [0.0,7.47712] + np.linspace(8.0,np.log10(tbinmax),nbins_sfh-2).tolist() + [np.log10(tuniv)]
else:
agelims = np.linspace(amin,np.log10(tbinmax),nbins_sfh).tolist() + [np.log10(tuniv)]
agelims[0] = 0
agebins = np.array([agelims[:-1], agelims[1:]])
return agebins.T
def logsfr_ratios_to_masses(logmass=None, logsfr_ratios=None, agebins=None, **extras):
"""This converts from an array of log_10(SFR_j / SFR_{j+1}) and a value of
log10(\Sum_i M_i) to values of M_i. j=0 is the most recent bin in lookback
time.
"""
nbins = agebins.shape[0]
sratios = 10**np.clip(logsfr_ratios, -10, 10) # numerical issues...
dt = (10**agebins[:, 1] - 10**agebins[:, 0])
coeffs = np.array([ (1. / np.prod(sratios[:i])) * (np.prod(dt[1: i+1]) / np.prod(dt[: i]))
for i in range(nbins)])
m1 = (10**logmass) / coeffs.sum()
return m1 * coeffs
def to_dust1(dust1_fraction=None, dust1=None, dust2=None, **extras):
return dust1_fraction*dust2
def to_fagn(log_fagn=None, **extras):
return 10**log_fagn
def to_agn_tau(log_agn_tau=None, **extras):
return 10**log_agn_tau
def to_duste_gamma(log_duste_gamma=None, **extras):
return 10**log_duste_gamma
from prospect.sources import FastStepBasis
def build_sps_fsps(zcontinuous=2, compute_vega_mags=False, **extras):
sps = FastStepBasis(zcontinuous=zcontinuous, compute_vega_mags=compute_vega_mags)
return sps