Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: galaxy-quenching model #516

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8ccafdb
Add feature to calculate the schechter params with de la Bella quench…
Lucia-Fonseca Feb 17, 2022
90153d6
Add feature to calculate the schechter params with de la Bella quench…
Lucia-Fonseca Feb 17, 2022
1ada400
Add placeholder for schechter_smf_parameters test
Lucia-Fonseca Feb 17, 2022
d69728a
Remove halo quenching file
Lucia-Fonseca Feb 17, 2022
7e90c0a
Fix pep8 errors for test
Lucia-Fonseca Feb 17, 2022
350310f
Remove test halo quenching file
Lucia-Fonseca Feb 17, 2022
e9339dd
Fix no end of line error
Lucia-Fonseca Feb 17, 2022
4ef1156
Clarify docstring
Lucia-Fonseca Feb 21, 2022
7670106
Clarify docstring for amplitude input
Lucia-Fonseca Feb 21, 2022
6ce403b
Add test for the schechter parameters function
Lucia-Fonseca Feb 21, 2022
d97bb79
Fix trailing whitespace
Lucia-Fonseca Feb 21, 2022
829e6b4
update case II assertment
Lucia-Fonseca Feb 21, 2022
4a920b6
Fix comment
Lucia-Fonseca Feb 21, 2022
e504479
Fix bug with mass-quenched galaxies
Lucia-Fonseca Feb 21, 2022
e85f24f
Address major refactoring review
Lucia-Fonseca Jun 15, 2022
133be5a
Fix docs by adding new functions to the galaxy rst file
Lucia-Fonseca Jun 15, 2022
03fd467
Fix broadcast issue
Lucia-Fonseca Jun 15, 2022
9a2d528
Add more tests for centrals
Lucia-Fonseca Jun 17, 2022
9e8db46
Delete redundant variable
Lucia-Fonseca Jun 17, 2022
63d92d8
Add extra test for mass quenched function
Lucia-Fonseca Jun 17, 2022
8405518
Change function names from amplitude to phi
Lucia-Fonseca Jul 5, 2022
3792b61
Modify docstrings and types
Lucia-Fonseca Jul 5, 2022
6c6f7a4
Fix function to allow for numpy broadcastability
Lucia-Fonseca Jul 5, 2022
4711b63
Update function names for tests
Lucia-Fonseca Jul 5, 2022
2358e19
Modify satellite functions by defining common functionality
Lucia-Fonseca Jul 5, 2022
cda6c68
Merge the satellite related tests into a single one
Lucia-Fonseca Jul 5, 2022
dbfb875
Add broadcastable example test
Lucia-Fonseca Jul 5, 2022
4a19bd5
Modify test for mass quenched galaxies by usng the hypothesis package
Lucia-Fonseca Jul 5, 2022
5462171
Update docs file
Lucia-Fonseca Jul 5, 2022
d0b5aef
Fix title of functions
Lucia-Fonseca Jul 5, 2022
7f70ffd
Fix title of functions for active galaxies
Lucia-Fonseca Jul 5, 2022
7dc5747
Merge branch 'main' into galaxyq
itrharrison Aug 18, 2022
8ea593e
Update test_skypy.py
itrharrison Aug 18, 2022
31be506
Update skypy.py
itrharrison Aug 18, 2022
f07ad41
Update photometry.py
itrharrison Aug 18, 2022
c09748c
revert flake8 failures
itrharrison Aug 25, 2022
c4db2b4
Merge branch 'main' into galaxyq
itrharrison Aug 26, 2022
b9a792d
Merge branch 'main' into galaxyq
itrharrison Aug 31, 2022
8410f33
Merge branch 'main' into galaxyq
itrharrison Nov 22, 2022
cfa436e
Merge branch 'main' into galaxyq
itrharrison Jan 3, 2023
e1952db
Merge branch 'main' into galaxyq
itrharrison Jan 4, 2023
7c2fab2
Merge branch 'main' into galaxyq
itrharrison Jan 9, 2023
a47b0ef
Add corner cases
Jan 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/galaxies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ The following models are found in the `skypy.galaxies.stellar_mass` package.
:nosignatures:

schechter_smf_mass
schechter_smf_parameters


Reference/API
Expand Down
56 changes: 56 additions & 0 deletions skypy/galaxies/stellar_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

__all__ = [
'schechter_smf_mass',
'schechter_smf_parameters',
]


