{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Flux and magnitude conversion" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this tutorial we will use the [F115W filter](http://svo2.cab.inta-csic.es/svo/theory/fps3/index.php?id=JWST/NIRCam.F115W&&mode=browse&gname=JWST&gname2=NIRCam#filter) of [JWST/NIRCam](https://www.jwst.nasa.gov/content/observatory/instruments/nircam.html) 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." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting started" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We start by importing `species` and initiating the database." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "==============\n", "species v0.6.0\n", "==============\n", "Working folder: /Users/tomasstolker/applications/species/docs/tutorials\n", "Creating species_config.ini... [DONE]\n", "Configuration settings:\n", " - Database: /Users/tomasstolker/applications/species/docs/tutorials/species_database.hdf5\n", " - Data folder: /Users/tomasstolker/applications/species/docs/tutorials/data\n", " - Interpolation method: linear\n", " - Magnitude of Vega: 0.03\n", "Creating species_database.hdf5... [DONE]\n", "Creating data folder... [DONE]\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import species\n", "species.SpeciesInit()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Magnitude to flux" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We now create an instance of [SyntheticPhotometry](https://species.readthedocs.io/en/latest/species.analysis.html#species.analysis.photometry.SyntheticPhotometry) with the filter name as listed by the [SVO Filter Profile Service](http://svo2.cab.inta-csic.es/svo/theory/fps3/index.php?mode=browse&gname=JWST&gname2=NIRCam)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Adding filter: JWST/NIRCam.F115W..." ] }, { "name": "stderr", "output_type": "stream", "text": [ "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'.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ " [DONE]\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|████████████████████████████████████████| 288k/288k [00:00<00:00, 130MB/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Adding Vega spectrum... [DONE]\n", "Reference: Bohlin et al. 2014, PASP, 126\n", "URL: https://ui.adsabs.harvard.edu/abs/2014PASP..126..711B/abstract\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "synphot = species.SyntheticPhotometry('JWST/NIRCam.F115W')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To covert from apparent magnitude to flux, we use the [magnitude_to_flux](https://species.readthedocs.io/en/latest/species.analysis.html#species.analysis.photometry.SyntheticPhotometry.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." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Flux (W m-2 um-1) = 4.04e-15 +/- 7.48e-16\n" ] } ], "source": [ "flux, error = synphot.magnitude_to_flux(15., error=0.2)\n", "print(f'Flux (W m-2 um-1) = {flux:.2e} +/- {error:.2e}')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Flux to magnitude" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To convert backwards from flux to magnitude, we use the [flux_to_magnitude](https://species.readthedocs.io/en/latest/species.analysis.html#species.analysis.photometry.SyntheticPhotometry.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." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Apparent magnitude = 15.00 +/- 0.20\n", "Absolute magnitude = 10.00 +/- 0.30\n" ] } ], "source": [ "app_mag, abs_mag = synphot.flux_to_magnitude(flux, error=error, parallax=(10., 1.))\n", "print(f'Apparent magnitude = {app_mag[0]:.2f} +/- {app_mag[1]:.2f}')\n", "print(f'Absolute magnitude = {abs_mag[0]:.2f} +/- {abs_mag[1]:.2f}')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As expected, we obtain again the magnitude that we started out with." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Zero point flux" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Zero point flux (W m-2 um-1) = 3.92908e-09\n" ] } ], "source": [ "print(f'Zero point flux (W m-2 um-1) = {synphot.zero_point:.5e}')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This flux is indeed very similar to the zero point that is provided on the website of the [SVO Filter Profile Service](http://svo2.cab.inta-csic.es/svo/theory/fps3/index.php?id=JWST/NIRCam.F115W&&mode=browse&gname=JWST&gname2=NIRCam#filter): 3.92904e-10 erg cm$^{-2}$ s$^{-1}$ A$^{-1}$." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" } }, "nbformat": 4, "nbformat_minor": 2 }