The IMF module¶
The IMF modules provides a set of tools to handle initial mass functions (IMFs).
In particular, it can be used to generate individual particles that sample a
given IMF.
Definition¶
An IMF is defined by a set of affine function (defined basically by a slope), each defined in a mass interval (\([m_i,m_{i+1}]\)) that provide the mass fraction of stars per unit mass interval:
\[\Phi(m)_{[m_i,m_{i+1}]} = b_i\, m^a_i\]
Here, \(a_i\) is the slope (in a given mass range) and \(b_i\) is a normalization factor automatically determined to guarantee that
\[\int_{M_{\rm{min}}}^{M_{\rm{max}}} \Phi(m) \, \textrm{d}m = \sum_i \int_{m_i}^{m_{i+1}} b_i\, m^a_i \, \textrm{d}m = 1,\]
with \(M_{\rm{min}}\) and \(M_{\rm{max}}\) the minimal and maximal masses considered for the IMF.
All units are in solar mass.
Examples¶
In the python interpreter,
First import the IMF module:
from pNbody.IMF import IMF
Optionally, you can define a set of parameters that defines the IMF itself:
params = {}
params["Mmax"] = 50. # maximal imf mass in Msol
params["Mmin"] = 0.05 # minimal imf mass in Msol
params["as"] = [0.7,-0.8,-1.7,-1.3] # imf slope in a given mass range
params["ms"] = [0.08,0.5,1.0] # mass range for the imf slope
An IMF with one single slope -1.3 will be parameterized by:
params = {}
params["Mmax"] = 50.
params["Mmin"] = 0.05
params["as"] = [-1.3]
params["ms"] = []
Then, create an IMF with a total mass of 1e5 solar mass, using the default
pNbody IMF (Kroupa 2001):
imf = IMF(params=params,M0=1e5)
or use the parameters you defined above:
imf = IMF(M0=1e5)
Once created, you can get information on the IMF:
imf.info()
IMF mass in solar mass
M0 = 100000
Total number of stars in the IMF
N = 351273
IMF minimal and maximal masses in solar mass
mmin = 0.05
mmax = 50
IMF slopes
as = [0.7, -0.8, -1.7, -1.3]
IMF masses ranges
ms = [0.08, 0.5, 1.0]
Current random seed
seed = 0
To generate individual stellar masses, use:
masses = imf.Sample()
the variable masses, an numpy array will contains their values.
To plot the IMF with matplotlib, use something like:
from matplotlib import pylab as plt
import numpy as np
mmin = imf.getMinMass()
mmax = imf.getMaxMass()
bins = np.logspace(np.log10(mmin)-0.1,np.log10(mmax)+0.1,100)
plt.hist(masses,bins=bins)
plt.xscale('log')
plt.yscale('log')
plt.xlabel("Stellar Mass [Solar Mass]")
plt.show()
pNbody.IMF module¶
The IMF class¶
- class pNbody.IMF.IMF(params={'Mmax': 50.0, 'Mmin': 0.05, 'as': [0.7, - 0.8, - 1.7, - 1.3], 'ms': [0.08, 0.5, 1.0]}, M0=10000, seed=0)¶
- Sample()¶
return a set of star mass, that sample the IMF By default the masses are sorted.
- Sample2Parts(Mt=1, Msp=20)¶
sample the IMF with macro particles below a given mass and with individual stars above.
Mt minimal discrete mass (minimal_discrete_mass_Msun) Msp mass of stellar particles (stellar_particle_mass_Msun)
The routine returns:
masses_d : the list of discrete stars masses_sp : the list of stellar particles (macro particles)
- getMaxMass()¶
return the maximal IMF mass in Msol
- getMinMass()¶
return the minimal IMF mass in Msol
- getNumberOfStarsInMassInterval(mmin, mmax)¶
return the number of stars in a given mass range defined by: mmin : lower mass bound mmax : upper mass bound
- getOneStar(f=None)¶
return one start mass (that sample the IMF)
f : random number if None, one is randomly picked between [0,1]
- getStellarMassInMassInterval(mmin, mmax)¶
return the stellar mass in a given mass range defined by: mmin : lower mass bound mmax : upper mass bound
- getTotalMass()¶
get the IMF total mass in Msol
- getTotalNumberOfStars()¶
get the total number of stars in the IMF
- info()¶
print some info
- setRandomSeed(seed=None)¶
init the random seed
seed : the random seed. If none, use the default value
- setTotalMass(M0)¶
set the IMF total mass in Msol
Scripts¶
imf_sample_IMF¶
usage: imf_sample_IMF [-h] [-o OUTPUTFILENAME] [--info] [--seed INT] [-p PARAMETER_FILE]
[--M0 FLOAT]
sample an IMF and display it
By default, the Kroupa 2001 IMF is used. It can be changed to anything providing a yaml parameter file containing
the IMF parametrisation:
'''
Mmin: 0.05
Mmax: 50
as: [0.7, -0.8, -1.7, -1.3]
ms: [0.08, 0.5, 1.0]
'''
where ``as`` is the slope of the IMF in the mass intervals ``ms`` given is solar masses.
options:
-h, --help show this help message and exit
-o OUTPUTFILENAME Name of the output file
--info get info on the IMF and exit.
--seed INT random seed
-p PARAMETER_FILE, --parameter-file PARAMETER_FILE
Name of the parameter file
--M0 FLOAT stellar mass to generate [Msol]
Examples:
--------
imf_sample_IMF
imf_sample_IMF --M0 1e6
imf_sample_IMF --M0 1e6 --info
imf_sample_IMF -p params.yml
imf_sample_IMF -p params.yml --info