Skip to content

Commit 173051a

Browse files
authored
Merge branch 'bd-j:main' into main
2 parents e6924e1 + b3e5ae6 commit 173051a

9 files changed

+626
-33
lines changed

doc/prospector-beta_priors.rst

+50-16
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
Prospector-beta Priors
33
==============
44

5-
This model is intended for fitting galaxy photometry where the redshift is unknown.
6-
The priors encode empirical constraints of redshifts, masses, and star formation histories in the galaxy population.
5+
This model is intended for fitting galaxy photometry where the redshift is
6+
unknown. The priors encode empirical constraints of redshifts, masses, and star
7+
formation histories in the galaxy population.
78

8-
N.B.: Please make sure to update to the Prospector-beta version post commit `09a83f2 <https://github.com/bd-j/prospector/commit/09a83f28cae3bcc0f0397b3a0b8d85aa4f96bf12>`_, merged on May 19, 2023. This is a major update to the SFH(M, z) prior, ensuring the expectation values of SFRs are well-behaved over the full prior space.
9+
N.B.: Please make sure to update to the Prospector-beta version post commit
10+
`09a83f2
11+
<https://github.com/bd-j/prospector/commit/09a83f28cae3bcc0f0397b3a0b8d85aa4f96bf12>`_,
12+
merged on May 19, 2023. This is a major update to the SFH(M, z) prior, ensuring
13+
the expectation values of SFRs are well-behaved over the full prior space.
914

10-
A set of prospector parameters implementing the full set of priors is available as the ``"beta"`` entry
11-
of :py:class:`prospect.models.templates.TemplateLibrary`.
15+
A set of prospector parameters implementing the full set of priors is available
16+
as the ``"beta"`` entry of
17+
:py:class:`prospect.models.templates.TemplateLibrary`.
1218

1319
Additionally we provide different combinations of the priors for flexibility, which includes the following:
1420

@@ -20,43 +26,71 @@ Additionally we provide different combinations of the priors for flexibility, wh
2026
* ``PhiSFHfixZred`` : same as above, but keeping zred fixed to a user-specified value, 'zred', during fitting
2127
* ``NzSFH`` : number density + mass function + mass-met + SFH(M, z); this is the full set of Prospector-beta priors.
2228

23-
We describe each of the priors briefly below. Please cite `wang23 <https://ui.adsabs.harvard.edu/abs/2023ApJ...944L..58W/abstract>`_ and the relevant papers if any of the priors are used.
29+
We describe each of the priors briefly below. Please cite `wang23
30+
<https://ui.adsabs.harvard.edu/abs/2023ApJ...944L..58W/abstract>`_ and the
31+
relevant papers if any of the priors are used.
2432

2533

2634
Stellar Mass Function
27-
-----------
35+
---------------------
2836

2937
Two options are available, the choice of which depends on the given scientific question.
3038
The relevant data files are ``prior_data/pdf_of_z_l20.txt`` & ``prior_data/pdf_of_z_l20t18.txt``.
3139
These mass functions can also be replaced by supplying new data files to ``prior_data/``
3240

3341
1. ``"const_phi = True"``
3442

35-
The mass functions between 0.2 ≤ z ≤ 3.0 are taken from `leja20 <https://ui.adsabs.harvard.edu/abs/2020ApJ...893..111L/abstract>`_. Outside this redshift range, we adopt a nearest-neighbor solution, i.e., the z = 0.2 and z = 3 mass functions.
43+
The mass functions between 0.2 ≤ z ≤ 3.0 are taken from `leja20
44+
<https://ui.adsabs.harvard.edu/abs/2020ApJ...893..111L/abstract>`_. Outside this
45+
redshift range, we adopt a nearest-neighbor solution, i.e., the z = 0.2 and z =
46+
3 mass functions.
3647

3748
2. ``"const_phi = False"``
3849

39-
The mass functions are switched to those from `tacchella18 <https://ui.adsabs.harvard.edu/abs/2018ApJ...868...92T/abstract>`_ between 4 < z < 12, with the 3 < z < 4 transition from `leja20 <https://ui.adsabs.harvard.edu/abs/2020ApJ...893..111L/abstract>`_ managed with a smoothly-varying average in number density space. We use the z = 12 mass function for z > 12.
50+
The mass functions are switched to those from `tacchella18
51+
<https://ui.adsabs.harvard.edu/abs/2018ApJ...868...92T/abstract>`_ between 4 < z
52+
< 12, with the 3 < z < 4 transition from `leja20
53+
<https://ui.adsabs.harvard.edu/abs/2020ApJ...893..111L/abstract>`_ managed with
54+
a smoothly-varying average in number density space. We use the z = 12 mass
55+
function for z > 12.
4056

