Skip to main content

IMF

Installation

Either use the dev version:

pip install https://github.com/keflavich/imf/archive/refs/heads/main.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.

  1. 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')
    
  2. 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)])
    
  3. 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])
    
  4. This figure was made with examples/imf_figure.py

    IMF example figure

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 some of this)
  • Sergey Koposov (@segasai, majorly refactored the distribution functions)
  • Theo Richardson (@richardson-t, refactored pre-IMF submodules and wrote/revised some functions, especially the PMF and CMF, and wrote all of the documentation)
  • Tiffany Christian (@teachristian, made some small corrections)

A companion paper describing the package is in prep.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

initial_mass_function-2026.7.11.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

initial_mass_function-2026.7.11-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file initial_mass_function-2026.7.11.tar.gz.

File metadata

File hashes

Hashes for initial_mass_function-2026.7.11.tar.gz
Algorithm Hash digest
SHA256 b4cf26634dceab9e77f5c20a34e7b066f3fffadde4bdf175236609daac847870
MD5 d082477a2da08716ed45622efd6da4c8
BLAKE2b-256 137cf2b207fcbbe37c77b4b87bdf6656e40e1b71906263daa372e8b8082ba0f6

See more details on using hashes here.

File details

Details for the file initial_mass_function-2026.7.11-py3-none-any.whl.

File metadata

File hashes

Hashes for initial_mass_function-2026.7.11-py3-none-any.whl
Algorithm Hash digest
SHA256 9da8f5e38ae83e6576ecff7279674f030b75592ec624c4b0314e70b899f2ad26
MD5 6b38925591af4321b4a5584aba4b07fe
BLAKE2b-256 834487105bcba1ae9874d4cf306884c9778fab773278d5efad10046af3b73455

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page