A Python tool for correcting a young stellar cluster's observed present-day mass function (PDMF) for photometric incompleteness, and for building a completeness-corrected mock catalog (observed stars + statistically-inferred missing members) that can feed back into ClusterForge's physical parameters.
This is a companion to ClusterForge rather than part of it: correcting for missing members is a distinct statistical problem (inference of unobserved stars) from characterizing the observed sample, and keeping it separate lets each tool be developed and reused independently.
Membership catalogs built from Gaia astrometry are affected by both
survey-instrumental limits (faint-end sensitivity, bright-star saturation)
and methodological quality cuts (parallax error, RUWE, astrometric
fidelity). These effects truncate the observed PDMF at low stellar masses,
which in turn biases any quantity that depends on the total cluster mass —
the virial radius, the virial dispersion, and therefore the virial parameter
The approach follows the completeness-correction procedure described in Sánchez-Sanjuán et al. (2026, see Citation below):
- Reference fit. The observed stellar masses (estimated from the CMD via isochrone interpolation) are binned, and a theoretical mass-function model is scaled to match the observed histogram at its most populated bin — assumed to mark the onset of incompleteness, since it typically falls in a mass range where Gaia photometry is both unsaturated and complete.
- Missing-star sampling. In every bin where the theoretical curve exceeds the observed counts, synthetic stars are drawn (uniformly in mass within that bin) to fill the gap, producing a completed mass sample.
- Monte Carlo ensemble. The fit and sampling are repeated (300 times by default), each time jittering the mass-function parameters within their uncertainties and adding Poisson noise to the missing-star counts. This produces a distribution of completeness ratios, total masses, and completed star counts, summarized by their median and percentile spread.
-
Spatial placement. The missing stars still need sky positions and
parallaxes. A 3D Gaussian kernel density estimate (KDE) is built from the
observed
$(\alpha, \delta, \varpi)$ distribution, with its bandwidth chosen by minimizing the residual between synthetic and observed 2D density maps. The number of synthetic stars drawn from this KDE is set so that, combined with the real observed stars, the total matches the Monte Carlo median star count from step 3 — real stars are always kept exactly as observed; only the shortfall is synthetic. - Diagnostics. Three figures summarize the correction: the observed histogram against the full ensemble of scaled mass-function realizations with the completeness ratio below it, the resulting total-mass distribution, and the spatial density maps with the real and synthetic populations shown together.
The method was validated in the original paper against synthetic clusters with imposed incompleteness levels of 25%, 50%, and 75%: median recovery of the star count exceeded ~90% at 25-50% incompleteness and stayed above ~85% even at 75% incompleteness, with mass recovery above ~95% in all cases.
Selected via the mf argument of mass_completeness() / mass_realizations():
mf value |
Model | Reference |
|---|---|---|
'tapered' |
Tapered power law: canonical power-law slope at intermediate/high mass, exponential taper below a turnover mass | Suárez et al. (2019) |
'kroupa' |
Two-part broken power law | Kroupa (2001) |
'chabrier' |
Log-normal below 1 |
Chabrier (2003) |
'lognormal' |
Simple log-normal form | — |
'two_segments' |
Broken power law with an independent low/high-mass segment | — |
mass_completeness(mass_obs, bins=None, mf='tapered', params=None, errors=None, randomize=False, poisson_jitter=False, mass_cutoff=0.08)— single scaled-mass-function fit and missing-star sampling; the building block used by everything else.mass_realizations(mass_obs, n_bins, mf, params, errors, n_iter=300)— the Monte Carlo ensemble described above; returns the per-realization mass-function curves, completeness ratios, total masses, and completed star counts.pdf_comparison(data)/final_kde(data_in, smooth, n_missing)— determine the optimal KDE bandwidth and sample the spatial positions of the missing stars.plot_mass_completeness(...)— Figure 1: observed mass histogram with the full ensemble of theoretical curves and the anchor point, plus the completeness ratio (median and 16th-84th / 5th-95th percentile bands) as a function of mass.plot_mass_histogram(...)— Figure 2: the Monte Carlo total-mass distribution, median, and 1σ interval.plot_star_locations(...)— Figure 3: RA-DEC and PLX-DEC density maps from the KDE, with the observed data overlaid, and the completed (real + synthetic) sample shown for comparison, using consistent axis ranges across matching panels.completeness_analysis(df_in, isochrone, mf='tapered', params=None, errors=None, n_iter=300, plot=False)— top-level entry point; runs the full pipeline above and returns the Monte Carlo ensemble together with the completed catalog (ra,dec,plxfor every real and synthetic star combined).
git clone <this-repo>
cd PDMFiller
pip install -r requirements.txtNo ClusterForge installation needed. mass_completeness.py uses two small
helper functions, freedman_diaconis_rule (bin-width selection) and
star_mass_estimate_spline (CMD-to-mass interpolation), that also live in
ClusterForge's general_tools.py and mass_estimation.py. This repo bundles
its own trimmed copies of those two functions (general_tools.py,
mass_estimation.py — see the header comment in each for provenance), and
mass_completeness.py imports them directly (from general_tools import ...) rather than as package-relative imports, so the whole repo runs flat
from wherever you clone it, with no __init__.py or package install step.
Verified end-to-end with a synthetic test cluster before packaging.
If ClusterForge ever changes those two functions, these vendored copies won't pick up the update automatically — check the source links in each file's header comment if you want to keep them in sync.
from mass_completeness import completeness_analysis
ensemble, (ra_all, dec_all, plx_all) = completeness_analysis(
my_cluster, # a ClusterForge-style object with .ra, .dec, .plx, .Gmag, .RP, ...
isochrone='path/to/best_fit_isochrone.csv',
mf='tapered',
params=(1.10, 0.31, 2.11), # initial (Gamma, m_p, beta) for the tapered power law
errors=(0.09, 0.03, 0.09),
n_iter=300,
plot=True,
)
print(f"Median total mass: {ensemble['total_mass'].mean():.1f} Msun")The completed catalog (ra_all, dec_all, plx_all) — real observed positions
plus the synthetically placed missing members — can be re-fit with
ClusterForge's density_profiles module to obtain completeness-corrected
structural parameters, and the ensemble's total mass can be passed to
physical_params.calculations(..., mass=(total_mass, total_mass_error)) to
recompute the virial state on the corrected sample.
Figs/Mass_Completeness.png,Figs/Total_Mass_Distribution.png,Figs/Star_Locations.pngoutput/Mass_Comp/mass_*.csv— completed mass sample for every Monte Carlo realizationparams_pdmf_01.csv— the mass-function parameters and scale factor drawn in each realization
If you use this tool in your research, please cite:
Sánchez-Sanjuán, S., Pérez-Villegas, Á., Hernández, J., & Aguilar, L. 2026, Dynamical evolution and dissolution time-scale of young stellar clusters in the Orion star-forming complex, Monthly Notices of the Royal Astronomical Society, 549, 4, stag1098, https://doi.org/10.1093/mnras/stag1098
@article{SanchezSanjuan2026,
author = {S{\'a}nchez-Sanju{\'a}n, Sergio and P{\'e}rez-Villegas, {\'A}ngeles and Hern{\'a}ndez, Jes{\'u}s and Aguilar, Luis},
title = {Dynamical evolution and dissolution time-scale of young stellar clusters in the Orion star-forming complex},
journal = {Monthly Notices of the Royal Astronomical Society},
year = {2026},
volume = {549},
number = {4},
pages = {stag1098},
doi = {10.1093/mnras/stag1098}
}