<jupyter_start><jupyter_text>Flux and magnitude conversion 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=NIRCamfilter) 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.  Getting started We start by importing `species` and initiating the database.<jupyter_code>import species
species.SpeciesInit()<jupyter_output>Initiating species v0.5.0... [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]<jupyter_text>Magnitude to flux We now create an instance of [SyntheticPhotometry](https://species.readthedocs.io/en/latest/species.analysis.htmlspecies.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).<jupyter_code>synphot = species.SyntheticPhotometry('JWST/NIRCam.F115W')<jupyter_output>Adding filter: JWST/NIRCam.F115W... [DONE]<jupyter_text>To covert from apparent magnitude to flux, we use the [magnitude_to_flux](https://species.readthedocs.io/en/latest/species.analysis.htmlspecies.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.<jupyter_code>flux, error = synphot.magnitude_to_flux(15., error=0.2, zp_flux=None)
print(f'Flux (W m-2 um-1) = {flux:.2e} +/- {error:.2e}')<jupyter_output>Downloading Vega spectrum (270 kB)... [DONE]
Adding Vega spectrum... [DONE]
Flux (W m-2 um-1) = 4.08e-15 +/- 7.56e-16<jupyter_text>Flux to magnitude To convert backwards from flux to magnitude, we use the [flux_to_magnitude](https://species.readthedocs.io/en/latest/species.analysis.htmlspecies.analysis.photometry.SyntheticPhotometry.flux_to_magnitude) method. When the `distance` is provide, both the apparent and absolute magnitude are calculated. The uncertainty on the distance is propagated into the uncertainty of the absolute magnitude<jupyter_code>app_mag, abs_mag = synphot.flux_to_magnitude(flux, error=error, distance=(30., 5.))
print(f'Apparent magnitude = {app_mag[0]:.2f} +/- {app_mag[1]:.2f}')
print(f'Absolute magnitude = {abs_mag[0]:.2f} +/- {abs_mag[1]:.2f}')<jupyter_output>Apparent magnitude = 15.00 +/- 0.20
Absolute magnitude = 12.61 +/- 0.42<jupyter_text>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.<jupyter_code>zp_flux = synphot.zero_point()
print(f'Zero point flux (W m-2 um-1) = {zp_flux:.2e}')<jupyter_output>Zero point flux (W m-2 um-1) = 3.97e-09
{'fraction_non_alphanumeric': 0.12027594481103779, 'fraction_numerical': 0.027294541091781643, 'mean_word_length': 5.683366733466934, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '207863', 'license': 'MIT', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1135, 'n_words': 286, 'path': 'docs/tutorials/flux_magnitude.ipynb', 'repo_name': 'tomasstolker/SPECIES', 'size': '3334'}