Skip to content

Commit 3b275c6

Browse files
authored
BUG: schechter_smf callable input and docs (#525)
1 parent 1dbda85 commit 3b275c6

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

skypy/galaxies/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
__all__ = [
77
'schechter_lf',
8+
'schechter_smf',
89
]
910

1011
from . import luminosity # noqa F401,F403

skypy/galaxies/stellar_mass.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
import numpy as np
55

66
from ..utils.random import schechter
7+
from ..utils import dependent_argument
78

89

910
__all__ = [
1011
'schechter_smf_mass',
1112
]
1213

1314

15+
@dependent_argument('m_star', 'redshift')
16+
@dependent_argument('alpha', 'redshift')
1417
def schechter_smf_mass(redshift, alpha, m_star, m_min, m_max, size=None,
1518
resolution=1000):
1619
r""" Stellar masses following the Schechter mass function [1]_.
@@ -19,9 +22,10 @@ def schechter_smf_mass(redshift, alpha, m_star, m_min, m_max, size=None,
1922
----------
2023
redshift : array_like
2124
Galaxy redshifts for which to sample magnitudes.
22-
alpha : float
23-
The alpha parameter in the Schechter stellar mass function.
24-
m_star : (nm,) array-like
25+
alpha : float or function
26+
The alpha parameter in the Schechter stellar mass function. If function,
27+
it must return a scalar value.
28+
m_star : (nm,) array-like or function
2529
Characteristic stellar mass m_*.
2630
size: int, optional
2731
Output shape of stellar mass samples. If size is None and m_star

skypy/galaxies/tests/test_stellar_mass.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import scipy.integrate
44
from scipy.special import gammaln
55
import pytest
6+
from astropy.modeling.models import Exponential1D
67

78
from skypy.galaxies import stellar_mass
89
from skypy.utils import special
@@ -25,12 +26,30 @@ def test_stellar_masses():
2526
with pytest.raises(ValueError):
2627
stellar_mass.schechter_smf_mass(0., -1.4, np.array([1e10, 2e10]), 1.e7, 1.e13, size=3)
2728

28-
# Test that an array with the sme shape as m_star is returned if m_star is
29+
# Test that an array with the same shape as m_star is returned if m_star is
2930
# an array and size = None
3031
m_star = np.array([1e10, 2e10])
3132
sample = stellar_mass.schechter_smf_mass(0., -1.4, m_star, 1.e7, 1.e13, size=None)
3233
assert m_star.shape == sample.shape
3334

35+
# Test m_star can be a function that returns an array of values for each redshift
36+
redshift = np.linspace(0, 2, 100)
37+
alpha = 0.357
38+
m_min = 10 ** 7
39+
m_max = 10 ** 14
40+
m_star_function = Exponential1D(10**10.626, np.log(10)/0.095)
41+
sample = stellar_mass.schechter_smf_mass(redshift, alpha, m_star_function, m_min, m_max)
42+
assert sample.shape == redshift.shape
43+
44+
# Test alpha can be a function returning a scalar value.
45+
sample = stellar_mass.schechter_smf_mass(redshift, lambda z: alpha, 10**10.626, m_min, m_max)
46+
assert sample.shape == redshift.shape
47+
48+
# Sampling with an array for alpha is not implemented
49+
alpha_array = np.full_like(redshift, alpha)
50+
with pytest.raises(NotImplementedError, match='only scalar alpha is supported'):
51+
sample = stellar_mass.schechter_smf_mass(redshift, alpha_array, m_star, m_min, m_max)
52+
3453
# Test that sampling corresponds to sampling from the right pdf.
3554
# For this, we sample an array of luminosities for redshift z = 1.0 and we
3655
# compare it to the corresponding cdf.

0 commit comments

Comments
 (0)