cphot 0.1
A C++ tool for computing photometry from spectra.
vega.hpp
Go to the documentation of this file.
1 /**
2  * @defgroup VEGA Vega
3  * @brief Handle vega spec/mags/fluxes manipulations
4  *
5  * Class that handles vega spectrum and references. This class knows where to
6  * find the Vega synthetic spectrum taken from <a
7  * href="https://iopscience.iop.org/article/10.1086/420715"> Bohlin 2007 </a> in
8  * order to compute fluxes and magnitudes in given filters.
9  *
10  * \note the Vega zeropoints are defined by the magnitude of Vega being exactly zero in all filters.
11  */
12 #pragma once
13 #include "rquantities.hpp"
14 #include "votable.hpp"
15 #include <xtensor/xadapt.hpp>
16 #include <xtensor/xarray.hpp>
18 
19 namespace cphot {
20 
21 using DMatrix = xt::xarray<double, xt::layout_type::row_major>;
22 
23 /**
24  * @brief Interface to Vega reference data
25  *
26  * Class that handles vega spectrum and references. This class knows where to
27  * find the Vega synthetic spectrum (Bohlin 2007) in order to compute fluxes and
28  * magnitudes in given filters
29  *
30  * @ingroup VEGA
31  **/
32 class Vega {
33  public:
34  Vega(const DMatrix& wavelength,
35  const DMatrix& flux,
36  const QLength& wavelength_unit,
37  const QSpectralFluxDensity& flux_unit);
38  Vega(const std::vector<double>& wavelength,
39  const std::vector<double>& flux,
40  const QLength& wavelength_unit,
41  const QSpectralFluxDensity& flux_unit);
42  Vega();
43 
45  DMatrix get_wavelength(const QLength& in);
46  DMatrix get_flux();
47  DMatrix get_flux(const QSpectralFluxDensity& in);
48 
49  private:
50  DMatrix wavelength_nm; ///< Wavelength in nm
51  DMatrix flux_flam; ///< flux in flam
52 
53 };
54 
55 /**
56  * @brief Construct a new Vega object from hardcoded data
57  */
59  std::vector<std::size_t> shape = { cphot_vega::wavelength_nm.size() };
60  DMatrix xt_wave = xt::adapt(cphot_vega::wavelength_nm, shape);
61  DMatrix xt_flux = xt::adapt(cphot_vega::flux_flam, shape);
62  this->wavelength_nm = xt_wave;
63  this->flux_flam = xt_flux;
64 }
65 
66 /**
67  * @brief Construct a new Vega object from data
68  *
69  * @param wavelength wavelength array
70  * @param flux flux array of vega spectrum
71  * @param wavelength_unit wavelength unit
72  * @param flux_unit flux unit of the spectrum
73  */
75  const DMatrix& flux,
76  const QLength& wavelength_unit,
77  const QSpectralFluxDensity& flux_unit) {
78  this->wavelength_nm = wavelength * wavelength_unit.to(nm);
79  this->flux_flam = flux * flux_unit.to(flam);
80 }
81 
82 /**
83  * @brief Construct a new Vega object from data
84  *
85  * @param wavelength wavelength array
86  * @param flux flux array of vega spectrum
87  * @param wavelength_unit wavelength unit
88  * @param flux_unit flux unit of the spectrum
89  */
90 Vega::Vega(const std::vector<double>& wavelength,
91  const std::vector<double>& flux,
92  const QLength& wavelength_unit,
93  const QSpectralFluxDensity& flux_unit) {
94 
95  std::vector<std::size_t> shape = { wavelength.size() };
96  DMatrix xt_wave = xt::adapt(wavelength, shape);
97  DMatrix xt_flux = xt::adapt(flux, shape);
98  this->wavelength_nm = xt_wave * wavelength_unit.to(nm);
99  this->flux_flam = xt_flux * flux_unit.to(flam);
100 }
101 
102 /**
103  * @brief Construct a new Vega object from a votable
104  *
105  * @param infile votable containing the vega spectrum
106  * @return Vega object
107  *
108  * \ingroup VEGA
109  */
110 Vega vega_from_votable(const std::string& infile){
111 
112  votable::VOTable vega(infile);
113  const auto & wave = vega.get<double>("WAVELENGTH");
114  const auto & flux = vega.get<double>("FLUX");
115  const QLength wavelength_unit = units::parse_length(wave.unit);
116  const QSpectralFluxDensity flux_unit = units::parse_spectralflux(flux.unit);
117 
118  Vega v(wave.data, flux.data, wavelength_unit, flux_unit);
119  return v;
120 }
121 
122 /**
123  * @brief Get the internal wavelength in nm
124  *
125  * @return Vega wavelength in nm
126  */
128  return this->wavelength_nm;
129 }
130 
131 /**
132  * @brief Get the internal wavelength in requested units
133  *
134  * @param in requested units for the wavelength
135  * @return Vega wavelength units of in
136  */
137 DMatrix Vega::get_wavelength(const QLength& in) {
138  return this->wavelength_nm * nm.to(in);
139 }
140 
141 /**
142  * @brief Get the internal flux in flam
143  *
144  * @return Vega flux in flam
145  */
147  return this->flux_flam;
148 }
149 
150 /**
151  * @brief Get the internal flux in requested units
152  *
153  * @param in requested units for the flux
154  * @return Vega flux units of in
155  */
156 DMatrix Vega::get_flux(const QSpectralFluxDensity& in) {
157  return this->flux_flam * flam.to(in);
158 }
159 
160 } // namespace cphot
cphot_vega::wavelength_nm
const std::vector< double > wavelength_nm
Definition: vega_data.hpp:14
cphot::vega_from_votable
Vega vega_from_votable(const std::string &infile)
Construct a new Vega object from a votable.
Definition: vega.hpp:110
cphot_sun_theoretical::wavelength
const std::vector< double > wavelength
Definition: sun_data.hpp:15
cphot_sun_theoretical::flux
const std::vector< double > flux
Definition: sun_data.hpp:17
votable::VOTable
Class defining a very simple parser of XML VOTable.
Definition: votable.hpp:162
rquantities.hpp
cphot_sun_theoretical::flux_unit
const QSpectralFluxDensity flux_unit
Definition: sun_data.hpp:20
cphot::DMatrix
xt::xarray< double, xt::layout_type::row_major > DMatrix
Definition: filter.hpp:32
cphot::Vega::get_flux
DMatrix get_flux()
Get the internal flux in flam.
Definition: vega.hpp:146
units::parse_spectralflux
QSpectralFluxDensity parse_spectralflux(const std::string &str)
find length units from a string
Definition: rquantities.hpp:638
vega_data.hpp
cphot::Vega::get_wavelength
DMatrix get_wavelength()
Get the internal wavelength in nm.
Definition: vega.hpp:127
cphot::Vega
Interface to Vega reference data.
Definition: vega.hpp:32
cphot_vega::flux_flam
const std::vector< double > flux_flam
Definition: vega_data.hpp:16
cphot::Vega::Vega
Vega()
Construct a new Vega object from hardcoded data.
Definition: vega.hpp:58
cphot
Definition: filter.hpp:30
nm
constexpr QLength nm
Definition: rquantities.hpp:273
cphot_sun_theoretical::wavelength_unit
const QLength wavelength_unit
Definition: sun_data.hpp:19
flam
constexpr QSpectralFluxDensity flam
Definition: rquantities.hpp:361
units::parse_length
QLength parse_length(const std::string &str)
find length units from a string
Definition: rquantities.hpp:629
votable::VOTable::get
VOField< T > get(std::string field_name)
Retrieve field data.
Definition: votable.hpp:330
votable.hpp