8#ifndef mx_astro_astroSpectrum_hpp
9#define mx_astro_astroSpectrum_hpp
28template <
typename realT>
64 template <
typename compSpectrumT>
70 for(
int i = 0; i <
_spectrum.size(); ++i )
86 for(
int i = 0; i <
_spectrum.size(); ++i )
103 template <
typename compSpectrumT>
104 realT
mean(
const compSpectrumT &T )
106 realT sum1 = 0, sum2 = 0;
108 for(
int i = 0; i <
_spectrum.size(); ++i )
136 std::vector<realT> &lambda
139 size_t N = lambda.size();
140 realT dl = lambda[1] - lambda[0];
141 realT half =
static_cast<realT
>( 0.5 );
144 for(
int i = 0; i < N; ++i )
151 for(
int i = 1; i < N - 1; ++i )
156 lambda0 = half * lambda[0] *
_spectrum[0];
157 for(
int i = 1; i < N - 1; ++i )
161 lambda0 += half * lambda[N - 1] *
_spectrum[N - 1];
162 lambda0 *= dl / max / weff;
167 while( i < lambda.size() )
202 template <
class filterT>
206 const realT &lambda_0,
207 const std::vector<realT> &lambda,
212 charFlux( flambda0, fnu0, fphot0, lambda_0, lambda, trans._spectrum );
230 const realT &lambda_0,
231 const std::vector<realT> &lambda,
232 const std::vector<realT> &trans
239 size_t N = lambda.size();
240 realT dl = lambda[1] - lambda[0];
241 realT half =
static_cast<realT
>( 0.5 );
245 realT denom = half * trans[0] * lambda[0];
246 for(
int i = 1; i < N - 1; ++i )
248 denom += trans[i] * lambda[i];
250 denom += half * trans[N - 1] * lambda[N - 1];
253 realT num = half *
_spectrum[0] * trans[0] * lambda[0];
254 for(
int i = 1; i < N - 1; ++i )
256 num +=
_spectrum[i] * trans[i] * lambda[i];
258 num += half *
_spectrum[N - 1] * trans[N - 1] * lambda[N - 1];
261 flambda0 = num / denom;
265 denom = half * trans[0] / lambda[0];
266 for(
int i = 1; i < N - 1; ++i )
268 denom += trans[i] / lambda[i];
270 denom += half * trans[N - 1] / lambda[N - 1];
277 fphot0 = flambda0 * lambda_0 / ( h * c );
297template <
typename _spectrumT,
bool freq = false,
typename verboseT = verbose::d>
300 typedef _spectrumT spectrumT;
301 typedef typename spectrumT::units units;
302 typedef typename units::realT realT;
303 typedef typename spectrumT::paramsT paramsT;
323 const std::string &dataDir
334 if( spectrumT::dataDirEnvVar )
348 const std::string &dataDir
358 template <
typename gr
idT>
363 std::vector<realT> rawLambda;
364 std::vector<realT> rawSpectrum;
366 std::string fileName = spectrumT::fileName(
_params );
370 if( fileName.size() < 1 )
375 if(
_dataDir ==
"" && fileName[0] ==
'/' )
387 error_t rv = spectrumT::readSpectrum( rawLambda, rawSpectrum, path,
_params );
394 for(
int i = 0; i < rawLambda.size(); ++i )
396 rawLambda[i] /= spectrumT::wavelengthUnits / ( units::length );
397 rawSpectrum[i] /= spectrumT::fluxUnits /
398 ( units::energy / ( units::time * units::length * units::length * units::length ) );
403 for(
int i = 0; i < lambda.size(); ++i )
405 if( !std::isnormal( this->
_spectrum[i] ) )
Utilities for working with the environment.
constexpr units::realT c()
The speed of light.
constexpr units::realT h()
Planck Constant.
error_t
The mxlib error codes.
@ noerror
No error has occurred.
@ paramnotset
A parameter was not set.
error_t mxlib_error_report(const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
Print a report to stderr given an mxlib error_t code and explanation and return the code.
int gsl_interpolate(const gsl_interp_type *interpT, realT *xin, realT *yin, size_t Nin, realT *xout, realT *yout, size_t Nout)
Interpolate a 1-D data X vs Y discrete function onto a new X axis.
std::string getEnv(const std::string &estr)
Return the value of an environment variable.
Wrappers for using the GNU Scientific Library 1-D interpolation functions.
A utility to read in columns from a text file.
std::string _dataDir
The directory containing the spectrum.
astroSpectrum(const paramsT ¶ms)
Constructor specifying name, the enivronment will be queried for data directory.
error_t setSpectrum(gridT &lambda)
Load the spectrum and interpolate it onto a wavelength scale.
astroSpectrum(const paramsT ¶ms, const std::string &dataDir)
Constructor specifying name and data directory.
int setParameters(const paramsT ¶ms)
Set the parameters of the spectrum, using the underlying spectrums parameter type.
astroSpectrum()
Default c'tor.
int setParameters(const paramsT ¶ms, const std::string &dataDir)
Set the parameters of the spectrum, using the underlying spectrum's parameter type.
Base spectrum class which provides manipulation and characterization functionality.
size_t size()
Get the current size of the spectrum.
const realT operator[](size_t i) const
Access a single point in the spectrum, specified by its vector index.
void charTrans(realT &lambda0, realT &weff, realT &max, realT &fwhm, std::vector< realT > &lambda)
Characterize the spectrum as a filter transmission curve.
realT & operator[](size_t i)
Access a single point in the spectrum, specified by its vector index.
realT mean()
Calculate the mean value of the spectrum.
void charFlux(realT &flambda0, realT &fnu0, realT &fphot0, const realT &lambda_0, const std::vector< realT > &lambda, const std::vector< realT > &trans)
Characterize the flux densities of the spectrum w.r.t. a filter transmission curve.
void charFlux(realT &flambda0, realT &fnu0, realT &fphot0, const realT &lambda_0, const std::vector< realT > &lambda, const filterT &trans)
Characterize the flux densities of the spectrum w.r.t. a filter transmission curve.
std::vector< realT > _spectrum
Contains the spectrum after it is set.
baseSpectrum< realT > operator*(const compSpectrumT &spec)
Multiply two spectra together.
realT mean(const compSpectrumT &T)
Calculate the mean value of the spectrum when mutiplied by another.
Unit specifications and conversions.