8#ifndef mx_astro_cahoyAlbedos_hpp
9#define mx_astro_cahoyAlbedos_hpp
15#include "../math/constants.hpp"
26template <
typename _units>
30 typedef typename units::realT realT;
41 static const bool freq =
false;
47 static constexpr realT
fluxUnits =
static_cast<realT
>( 1 );
49 static constexpr const char *dataDirEnvVar =
"CAHOYALBEDO_DATADIR";
52 static std::string
fileName(
const paramsT ¶ms )
56 if( params.sep == 0.8 )
60 else if( params.sep == 2.0 )
64 else if( params.sep == 5.0 )
68 else if( params.sep == 10.0 )
80 fname +=
"x_albedos/00_Spectral_Albedos ";
83 snprintf( pstr, 9,
"%0.5f", params.phase );
94 std::vector<realT> &rawSpectrum,
95 const std::string &path,
96 const paramsT ¶ms )
122template <
typename _units>
125 typedef _units units;
126 typedef typename units::realT realT;
136 std::vector<realT> _sep;
137 std::vector<realT> _phase;
139 std::vector<realT> _lambda;
140 std::vector<std::vector<std::vector<realT>>> _ag;
144 std::vector<realT> &lambda
147 _sep = { 0.8, 2.0, 2.0, 5.0, 10.0 };
168 _ag.resize( _sep.size() );
169 for(
int i = 0; i < _ag.size(); ++i )
170 _ag[i].resize( _phase.size() );
174 for(
int i = 0; i < _sep.size(); ++i )
176 for(
int j = 0; j < _phase.size(); ++j )
210 int i_l, i_u, j_l, j_u;
213 if( lambda.size() != this->_spectrum.size() )
216 "cahoyGrid::setSpectrum",
218 "wavelength grid (lambda) is not the same size as used for openGrid, or loadGrid not yet called." );
229 i_l = _sep.size() - 1;
230 while( _sep[i_l] > sep && i_l > 0 )
234 while( i_u < _sep.size() - 1 )
236 if( _sep[i_u] >= sep )
241 j_l = _phase.size() - 1;
244 if( _phase[j_l] <= phase )
250 while( j_u < _phase.size() - 1 )
252 if( _phase[j_u] >= phase )
257 realT x = sep - _sep[i_l];
261 realT y = ( phase - _phase[j_l] );
267 for(
int i = 0; i < this->
_spectrum.size(); ++i )
269 x0 = _ag[i_l][j_l][i];
270 x1 = _ag[i_u][j_l][i];
272 if( y != 0 && j_u != j_l )
274 x0 += ( _ag[i_l][j_u][i] - _ag[i_l][j_l][i] ) * y / ( _phase[j_u] - _phase[j_l] );
275 x1 += ( _ag[i_u][j_u][i] - _ag[i_u][j_l][i] ) * y / ( _phase[j_u] - _phase[j_l] );
277 if( x == 0 || i_u == i_l )
280 this->
_spectrum[i] = x0 + ( x1 - x0 ) * x / ( _sep[i_u] - _sep[i_l] );
A class for working with astronomical spectra.
error_t readColumns(const std::string &fname, arrTs &...arrays)
Read in columns from a text file.
error_t
The mxlib error codes.
@ noerror
No error has occurred.
#define mxError(esrc, ecode, expl)
This reports an mxlib specific error.
constexpr T pi()
Get the value of pi.
#define MXE_FILERERR
An error occurred while reading from a file.
#define MXE_INVALIDARG
An argument was invalid.
std::string convertToString(const typeT &value, int precision=0)
Convert a numerical value to a string.
Old version. Deprecated. Declares and defines the mxlib error reporting system.
A utility to read in columns from a text file.
Class to manage an astronomical spectrum.
error_t setSpectrum(gridT &lambda)
Load the spectrum and interpolate it onto a wavelength scale.
int setParameters(const paramsT ¶ms)
Set the parameters of the spectrum, using the underlying spectrums parameter type.
Base spectrum class which provides manipulation and characterization functionality.
std::vector< realT > _spectrum
Contains the spectrum after it is set.
int loadGrid(int metal, std::vector< realT > &lambda)
Load the grid into memory for one of the metallicities and pre-interpolate onto the wavelength scale.
int setSpectrum(std::vector< realT > &lambda)
Get an interpolated spectrum at arbitrary non-grid point using bilinear interpolation.
int setParameters(const paramsT ¶ms)
Set the separatio and phase of the spectrum.
An albedo spectrum directly from the Cahoy et al (2010) cahoy_2010 grid.
static constexpr realT fluxUnits
Geometric albedos are dimensionless.
static std::string fileName(const paramsT ¶ms)
The file name is constructed from the paramerters sep, metal, and phase.
static constexpr realT wavelengthUnits
Convert from um to SI m.
static error_t readSpectrum(std::vector< realT > &rawLambda, std::vector< realT > &rawSpectrum, const std::string &path, const paramsT ¶ms)
Read the spectrum from the file specified by path. Extra columns are discarded.
A dummy class to allow mx::readColumns to skip a column(s) in a file without requiring memory allocat...
Unit specifications and conversions.