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 39 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
4 changes: 4 additions & 0 deletions docs/galaxies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ The following models are found in the `skypy.galaxies.stellar_mass` package.
:nosignatures:

schechter_smf_mass
schechter_smf_phi_centrals
schechter_smf_phi_satellites
schechter_smf_phi_mass_quenched
schechter_smf_phi_satellite_quenched


Velocity dispersion
Expand Down
133 changes: 133 additions & 0 deletions skypy/galaxies/stellar_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

__all__ = [
'schechter_smf_mass',
'schechter_smf_phi_centrals',
'schechter_smf_phi_satellites',
'schechter_smf_phi_mass_quenched',
'schechter_smf_phi_satellite_quenched',
]


Expand Down Expand Up @@ -78,3 +82,132 @@ 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_phi_centrals(phi_blue_total, fsatellite):
r'''Schechter amplitude of central galaxies.
This function returns the Schechter mass function amplitude
for active central population based on equation (15)
in de la Bella et al. 2021 [1]_.

Parameters
----------
phi_blue_total: array_like
Schechter mass function amplitude for the entire active
sample of galaxies, :math:`(\phi_b, \alpha_b, m_{*})`.

fsatellite: 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.

Returns
-------
amplitude: array_like
Amplitude of the Schechter mass function.

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

'''

sum_phics = (1 - fsatellite) * (1 - np.log(1 - fsatellite))

return (1 - fsatellite) * phi_blue_total / sum_phics
Lucia-Fonseca marked this conversation as resolved.
Show resolved Hide resolved


def schechter_smf_phi_satellites(phi_centrals, fsatellite):
r'''Schechter amplitude of satellite galaxies.
This function returns the Schechter mass function amplitude
for active satellite population based on equation (15)
in de la Bella et al. 2021 [1]_.

Parameters
----------
phi_centrals: array_like
Schechter mass function amplitude of the central
active galaxies.

fsatellite: float, (nm, ) 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.

Returns
-------
amplitude: array_like
Amplitude of the Schechter mass function.

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

'''

return _satellite_computation(phi_centrals, fsatellite)


def schechter_smf_phi_mass_quenched(phi_centrals, phi_satellites):
r'''Schechter amplitude of mass-quenched galaxies.
This function returns the Schechter mass function amplitude
for passive mass-quenched population based on equation (15)
in de la Bella et al. 2021 [1]_.

Parameters
----------
phi_centrals: array_like
Schechter mass function amplitude of the central
active galaxies.

phi_satellites: array_like
Schechter mass function amplitude of the satellite
active galaxies.

Returns
-------
amplitude: array_like
Amplitude of the Schechter mass function.

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

'''

return phi_centrals + phi_satellites
Lucia-Fonseca marked this conversation as resolved.
Show resolved Hide resolved


def schechter_smf_phi_satellite_quenched(phi_satellites, fenvironment):
r'''Schechter amplitude of satellite-quenched galaxies.
This function returns the Schechter mass function amplitude
for active central population based on equation (15)
in de la Bella et al. 2021 [1]_.

Parameters
----------
phi_satellites: array_like
Schechter mass function amplitude of the satellite
active galaxies.

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

Returns
-------
amplitude: array_like
Amplitude of the Schechter mass function.

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

'''

return _satellite_computation(phi_satellites, fenvironment)


def _satellite_computation(amplitude, fraction):
return - np.log(1 - fraction) * amplitude
81 changes: 81 additions & 0 deletions skypy/galaxies/tests/test_stellar_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import scipy.integrate
from scipy.special import gammaln
import pytest

from hypothesis import given
from hypothesis.strategies import integers
from astropy.modeling.models import Exponential1D

from skypy.galaxies import stellar_mass
Expand Down Expand Up @@ -79,3 +82,81 @@ 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_phi_centrals():
# Scalar inputs
phiblue_scalar = 10**-2.423
fsat_scalar = 0.4

# Array inputs
phiblue_array = np.array([10**-2.423, 10**-2.422])
fsat_array = np.array([0.40, 0.41, 0.42])

# Test for scalar output
phic_scalar = stellar_mass.schechter_smf_phi_centrals(phiblue_scalar, fsat_scalar)
assert np.isscalar(phic_scalar)

# Test for 1 dim output
phic_1d_phib = stellar_mass.schechter_smf_phi_centrals(phiblue_array, fsat_scalar)
phic_1d_fsat = stellar_mass.schechter_smf_phi_centrals(phiblue_scalar, fsat_array)
assert phic_1d_phib.shape == phiblue_array.shape
assert phic_1d_fsat.shape == fsat_array.shape

# Test for 2 dim output
phic_2d = stellar_mass.schechter_smf_phi_centrals(phiblue_array[:, np.newaxis], fsat_array)
assert phic_2d.shape == (len(phiblue_array), len(fsat_array))

# Special case
fsat_special = 1 - np.exp(-1)
phic_special = stellar_mass.schechter_smf_phi_centrals(phiblue_scalar, fsat_special)
assert phic_special == 0.5 * phiblue_scalar


@given(integers(), integers())
def test_schechter_smf_phi_mass_quenched(phic, phis):

# Array inputs
phic_1d = np.array([phic, phic])
phis_1d = np.array([phis, phis])

# Test for scalar output
phimq_scalar = stellar_mass.schechter_smf_phi_mass_quenched(phic, phis)
assert np.isscalar(phimq_scalar)
assert phimq_scalar == phic + phis

# Test for array output
phimq_1d = stellar_mass.schechter_smf_phi_mass_quenched(phic_1d, phis_1d)
assert phimq_1d.shape == phic_1d.shape == phis_1d.shape
assert np.all(phimq_1d == phic_1d + phis_1d)


SATELLITE_FUNCTIONS = [
stellar_mass.schechter_smf_phi_satellites,
stellar_mass.schechter_smf_phi_satellite_quenched,
]


@pytest.mark.parametrize('satellite_function', SATELLITE_FUNCTIONS)
def test_schechter_smf_phi_satellites_common(satellite_function):
# Scalar inputs
phis_scalar = 10**-2.423
fraction_scalar = 0.2

# Array inputs
phis_array = np.array([10**-2.423, 10**-2.422])

# Test for scalar output
phis_sat_scalar = satellite_function(phis_scalar, fraction_scalar)
assert np.isscalar(phis_sat_scalar)

# Test for 1 dim output
phis_sat_1d_phib = satellite_function(phis_array, fraction_scalar)
assert phis_sat_1d_phib.shape == phis_array.shape

# Corner case no satellite galaxies
fraction_null = 0
phis_sat_null_scalar = satellite_function(phis_scalar, fraction_null)
phis_sat_null_array = satellite_function(phis_array, fraction_null)
assert phis_sat_null_scalar == 0
assert np.all(phis_sat_null_array == np.zeros(len(phis_array)))