<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 pyphot - A tool for computing photometry from spectra
Some examples are provided in this notebook
Full documentation available at http
Step1:  The Sun and Vega
pyphot provides convenient interfaces to a spectral representation of the Sun and Vega.
In this notebook, we show how they can be used.
Step2:  Vega
Suppose one has a calibrated spectrum and wants to compute the vega magnitude throug the HST WFC3 F110W passband,
Step3:  The Sun
The internal reference to the Solar spectrum comes in two flavors
Step4:  One can see the differences between the two flavors.
The theoretical spectrum is scaled to match the observed spectrum from 1.5 - 2.5 microns, and then it is used where the observed spectrum ends. The theoretical model of the Sun from Kurucz‘93 atlas using the following parameters when the Sun is at 1 au.
|log_Z | T_eff | log_g | V$_{Johnson}$ |
|------|-------|-------|---------------|
|+0.0  | 5777  |+4.44  | -26.76        |
The Sun is also know to have a Johnson V (vega-)magnitude of -26.76 mag.
Let's verify this.
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import pylab as plt
import numpy as np
import sys
sys.path.append('../')
import pyphot
Explanation: pyphot - A tool for computing photometry from spectra
Some examples are provided in this notebook
Full documentation available at http://mfouesneau.github.io/docs/pyphot/
End of explanation
import pyphot
# get the internal default library of passbands filters
lib = pyphot.get_library()
print("Library contains: ", len(lib), " filters")
Explanation: The Sun and Vega
pyphot provides convenient interfaces to a spectral representation of the Sun and Vega.
In this notebook, we show how they can be used.
End of explanation
# convert to magnitudes
import numpy as np
# We'll use Vega spectrum as example
vega = pyphot.Vega()
f = lib['HST_WFC3_F110W']
# compute the integrated flux through the filter f
# note that it work on many spectra at once
fluxes = f.get_flux(vega.wavelength, vega.flux, axis=-1)
# convert to vega magnitudes
mags = -2.5 * np.log10(fluxes) - f.Vega_zero_mag
print("Vega magnitude of Vega in {0:s} is : {1:f} mag".format(f.name, mags))
mags = -2.5 * np.log10(fluxes) - f.AB_zero_mag
print("AB magnitude of Vega in {0:s} is : {1:f} mag".format(f.name, mags))
mags = -2.5 * np.log10(fluxes) - f.ST_zero_mag
print("ST magnitude of Vega in {0:s} is : {1:f} mag".format(f.name, mags))
Explanation: Vega
Suppose one has a calibrated spectrum and wants to compute the vega magnitude throug the HST WFC3 F110W passband,
End of explanation
from pyphot import unit
sun_obs = pyphot.Sun(flavor='observed')
sun_th = pyphot.Sun()
sun_th_10pc = pyphot.Sun(distance=10 * unit['pc'])
plt.loglog(sun_obs.wavelength.magnitude, sun_obs.flux.magnitude, label='observed')
plt.loglog(sun_th.wavelength.magnitude, sun_th.flux.magnitude, label='theoretical')
plt.legend();
plt.xlabel('wavelength [{0:s}]'.format(str(sun_obs.wavelength.units)));
plt.ylabel('flux [{0:s}]'.format(str(sun_obs.flux.units)));
Explanation: The Sun
The internal reference to the Solar spectrum comes in two flavors: an observed one and a theoretical one.
By default, the interface is set to theoretical.
In addition, the Sun is at $1\,au$ but can be set to any distance. Below we instanciate the two flavors and also the Sun if it was at $10\, pc$ (absolute flux units).
End of explanation
f = lib['GROUND_JOHNSON_V']
for name, sun in zip(('observed', 'theoretical', 'th. 10pc'), (sun_obs,sun_th, sun_th_10pc)):
    flux = f.get_flux(sun.wavelength, sun.flux)
    vegamag = f.Vega_zero_mag
    print('{0:12s} {1:0.5e} {2:+3.4f}'.format(name, flux, -2.5 * np.log10(flux) - vegamag))
filter_names = ['GROUND_JOHNSON_B', 'GROUND_JOHNSON_V', 'GROUND_BESSELL_J', 'GROUND_BESSELL_K']
filter_names +=  lib.find('GaiaDR2')
filters = lib.load_filters(filter_names, lamb=sun_th.wavelength)
mags = {}
for name, fn in zip(filter_names, filters):
    flux = fn.get_flux(sun_th.wavelength, sun_th.flux)
    vegamag = fn.Vega_zero_mag
    mag = -2.5 * np.log10(flux) - vegamag
    mags[name] = mag
    print('{0:>25s} {1:+3.4f} mag'.format(name, mag))
colors = (('GROUND_JOHNSON_B', 'GROUND_JOHNSON_V'),
          ('GROUND_JOHNSON_V', 'GROUND_BESSELL_K'),
          ('GROUND_BESSELL_J', 'GROUND_BESSELL_K'),
          ('GaiaDR2_BP', 'GaiaDR2_RP'),
          ('GaiaDR2_BP', 'GaiaDR2_G'),
          ('GaiaDR2_G', 'GaiaDR2_RP'),
          ('GaiaDR2v2_BP', 'GaiaDR2v2_RP'),
          ('GaiaDR2v2_BP', 'GaiaDR2v2_G'),
          ('GaiaDR2v2_G', 'GaiaDR2v2_RP'),
          ('GaiaDR2_weiler_BPbright', 'GaiaDR2_weiler_RP'),
          ('GaiaDR2_weiler_BPfaint', 'GaiaDR2_weiler_RP'),
          ('GaiaDR2_weiler_BPbright', 'GaiaDR2_weiler_G'),
          ('GaiaDR2_weiler_BPfaint', 'GaiaDR2_weiler_G'),
          ('GaiaDR2_weiler_G', 'GaiaDR2_weiler_RP'))
color_values = {}
for color in colors:
    color_values[color] = mags[color[0]] - mags[color[1]]
    print('{0:>25s} - {1:<25s} = {2:3.4f} mag'.format(color[0], color[1], mags[color[0]] - mags[color[1]]))
          
Explanation: One can see the differences between the two flavors.
The theoretical spectrum is scaled to match the observed spectrum from 1.5 - 2.5 microns, and then it is used where the observed spectrum ends. The theoretical model of the Sun from Kurucz‘93 atlas using the following parameters when the Sun is at 1 au.
|log_Z | T_eff | log_g | V$_{Johnson}$ |
|------|-------|-------|---------------|
|+0.0  | 5777  |+4.44  | -26.76        |
The Sun is also know to have a Johnson V (vega-)magnitude of -26.76 mag.
Let's verify this.
End of explanation
<END_TASK>