8#ifndef turbSequence_hpp
9#define turbSequence_hpp
16#include "../../ioutils/fileUtils.hpp"
17#include "../../ioutils/fits/fitsFile.hpp"
18#include "../../improc/eigenCube.hpp"
20#include "wavefront.hpp"
29template <
typename _realT>
33 typedef Eigen::Array<realT, Eigen::Dynamic, Eigen::Dynamic> imageT;
35 std::vector<std::string> _phaseFnames;
36 std::vector<std::string> _ampFnames;
47 int _currFrameNo{ 0 };
50 realT _F0Photons{ 2e11 };
60 improc::eigenCube<realT> _currPhase;
61 improc::eigenCube<realT> _currAmp;
63 bool _phaseOnly{
false };
110 void wfPS( realT ps )
121 void F0Photons( realT f0 )
132 void starMag( realT sm )
146 _pixVal = sqrt( _F0Photons ) * pow( 10., -0.2 * _starMag ) * _wfPS;
157 int turbFnames( std::string dir,
int max = 0 );
159 void openPhaseFrame(
int fn );
161 void nextPhase( wavefront<realT> &wf );
163 void nextWF( wavefront<realT> &wf );
166template <
typename realT>
167int turbSequence<realT>::turbFnames( std::string dir,
int max )
172 if( _phaseFnames.size() == 0 )
174 mxError(
"turbSequence", MXE_FILENOTFOUND,
"No turbulent phase files found." );
178 if( _ampFnames.size() == 0 )
180 std::cerr <<
"turbSequence: no turbulent amplitude files found.\n";
187 _phaseFnames.erase( _phaseFnames.begin() + max, _phaseFnames.end() );
188 if( _phaseOnly ==
false )
189 _ampFnames.erase( _ampFnames.begin() + max, _ampFnames.end() );
192 _files = _phaseFnames.size();
196 _size = _currPhase.rows();
197 _nPerCube = _currPhase.planes();
199 _frames = _nPerCube * _phaseFnames.size();
202template <
typename realT>
203void turbSequence<realT>::openPhaseFrame(
int fn )
205 fits::fitsFile<float> ff;
207 std::cout << _phaseFnames[fn] <<
"\n";
209 ff.read( _phaseFnames[fn], _currPhase );
212 if( _phaseOnly ==
false )
214 ff.read( _ampFnames[fn], _currAmp );
222template <
typename realT>
223void turbSequence<realT>::nextPhase( wavefront<realT> &wf )
226 int Npix = _pupil->sum();
228 if( _currFrameNo > _nPerCube - 1 )
230 openPhaseFrame( _currFileNo + 1 );
233 wf.phase.resize( _pupil->rows(), _pupil->cols() );
236 wf.phase = _currPhase.image( _currFrameNo )
237 .block( 0.5 * ( _currPhase.rows() - _pupil->rows() ),
238 0.5 * ( _currPhase.cols() - _pupil->cols() ),
242 wf.phase = ( wf.phase - ( wf.phase * ( *_pupil ) ).sum() / Npix ) * ( *_pupil );
246 wf.amplitude = ( *_pupil ) * _pixVal;
251template <
typename realT>
252void turbSequence<realT>::nextWF( wavefront<realT> &wf )
255 int Npix = _pupil->sum();
257 if( _currFrameNo > _nPerCube - 1 )
259 openPhaseFrame( _currFileNo + 1 );
261 wf.phase.resize( _pupil->rows(), _pupil->cols() );
263 wf.phase = _currPhase.image( _currFrameNo )
264 .block( 0.5 * ( _currPhase.rows() - _pupil->rows() ),
265 0.5 * ( _currPhase.cols() - _pupil->cols() ),
269 wf.phase = ( wf.phase - ( wf.phase * ( *_pupil ) ).sum() / Npix ) * ( *_pupil );
273 wf.amplitude = _pixVal * ( *_pupil );
277 wf.amplitude.resize( _pupil->rows(), _pupil->cols() );
279 wf.amplitude = _currAmp.image( _currFrameNo )
280 .block( 0.5 * ( _currAmp.rows() - _pupil->rows() ),
281 0.5 * ( _currAmp.cols() - _pupil->cols() ),
285 wf.amplitude *= _pixVal * ( *_pupil );
std::vector< std::string > getFileNames(const std::string &directory, const std::string &prefix, const std::string &substr, const std::string &extension)
Get a list of file names from the specified directory, specifying a prefix, a substring to match,...