Tools for sampling from and working with functional forms of the initial mass function
Project description
IMF
Installation
Either use the dev version:
pip install https://github.com/keflavich/imf/archive/refs/heads/master.zip
or use pypi:
pip install initial_mass_function
Note that the project name (initial_mass_function) is different from the
packagename you import (imf) because the latter was taken.
Usage
Simple tools to work with the Initial Mass Function
Some basic examples below.
-
Make a simple 1000 Msun cluster sampled from the default Kroupa IMF:
cluster = imf.make_cluster(1000)or from a Salpeter IMF:
cluster = imf.make_cluster(1000, massfunc='salpeter') -
Create a sample of clusters to do some analysis of later. This will make clusters with masses Gaussian-distributed around a given mean mass in the list of cluster_masses, so that you could then do things like estimate the typical luminosity of a cluster for a given mass:
from imf import imf from tqdm.auto import tqdm cluster_masses = [100, 1000, 10000] nclusters_per_bin = 30 clusters = np.array([[imf.make_cluster(mass*(np.random.randn()/20.+1.), silent=True) for ii in range(nclusters_per_bin)] for mass in tqdm(cluster_masses)])
-
Calculate the mass fraction represented by M>8 Msun stars in a Kroupa IMF when the maximum mass is 200 Msun:
kroupa = imf.Kroupa() mmax = 200 cutoff1 = 8 over8fraction = (kroupa.m_integrate(cutoff1, mmax)[0] / kroupa.m_integrate(kroupa.mmin, mmax)[0])
-
This figure was made with examples/imf_figure.py
Contributing
To avoid committing notebook cell outputs (plots/images), install the repository hooks:
pip install pre-commit
pre-commit install
The nbstripout hook will clear output from .ipynb files before commit, and CI enforces the same check.
Credits
- Adam Ginsburg (@keflavich, wrote most of this)
- Sergey Koposov (@segasai, majorly refactored the distribution functions)
- Theo Richardson (@richardson-t, refactored pre-IMF submodules and wrote/revised some functions and documentation)
- Tiffany Christian (@teachristian, made some small corrections)
A companion paper describing the package is in prep.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file initial_mass_function-2026.3.23.tar.gz.
File metadata
- Download URL: initial_mass_function-2026.3.23.tar.gz
- Upload date:
- Size: 1.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0aaed26f62b2f2289369fe6e7b1e2160e70612a8a8227f82f4d6ee9237e0a57
|
|
| MD5 |
dc234b48a7fb76cb78e407e0875fa011
|
|
| BLAKE2b-256 |
9ed14734b4de1dd2b11ccea9e58adcfeee7f8df6e7d7ec90889b9a0ce3810afc
|
File details
Details for the file initial_mass_function-2026.3.23-py3-none-any.whl.
File metadata
- Download URL: initial_mass_function-2026.3.23-py3-none-any.whl
- Upload date:
- Size: 1.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb5588bab9e749f47dcf91f1df27edaaf0c907672be3a8c1f1cbccc4f6e0649a
|
|
| MD5 |
90459156a0847e9d3b85389531851d6c
|
|
| BLAKE2b-256 |
d0ef534984f98e1ab69f03781b597106f3be6775ed0ddd3bd98bd62d8f657425
|