4157

4258
Galaxy Number Density
4359
-----------
4460

45-
This prior informs the model about the survey volume being probed. It is sensitive to the mass-completeness limit of the data. We provide a default setting derived from a mock JWST catalog, which is contained in ``prior_data/mc_from_mocks.txt``.
46-
In practice one would likely need to obtain the mass-completeness limits from using SED-modeling heuristics based on the flux-completeness limits in a given catalog.
61+
This prior informs the model about the survey volume being probed. It is
62+
sensitive to the mass-completeness limit of the data. We provide a default
63+
setting derived from a mock JWST catalog, which is contained in
64+
``prior_data/mc_from_mocks.txt``.
65+
In practice one would likely need to obtain
66+
the mass-completeness limits from using SED-modeling heuristics based on the
67+
flux-completeness limits in a given catalog.
4768

4869

4970
Dynamic Star-formation History
5071
-----------
5172

52-
The SFH is described non-parametrically as in Prospector-alpha; the number of age bins is set by ``"nbins_sfh"``.
73+
The SFH is described non-parametrically as in Prospector-alpha; the number of
74+
age bins is set by ``"nbins_sfh"``.
5375

54-
In contrast to the null expectation assumed in Prospector-alpha, the expectation value in each age bin is matched to the cosmic star formation rate densities in `behroozi19 <https://ui.adsabs.harvard.edu/abs/2019MNRAS.488.3143B/abstract>`_, while the distribution about the mean remains to be the Student’s-t distribution. The sigma of the Student’s-t distribution is set by ``"logsfr_ratio_tscale"``, and the range is clipped to be within ``"logsfr_ratio_mini"`` and ``"logsfr_ratio_maxi"``.
76+
In contrast to the null expectation assumed in Prospector-alpha, the expectation
77+
value in each age bin is matched to the cosmic star formation rate densities in
78+
`behroozi19 <https://ui.adsabs.harvard.edu/abs/2019MNRAS.488.3143B/abstract>`_,
79+
while the distribution about the mean remains to be the Student's-t
80+
distribution. The sigma of the Student's-t distribution is set by
81+
``"logsfr_ratio_tscale"``, and the range is clipped to be within
82+
``"logsfr_ratio_mini"`` and ``"logsfr_ratio_maxi"``.
5583

56-
A simple mass dependence on SFH is further introduced by shifting the start of the age bins as a function of mass. This SFH prior effectively encodes an expectation that high-mass galaxies form earlier, and low-mass galaxies form later, than naive expectations from the cosmic SFRD.
84+
A simple mass dependence on SFH is further introduced by shifting the start of
85+
the age bins as a function of mass. This SFH prior effectively encodes an
86+
expectation that high-mass galaxies form earlier, and low-mass galaxies form
87+
later, than naive expectations from the cosmic SFRD.
5788

5889

59-
Stellar MassStellar Metallicity
90+
Stellar Mass-Stellar Metallicity
6091
-----------
6192

62-
This is the stellar mass–stellar metallicity relationship measured from the SDSS in `gallazzi05 <https://ui.adsabs.harvard.edu/abs/2005MNRAS.362...41G/abstract>`_, introduced in `leja19 <https://ui.adsabs.harvard.edu/abs/2019ApJ...876....3L/abstract>`_.
93+
This is the stellar mass-stellar metallicity relationship measured from the SDSS
94+
in `gallazzi05
95+
<https://ui.adsabs.harvard.edu/abs/2005MNRAS.362...41G/abstract>`_, introduced
96+
in `leja19 <https://ui.adsabs.harvard.edu/abs/2019ApJ...876....3L/abstract>`_.

doc/sfhs.rst

+16-3
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,17 @@ Continuity SFH
7777
^^^^^^^^^^^^^^
7878
See `leja19 <https://ui.adsabs.harvard.edu/abs/2019ApJ...876....3L/abstract>`_,
7979
`johnson21 <https://ui.adsabs.harvard.edu/abs/2021ApJS..254...22J/abstract>`_
80-
for more details. A set of propsector parameters implementing this treatment
81-
with 3 bins is available as the ``"continuity_sfh"`` entry of
80+
for more details. A basic set of prospector parameters implementing this
81+
treatment with 3 bins is available as the ``"continuity_sfh"`` entry of
8282
:py:class:`prospect.models.templates.TemplateLibrary`.
8383

