Flux and magnitude conversion

Flux and magnitude conversion#

In this tutorial we will use the F115W filter of JWST/NIRCam to convert a magnitude into a flux and vice versa. The magnitudes are defined in the Vega System with the magnitude of Vega set to 0.03 for each filter (see configuration file).

Getting started#

We start by importing species and initiating the database.

from species import SpeciesInit
from species.phot.syn_phot import SyntheticPhotometry
species v0.7.4

Working folder: /Users/tomasstolker/applications/species/docs/tutorials
Creating species_config.ini... [DONE]

Configuration settings:
   - Database: /Users/tomasstolker/applications/species/docs/tutorials/species_database.hdf5
   - Data folder: /Users/tomasstolker/applications/species/docs/tutorials/data
   - Magnitude of Vega: 0.03
Creating species_database.hdf5... [DONE]
Creating data folder... [DONE]

Multiprocessing: mpi4py installed
Process number 1 out of 1...
<species.core.species_init.SpeciesInit at 0x12bd0b110>

Magnitude to flux#

We now create an instance of SyntheticPhotometry with the filter name as listed by the SVO Filter Profile Service.

synphot = SyntheticPhotometry('JWST/NIRCam.F115W')
Downloading data from 'https://archive.stsci.edu/hlsps/reference-atlases/cdbs/current_calspec/alpha_lyr_stis_011.fits' to file '/Users/tomasstolker/applications/species/docs/tutorials/data/alpha_lyr_stis_011.fits'.
100%|████████████████████████████████████████| 288k/288k [00:00<00:00, 113MB/s]
Adding Vega spectrum... [DONE]
Reference: Bohlin et al. 2014, PASP, 126
URL: https://ui.adsabs.harvard.edu/abs/2014PASP..126..711B/abstract

To covert from apparent magnitude to flux, we use the magnitude_to_flux method. The zero-point flux can be provided but is otherwise calculated from a flux-calibration Vega spectrum. Both the filter profile and the Vega spectrum will be downloaded and stored into the database. Let’s calculate the flux for a magnitude of 15 +/- 0.2.

flux, error = synphot.magnitude_to_flux(15., error=0.2)
print(f'Flux (W m-2 um-1) = {flux:.2e} +/- {error:.2e}')
Flux (W m-2 um-1) = 4.04e-15 +/- 7.48e-16

Flux to magnitude#

To convert backwards from flux to magnitude, we use the flux_to_magnitude method. When the parallax (in mas) or distance (in pc) is provide, both the apparent and absolute magnitude are calculated. The uncertainty on the parallax/distance is propagated into the uncertainty of the absolute magnitude.

app_mag, abs_mag = synphot.flux_to_magnitude(flux, error=error, parallax=(10., 1.))
print(f'Apparent magnitude = {app_mag[0]:.2f} +/- {app_mag[1]:.2f}')
print(f'Absolute magnitude = {abs_mag[0]:.2f} +/- {abs_mag[1]:.2f}')
Apparent magnitude = 15.00 +/- 0.20
Absolute magnitude = 10.00 +/- 0.30

As expected, we obtain again the magnitude that we started out with.

Zero point flux#

Finally, let’s see what the zero-point flux (i.e. the flux of Vega) is for the JWST/NIRCam.F115W filter. The value is stored by the zero_point attribute of the SyntheticPhotometry object.

print(f'Zero point flux (W m-2 um-1) = {synphot.zero_point:.5e}')
Zero point flux (W m-2 um-1) = 3.92908e-09

This flux is indeed very similar to the zero point that is provided on the website of the SVO Filter Profile Service: 3.92904e-10 erg cm\(^{-2}\) s\(^{-1}\) A\(^{-1}\).