Logo FIREFLY
Credit: Samuel Helps (FIREFLY Collaboration) — CC BY 4.0

Configuration

Configuring FIREFLY for Spectral Fitting

Before launching into full spectral fitting with FIREFLY, it's essential to prepare your input data and define your fitting configuration. This guide walks you through the different settings FIREFLY has available, how to define your desired model parameters, and construct the appropriate input FITS files that FIREFLY requires. If you are interested in how to add your own/new models to FIREFLY, see Adding Your Own Stellar Population Models to FIREFLY.

Configuration Options

FIREFLY offers multiple degrees of freedom in modeling:

Input Data Requirements

Input FITS File Structure

Most FIREFLY launch pipelines expect a multi-spectrum FITS file with the following structure:

Each spectrum must be self-contained with associated metadata embedded either in the header or the table structure.

Creating FITS Files for FIREFLY

The repository presents three different methods you can use to generate the input FITS files for FIREFLY (Note: these examples are for DESI):

Option 1: FIREFLY 'All-in-one' launch scripts on NERSC

The firefly(AIO)_DESI_DR1.py and firefly(AIO)_DESI_EDR.py scripts offer the quickest and most efficent way to fit DESI spectra. Because NERSC already hosts all DESI data releases, these scripts can read everything directly from the shared filesystem and fit the spectra straight away. If you have a NERSC account, this method handles all data retrieval internally, letting you skip the fits file creation needed in other approaches.

On NERSC, launch these runs through SLURM using the provided SBATCH_Fuji.sh (DESI-EDR) and SBATCH_Iron.sh (DESI-DR1) batch scripts. The only part that usually needs editing in the sbatch files is the desired galaxy index range you want to fit and the correct path to the firefly(AIO) script:

START_INDEX=2600000
END_INDEX=2700000
SCRIPT_PATH="/global/cfs/cdirs/desi/users/helpss/FIREFLY/firefly/Launch/DESI/NERSC/run_scripts/SBATCH_Iron.sh" 

Option 2: NERSC → FIREFLY File Builder (for SCIAMA or other HPCs)

If you want to run FIREFLY on another HPC system (e.g. SCIAMA) but still take advantage of NERSC's fast access to DESI spectra, the NERSC_fits_create.py script provides the ideal workflow. It retrieves all required DESI spectral data on NERSC, merges the B/R/Z arms, attaches the required metadata and FastSpecFit values, and outputs fully FIREFLY-ready FITS files that can be copied to any external machine for fitting.

To choose which galaxies to export, edit the index range at the top of the script:

START_SPECTRUM = 5000
END_SPECTRUM   = 10000

These indices correspond to rows in the DESI EDR zall-pix-fuji.fits catalog. (Note: this method was used to fit over a million galaxies on SCIAMA which utilised blocks of 5000 spectra per fits file for speed and memory optismisation on the HPC).

Running the script on NERSC

Once the desired galaxy index range is set, simply run the script via a terminal on NERSC:

python NERSC_fits_create.py

This will create an output file in your NERSC directory:

Data/DESI/DESI_EDR_data/DESI_EDR_5000-10000.fits

(Important: Ensure that all the file input and output paths are corrected for your placement the scirpt in your NERSC directory or within the cloned FIREFLY repoistory uploaded to NERSC. Remember that all file paths on NERSC require an extra / before global.)

What this script does

Option 3: Manual Download FITS Builder (DESI)

If you do not have access to NERSC you can still manually download galaxy spectra from the public DESI data directory or run the Local_fits_create.py script on a normal machine to generate FIREFLY-compatible FITS files.

Adding Your Own Stellar Population Models to FIREFLY

This guide explains the format FIREFLY expects for stellar population models, where to place them inside the repository, and two simple ways to plug new models into firefly_models.py. All examples and requirements below are taken from the existing firefly_models.py script in the fitting engine as it is recommend that this is script you alter to implement compatible models with minimal editing.

Where to put your models

The models directory used by the code is defined at the top of firefly_models.py:

MODELS_DIR = join(dirname(__file__), 'stellar_population_models')

So upload your model files under the repository path:

firefly/Fitting_Engine/stellar_population_models/

Follow the existing folder conventions:

Format & structure FIREFLY expects (by model type)

Important processing behaviour (so your models are compatible)

Two simple ways to make FIREFLY use your models

Quick checklist before running

  1. Your files are uploaded into firefly/Fitting_Engine/stellar_population_models/
  2. If you used an existing reader format (m11 / MaStar / E-MILES) ensure filenames and tokens follow the parser's expectations (see tokens listed above)
  3. Decide whether to set self.downgrade_models=True (recommended if your models are higher resolution than the instrument) so FIREFLY will call downgrade()
  4. Ensure data_wave_medium and fit_wave_medium are set correctly (air vs vacuum)
  5. If you added a new branch in get_model(), restart any running Python sessions so the modified module is reloaded