8 #ifndef mx_astro_cahoyAlbedos_hpp
9 #define mx_astro_cahoyAlbedos_hpp
12 #include "../ioutils/readColumns.hpp"
23 template<
typename _units>
27 typedef typename units::realT realT;
37 static const bool freq =
false;
43 static constexpr realT
fluxUnits =
static_cast<realT
>(1);
45 static constexpr
const char * dataDirEnvVar =
"CAHOYALBEDO_DATADIR";
48 static std::string
fileName(
const paramsT & params )
56 else if(params.sep == 2.0)
60 else if(params.sep == 5.0)
64 else if(params.sep == 10.0)
70 mxError(
"cahoyAlbedos::fileName", MXE_INVALIDARG,
"invalid separation (params.sep)");
75 fname += ioutils::convertToString<int>(params.metal);
76 fname +=
"x_albedos/00_Spectral_Albedos ";
79 snprintf(pstr, 9,
"%0.5f", params.phase);
91 std::vector<realT> & rawSpectrum,
92 const std::string & path,
93 const paramsT & params
120 template<
typename _units>
123 typedef _units units;
124 typedef typename units::realT realT;
134 std::vector<realT> _sep;
135 std::vector<realT> _phase;
137 std::vector<realT> _lambda;
138 std::vector<std::vector<std::vector<realT>>> _ag;
142 std::vector<realT> & lambda
145 _sep = {0.8, 2.0, 2.0, 5.0, 10.0};
146 _phase = {0.0, 0.1745, 0.3491, 0.5236, 0.6981, 0.8727, 1.0472, 1.2217, 1.3963,1.5708,1.7453,1.9199, 2.0944, 2.2689, 2.4435, 2.6180, 2.7925,2.9671, 3.139};
148 _ag.resize( _sep.size());
149 for(
int i=0; i< _ag.size(); ++i) _ag[i].resize(_phase.size());
153 for(
int i=0; i< _sep.size(); ++i)
155 for(
int j=0; j < _phase.size(); ++j)
160 mxError(
"cahoGrid::loadGrid", MXE_FILERERR,
"Error reading albedo spectrum.");
188 int i_l, i_u, j_l, j_u;
192 if(lambda.size() != this->_spectrum.size())
194 mxError(
"cahoyGrid::setSpectrum", MXE_INVALIDARG,
"wavelength grid (lambda) is not the same size as used for openGrid, or loadGrid not yet called.");
199 phase = fmod(_params.phase, math::pi<realT>());
200 if(phase < 0) phase += math::pi<realT>();
205 while( _sep[i_l] > sep && i_l > 0) --i_l;
208 while( i_u < _sep.size()-1)
210 if(_sep[i_u] >= sep)
break;
214 j_l = _phase.size()-1;
217 if(_phase[j_l] <= phase)
break;
222 while( j_u < _phase.size()-1)
224 if(_phase[j_u] >= phase)
break;
228 realT x = sep - _sep[i_l];
231 realT y = (phase - _phase[j_l]);
236 for(
int i=0; i< this->
_spectrum.size(); ++i)
238 x0 = _ag[i_l][j_l][i];
239 x1 = _ag[i_u][j_l][i];
241 if(y != 0 && j_u != j_l)
243 x0 += (_ag[i_l][j_u][i] - _ag[i_l][j_l][i])*y/(_phase[j_u] - _phase[j_l]);
244 x1 += (_ag[i_u][j_u][i] - _ag[i_u][j_l][i])*y/(_phase[j_u] - _phase[j_l]);
246 if( x == 0 || i_u==i_l ) this->
_spectrum[i] = x0;
247 else this->
_spectrum[i] = x0 + (x1-x0)*x/( _sep[i_u] - _sep[i_l]);
int readColumns(const std::string &fname, arrTs &... arrays)
Read in columns from a text file.
Class to manage an astronomical spectrum.
int 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.
A class to manage interpolation in separation and phase on the albedo spectrum grid from Cahoy et al ...
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) grid.
static constexpr realT fluxUnits
Geometric albedos are dimensionless.
static int 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.
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.
A dummy class to allow mx::readColumns to skip a column(s) in a file without requiring memory allocat...
Unit specifications and conversions.