MC-SPF is a Python-based tool for fitting Spectral Energy Distributions (SEDs) of galaxies using detailed stellar population models. It supports both photometric and spectroscopic data fitting, leveraging advanced nested sampling algorithms to explore the parameter space and estimate Bayesian evidence.
- Multi-Modal Fitting: Fit photometry and spectroscopy.
- Robust Solvers: Supports multiple nested sampling backends:
multinest(viapymultinest) - Default, robust for multimodal posteriors. Supports parallel processing via mpirundynesty(DEFAULT) - Pure Python dynamic nested sampling, supports parallel processing.ultranest- For high-dimensional problems (experimental support).
- Parallel Processing: Accelerate
dynestyfits using multiple CPU cores with the--ncoresflag. Formultinest, usempirun -np X mc-spf .... - Visualization: Includes plotting tools (
PLOT) to visualize SEDs, Star Formation Histories (SFHs), and corner plots of posterior distributions. - Modular Design: Easily extensible for new models and filters.
Ideally, use a dedicated Conda environment:
conda create -n mcspf python=3.13
conda activate mcspfClone the repository and install the package:
git clone https://github.com/matteofox/MC-SPF.git
cd MC-SPF
python -m pip install .Note: If you encounter build isolation issues, try installing with pip install . --no-build-isolation.
The main executable script is mc-spf.
mc-spf <CATALOG> <FILTERS> <MODE> [OPTIONS]CATALOG: Path to the input FITS catalog file (e.g.,TESTDATA_phot.fits).FILTERS: Path to the filter definition file (e.g.,filters.txt).MODE: Operation mode (see below).
FIT: Standard fitting mode (Simultaneous Photometry + Spectroscopy if available).FITPHOT: Fit only Photometric data.FITSPEC: Fit only Spectroscopic data.PLOT: Plot results from a previous fit (requires outputs from FIT, at leastpost_equal_weights.datandstats.dat).PLOTMINIMAL: Simplified plotting mode.
--outdir <DIR>: Directory for output files (default:./).--solver <SOLVER>: Choose nested sampling backend. Options:dynesty(default),multinest,ultranest.--ncores <N>: Number of cores to use fordynestysolver (default: 1).--objlist <ID>: Run only for specific object IDs (comma-separated, e.g.,1741,770).--nlive <N>: Number of live points for the sampler (default: 500).--sampeff <FLOAT>: Sampling efficiency (default: 0.7).--write_models: Write best-fit model spectra to FITS files. Use '-h' to see more options.
Fit object 1741 from the test catalog using the default dynesty solver:
cd testdata
mc-spf TESTDATA_phot.fits filters.txt FIT --objlist 1741Fit the same object using dynesty on 4 cores:
cd testdata
mc-spf TESTDATA_phot.fits filters.txt FIT --ncores 4 --objlist 1741Generate summary plots for the fitted object. This mode automatically detects the solver output format:
cd testdata
mc-spf TESTDATA_phot.fits filters.txt PLOT --objlist 1741The code generates two main output directories:
Fits/: Contains posterior samples (post_equal_weights.dat), statistics (stats.dat), and resumed run data.Plots/: Contains PDF summary plots (idXXXX_summary.pdf) and best-fit value tables.
- Matteo Fossati (UNIMIB) Contact for correspondence matteo.fossati@unimib.it
- J.T. Mendel (ANU)
- Davide Tornotti (UNIMIB)