pimf.initialmassfunction
Some python classes to analytically do Initial Mass Function integrals, and easily keep track of the type of IMF.
Module Contents
Classes
Implement a power law IMF of the form \(\xi(m)dm = \xi_0 m^\alpha dm\). |
|
Implement a Chabrier IMF of the form
\[\begin{split}
\xi(m)dm = \xi_0
\begin{cases}
\frac{1}{m}\exp\left(\frac{-\left(\log m - \log m_c\right)^2}{2\sigma^2}\right), & m \leq 1M_\odot\\
\xi_\textrm{continuity} m^{\alpha}, & 1M_\odot \leq m
\end{cases}
\end{split}\]
|
|
Implement a broken power law IMF of the form:
\[\begin{split}
\xi(m)dm =
\xi_0\begin{cases}
m^{\alpha_1}, & m \leq M_\textrm{transition} \\
\xi_\textrm{continuity}m^{\alpha_2}, & M_\textrm{transition} \leq m
\end{cases}
\end{split}\]
|
|
Implement an L3 IMF of the form
\[
\xi(m)dm = \xi_0 \left(\frac{m}{\mu}\right)^{-\alpha}\left(1 + \left(\frac{m}{\mu}\right)^{1-\alpha}\right)^{-\beta} dm,
\]
introduced in Maschberger (2013). |
|
Implement a Lognormal IMF of the form
\[
\xi(m)dm = \xi_0\frac{1}{m}\exp\left(\frac{-\left(\log m - \log m_c\right)^2}{2\sigma^2}\right)
\]
|
|
Implement a Generalised Gamma Function IMF of the form \(\xi(m) = \xi_0 m^\alpha\exp\left[-\left(\frac{m}{m_c}\right)^\beta\right]\). |
|
Implement a Generalised Gamma Function IMF of the form \(\xi(m) = \xi_0 m^\alpha\exp\left[-\left(\frac{m}{m_c}\right)^\beta\right]\). |
Functions
Data
API
- pimf.initialmassfunction.__all__ = ['InitialMassFunction', 'PowerLawIMF', 'ChabrierIMF', 'BrokenPowerLawIMF', 'L3IMF', 'LognormalIMF', ...
- class pimf.initialmassfunction.InitialMassFunction
-
- set_normalisation(ξ0)
Directly set the normalisation constant \(\xi_0\), storing the flag normalised.
- normalise_by_number(Mmin, Mmax, value=1)
Normalise the IMF by number, so \(\int^{M_\mathrm{max}}_{M_\mathrm{min}} \xi(m)\mathrm{d}m = x\), where x is a user provided value, default 1.
- normalise_by_mass(Mmin, Mmax, value=1)
Normalise the IMF by mass, so \(\int^{M_\mathrm{max}}_{M_\mathrm{min}} m\xi(m)\mathrm{d}m = x\), where x is a user provided value, default 1.
- mean_mass(Mmin, Mmax)
Calculate mean mass of an IMF.
\[M_\mathrm{mean} = \frac{\int^{M_\mathrm{max}}_{M_\mathrm{min}} m\xi(m)\mathrm{d}m}{\int^{M_\mathrm{max}}_{M_\mathrm{min}} m\xi(m)\mathrm{d}m}\]Parameters
Mmin : int or float Minimum mass. Mmax : int or float. Maximum mass.
Returns
float The mean mass of a star for the IMF.
- integrate_linear_piecewise_interpolated_product(a, b, x, y, extrapolate_grid=False)
Integrate between a and b, assuming the IMF is multiplied by a linear piecewise function defined by the points (xi, yi).
Assume f s.t. f(xi) = yi, where f is linear and piecewise. This function solves the integral \(\int^b_a f(m)\xi(m)dm\).
Passing
extrapolate_grid=True(Falseby default) will use the slope between (x0, y0), (x1, y1) for x < x0, and similarly for x > xN.
- abstractmethod inverse_cdf(x)
Calculate the inverse cumulative distribution function for this IMF.
MATHS
This is intended to be used for stochastically sampling stars from the IMF using
LINKParameters
x : int, float, or numpy array The value of the CDF at a given mass. Between 0 and 1.
Returns
type of x The mass(es) that give the x value(s) in the CDF.
- class pimf.initialmassfunction.PowerLawIMF(alpha=-2.35, normalisation='number', normalisation_value=1, Mmin=0.1, Mmax=100)
Bases:
pimf.initialmassfunction.InitialMassFunctionImplement a power law IMF of the form \(\xi(m)dm = \xi_0 m^\alpha dm\).
You can specify if you want to normalise by mass or number, and the range. If a number is passed to normalisation then it is used If no normalisation is specified, then we use “number”, which with
normalisation_value=1will yield a PDF.Normalisation value provides the value we are normalising to, i.e. if you want the IMF to represent 100 solar masses.
With the default slope of -2.35 this represents a Salpeter (1955) IMF.
Initialization
- integrate(Mmin, Mmax)
Gives the analytical solution to the integral: \(\int^{M_{max}}_{M_{min}} \xi(m)dm = \xi_0 \frac{M_{max}^{\alpha+1} - M_{min}^{\alpha+1}}{\alpha + 1}\).
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- integrate_product(Mmin, Mmax)
Gives the analytical solution to the integral: \(\int^{M_{max}}_{M_{min}} m\xi(m)dm = \xi_0 \frac{M_{max}^{\alpha+2} - M_{min}^{\alpha+2}}{\alpha + 2}\).
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- inverse_cdf(x)
Calculate the inverse cumulative distribution function for this IMF.
MATHS
This is intended to be used for stochastically sampling stars from the IMF using
LINKParameters
x : int, float, or numpy array The value of the CDF at a given mass. Between 0 and 1.
Returns
type of x The mass(es) that give the x value(s) in the CDF.
- class pimf.initialmassfunction.ChabrierIMF(mc=0.079, sigma=0.69, alpha=-2.3, normalisation='number', normalisation_value=1, Mmin=0.1, Mmax=100)
Bases:
pimf.initialmassfunction.InitialMassFunctionImplement a Chabrier IMF of the form
\[\begin{split} \xi(m)dm = \xi_0 \begin{cases} \frac{1}{m}\exp\left(\frac{-\left(\log m - \log m_c\right)^2}{2\sigma^2}\right), & m \leq 1M_\odot\\ \xi_\textrm{continuity} m^{\alpha}, & 1M_\odot \leq m \end{cases} \end{split}\]You can specify if you want to normalise by mass or number, and the range. If a number is passed to normalisation then it is used If no normalisation is specified, then we take \(\xi_0 = 1\).
Normalisation value provides the value we are normalising to, i.e. if you want the IMF to represent 100 solar masses.
With the default values this represents a Chabrier (2003) IMF.
Initialization
- integrate(Mmin, Mmax)
Gives the analytical solution to the integral: \(\int^{M_{max}}_{M_{min}} \xi(m)dm = FILL IN\).
Note
The above equation doesn’t take into account that Mmin and Mmax could both be above/below the transition mass, but the function call does.
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- integrate_product(Mmin, Mmax)
Gives the analytical solution to the integral: \(\int^{M_{max}}_{M_{min}} m\xi(m)dm = FILL IN\).
Note
The above equation doesn’t take into account that Mmin and Mmax could both be above/below the transition mass, but the function call does.
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- calculate_continuity_constant()
Calculate the continuity constant \(\xi_\textrm{continuity}\) such that the lognormal and power law sections are continuous.
- inverse_cdf(x)
Calculate the inverse cumulative distribution function for this IMF.
MATHS
This is intended to be used for stochastically sampling stars from the IMF using
LINKParameters
x : int, float, or numpy array The value of the CDF at a given mass. Between 0 and 1.
Returns
type of x The mass(es) that give the x value(s) in the CDF.
- class pimf.initialmassfunction.BrokenPowerLawIMF(alpha1=-1.3, alpha2=-2.3, Mtransition=0.5, normalisation='number', normalisation_value=1, Mmin=0.1, Mmax=100)
Bases:
pimf.initialmassfunction.InitialMassFunctionImplement a broken power law IMF of the form:
\[\begin{split} \xi(m)dm = \xi_0\begin{cases} m^{\alpha_1}, & m \leq M_\textrm{transition} \\ \xi_\textrm{continuity}m^{\alpha_2}, & M_\textrm{transition} \leq m \end{cases} \end{split}\]You can specify if you want to normalise by mass or number, and the range. If a number is passed to normalisation then it is used If no normalisation is specified, then we use “number”, which with
normalisation_value=1will yield a PDF.Normalisation value provides the value we are normalising to, i.e. if you want the IMF to represent 100 solar masses.
With the default values this represents a Kroupa (2001) IMF above \(0.08M_\odot\).
Initialization
- integrate(Mmin, Mmax)
Gives the analytical solution to the integral:
\[ \int^{M_{max}}_{M_{min}} \xi(m)dm = \xi_0 \frac{M_{max}^{\alpha_1+1} - M_{min}^{\alpha_1+1}}{\alpha + 1} + \xi_0 \xi_\textrm{continuity} \frac{M_{max}^{\alpha_2+1} - M_{min}^{\alpha_2+1}}{\alpha + 1}, \]Note
The above equation doesn’t take into account that Mmin and Mmax could both be above/below the transition mass, but the function call does.
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- integrate_product(Mmin, Mmax)
Gives the analytical solution to the integral:
\[ \int^{M_{max}}_{M_{min}} \xi(m)dm = \xi_0 \frac{M_{max}^{\alpha_1+2} - M_{min}^{\alpha_1+2}}{\alpha + 2} + \xi_0 \xi_\textrm{continuity} \frac{M_{max}^{\alpha_2+2} - M_{min}^{\alpha_2+2}}{\alpha + 2}, \]Note
The above equation doesn’t take into account that Mmin and Mmax could both be above/below the transition mass, but the function call does.
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- inverse_cdf(x)
Calculate the inverse cumulative distribution function for this IMF.
MATHS
This is intended to be used for stochastically sampling stars from the IMF using
LINKParameters
x : int, float, or numpy array The value of the CDF at a given mass. Between 0 and 1.
Returns
type of x The mass(es) that give the x value(s) in the CDF.
- class pimf.initialmassfunction.L3IMF(alpha=2.3, beta=1.4, mu=0.2, normalisation='number', normalisation_value=1, Mmin=0.1, Mmax=100)
Bases:
pimf.initialmassfunction.InitialMassFunctionImplement an L3 IMF of the form
\[ \xi(m)dm = \xi_0 \left(\frac{m}{\mu}\right)^{-\alpha}\left(1 + \left(\frac{m}{\mu}\right)^{1-\alpha}\right)^{-\beta} dm, \]introduced in Maschberger (2013).You can specify if you want to normalise by mass or number, and the range. If a number is passed to normalisation then it is used If no normalisation is specified, then we use “number”, which with
normalisation_value=1will yield a PDF.Normalisation value provides the value we are normalising to, i.e. if you want the IMF to represent 100 solar masses.
With the default parameter values of 2.3, 1.4, 0.2 this represents a best fit to Kroupa/Charier IMFs, provided in Maschberger (2013).
Initialization
- _create_B_closure(a, b)
Create a closure for the beta function as in Maschberger (2013), so we don’t need to carry around a, b params.
- _G(M)
Auxilliary function from Maschberger (2013) used in other calculations.
Has the form
\[ G(m) = \left[1 + \left(\frac{m}{\mu}\right)^{1-\alpha} \right]^{1-\beta} \]
- integrate(Mmin, Mmax)
Gives the analytical solution to the integral: $\int^{M_{max}}{M{min}} \xi(m)dm = .
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- integrate_product(Mmin, Mmax)
Gives the analytical solution to the integral: $\int^{M_{max}}{M{min}} m\xi(m)dm = …
From equation 25 of Maschberger (2013).
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- inverse_cdf(x)
Calculate the inverse cumulative distribution function for this IMF.
MATHS
This is intended to be used for stochastically sampling stars from the IMF using
LINKParameters
x : int, float, or numpy array The value of the CDF at a given mass. Between 0 and 1. Mmin : int or float, optional The minimum mass to integrate from, by default None, which means integrate from the minimum mass of normalisation.
Returns
type of x The mass(es) that give the x value(s) in the CDF.
- class pimf.initialmassfunction.LognormalIMF(mc, sigma=1, normalisation='number', normalisation_value=1, Mmin=1, Mmax=500)
Bases:
pimf.initialmassfunction.InitialMassFunctionImplement a Lognormal IMF of the form
\[ \xi(m)dm = \xi_0\frac{1}{m}\exp\left(\frac{-\left(\log m - \log m_c\right)^2}{2\sigma^2}\right) \]You can specify if you want to normalise by mass or number, and the range. If a number is passed to normalisation then it is used If no normalisation is specified, then we use “number”, which with
normalisation_value=1will yield a PDF.Normalisation value provides the value we are normalising to, i.e. if you want the IMF to represent 100 solar masses.
Default values are not to be trusted blindly when considering Population III! The IMF is highly uncertain and you will need to make a decision.
Initialization
- integrate(Mmin, Mmax)
Gives the analytical[1] solution to the integral: \(\int^{M_{max}}_{M_{min}} \xi(m)dm = FILL IN\).
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- integrate_product(Mmin, Mmax)
Gives the analytical[1] solution to the integral: \(\int^{M_{max}}_{M_{min}} m\xi(m)dm = FILL IN\).
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- inverse_cdf(x)
Calculate the inverse cumulative distribution function for this IMF.
MATHS
This is intended to be used for stochastically sampling stars from the IMF using
LINKParameters
x : int, float, or numpy array The value of the CDF at a given mass. Between 0 and 1.
Returns
type of x The mass(es) that give the x value(s) in the CDF.
- class pimf.initialmassfunction.GeneralisedGammaIMF(alpha=-2.3, beta=-1.6, mc=10, normalisation='number', normalisation_value=1, Mmin=0.1, Mmax=100)
Bases:
pimf.initialmassfunction.InitialMassFunctionImplement a Generalised Gamma Function IMF of the form \(\xi(m) = \xi_0 m^\alpha\exp\left[-\left(\frac{m}{m_c}\right)^\beta\right]\).
You can specify if you want to normalise by mass or number, and the range. If a number is passed to normalisation then it is used If no normalisation is specified, then we use “number”, which with
normalisation_value=1will yield a PDF.Normalisation value provides the value we are normalising to, i.e. if you want the IMF to represent 100 solar masses.
The default values of alpha, beta, mc come from Brauer+ (2025).
Initialization
- static Γ_lower_incomplete(n_plus_1, u)
Lower incomplete gamma function for a given exponent.
Defined as \(\Gamma(n+1, u) = \int_0^u t^n e^{-t}dt\).
- __call__(M)
Calculate the value \(\xi(m) = \xi_0 m^\alpha\exp\left[-\left(\frac{m}{m_c}\right)^\beta\right]\).
- integrate(Mmin, Mmax)
Gives the analytical solution to the integral: \(\int^{M_{max}}_{M_{min}} \xi(m)dm = \xi_0 \frac{M_c^{\alpha+1}}{\beta}\left[\Gamma(n+1, u_{max}) - \Gamma(n+1, u_{min})\right]\).
Where \(\Gamma(n+1, u) = \int_0^u t^n e^{-t}dt\) is the lower incomplete gamma function, \(n+1 = \frac{\alpha+1}{\beta}\), and \(u_X = \left(\frac{M_X}{M_c}\right)^{\beta}\).
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- integrate_product(Mmin, Mmax)
Gives the analytical solution to the integral: \(\int^{M_{max}}_{M_{min}} \xi(m)dm = \xi_0 \frac{M_c^{\alpha+2}}{\beta}\left[\Gamma(n+1, u_{max}) - \Gamma(n+1, u_{min})\right]\).
Where \(\Gamma(n+1, u) = \int_0^u t^n e^{-t}dt\) is the lower incomplete gamma function, \(n+1 = \frac{\alpha+2}{\beta}\), and \(u_X = \left(\frac{M_X}{M_c}\right)^{\beta}\).
Warning
For performance reasons we do not check Mmin < Mmax, or are within the bounds provided for normalisation.
- inverse_cdf(x)
Calculate the inverse cumulative distribution function for this IMF.
MATHS
This is intended to be used for stochastically sampling stars from the IMF using
LINKParameters
x : int, float, or numpy array The value of the CDF at a given mass. Between 0 and 1.
Returns
type of x The mass(es) that give the x value(s) in the CDF.
- class pimf.initialmassfunction.ExponentialCutoffPowerLawIMF(*args, **kwargs)
Bases:
pimf.initialmassfunction.GeneralisedGammaIMFImplement a Generalised Gamma Function IMF of the form \(\xi(m) = \xi_0 m^\alpha\exp\left[-\left(\frac{m}{m_c}\right)^\beta\right]\).
You can specify if you want to normalise by mass or number, and the range. If a number is passed to normalisation then it is used If no normalisation is specified, then we use “number”, which with
normalisation_value=1will yield a PDF.Normalisation value provides the value we are normalising to, i.e. if you want the IMF to represent 100 solar masses.
The default values of alpha, beta, mc come from Brauer+ (2025).
Initialization