3
3
import scipy .integrate
4
4
from scipy .special import gammaln
5
5
import pytest
6
+ from astropy .modeling .models import Exponential1D
6
7
7
8
from skypy .galaxies import stellar_mass
8
9
from skypy .utils import special
@@ -25,12 +26,30 @@ def test_stellar_masses():
25
26
with pytest .raises (ValueError ):
26
27
stellar_mass .schechter_smf_mass (0. , - 1.4 , np .array ([1e10 , 2e10 ]), 1.e7 , 1.e13 , size = 3 )
27
28
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
29
30
# an array and size = None
30
31
m_star = np .array ([1e10 , 2e10 ])
31
32
sample = stellar_mass .schechter_smf_mass (0. , - 1.4 , m_star , 1.e7 , 1.e13 , size = None )
32
33
assert m_star .shape == sample .shape
33
34
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
+
34
53
# Test that sampling corresponds to sampling from the right pdf.
35
54
# For this, we sample an array of luminosities for redshift z = 1.0 and we
36
55
# compare it to the corresponding cdf.
0 commit comments