Flux and magnitude conversion¶
In this tutorial we will use the F115W filter of JWST/NIRCam to convert an apparent magnitude into a flux and vice versa. The magnitudes are defined in the Vega System with the magnitude of Vega set to 0.03 mag for each filter.
Getting started¶
We start by importing species and initiating the database.
[1]:
import species
species.SpeciesInit()
Initiating species v0.1.4... [DONE]
Creating species_config.ini... [DONE]
Database: /Users/tomasstolker/applications/species/docs/tutorials/species_database.hdf5
Data folder: /Users/tomasstolker/applications/species/docs/tutorials/data
Working folder: /Users/tomasstolker/applications/species/docs/tutorials
Creating species_database.hdf5... [DONE]
Creating data folder... [DONE]
[1]:
<species.core.setup.SpeciesInit at 0x10a9b0898>
Magnitude to flux¶
We now create an instance of SyntheticPhotometry
with the filter name as listed on the SVO Filter Profile Service.
[2]:
synphot = species.SyntheticPhotometry('JWST/NIRCam.F115W')
To covert from apparent magnitude to flux, we use the magnitude_to_flux
function. 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.
[3]:
flux, error = synphot.magnitude_to_flux(15., error=0.2, zp_flux=None)
print(f'Flux density [W m-2 micron-1] = {flux:.2e} +/- {error:.2e}')
Adding filter: JWST/NIRCam.F115W... [DONE]
Downloading Vega spectrum (270 kB)... [DONE]
Adding Vega spectrum... [DONE]
Flux density [W m-2 micron-1] = 4.15e-15 +/- 7.69e-16
Flux to magnitude¶
To convert backwards from flux to magnitude, we use the flux_to_magnitude
function. When the distance
is provide, both the apparent and absolute magnitude are calculated.
[4]:
app_mag, abs_mag = synphot.flux_to_magnitude(flux, error=error, distance=(30., 5.))
print(f'Apparent magnitude [mag] = {app_mag[0]:.2f} +/- {app_mag[1]:.2f}')
print(f'Absolute magnitude [mag] = {abs_mag[0]:.2f} +/- {abs_mag[1]:.2f}')
Apparent magnitude [mag] = 15.00 +/- 0.20
Absolute magnitude [mag] = 12.61 +/- 0.42
As expected, we obtain again the initial apparent magnitude.
Zero point flux¶
Finally, let’s see what the zero-point flux is for the JWST/NIRCam.F115W
filter (i.e. the flux of Vega).
[5]:
zp_flux = synphot.zero_point()
print(f'Zero point flux [W m-2 micron-1] = {zp_flux:.2e}')
Zero point flux [W m-2 micron-1] = 4.04e-09
This flux is indeed consistent with the zero point that is listed by the SVO Filter Profile Service: 3.993e-10 erg cm\(^{-2}\) s\(^{-1}\) A\(^{-1}\).