skypyproject / skypy

SkyPy: A package for modelling the Universe.
BSD 3-Clause "New" or "Revised" License
118 stars 38 forks source link

BUG: `schechter_smf` does not accept `m_star` and `alpha` as callable #523

Closed philipp128 closed 2 years ago

philipp128 commented 2 years ago

Describe the bug The method schechter_smf (here) in skypy.galaxies._schechter.py accepts the parameters m_star and 'alpha' as a callables.

However, an error is returned such that a callable is not accepted at the moment.

To Reproduce Steps to reproduce the behavior: 1) Run:

import numpy as np
from skypy.galaxies import schechter_smf
from astropy.cosmology import FlatLambdaCDM
from astropy.modeling.models import Linear1D, Exponential1D
from astropy.units import Quantity

redshift_range = [0,2]
m_min = 10**7
m_max = 10**14
cosmology = FlatLambdaCDM(H0=70, Om0=0.3)
sky_area = Quantity(1.27, "deg2")

phi_star = np.exp(-5.215 - 1.675 * 0)
M_star = Exponential1D(10**10.626, np.log(10)*1/0.095)
alpha = 0.357    ### no evolution allowed

redshift, mass = schechter_smf(redshift_range, M_star, phi_star, alpha, m_min, m_max, sky_area, cosmology)

2) The following error is returned:

TypeError                                 Traceback (most recent call last)
<ipython-input-6-e4a8c8eb2786> in <module>
     26 
     27 print("Check M_star callable")
---> 28 redshift, mass = schechter_smf(redshift_range, M_star, phi_star, alpha, m_min, m_max, sky_area, cosmology)
     29 print(len(redshift))

/Applications/anaconda3/lib/python3.7/site-packages/astropy/units/decorators.py in wrapper(*func_args, **func_kwargs)
    232             # Call the original function with any equivalencies in force.
    233             with add_enabled_equivalencies(self.equivalencies):
--> 234                 return_ = wrapped_function(*func_args, **func_kwargs)
    235             if wrapped_signature.return_annotation not in (inspect.Signature.empty, None):
    236                 return return_.to(wrapped_signature.return_annotation)

/Applications/anaconda3/lib/python3.7/site-packages/skypy/galaxies/_schechter.py in schechter_smf(redshift, m_star, phi_star, alpha, m_min, m_max, sky_area, cosmology, noise)
    138 
    139     # sample galaxy mass for redshifts
--> 140     m = schechter_smf_mass(z, alpha, m_star, m_min, m_max)
    141 
    142     return z, m

/Applications/anaconda3/lib/python3.7/site-packages/skypy/galaxies/stellar_mass.py in schechter_smf_mass(redshift, alpha, m_star, m_min, m_max, size, resolution)
     68 
     69     # convert m_min, m_max to units of m_star
---> 70     x_min = m_min / m_star
     71     x_max = m_max / m_star
     72 

TypeError: unsupported operand type(s) for /: 'int' and 'Exponential1D'

Expected behavior No error but the redshift z and mass m should be returned

Desktop (please complete the following information):

Additional context The problem is that the @dependent_argument decorator is missing. Compare to schechter_lf calling schechter_lf_magnitude (here)

philipp128 commented 2 years ago

One should add decorator to schechter_smf_mass.