cphot 0.1
A C++ tool for computing photometry from spectra.
sun.hpp
Go to the documentation of this file.
1 /**
2  * @defgroup SUN Sun
3  * @brief Handle the Sun Spectrum
4  *
5  * Observed solar spectrum comes from:
6  * ftp://ftp.stsci.edu/cdbs/current_calspec/sun_reference_stis_001.fits
7  *
8  * and theoretical spectrum comes from:
9  * ftp://ftp.stsci.edu/cdbs/grid/k93models/standards/sun_kurucz93.fits
10  *
11  * The theoretical spectrum is scaled to match the observed spectrum from 1.5 -
12  * 2.5 microns, and then it is used where the observed spectrum ends.
13  * The theoretical model of the Sun from Kurucz'93 atlas using the following
14  * parameters when the Sun is at 1 au.
15  *
16  * log_Z | T_eff | log_g | V_{Johnson}
17  * ------- | ------- | ------ | --------------
18  * +0.0 | 5777 K | +4.44 | -26.75 mag
19  */
20 #pragma once
21 #include "rquantities.hpp"
22 #include <cmath>
23 #include <exception>
24 #include <iostream>
25 #include <regex>
26 #include <stdexcept>
27 #include <string>
28 #include <xtensor/xadapt.hpp>
29 #include <xtensor/xarray.hpp>
31 
32 
33 
34 namespace cphot {
35 
36 using DMatrix = xt::xarray<double, xt::layout_type::row_major>;
37 
38 /**
39  * @ingroup SUN
40  * @brief Class that handles the Sun's spectrum and references.
41  *
42  */
43 class Sun{
44  private:
45  DMatrix wavelength_nm; ///< Wavelength in nm
46  DMatrix flux_flam; ///< flux in flam
47  QLength distance; ///< distance to the sun
48  double distance_conversion; ///< conversion factor for distance
49 
50  public:
51  Sun(const QLength & distance=1 * au,
52  const std::string & flavor="theoretical");
53 
55  DMatrix get_wavelength(const QLength& in);
56  DMatrix get_flux();
57  DMatrix get_flux(const QSpectralFluxDensity& in);
58 
59 };
60 
61 /**
62  * @brief Construct a new Sun object
63  *
64  * @param distance to the Sun (default 1 au)
65  * @param flavor theoretical or observed (default theoretical)
66  */
67 Sun::Sun(const QLength & distance,
68  const std::string & flavor){
69 
70  this->distance = distance;
71  if (flavor.compare("theoretical") == 0){
72  // read the theoretical spectrum
74  this->flux_flam = xt::adapt(cphot_sun_theoretical::flux) * cphot_sun_theoretical::flux_unit.to(flam);
75  // distance_conversion = (default distance / distance) ** 2
76  this->distance_conversion = std::pow((cphot_sun_theoretical::distance/distance).value, 2);
77  } else {
78  // read the theoretical spectrum
79  this->wavelength_nm = xt::adapt(cphot_sun_observed::wavelength) * cphot_sun_observed::wavelength_unit.to(nm);
80  this->flux_flam = xt::adapt(cphot_sun_observed::flux) * cphot_sun_observed::flux_unit.to(flam);
81  this->distance_conversion = std::pow((cphot_sun_theoretical::distance/distance).value, 2);
82  }
83 }
84 
85 /**
86  * @brief Get the internal wavelength in nm
87  *
88  * @return Sun wavelength in nm
89  */
91  return this->wavelength_nm;
92 }
93 
94 /**
95  * @brief Get the internal wavelength in requested units
96  *
97  * @param in requested units for the wavelength
98  * @return Sun wavelength units of in
99  */
100 DMatrix Sun::get_wavelength(const QLength& in) {
101  return this->wavelength_nm * nm.to(in);
102 }
103 
104 /**
105  * @brief Get the internal flux in flam
106  *
107  * @return Sun flux in flam
108  */
110  return this->flux_flam * this->distance_conversion;
111 }
112 
113 /**
114  * @brief Get the internal flux in requested units
115  *
116  * @param in requested units for the flux
117  * @return Sun flux units of in
118  */
119 DMatrix Sun::get_flux(const QSpectralFluxDensity& in) {
120  return this->flux_flam * flam.to(in) * this->distance_conversion;;
121 }
122 
123 
124 } // namespace cphot
cphot::Sun::Sun
Sun(const QLength &distance=1 *au, const std::string &flavor="theoretical")
Construct a new Sun object.
Definition: sun.hpp:67
cphot_sun_theoretical::wavelength
const std::vector< double > wavelength
Definition: sun_data.hpp:15
cphot_sun_observed::flux_unit
const QSpectralFluxDensity flux_unit
Definition: sun_data.hpp:32
cphot_sun_theoretical::flux
const std::vector< double > flux
Definition: sun_data.hpp:17
rquantities.hpp
cphot_sun_observed::wavelength_unit
const QLength wavelength_unit
Definition: sun_data.hpp:31
cphot_sun_theoretical::flux_unit
const QSpectralFluxDensity flux_unit
Definition: sun_data.hpp:20
cphot_sun_observed::flux
const std::vector< double > flux
Definition: sun_data.hpp:29
cphot::DMatrix
xt::xarray< double, xt::layout_type::row_major > DMatrix
Definition: filter.hpp:32
au
constexpr QLength au
Definition: rquantities.hpp:349
cphot::Sun::get_flux
DMatrix get_flux()
Get the internal flux in flam.
Definition: sun.hpp:109
cphot
Definition: filter.hpp:30
sun_data.hpp
cphot_sun_observed::wavelength
const std::vector< double > wavelength
Definition: sun_data.hpp:27
cphot::Sun
Class that handles the Sun's spectrum and references.
Definition: sun.hpp:43
cphot::Sun::get_wavelength
DMatrix get_wavelength()
Get the internal wavelength in nm.
Definition: sun.hpp:90
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
value
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1222
cphot_sun_theoretical::distance
const QLength distance
Definition: sun_data.hpp:21