Expand Down Expand Up @@ -74,3 +75,58 @@ def schechter_smf_mass(redshift, alpha, m_star, m_min, m_max, size=None,
m = schechter(alpha, x_min, x_max, resolution, size=size, scale=m_star)

return m


def schechter_smf_parameters(active_parameters, fsatellite, fenvironment):
Lucia-Fonseca marked this conversation as resolved.
Show resolved Hide resolved
r'''Schechter parameters.
This function returns the Schechter mass function parameters
for active galaxies (centrals and satellites)
and passive galaxies (mass- and satellite-quenched)
based on equation (15) in de la Bella et al. 2021 [1]_.

Parameters
----------
active_parameters: tuple
Schechter mass function parameters for the entire active
sample of galaxies: :math:`(\phi_b, \alpha_b, m_{*})`.
Lucia-Fonseca marked this conversation as resolved.
Show resolved Hide resolved
Note: in [1], :math:`\alpha_b` and :math:`m_{*}` are
constants. The elements of the tuple should be scalars.
Exception: :math:`\phi_b` can be array only when
Lucia-Fonseca marked this conversation as resolved.
Show resolved Hide resolved
fsatellite is scalar.

fsatellite: float, (n, ) array_like
Fraction of active satellite galaxies between 0 and 1.
It could be a float or an array, depending on the model you choose.

fenvironment: float
Fraction of satellite-quenched galaxies between 0 and 1.


Returns
-------
parameters: dic
It returns a dictionary with the parameters of the
Schechter mass function. The dictionary keywords:
`centrals`, `satellites`, `mass_quenched` and
`satellite_quenched`. The values correspond to a
tuple :math:`(\phi, \alpha, m_{*})`.

References
----------
.. [1] de la Bella et al. 2021, Quenching and Galaxy Demographics,
arXiv 2112.11110.

'''
phi, alpha, mstar = active_parameters
Lucia-Fonseca marked this conversation as resolved.
Show resolved Hide resolved

sum_phics = (1 - fsatellite) * (1 - np.log(1 - fsatellite))
phic = (1 - fsatellite) * phi / sum_phics
phis = phic * np.log(1 / (1 - fsatellite))
Lucia-Fonseca marked this conversation as resolved.
Show resolved Hide resolved

centrals = (phic, alpha, mstar)
satellites = (phis, alpha, mstar)
mass_quenched = (phic + phis, alpha + 1, mstar)
satellite_quenched = (- np.log(1 - fenvironment) * phis, alpha, mstar)
Lucia-Fonseca marked this conversation as resolved.
Show resolved Hide resolved

return {'centrals': centrals, 'satellites': satellites,
'mass_quenched': mass_quenched, 'satellite_quenched': satellite_quenched}
58 changes: 58 additions & 0 deletions skypy/galaxies/tests/test_stellar_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,61 @@ def calc_cdf(m):
size=1000, resolution=100)
p_value = scipy.stats.kstest(sample, calc_cdf)[1]
assert p_value >= 0.01


def test_schechter_smf_parameters():
from skypy.galaxies.stellar_mass import schechter_smf_parameters
# Check scalar inputs
blue = (10**-2.423, 10**10.60, -1.21)
fsat_scalar, frho = 0.4, 0.2
Lucia-Fonseca marked this conversation as resolved.
Show resolved Hide resolved
sp_scalar = schechter_smf_parameters(blue, fsat_scalar, frho)

assert type(sp_scalar) == dict, 'active_parameters is not a dict: {}'.format(type(sp_scalar))
assert len(sp_scalar) == 4, 'The length of the tuple is not four: {}'.format(len(sp_scalar))
for p in sp_scalar:
for k in range(3):
assert type(sp_scalar[p][k]) is not np.ndarray, \
'{} tuple is not a scalar {}'.format(p, type(sp_scalar[p][k]))

# Check array input for the satellite fraction
fsat_array = np.array([0.4, 0.5])
sp_array = schechter_smf_parameters(blue, fsat_array, frho)
assert type(sp_array) is dict, 'active_parameters is not a dict: {}'.format(type(sp_array))
assert len(sp_array) == 4, 'The length of the tuple is not four: {}'.format(len(sp_array))
for p in sp_array:
assert type(sp_array[p][0]) == np.ndarray, \
'{} amplitude is not an array {}'.format(p, type(sp_array[p][0]))
assert len(sp_array[p][0]) == len(fsat_array), \
'{} amplitude does not match input length {}'.format(p, len(fsat_array))
for k in range(1, 3):
assert type(sp_array[p][k]) != np.ndarray, \
'{} slope or mstar not a scalar {}'.format(p, type(sp_array[p][k]))

# Check array input for the amplitude
amplitude_array = np.array([10**-2.4, 10**-2.3])
blue_array = (amplitude_array, 10**10.60, -1.21)
sp_array = schechter_smf_parameters(blue_array, fsat_scalar, frho)
assert type(sp_array) is dict, 'active_parameters is not a dict: {}'.format(type(sp_array))
assert len(sp_array) == 4, 'The length of the tuple is not four: {}'.format(len(sp_array))
for p in sp_array:
assert type(sp_array[p][0]) is np.ndarray, \
'{} amplitude is not an array {}'.format(p, type(sp_array[p][0]))
assert len(sp_array[p][0]) is len(fsat_array), \
'{} amplitude does not match input length {}'.format(p, len(amplitude_array))
for k in range(1, 3):
assert type(sp_array[p][k]) is not np.ndarray, \
'{} slope or mstar not a scalar {}'.format(p, type(sp_array[p][k]))

# Corner cases
# Case I: no satellite galaxies
sp_sat0 = schechter_smf_parameters(blue, 0, frho)
assert sp_sat0['centrals'][0] == sp_sat0['mass_quenched'][0] == blue[0], \
'The amplitude of centrals and mass-quenched are not equal to the \
amplitude of the blue sample'
assert sp_sat0['satellites'][0] == sp_sat0['satellite_quenched'][0] == 0, \
'The amplitude of satellites and satellite-quenched are not zero'

# Case II: no satellite-quenched galaxies
sp_rho0 = schechter_smf_parameters(blue, fsat_scalar, 0)
assert sp_rho0['satellite_quenched'][0] == 0, \
'The satellite-quenched is not zero {}'.format(sp_rho0['satellite_quenched'][0])