8484
In this parameterization, the SFR of each bin is derived from sampling a vector
8585
of parameters describing the *ratio* of SFRs in adjacent temporal bins. By
8686
default, a Student-t prior distribution (like a Gaussian but with heavier tails)
8787
is placed on the log of these ratios. This results in a prior SFH that tends
8888
toward constant SFR, and down-weights drmamtic changes in the SFR between
89-
adjacent bins. The overall normalization is provided by the ``logmass``
89+
adjacent bins. The width of the distribution can be ajusted to produce smoother
90+
or burstier SFHs.The overall normalization is provided by the ``logmass``
9091
parameter.
9192

9293
In detail, the SFR in each timetime is computed as
@@ -140,6 +141,18 @@ required to model post-starburst SFHs. A set of prospector parameters
140141
implementing this treatment is available as the ``"continuity_psb_sfh"`` entry
141142
of :py:class:`prospect.models.templates.TemplateLibrary`
142143

144+
145+
'Stochastic' SFH
146+
^^^^^^^^^^^^^^^^
147+
This SFH (hyper-)prior uses the power spectrum of SFH fluctuations -- the
148+
parameters of which can be sampled -- to determine the covariance matrix between
149+
(adjacent and non-adjacent) temporal bins of SFR. See `Wan et al. 24 <https://ui.adsabs.harvard.edu/abs/2024arXiv240414494W/abstract>`_ for
150+
details. This prior is adapted from the Extended Regulator model developed in
151+
`Caplar & Tacchella (2019) <https://ui.adsabs.harvard.edu/abs/2019MNRAS.487.3845C/abstract>`_ and `Tacchella, Forbes & Caplar (2020) <https://ui.adsabs.harvard.edu/abs/2020MNRAS.497..698T/abstract>`_ , in
152+
conjunction with the GP implementation of `Iyer & Speagle et al. (2024) <https://ui.adsabs.harvard.edu/abs/2024ApJ...961...53I/abstract>`_ taken from `this module <https://github.com/kartheikiyer/GP-SFH>`_ .
153+
154+
155+
143156
Dirichlet SFH
144157
^^^^^^^^^^^^^
145158
See `leja17 <https://ui.adsabs.harvard.edu/abs/2017ApJ...837..170L/abstract>`_,
+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
"""hyperparam_transforms.py -- This module contains parameter transformations that are
5+
used in the stochastic SFH prior.
6+
7+
These are taken from the implementation of
8+
https://ui.adsabs.harvard.edu/abs/2024ApJ...961...53I/abstract given in
9+
https://github.com/kartheikiyer/GP-SFH
10+
11+
They can be used as ``"depends_on"`` entries in parameter specifications.
12+
"""
13+
14+
import numpy as np
15+
from astropy.cosmology import FlatLambdaCDM
16+
17+
__all__ = ["get_sfr_covar", "sfr_covar_to_sfr_ratio_covar"]
18+
19+
20+
# --------------------------------------
21+
# --- Functions/transforms for stochastic SFH prior ---
22+
# --------------------------------------
23+
24+
25+
# Creating a base class that simplifies a lot of things.
26+
# The way this is set up, you can pass a kernel as an argument
27+
# to compute the covariance matrix and draw samples from it.
28+
class simple_GP_sfh():
29+
30+
"""
31+
A class that creates and holds information about a specific
32+
kernel, and can generate samples from it.
33+
34+
From https://github.com/kartheikiyer/GP-SFH
35+
36+
Attributes
37+
----------
38+
tarr: fiducial time array used to draw samples
39+
kernel: accepts an input function as an argument,
40+
of the format:
41+
42+
def kernel_function(delta_t, **kwargs):
43+
... function interior ...
44+
return kernel_val[array of len(delta_t)]
45+
46+
Methods
47+
-------
48+
get_covariance_matrix
49+
[although this has double for loops for maximum flexibility
50+
with generic kernel functions, it only has to be computed once,
51+
which makes drawing random samples super fast once it's computed.]
52+
sample_kernel
53+
plot_samples
54+
plot_kernel
55+
[to-do] condition on data
56+
57+
"""
58+
59+
def __init__(self, sp = 'none', cosmo = FlatLambdaCDM(H0=70, Om0=0.3), zval = 0.1):
60+
61+
62+
self.kernel = []
63+
self.covariance_matrix = []
64+
self.zval = zval
65+
self.sp = sp
66+
self.cosmo = cosmo
67+
self.get_t_univ()
68+
self.get_tarr()
69+
70+
71+
def get_t_univ(self):
72+
73+
self.t_univ = self.cosmo.age(self.zval).value
74+
return
75+
76+
def get_tarr(self, n_tarr = 1000):
77+
78+
self.get_t_univ()
79+
if n_tarr > 1:
80+
self.tarr = np.linspace(0,self.t_univ, n_tarr)
81+
elif n_tarr < 1:
82+
self.tarr = np.arange(0,self.t_univ, n_tarr)
83+
else:
84+
raise('Undefined n_tarr: expected int or float.')
85+
return
86+
87+
88+
def get_covariance_matrix(self, show_prog = True, **kwargs):
89+
"""
90+
Evaluate covariance matrix with a particular kernel
91+
"""
92+
93+
cov_matrix = np.zeros((len(self.tarr),len(self.tarr)))
94+
95+
if show_prog == True:
96+
iterrange = range(len(cov_matrix))
97+
else:
98+
iterrange = range(len(cov_matrix))
99+
for i in iterrange:
100+
for j in range(len(cov_matrix)):
101+
cov_matrix[i,j] = self.kernel(self.tarr[i] - self.tarr[j], **kwargs)
102+
103+
return cov_matrix
104+
105+
106+
107+
def extended_regulator_model_kernel_paramlist(delta_t, kernel_params, base_e_to_10 = False):
108+
"""
109+
A basic implementation of the regulator model kernel, with five parameters:
110+
kernel_params = [sigma, tau_eq, tau_in, sigma_gmc, tau_gmc]
111+
sigma: \sigma, the amount of overall variance
112+
tau_eq: equilibrium timescale
113+
tau_x: inflow correlation timescale (includes 2pi factor)
114+
sigma_gmc: gmc variability
115+
tau_l: cloud lifetime
116+
117+
from https://github.com/kartheikiyer/GP-SFH
118+
"""
119+
120+
sigma, tau_eq, tau_in, sigma_gmc, tau_gmc = kernel_params
121+
122+
if base_e_to_10 == True:
123+
# in TCF20, this is defined in base e, so convert to base 10
124+
sigma = sigma*np.log10(np.e)
125+
sigma_gmc = sigma_gmc*np.log10(np.e)
126+
127+
tau = np.abs(delta_t)
128+
129+
if tau_in == tau_eq:
130+
c_reg = sigma**2 * (1 + tau/tau_eq) * (np.exp(-tau/tau_eq))
131+
else:
132+
c_reg = sigma**2 / (tau_in - tau_eq) * (tau_in*np.exp(-tau/tau_in) - tau_eq*np.exp(-tau/tau_eq))
133+
134+
c_gmc = sigma_gmc**2 * np.exp(-tau/tau_gmc)
135+
136+
kernel_val = (c_reg + c_gmc)
137+
return kernel_val
138+
139+
140+
141+
def get_sfr_covar(psd_params, agebins=[], **extras):
142+
"""Caluclates SFR covariance matrix for a given set of PSD parameters and agebins
143+
PSD parameters must be in the order: [sigma_reg, tau_eq, tau_in, sigma_dyn, tau_dyn]
144+
145+
from https://github.com/kartheikiyer/GP-SFH
146+
147+
Returns
148+
-------
149+
covar_matrix: (Nbins, Nbins)-dim array of covariance values for SFR
150+
"""
151+
152+
bincenters = np.array([np.mean(agebins[i]) for i in range(len(agebins))])
153+
bincenters = (10**bincenters)/1e9
154+
case1 = simple_GP_sfh()
155+
case1.tarr = bincenters
156+
case1.kernel = extended_regulator_model_kernel_paramlist
157+
covar_matrix = case1.get_covariance_matrix(kernel_params = psd_params, show_prog=False)
158+
159+
return covar_matrix
160+
161+
162+
def sfr_covar_to_sfr_ratio_covar(covar_matrix):
163+
"""Caluclates log SFR ratio covariance matrix from SFR covariance matrix
164+
165+
from https://github.com/kartheikiyer/GP-SFH
166+
167+
Returns
168+
-------
169+
sfr_ratio_covar: (Nbins-1, Nbins-1)-dim array of covariance values for log SFR
170+
"""
171+
172+
dim = covar_matrix.shape[0]
173+
174+
sfr_ratio_covar = []
175+
176+
for i in range(dim-1):
177+
row = []
178+
for j in range(dim-1):
179+
cov = covar_matrix[i][j] - covar_matrix[i+1][j] - covar_matrix[i][j+1] + covar_matrix[i+1][j+1]
180+
row.append(cov)
181+
sfr_ratio_covar.append(row)
182+
183+
return np.array(sfr_ratio_covar)

0 commit comments

Comments
 (0)