Line data Source code
1 : /** \file astroSpectra.hpp
2 : * \author Jared R. Males
3 : * \brief Type definitions for the astronomical spectral libraries.
4 : * \ingroup astrophot
5 : *
6 : */
7 :
8 : #ifndef mx_astro_astroSpectra_hpp
9 : #define mx_astro_astroSpectra_hpp
10 :
11 : #include "units.hpp"
12 : #include "../ioutils/readColumns.hpp"
13 :
14 : namespace mx
15 : {
16 : namespace astro
17 : {
18 :
19 : /// A basic spectrum
20 : /**
21 : * \ingroup astrophot_spectra
22 : */
23 : template <typename _units>
24 : struct basicSpectrum
25 : {
26 : typedef _units units;
27 : typedef typename units::realT realT;
28 :
29 : static const bool freq = false;
30 :
31 : typedef std::string paramsT; ///< The parameter is a string name.
32 :
33 : /// Specify how to convert to SI wavelength units. No conversions are performed in the basic spectrum
34 : static constexpr realT wavelengthUnits = static_cast<realT>( 1 );
35 :
36 : /// Specify how to convert to SI flux units. No conversions are performed in the basic spectrum
37 : static constexpr realT fluxUnits = static_cast<realT>( 1 );
38 :
39 : /// The data directory environment variable name.
40 : static constexpr const char *dataDirEnvVar = 0;
41 :
42 : /// This function should calculate the file name (without the path) for the spectrum parameters.
43 : static std::string
44 0 : fileName( const paramsT &name /**< [in] The parameters of the spectrum, in this case just its file name.*/ )
45 : {
46 0 : return name;
47 : }
48 :
49 : /// This function reads the spectrum, returning its raw wavelength and spectrum points.
50 : /** No unit conversions or interpolations should take place.
51 : */
52 0 : static error_t readSpectrum( std::vector<realT> &rawLambda, /**< [out] the raw wavelength. Should be empty on
53 : input. */
54 : std::vector<realT> &rawSpectrum, /**< [out] the raw spectrum. Should be empty on
55 : input. */
56 : const std::string &path, /**< [in] the full path to the file. */
57 : const paramsT ¶ms /**< [in] the parameters needed to construct the
58 : spectrum */
59 : )
60 : {
61 0 : return mx::ioutils::readColumns( path, rawLambda, rawSpectrum );
62 : }
63 : };
64 :
65 : /// A spectrum from the astroFilt filter library
66 : /**
67 : * \ingroup astrophot_spectra
68 : */
69 : template <typename _units, bool _rsr = true>
70 : struct astroFilter
71 : {
72 : typedef _units units;
73 : typedef typename units::realT realT;
74 :
75 : static const bool freq = false;
76 :
77 : typedef std::string paramsT; ///< The astroFilters are parameterized by name.
78 :
79 : /// Convert from um to SI m
80 : static constexpr realT wavelengthUnits = static_cast<realT>( 1e6 );
81 :
82 : /// No conversion is performed on filter transmission.
83 : static constexpr realT fluxUnits = static_cast<realT>( 1 );
84 :
85 : static constexpr const char *dataDirEnvVar = "ASTROFILT_DATADIR";
86 :
87 0 : static std::string fileName( const std::string &name )
88 : {
89 0 : return name + ".dat";
90 : }
91 :
92 0 : static error_t readSpectrum( std::vector<realT> &rawLambda, /**< [out] the raw wavelength. Should be empty on
93 : input. */
94 : std::vector<realT> &rawSpectrum, /**< [out] the raw spectrum. Should be empty on
95 : input. */
96 : const std::string &path, /**< [in] the full path to the file. */
97 : const paramsT ¶ms /**< [in] the parameters needed to construct the
98 : spectrum */
99 : )
100 : {
101 0 : mx::error_t errc = mx::ioutils::readColumns( path, rawLambda, rawSpectrum );
102 0 : if( !!errc )
103 : {
104 0 : return errc;
105 : }
106 :
107 0 : realT max = 0;
108 :
109 0 : for( int i = 0; i < rawLambda.size(); ++i )
110 : {
111 : // if(_rsr) rawSpectrum[i] = rawSpectrum[i]*rawLambda[i];
112 0 : if( rawSpectrum[i] > max )
113 0 : max = rawSpectrum[i];
114 : }
115 :
116 0 : for( int i = 0; i < rawLambda.size(); ++i )
117 : {
118 0 : rawSpectrum[i] /= max;
119 : }
120 :
121 0 : return error_t::noerror;
122 : }
123 : };
124 :
125 : /// A square-wave filter spectrum
126 : /** Parameters specify the central wavelength, width, and sampling (all in microns) of a square-wave type filter.
127 : *
128 : * To create this filter:
129 : * \code
130 : * typedef double realT;
131 : *
132 : * realT lam0 = 0.5; //Central wavelength in microns
133 : * realT fw = 0.05; //Full-width, in microns.
134 : * realT dlam = 0.001; //Delta-lambda for specifying the defining points. See note.
135 : *
136 : * astroSpectrum<sqWaveFilter<units::si<realT>>> filt({ lam0, fw, dlam});
137 : *
138 : * filt.setSpectrum(grid_meters); // grid_meters is a vector<realT> specifying the wavelength grid in meters
139 : *
140 : * \endcode
141 : *
142 : * Note that dlam specifies how sharp the filter edges are when interpolated. Larger values will make the filter more
143 : * trapezoidal.
144 : *
145 : * \ingroup astrophot_spectra
146 : */
147 : template <typename _units, bool _rsr = true>
148 : struct sqWaveFilter
149 : {
150 : typedef _units units;
151 : typedef typename units::realT realT;
152 :
153 : static const bool freq = false;
154 :
155 : /// The square wave is parameterized by the central wavelength, width, and sampling (all in microns).
156 : typedef struct
157 : {
158 : realT lam0; ///< The central Wavelength in microns
159 : realT fw; ///< The full width of the filter in microns
160 : realT dlam; ///< The wavelength sampling to use in microns.
161 : } paramsT;
162 :
163 : /// Convert from um to SI m
164 : static constexpr realT wavelengthUnits = static_cast<realT>( 1e6 );
165 :
166 : /// No conversion is performed on filter transmission.
167 : static constexpr realT fluxUnits = static_cast<realT>( 1 );
168 :
169 : static constexpr const char *dataDirEnvVar = 0;
170 :
171 0 : static std::string fileName( const paramsT ¶ms )
172 : {
173 0 : return " "; // must not be empty to avoid error
174 : }
175 :
176 0 : static error_t readSpectrum( std::vector<realT> &rawLambda, /**< [out] the raw wavelength. Should be empty on
177 : input. */
178 : std::vector<realT> &rawSpectrum, /**< [out] the raw spectrum. Should be empty on
179 : input. */
180 : const std::string &path, /**< [in] the full path to the file. */
181 : const paramsT ¶ms /**< [in] the parameters needed to construct the
182 : spectrum */
183 : )
184 : {
185 0 : rawLambda.resize( 4 );
186 0 : rawSpectrum.resize( 4 );
187 :
188 0 : rawLambda[0] = params.lam0 - 0.5 * params.fw - 0.5 * params.dlam;
189 0 : rawSpectrum[0] = 0.0;
190 :
191 0 : rawLambda[1] = params.lam0 - 0.5 * params.fw + 0.5 * params.dlam;
192 0 : rawSpectrum[1] = 1.0;
193 :
194 0 : rawLambda[2] = params.lam0 + 0.5 * params.fw - 0.5 * params.dlam;
195 0 : rawSpectrum[2] = 1.0;
196 :
197 0 : rawLambda[3] = params.lam0 + 0.5 * params.fw + 0.5 * params.dlam;
198 0 : rawSpectrum[3] = 0.0;
199 :
200 0 : return error_t::noerror;
201 : }
202 : };
203 :
204 : /// A spectrum from the HST calspec library
205 : /** See http://www.stsci.edu/hst/observatory/crds/calspec.html
206 : *
207 : * \ingroup astrophot_spectra
208 : */
209 : template <typename _units>
210 : struct calspecSpectrum
211 : {
212 : typedef _units units;
213 : typedef typename units::realT realT;
214 :
215 : static const bool freq = false;
216 :
217 : typedef std::string paramsT; ///< The calspec Spectra are parameterized by star name.
218 :
219 : /// Convert from A to SI m
220 : static constexpr realT wavelengthUnits = static_cast<realT>( 1e10 );
221 :
222 : /// Convert from erg s-1 cm-2 A-1 to SI W m-3
223 : static constexpr realT fluxUnits =
224 : static_cast<realT>( 1e7 ) / ( static_cast<realT>( 1e4 ) * static_cast<realT>( 1e10 ) );
225 :
226 : static constexpr const char *dataDirEnvVar = "CALSPEC_DATADIR";
227 :
228 : /// The file name is found from the star's name.
229 0 : static std::string fileName( const std::string &name )
230 : {
231 0 : if( name == "alpha_lyr" || name == "vega" )
232 0 : return "alpha_lyr_stis_005.asc";
233 0 : else if( name == "1740346" )
234 0 : return "1740346_nic_002.ascii";
235 0 : else if( name == "sun" || name == "sun_reference" )
236 0 : return "sun_reference_stis.002.asc";
237 :
238 0 : return "";
239 : }
240 :
241 : /// Read a CALSPEC spectrum, which is a simple two column ASCII format.
242 0 : static error_t readSpectrum( std::vector<realT> &rawLambda, /**< [out] the raw wavelength. Should be empty on
243 : input. */
244 : std::vector<realT> &rawSpectrum, /**< [out] the raw spectrum. Should be empty on
245 : input. */
246 : const std::string &path, /**< [in] the full path to the file. */
247 : const paramsT ¶ms /**< [in] the parameters needed to construct the
248 : spectrum */
249 : )
250 : {
251 0 : return mx::ioutils::readColumns( path, rawLambda, rawSpectrum );
252 : }
253 : };
254 :
255 : /// A spectrum from the Pickles library
256 : /**
257 : * \ingroup astrophot_spectra
258 : */
259 : template <typename _units>
260 : struct picklesSpectrum
261 : {
262 : typedef _units units;
263 : typedef typename units::realT realT;
264 :
265 : static const bool freq = false;
266 :
267 : typedef std::string paramsT; ///< The Pickles spectra are parameterized by a spectral type string.
268 :
269 : /// Convert from A to SI m
270 : static constexpr realT wavelengthUnits = static_cast<realT>( 1e10 );
271 :
272 : /// The Pickles spectra are dimensionless.
273 : static constexpr realT fluxUnits = static_cast<realT>( 1 );
274 :
275 : /// The Pickles spectra location is specified by the PICKLES_DATADIR environment variable.
276 : static constexpr const char *dataDirEnvVar = "PICKLES_DATADIR";
277 :
278 : /// The name of the datafile is constructed from its spectral type string.
279 0 : static std::string fileName( const std::string &spt )
280 : {
281 0 : return "uk" + ioutils::toLower( spt ) + ".dat";
282 : }
283 :
284 : /// Read a Pickles spectrum, which for these purposes is a simple two column ASCII format.
285 0 : static error_t readSpectrum( std::vector<realT> &rawLambda, /**< [out] the raw wavelength. Should be empty on
286 : input. */
287 : std::vector<realT> &rawSpectrum, /**< [out] the raw spectrum. Should be empty on
288 : input. */
289 : const std::string &path, /**< [in] the full path to the file. */
290 : const paramsT ¶ms /**< [in] the parameters needed to construct the
291 : spectrum */
292 : )
293 : {
294 0 : return mx::ioutils::readColumns( path, rawLambda, rawSpectrum );
295 : }
296 : };
297 :
298 : /// Earth Albedo Spectra
299 : /** The spectra can be one of:
300 : * - "EPOXI" returns the apparent albedo spectrum from Cowan and Strait (2013) \cite cowan_2013.
301 : * - "RawEarthshine" returns the unnormalized albedo spectrum measured using Earthshine by Turnbull et al. (2006)
302 : * \cite turnbull_20016
303 : * - "Earthshine" returns the Earthshine spectrum normalized to match the EPOXI result of 0.27 in the 550 nm band.
304 : *
305 : * \ingroup astrophot_spectra
306 : */
307 : template <typename _units, typename verboseT = verbose::d>
308 : struct earthAlbedo
309 : {
310 : typedef _units units;
311 : typedef typename units::realT realT;
312 :
313 : static const bool freq = false;
314 :
315 : typedef std::string paramsT; ///< The name of the spectrum can be "EPOXI", "Earthshine", or "RawEarthshine".
316 :
317 : /// Convert from A to SI m
318 : static constexpr realT wavelengthUnits = static_cast<realT>( 1e6 );
319 :
320 : /// The Earthshine is a dimensionless albedo.
321 : static constexpr realT fluxUnits = static_cast<realT>( 1 );
322 :
323 : /// The location is specified by the EARTHSHINE_DATADIR environment variable.
324 : static constexpr const char *dataDirEnvVar = "EARTHSHINE_DATADIR";
325 :
326 : /// The name of the datafile is a constant.
327 0 : static std::string fileName( const std::string &name )
328 : {
329 0 : if( name == "EPOXI" )
330 0 : return "cowan_2013_EPOXI_albedo.dat";
331 0 : if( name == "Earthshine" )
332 0 : return "earthshine_epoxi_normalized.dat";
333 0 : if( name == "RawEarthshine" )
334 0 : return "Earthshine/F7_opt_NIR_ES_data.txt";
335 :
336 0 : internal::mxlib_error_report<verboseT>( error_t::invalidarg, "name not recognized." );
337 :
338 0 : return "";
339 : }
340 :
341 : /// Read the Earthshine albedo spectrum, which is a simple two column ASCII format.
342 0 : static error_t readSpectrum( std::vector<realT> &rawLambda, /**< [out] the raw wavelength. Should be empty on
343 : input. */
344 : std::vector<realT> &rawSpectrum, /**< [out] the raw spectrum. Should be empty on
345 : input. */
346 : const std::string &path, /**< [in] the full path to the file. */
347 : const paramsT ¶ms /**< [in] the parameters needed to construct the
348 : spectrum */
349 : )
350 : {
351 0 : return mx::ioutils::readColumns( path, rawLambda, rawSpectrum );
352 : }
353 : };
354 :
355 : /// Venus Spectra
356 : /**
357 : *
358 : * \ingroup astrophot_spectra
359 : */
360 : template <typename _units, typename verboseT = verbose::d>
361 : struct venusAlbedo
362 : {
363 : typedef _units units;
364 : typedef typename units::realT realT;
365 :
366 : static const bool freq = false;
367 :
368 : typedef std::string paramsT; ///< The name of the spectrum can be "venus"
369 :
370 : /// Convert from A to SI m
371 : static constexpr realT wavelengthUnits = static_cast<realT>( 1e6 );
372 :
373 : /// The Earthshine is a dimensionless albedo.
374 : static constexpr realT fluxUnits = static_cast<realT>( 1 );
375 :
376 : /// The location is specified by the EARTHSHINE_DATADIR environment variable.
377 : static constexpr const char *dataDirEnvVar = "VENUS_DATADIR";
378 :
379 : /// The name of the datafile is a constant.
380 0 : static std::string fileName( const std::string &name )
381 : {
382 0 : if( name == "Venus" )
383 0 : return "venus_combined_albedo.dat";
384 :
385 0 : internal::mxlib_error_report<verboseT>( error_t::invalidarg, "name not recognized." );
386 :
387 0 : return "";
388 : }
389 :
390 : /// Read the Earthshine albedo spectrum, which is a simple two column ASCII format.
391 0 : static error_t readSpectrum( std::vector<realT> &rawLambda, /**< [out] the raw wavelength. Should be empty on
392 : input. */
393 : std::vector<realT> &rawSpectrum, /**< [out] the raw spectrum. Should be empty on
394 : input. */
395 : const std::string &path, /**< [in] the full path to the file. */
396 : const paramsT ¶ms /**< [in] the parameters needed to construct the
397 : spectrum */
398 : )
399 : {
400 0 : return mx::ioutils::readColumns( path, rawLambda, rawSpectrum );
401 : }
402 : };
403 :
404 : } // namespace astro
405 :
406 : } // namespace mx
407 :
408 : #endif // mx_astro_astroSpectra_hpp
|