27 #ifndef zernikeTemporalPSD_hpp
28 #define zernikeTemporalPSD_hpp
36 #include <gsl/gsl_integration.h>
37 #include <gsl/gsl_errno.h>
39 #include <Eigen/Dense>
41 #include "../../math/constants.hpp"
42 #include "../../math/func/jinc.hpp"
43 #include "../../math/func/airyPattern.hpp"
44 #include "../../math/vectorUtils.hpp"
45 #include "../../ioutils/fits/fitsFile.hpp"
46 #include "../../sigproc/zernike.hpp"
47 #include "../../ioutils/stringUtils.hpp"
48 #include "../../ioutils/readColumns.hpp"
49 #include "../../ioutils/binVector.hpp"
50 #include "../../ioutils/fileUtils.hpp"
52 #include "../../ipc/ompLoopWatcher.hpp"
53 #include "../../mxError.hpp"
84 template<
typename realT,
typename aosysT>
85 realT
F_zernike (realT kv,
void * params);
100 template<
typename _realT,
typename aosysT>
103 typedef _realT realT;
104 typedef std::complex<realT> complexT;
121 gsl_integration_workspace *
_w;
128 std::vector<realT> Jps;
129 std::vector<realT> Jms;
131 std::vector<realT> ms;
132 std::vector<realT> ns;
200 std::vector<realT> &freq,
211 template<
bool m_parallel>
215 int m_multiLayerPSD( std::vector<realT> & PSD,
216 std::vector<realT> & freq,
219 isParallel<true> parallel );
222 int m_multiLayerPSD( std::vector<realT> & PSD,
223 std::vector<realT> & freq,
226 isParallel<false> parallel );
240 template<
bool parallel=true>
242 std::vector<realT> & freq,
251 template<
typename realT,
typename aosysT>
258 template<
typename realT,
typename aosysT>
266 _w = gsl_integration_workspace_alloc (WSZ);
270 template<
typename realT,
typename aosysT>
275 gsl_integration_workspace_free (_w);
279 template<
typename realT,
typename aosysT>
288 template<
typename realT,
typename aosysT>
294 template<
typename realT,
typename aosysT>
300 template<
typename realT,
typename aosysT>
306 template<
typename realT,
typename aosysT>
313 template<
typename realT,
typename aosysT>
315 std::vector<realT> &freq,
320 if(fmax == 0) fmax = freq[freq.size()-1];
322 realT v_wind = m_aosys->atm.layer_v_wind(layer_i);
323 realT q_wind = m_aosys->atm.layer_dir(layer_i);
326 realT cq = cos(q_wind);
327 realT sq = sin(q_wind);
330 realT scale = 2*(1/v_wind);
333 gsl_set_error_handler_off();
344 if(m_aosys->spatialFilter_ku() < std::numeric_limits<realT>::max() || m_aosys->spatialFilter_kv() < std::numeric_limits<realT>::max()) params.
m_spatialFilter =
true;
352 func.function = &F_zernike<realT, aosysT>;
355 func.params = ¶ms;
360 while( freq[i] <= fmax )
362 params.
m_f = freq[i];
364 int ec = gsl_integration_qagi (&func, _absTol, _relTol, WSZ, params.
_w, &result, &error);
366 if(ec == GSL_EDIVERGE)
368 std::cerr <<
"GSL_EDIVERGE:" <<
" " << freq[i] <<
" " << v_wind <<
" " << zern_j <<
"\n";
369 std::cerr <<
"ignoring . . .\n";
372 PSD[i] = scale*result;
375 if(i >= freq.size())
break;
404 template<
typename realT,
typename aosysT>
406 std::vector<realT> & freq,
409 isParallel<true> parallel )
411 static_cast<void>(parallel);
416 std::vector<realT> single_PSD(freq.size());
419 for(
size_t i=0; i< m_aosys->atm.n_layers(); ++i)
421 singleLayerPSD(single_PSD, freq, zern_j, i, fmax);
425 for(
size_t j=0; j<freq.size(); ++j)
427 PSD[j] += m_aosys->atm.layer_Cn2(i)*single_PSD[j];
435 template<
typename realT,
typename aosysT>
436 int zernikeTemporalPSD<realT, aosysT>::m_multiLayerPSD( std::vector<realT> & PSD,
437 std::vector<realT> & freq,
440 isParallel<false> parallel )
442 static_cast<void>(parallel);
445 std::vector<realT> single_PSD(freq.size());
447 for(
size_t i=0; i< m_aosys->atm.n_layers(); ++i)
449 singleLayerPSD(single_PSD, freq, zern_j, i, fmax);
452 for(
size_t j=0; j<freq.size(); ++j)
454 PSD[j] += m_aosys->atm.layer_Cn2(i)*single_PSD[j];
462 template<
typename realT,
typename aosysT>
463 template<
bool parallel>
465 std::vector<realT> & freq,
470 for(
size_t j=0;j<PSD.size(); ++j) PSD[j] = 0;
477 return m_multiLayerPSD( PSD, freq, zern_j, fmax, isParallel<parallel>());
489 template<
typename realT,
typename aosysT>
500 realT phi = atan(kv/ku);
502 realT
k = sqrt( pow(ku,2) + pow(kv,2) );
Calculate and provide constants related to adaptive optics.
Spatial power spectra used in adaptive optics.
Declares and defines an analytical AO system.
Provides a class to manage closed loop gain linear predictor determination.
Provides a class to manage closed loop gain optimization.
constexpr units::realT k()
Boltzmann Constant.
realT F_zernike(realT kv, void *params)
Worker function for GSL Integration for the basic sin/cos Fourier modes.
int noll_nm(int &n, int &m, int j)
Get the Zernike coefficients n,m corrresponding the Noll index j.
realT zernikeQNorm(realT k, realT phi, int n, int m)
Calculate the square-normed Fourier transform of a Zernike polynomial at position (k,...
Calculates the PSD of speckle intensity given a modified Fourier mode amplitude PSD.
Class to manage the calculation of temporal PSDs of the Fourier modes in atmospheric turbulence.
int singleLayerPSD(std::vector< realT > &PSD, std::vector< realT > &freq, int zern_j, int layer_i, realT fmax=0)
Calculate the temporal PSD for a Fourier mode for a single layer.
realT m_spatialFilter
Flag indicating if a spatial filter is applied.
realT m_zern_j
the current mode number
void initialize()
Initialize parameters to default values.
int m_zern_m
The current mode m.
gsl_integration_workspace * _w
Worskspace for the gsl integrators, allocated to WSZ if constructed as worker (with allocate == true)...
realT _relTol
The relative tolerance to use in the GSL integrator.
realT m_cq
The cosine of the wind direction.
int m_zern_n
The current mode n.
aosysT * m_aosys
Pointer to an AO system structure.
int _layer_i
The index of the current layer.
zernikeTemporalPSD()
Default c'tor.
realT m_f
the current temporal frequency0
realT relTol()
Get the current relative tolerance.
~zernikeTemporalPSD()
Destructor.
int multiLayerPSD(std::vector< realT > &PSD, std::vector< realT > &freq, int zern_j, realT fmax=0)
Calculate the temporal PSD for a Fourier mode in a multi-layer model.
realT m_sq
The sine of the wind direction.
realT absTol()
Get the current absolute tolerance.
realT _absTol
The absolute tolerance to use in the GSL integrator.
A utility to convert a wavefront variance map to an intensity image.
Declares and defines a function to calculate the measurement noise PSD.