30#include "../../mxlib.hpp"
31#include "../../math/constants.hpp"
32#include "../../math/roots.hpp"
33#include "../../mxError.hpp"
34#include "../../mxException.hpp"
42#define FITTING_ERROR_NO 0
43#define FITTING_ERROR_ZERO 1
44#define FITTING_ERROR_X 2
45#define FITTING_ERROR_Y 3
64template <
typename _realT,
class _inputSpectT,
typename iosT = std::ostream>
70 typedef _inputSpectT inputSpectT;
186 void d_min(
const std::vector<realT> &nd );
199 realT
d_min(
size_t idx );
205 std::vector<realT>
d_min();
210 void optd(
bool od );
234 template <
typename wfsT>
242 template<
typename wfsT>
243 void wfsBeta(
const wfsT * w );
295 void npix_wfs(
const std::vector<realT> &npix );
319 void ron_wfs(
const std::vector<realT> &nron );
343 void Fbg(
const std::vector<realT> &fbg );
356 realT
Fbg(
size_t idx );
362 std::vector<realT>
Fbg();
367 void minTauWFS(
const std::vector<realT> &ntau );
411 void tauWFS( realT ntau );
455 void zeta( realT nz );
537 void F0( realT nF0 );
560 realT
Fg( realT mag );
877 template <
typename varFuncT>
895 template <
typename imageT,
typename CfuncT>
896 void C_Map( imageT &im,
906 realT
C0var( realT m,
920 bool normStrehl =
true
927 template <
typename imageT>
928 void C0Map( imageT &map,
936 realT
C1var( realT m,
948 bool normStrehl =
true
958 template <
typename imageT>
959 void C1Map( imageT &map,
967 realT
C2var( realT m,
980 bool normStrehl =
true
990 template <
typename imageT>
991 void C2Map( imageT &map,
999 realT
C3var( realT m,
1012 bool normStrehl =
true
1022 template <
typename imageT>
1023 void C3Map( imageT &map,
1031 realT
C4var( realT m,
1044 bool normStrehl =
true
1054 template <
typename imageT>
1055 void C4Map( imageT &map,
1065 realT
C5var( realT m,
1078 bool normStrehl =
true
1088 template <
typename imageT>
1089 void C5Map( imageT &map,
1097 realT
C6var( realT m,
1110 bool normStrehl =
true
1120 template <
typename imageT>
1121 void C6Map( imageT &map,
1129 realT
C7var( realT m,
1141 bool normStrehl =
true
1151 template <
typename imageT>
1152 void C7Map( imageT &map,
1176template <
typename realT,
class inputSpectT,
typename iosT>
1179 wfsBeta<wfs<realT, iosT>>( nullptr );
1182template <
typename realT,
class inputSpectT,
typename iosT>
1185 if( m_wfsBeta && m_ownWfsBeta )
1191template <
typename realT,
class inputSpectT,
typename iosT>
1194 atm.loadGuyon2005();
1203 npix_wfs( std::vector<realT>( { 12868 } ) );
1204 ron_wfs( std::vector<realT>( { 0.0 } ) );
1205 Fbg( std::vector<realT>( { 0.0 } ) );
1208 minTauWFS( (realT)( 1. / 1e9 ) );
1211 m_specsChanged =
true;
1212 m_dminChanged =
true;
1215template <
typename realT,
class inputSpectT,
typename iosT>
1220 lam_wfs( 0.791e-6 );
1221 lam_sci( 0.656e-6 );
1223 npix_wfs( std::vector<realT>( { 9024 } ) );
1224 ron_wfs( std::vector<realT>( { 0.57 } ) );
1225 Fbg( std::vector<realT>( { 0.22 } ) );
1227 d_min( std::vector<realT>( { 6.5 / 48.0 } ) );
1228 minTauWFS( std::vector<realT>( { 1. / 3622. } ) );
1229 tauWFS( 1. / 3622. );
1233 m_specsChanged =
true;
1234 m_dminChanged =
true;
1237template <
typename realT,
class inputSpectT,
typename iosT>
1243 F0( 7.6e10 * 368.0 / ( 0.25 *
math::pi<realT>() * 6.5 * 6.5 * ( 1. - 0.29 * 0.29 ) ) );
1247 m_specsChanged =
true;
1248 m_dminChanged =
true;
1251template <
typename realT,
class inputSpectT,
typename iosT>
1257 m_specsChanged =
true;
1258 m_dminChanged =
true;
1261template <
typename realT,
class inputSpectT,
typename iosT>
1267template <
typename realT,
class inputSpectT,
typename iosT>
1270 m_d_min.assign( nd.begin(), nd.end() );
1271 m_specsChanged =
true;
1272 m_dminChanged =
true;
1275template <
typename realT,
class inputSpectT,
typename iosT>
1278 if( m_d_min.size() < idx + 1 )
1285 m_specsChanged =
true;
1286 m_dminChanged =
true;
1289template <
typename realT,
class inputSpectT,
typename iosT>
1292 if( m_d_min.size() < idx + 1 )
1297 return m_d_min[idx];
1300template <
typename realT,
class inputSpectT,
typename iosT>
1306template <
typename realT,
class inputSpectT,
typename iosT>
1310 m_specsChanged =
true;
1311 m_dminChanged =
true;
1314template <
typename realT,
class inputSpectT,
typename iosT>
1320template <
typename realT,
class inputSpectT,
typename iosT>
1324 m_specsChanged =
true;
1325 m_dminChanged =
true;
1328template <
typename realT,
class inputSpectT,
typename iosT>
1331 return m_optd_delta;
1334template <
typename realT,
class inputSpectT,
typename iosT>
1335template <
typename wfsT>
1338 if( m_wfsBeta && m_ownWfsBeta )
1341 m_wfsBeta =
nullptr;
1345 m_ownWfsBeta =
false;
1348template <
typename realT,
class inputSpectT,
typename iosT>
1349template <
typename wfsT>
1352 if( m_wfsBeta && m_ownWfsBeta )
1355 m_wfsBeta =
nullptr;
1361 m_ownWfsBeta =
false;
1365 m_wfsBeta =
new wfsT;
1366 m_ownWfsBeta =
true;
1370template <
typename realT,
class inputSpectT,
typename iosT>
1376template <
typename realT,
class inputSpectT,
typename iosT>
1379 if( m_wfsBeta == 0 )
1382 return m_wfsBeta->beta_p( m, n, m_D, d_opt(), atm.r_0( m_lam_sci ) );
1385template <
typename realT,
class inputSpectT,
typename iosT>
1388 if( m_wfsBeta == 0 )
1391 return m_wfsBeta->beta_r( m, n, m_D, d_opt(), atm.r_0( m_lam_sci ) );
1394template <
typename realT,
class inputSpectT,
typename iosT>
1398 m_specsChanged =
true;
1399 m_dminChanged =
true;
1402template <
typename realT,
class inputSpectT,
typename iosT>
1405 return m_opticalGain;
1408template <
typename realT,
class inputSpectT,
typename iosT>
1412 m_specsChanged =
true;
1413 m_dminChanged =
true;
1416template <
typename realT,
class inputSpectT,
typename iosT>
1422template <
typename realT,
class inputSpectT,
typename iosT>
1425 m_npix_wfs.resize( npix.size() );
1426 for(
size_t n = 0; n < npix.size(); ++n )
1428 m_npix_wfs[n] = npix[n];
1431 m_specsChanged =
true;
1432 m_dminChanged =
true;
1435template <
typename realT,
class inputSpectT,
typename iosT>
1438 if( m_npix_wfs.size() < idx + 1 )
1443 m_npix_wfs[idx] = npix;
1445 m_specsChanged =
true;
1446 m_dminChanged =
true;
1449template <
typename realT,
class inputSpectT,
typename iosT>
1452 if( m_npix_wfs.size() < idx + 1 )
1457 return m_npix_wfs[idx];
1460template <
typename realT,
class inputSpectT,
typename iosT>
1466template <
typename realT,
class inputSpectT,
typename iosT>
1469 m_ron_wfs.resize( nron.size() );
1470 for(
size_t n = 0; n < nron.size(); ++n )
1472 m_ron_wfs[n] = nron[n];
1475 m_specsChanged =
true;
1476 m_dminChanged =
true;
1479template <
typename realT,
class inputSpectT,
typename iosT>
1482 if( m_ron_wfs.size() < idx + 1 )
1487 m_ron_wfs[idx] = nron;
1489 m_specsChanged =
true;
1490 m_dminChanged =
true;
1493template <
typename realT,
class inputSpectT,
typename iosT>
1496 if( m_ron_wfs.size() < idx + 1 )
1501 return m_ron_wfs[idx];
1504template <
typename realT,
class inputSpectT,
typename iosT>
1510template <
typename realT,
class inputSpectT,
typename iosT>
1513 m_Fbg.resize( fbg.size() );
1514 for(
size_t n = 0; n < fbg.size(); ++n )
1519 m_specsChanged =
true;
1520 m_dminChanged =
true;
1523template <
typename realT,
class inputSpectT,
typename iosT>
1526 if( m_Fbg.size() < idx + 1 )
1533 m_specsChanged =
true;
1534 m_dminChanged =
true;
1537template <
typename realT,
class inputSpectT,
typename iosT>
1540 if( m_Fbg.size() < idx + 1 )
1548template <
typename realT,
class inputSpectT,
typename iosT>
1554template <
typename realT,
class inputSpectT,
typename iosT>
1557 m_minTauWFS.resize( ntau.size() );
1558 for(
size_t n = 0; n < ntau.size(); ++n )
1560 m_minTauWFS[n] = ntau[n];
1563 m_specsChanged =
true;
1564 m_dminChanged =
true;
1567template <
typename realT,
class inputSpectT,
typename iosT>
1570 if( m_minTauWFS.size() < idx + 1 )
1575 m_minTauWFS[idx] = ntau;
1577 m_specsChanged =
true;
1578 m_dminChanged =
true;
1581template <
typename realT,
class inputSpectT,
typename iosT>
1584 if( m_minTauWFS.size() < idx + 1 )
1589 return m_minTauWFS[idx];
1592template <
typename realT,
class inputSpectT,
typename iosT>
1598template <
typename realT,
class inputSpectT,
typename iosT>
1601 if( bnp != m_bin_npix )
1604 m_specsChanged =
true;
1605 m_dminChanged =
true;
1609template <
typename realT,
class inputSpectT,
typename iosT>
1615template <
typename realT,
class inputSpectT,
typename iosT>
1622template <
typename realT,
class inputSpectT,
typename iosT>
1626 m_specsChanged =
true;
1627 m_dminChanged =
true;
1630template <
typename realT,
class inputSpectT,
typename iosT>
1636template <
typename realT,
class inputSpectT,
typename iosT>
1640 m_specsChanged =
true;
1641 m_dminChanged =
true;
1644template <
typename realT,
class inputSpectT,
typename iosT>
1650template <
typename realT,
class inputSpectT,
typename iosT>
1654 m_specsChanged =
true;
1655 m_dminChanged =
true;
1658template <
typename realT,
class inputSpectT,
typename iosT>
1664template <
typename realT,
class inputSpectT,
typename iosT>
1668 m_specsChanged =
true;
1669 m_dminChanged =
true;
1672template <
typename realT,
class inputSpectT,
typename iosT>
1678template <
typename realT,
class inputSpectT,
typename iosT>
1682 m_secZeta = 1 / cos( m_zeta );
1684 m_specsChanged =
true;
1685 m_dminChanged =
true;
1688template <
typename realT,
class inputSpectT,
typename iosT>
1694template <
typename realT,
class inputSpectT,
typename iosT>
1700template <
typename realT,
class inputSpectT,
typename iosT>
1708template <
typename realT,
class inputSpectT,
typename iosT>
1711 return m_fit_mn_max;
1714template <
typename realT,
class inputSpectT,
typename iosT>
1717 m_circularLimit = cl;
1718 m_specsChanged =
true;
1719 m_dminChanged =
true;
1722template <
typename realT,
class inputSpectT,
typename iosT>
1725 return m_circularLimit;
1728template <
typename realT,
class inputSpectT,
typename iosT>
1731 m_spatialFilter_ku = fabs( kx );
1732 m_specsChanged =
true;
1733 m_dminChanged =
true;
1736template <
typename realT,
class inputSpectT,
typename iosT>
1739 return m_spatialFilter_ku;
1742template <
typename realT,
class inputSpectT,
typename iosT>
1745 m_spatialFilter_kv = fabs( ky );
1746 m_specsChanged =
true;
1747 m_dminChanged =
true;
1750template <
typename realT,
class inputSpectT,
typename iosT>
1753 return m_spatialFilter_kv;
1756template <
typename realT,
class inputSpectT,
typename iosT>
1760 m_specsChanged =
true;
1761 m_dminChanged =
true;
1764template <
typename realT,
class inputSpectT,
typename iosT>
1770template <
typename realT,
class inputSpectT,
typename iosT>
1773 m_ncp_alpha = alpha;
1774 m_specsChanged =
true;
1775 m_dminChanged =
true;
1778template <
typename realT,
class inputSpectT,
typename iosT>
1784template <
typename realT,
class inputSpectT,
typename iosT>
1788 m_specsChanged =
true;
1789 m_dminChanged =
true;
1792template <
typename realT,
class inputSpectT,
typename iosT>
1798template <
typename realT,
class inputSpectT,
typename iosT>
1802 m_specsChanged =
true;
1803 m_dminChanged =
true;
1806template <
typename realT,
class inputSpectT,
typename iosT>
1812template <
typename realT,
class inputSpectT,
typename iosT>
1815 return m_F0 * pow( 10.0, -0.4 * mag );
1818template <
typename realT,
class inputSpectT,
typename iosT>
1821 return Fg( m_starMag );
1824template <
typename realT,
class inputSpectT,
typename iosT>
1827 if( m_specsChanged || m_dminChanged )
1830 return m_controlledModes;
1833template <
typename realT,
class inputSpectT,
typename iosT>
1836 Nph = Fg() * tau_wfs;
1838 double binfact = 1.0;
1842 if( m_npix_wfs.size() == 1 )
1844 binfact = 1. / pow( (realT)b + 1, 2 );
1850 return pow( Nph, 2 ) / ( m_npix_wfs[binidx] * binfact * ( m_Fbg[binidx] * tau_wfs + pow( m_ron_wfs[binidx], 2 ) ) );
1853template <
typename realT,
class inputSpectT,
typename iosT>
1856 if( m == 0 and n == 0 )
1862 tau_wfs = optimumTauWFS( m, n, d, b );
1866 if( m_wfsBeta == 0 )
1869 realT beta_p = m_wfsBeta->beta_p( m, n, m_D, d, atm.r_0( m_lam_wfs ) ) / sqrt( m_opticalGain );
1870 realT beta_r = m_wfsBeta->beta_r( m, n, m_D, d, atm.r_0( m_lam_wfs ) );
1872 realT snr2 = signal2Noise2( Nph, tau_wfs, d, b );
1874 return ( pow( beta_r, 2 ) / snr2 + pow( beta_p, 2 ) / Nph ) * pow( m_lam_wfs / m_lam_sci, 2 );
1877template <
typename realT,
class inputSpectT,
typename iosT>
1880 if( m_specsChanged || m_dminChanged )
1882 return m_wfeMeasurement;
1885template <
typename realT,
class inputSpectT,
typename iosT>
1888 if( m == 0 and n == 0 )
1891 realT k = sqrt( m * m + n * n ) / m_D;
1896 tau_wfs = optimumTauWFS( m, n, d, b );
1900 realT tau = tau_wfs + m_deltaTau;
1903 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
1904 sqrt( atm.X( k, m_lam_sci, m_secZeta ) ) * pow(
math::two_pi<realT>() * atm.v_wind() * k, 2 ) *
1908template <
typename realT,
class inputSpectT,
typename iosT>
1911 if( m_specsChanged || m_dminChanged )
1913 return m_wfeTimeDelay;
1916template <
typename realT,
class inputSpectT,
typename iosT>
1919 realT k = sqrt( m * m + n * n ) / m_D;
1922 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 );
1925template <
typename realT,
class inputSpectT,
typename iosT>
1928 if( m_specsChanged || m_dminChanged )
1930 return m_wfeFitting;
1933template <
typename realT,
class inputSpectT,
typename iosT>
1936 return C4var( m, n );
1939template <
typename realT,
class inputSpectT,
typename iosT>
1942 if( m_specsChanged || m_dminChanged )
1944 return m_wfeChromScintOPD;
1947template <
typename realT,
class inputSpectT,
typename iosT>
1950 return C5var( m, n );
1953 int mn_max = floor(0.5*m_D/d_opt());
1957 for(
int m = -mn_max; m <= mn_max; ++m)
1959 for(
int n = -mn_max; n <= mn_max; ++n)
1961 if(n == 0 && m == 0)
continue;
1971template <
typename realT,
class inputSpectT,
typename iosT>
1974 return C6var( m, n );
1977template <
typename realT,
class inputSpectT,
typename iosT>
1980 if( m_specsChanged || m_dminChanged )
1982 return m_wfeChromIndex;
1985template <
typename realT,
class inputSpectT,
typename iosT>
1988 return C7var( m, n );
1991template <
typename realT,
class inputSpectT,
typename iosT>
1994 if( m_specsChanged || m_dminChanged )
1996 return m_wfeAnisoOPD;
1999template <
typename realT,
class inputSpectT,
typename iosT>
2005 int mn_max = floor(0.5*m_D/d_opt());
2009 for(
int m = -mn_max; m <= mn_max; ++m)
2011 for(
int n = -mn_max; n <= mn_max; ++n)
2013 if(n == 0 && m == 0)
continue;
2015 if( m_circularLimit )
2017 if( m*m + n*n > mn_max*mn_max )
continue;
2028template <
typename realT,
class inputSpectT,
typename iosT>
2047 double binfact = 1.0;
2051 if( m_npix_wfs.size() > 1 )
2057 binfact = 1.0 / pow( (realT)( bbin + 1 ), 2 );
2061 realT k = sqrt( m * m + n * n ) / m_D;
2065 if( m_wfsBeta == 0 )
2068 realT beta_p = m_wfsBeta->beta_p( m, n, m_D, dact, atm.r_0( m_lam_wfs ) ) / sqrt( m_opticalGain );
2069 realT beta_r = m_wfsBeta->beta_r( m, n, m_D, dact, atm.r_0( m_lam_wfs ) ) / sqrt( m_opticalGain );
2072 realT a, b, c, d, e;
2075 realT Atmp = 2 * pow( atm.lam_0(), 2 ) * psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) *
2076 ( atm.X( k, m_lam_wfs, m_secZeta ) ) * pow(
math::two_pi<realT>() * atm.v_wind() * k, 2 );
2079 b = Atmp * m_deltaTau;
2081 d = -1 * ( pow( m_lam_wfs, 2 ) / F ) *
2082 ( ( m_npix_wfs[binidx] * binfact * m_Fbg[binidx] / F ) * pow( beta_r, 2 ) + pow( beta_p, 2 ) );
2083 e = -2 * pow( m_lam_wfs, 2 ) * ( m_npix_wfs[binidx] * binfact ) * pow( m_ron_wfs[binidx], 2 ) * pow( beta_r, 2 ) /
2086 std::vector<std::complex<realT>> x;
2094 for(
int i = 0; i < 4; i++ )
2096 if( real( x[i] ) > 0 && imag( x[i] ) == 0 && real( x[i] ) > tauopt )
2097 tauopt = real( x[i] );
2100 if( tauopt < m_minTauWFS[binidx] )
2101 tauopt = m_minTauWFS[binidx];
2106template <
typename realT,
class inputSpectT,
typename iosT>
2110 return optimumTauWFS( m, n, m_d_opt, m_bin_opt );
2113template <
typename realT,
class inputSpectT,
typename iosT>
2116 if( !m_dminChanged )
2121 if( m_npix_wfs.size() < 1 )
2126 if( m_d_min.size() != m_npix_wfs.size() )
2131 if( m_ron_wfs.size() != m_npix_wfs.size() )
2136 if( m_Fbg.size() != m_npix_wfs.size() )
2141 if( m_minTauWFS.size() != m_npix_wfs.size() )
2147 if( m_d_min.size() == 1 && m_d_min[0] == 0 )
2151 m_dminChanged =
false;
2157 m_d_opt = m_d_min[0];
2159 m_dminChanged =
false;
2168 if( m_npix_wfs.size() > 1 )
2171 best_d = m_d_min[0];
2173 realT bestStrehlOverall = 0;
2175 for(
int b = 0; b < m_npix_wfs.size(); ++b )
2177 realT d = m_d_min[b];
2178 realT s = strehl( d, b );
2179 realT bestStrehl = s;
2182 while( d < m_D / 2 )
2184 d += m_d_min[b] / m_optd_delta;
2187 if( s < bestStrehl )
2190 d -= m_d_min[b] / m_optd_delta;
2198 if( bestStrehl >= bestStrehlOverall )
2200 bestStrehlOverall = bestStrehl;
2206 m_bin_opt = best_idx;
2210 realT d = m_d_min[0];
2213 realT s = strehl( d, m_bin_opt );
2214 realT bestStrehl = s;
2216 while( d < m_D / 2 )
2218 d += m_d_min[0] / m_optd_delta;
2219 m_bin_opt = d / m_d_min[0] - 1;
2223 s = strehl( d, m_bin_opt );
2225 if( s < bestStrehl )
2228 d -= m_d_min[0] / m_optd_delta;
2229 m_bin_opt = d / m_d_min[0] - 1;
2242 realT d = m_d_min[0];
2245 realT s = strehl( d, m_bin_opt );
2246 realT bestStrehl = s;
2249 while( d < m_D / 2 )
2251 d += m_d_min[0] / m_optd_delta;
2253 s = strehl( d, m_bin_opt );
2254 if( s < bestStrehl )
2256 d -= m_d_min[0] / m_optd_delta;
2266 m_dminChanged =
false;
2271template <
typename realT,
class inputSpectT,
typename iosT>
2274 if( m == 0 and n == 0 )
2277 realT k = sqrt( m * m + n * n ) / m_D;
2279 realT kmax = m_fit_mn_max / m_D;
2280 realT kmin = 1. / m_D;
2283 if( m_ncp_alpha != 2 )
2286 ( pow( kmin, -m_ncp_alpha + 2 ) - pow( kmax, -m_ncp_alpha + 2 ) );
2292 return beta * ncpError() * pow( k, -m_ncp_alpha ) * pow( kmin, 2 );
2295template <
typename realT,
class inputSpectT,
typename iosT>
2301template <
typename realT,
class inputSpectT,
typename iosT>
2305 int mn_max = floor( 0.5 * m_D / d );
2310 for(
int m = -m_fit_mn_max; m <= m_fit_mn_max; ++m )
2312 for(
int n = -m_fit_mn_max; n <= m_fit_mn_max; ++n )
2315 if( m_circularLimit )
2317 if( m * m + n * n <= mn_max * mn_max )
2322 if( abs( m ) <= mn_max && abs( n ) <= mn_max )
2328 realT wfeMeasurement = measurementError( m, n, d, b );
2329 realT wfeTimeDelay = timeDelayError( m, n, d, b );
2330 realT wfeChromScintOPD = chromScintOPDError( m, n );
2331 realT wfeChromIndex = chromIndexError( m, n );
2332 realT wfeAnisoOPD = dispAnisoOPDError( m, n );
2334 realT wfeFitting = fittingError( m, n );
2336 if( wfeFitting < wfeMeasurement + wfeTimeDelay + wfeChromScintOPD + wfeChromIndex + wfeAnisoOPD )
2338 wfeVar += wfeFitting;
2342 wfeVar += wfeMeasurement + wfeTimeDelay + wfeChromScintOPD + wfeChromIndex + wfeAnisoOPD;
2347 wfeVar += fittingError( m, n );
2352 wfeVar += ncpError();
2353 return exp( -1 * wfeVar );
2356template <
typename realT,
class inputSpectT,
typename iosT>
2362 int mn_max = floor( 0.5 * m_D / d );
2364 m_wfeMeasurement = 0;
2366 m_wfeChromScintOPD = 0;
2367 m_wfeChromIndex = 0;
2374 m_controlledModes.resize( 2 * m_fit_mn_max + 1, 2 * m_fit_mn_max + 1 );
2375 m_controlledModes.setZero();
2378 for(
int m = -m_fit_mn_max; m <= m_fit_mn_max; ++m )
2380 for(
int n = -m_fit_mn_max; n <= m_fit_mn_max; ++n )
2382 if( m == 0 && n == 0 )
2388 if( m_circularLimit )
2390 if( m * m + n * n <= mn_max * mn_max )
2395 if( abs( m ) <= mn_max && abs( n ) <= mn_max )
2401 realT wfeMeasurement = measurementError( m, n, d, b );
2402 realT wfeTimeDelay = timeDelayError( m, n, d, b );
2403 realT wfeChromScintOPD = chromScintOPDError( m, n );
2404 realT wfeChromIndex = chromIndexError( m, n );
2405 realT wfeAnisoOPD = dispAnisoOPDError( m, n );
2407 realT wfeFitting = fittingError( m, n );
2409 if( wfeFitting < wfeMeasurement + wfeTimeDelay + wfeChromScintOPD + wfeChromIndex + wfeAnisoOPD )
2411 m_wfeFitting += wfeFitting;
2415 m_wfeMeasurement += wfeMeasurement;
2416 m_wfeTimeDelay += wfeTimeDelay;
2417 m_wfeChromScintOPD += wfeChromScintOPD;
2418 m_wfeChromIndex += wfeChromIndex;
2419 m_wfeAnisoOPD += wfeAnisoOPD;
2420 m_controlledModes( m_fit_mn_max + m, m_fit_mn_max + n ) = 1;
2425 m_wfeFitting += fittingError( m, n );
2430 m_wfeNCP = ncpError();
2432 m_wfeVar = m_wfeMeasurement + m_wfeTimeDelay + m_wfeFitting + m_wfeChromScintOPD + m_wfeChromIndex + m_wfeAnisoOPD +
2435 m_strehl = exp( -1 * m_wfeVar );
2437 m_specsChanged =
false;
2440template <
typename realT,
class inputSpectT,
typename iosT>
2443 if( m_specsChanged || m_dminChanged )
2449template <
typename realT,
class inputSpectT,
typename iosT>
2452 if( m_specsChanged || m_dminChanged )
2458template <
typename realT,
class inputSpectT,
typename iosT>
2459template <
typename varFuncT>
2462 if( m == 0 && n == 0 )
2472 if( doFittingError != FITTING_ERROR_NO )
2474 int mn_max = m_D / ( 2. * d_opt() );
2476 if( m_controlledModes( m_fit_mn_max + m, m_fit_mn_max + n ) == false )
2478 if( doFittingError == FITTING_ERROR_ZERO )
2481 realT fe = fittingError( m, n );
2483 realT k = sqrt( m * m + n * n ) / m_D;
2485 if( doFittingError == FITTING_ERROR_X )
2486 fe *= ( atm.X( k, m_lam_sci, m_secZeta ) );
2487 else if( doFittingError == FITTING_ERROR_Y )
2488 fe *= ( atm.Y( k, m_lam_sci, m_secZeta ) );
2491 std::cerr <<
"Unknown doFittingError\n";
2500 realT var = ( this->*varFunc )( m, n );
2505template <
typename realT,
class inputSpectT,
typename iosT>
2506template <
typename imageT,
typename CfuncT>
2509 int dim1 = im.rows();
2510 int dim2 = im.cols();
2512 int mc = 0.5 * ( dim1 - 1 );
2513 int nc = 0.5 * ( dim2 - 1 );
2515 for(
int i = 0; i < dim1; ++i )
2519 for(
int j = 0; j < dim2; ++j )
2523 im( i, j ) = ( this->*Cfunc )( m, n, normStrehl );
2528template <
typename realT,
class inputSpectT,
typename iosT>
2531 realT k = sqrt( m * m + n * n ) / m_D;
2533 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
2534 ( atm.X( k, m_lam_sci, m_secZeta ) );
2537template <
typename realT,
class inputSpectT,
typename iosT>
2544template <
typename realT,
class inputSpectT,
typename iosT>
2545template <
typename imageT>
2551template <
typename realT,
class inputSpectT,
typename iosT>
2554 realT k = sqrt( m * m + n * n ) / m_D;
2557 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
2558 ( atm.Y( k, m_lam_sci, m_secZeta ) );
2561template <
typename realT,
class inputSpectT,
typename iosT>
2567template <
typename realT,
class inputSpectT,
typename iosT>
2568template <
typename imageT>
2574template <
typename realT,
class inputSpectT,
typename iosT>
2578 return measurementError( m, n, d_opt(), m_bin_opt ) + timeDelayError( m, n, d_opt(), m_bin_opt );
2581template <
typename realT,
class inputSpectT,
typename iosT>
2587template <
typename realT,
class inputSpectT,
typename iosT>
2588template <
typename imageT>
2594template <
typename realT,
class inputSpectT,
typename iosT>
2600template <
typename realT,
class inputSpectT,
typename iosT>
2606template <
typename realT,
class inputSpectT,
typename iosT>
2607template <
typename imageT>
2613template <
typename realT,
class inputSpectT,
typename iosT>
2616 realT k = sqrt( m * m + n * n ) / m_D;
2620 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
2621 atm.dX( k, m_lam_sci, m_lam_wfs );
2624template <
typename realT,
class inputSpectT,
typename iosT>
2630template <
typename realT,
class inputSpectT,
typename iosT>
2631template <
typename imageT>
2637template <
typename realT,
class inputSpectT,
typename iosT>
2640 realT k = sqrt( m * m + n * n ) / m_D;
2644 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
2645 atm.dY( k, m_lam_sci, m_lam_wfs );
2648template <
typename realT,
class inputSpectT,
typename iosT>
2654template <
typename realT,
class inputSpectT,
typename iosT>
2655template <
typename imageT>
2661template <
typename realT,
class inputSpectT,
typename iosT>
2664 realT ni = atm.n_air( m_lam_sci );
2665 realT nw = atm.n_air( m_lam_wfs );
2667 return C0var( m, n ) * pow( ( ni - nw ) / ( ni - 1 ), 2 );
2670template <
typename realT,
class inputSpectT,
typename iosT>
2676template <
typename realT,
class inputSpectT,
typename iosT>
2677template <
typename imageT>
2683template <
typename realT,
class inputSpectT,
typename iosT>
2686 realT k = sqrt( m * m + n * n ) / m_D;
2689 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
2690 atm.X_Z( k, m_lam_wfs, m_lam_sci, m_secZeta );
2693template <
typename realT,
class inputSpectT,
typename iosT>
2699template <
typename realT,
class inputSpectT,
typename iosT>
2700template <
typename imageT>
2706template <
typename realT,
class inputSpectT,
typename iosT>
2709 ios <<
"# AO Params:\n";
2710 ios <<
"# D = " << D() <<
'\n';
2712 if( m_d_min.size() > 0 )
2714 ios <<
"# d_min = " << d_min( (
size_t)0 );
2715 for(
size_t n = 1; n < m_d_min.size(); ++n )
2716 ios <<
',' << d_min( n );
2720 ios <<
"# d_min = null\n";
2722 ios <<
"# optd = " << std::boolalpha << m_optd <<
'\n';
2723 ios <<
"# d_opt_delta = " << optd_delta() <<
'\n';
2724 ios <<
"# lam_sci = " << lam_sci() <<
'\n';
2725 ios <<
"# F0 = " << F0() <<
'\n';
2726 ios <<
"# starMag = " << starMag() <<
'\n';
2727 ios <<
"# lam_sci = " << lam_sci() <<
'\n';
2728 ios <<
"# zeta = " << zeta() <<
'\n';
2729 ios <<
"# lam_wfs = " << lam_wfs() <<
'\n';
2731 if( npix_wfs().size() > 0 )
2733 ios <<
"# npix_wfs = " << npix_wfs( (
size_t)0 );
2734 for(
size_t n = 1; n < npix_wfs().size(); ++n )
2735 ios <<
',' << npix_wfs( n );
2739 ios <<
"# npix_wfs = null\n";
2741 if( ron_wfs().size() > 0 )
2743 ios <<
"# ron_wfs = " << ron_wfs( (
size_t)0 );
2744 for(
size_t n = 1; n < ron_wfs().size(); ++n )
2745 ios <<
',' << ron_wfs( n );
2749 ios <<
"# ron_wfs = null\n";
2751 if( Fbg().size() > 0 )
2753 ios <<
"# Fbg = " << Fbg( (
size_t)0 );
2754 for(
size_t n = 1; n < Fbg().size(); ++n )
2755 ios <<
',' << Fbg( n );
2759 ios <<
"# Fbg = null\n";
2761 if( minTauWFS().size() > 0 )
2763 ios <<
"# minTauWFS = " << minTauWFS( (
size_t)0 );
2764 for(
size_t n = 1; n < minTauWFS().size(); ++n )
2765 ios <<
',' << minTauWFS( n );
2769 ios <<
"# minTauWFS = null\n";
2771 ios <<
"# bin_npix = " << std::boolalpha << m_bin_npix <<
'\n';
2772 ios <<
"# tauWFS = " << tauWFS() <<
'\n';
2773 ios <<
"# optTau = " << std::boolalpha << m_optTau <<
'\n';
2774 ios <<
"# deltaTau = " << deltaTau() <<
'\n';
2775 ios <<
"# fit_mn_max = " << m_fit_mn_max <<
'\n';
2776 ios <<
"# spatialFilter_ku = " << m_spatialFilter_ku <<
'\n';
2777 ios <<
"# spatialFilter_kv = " << m_spatialFilter_kv <<
'\n';
2778 ios <<
"# ncp_wfe = " << m_ncp_wfe <<
'\n';
2779 ios <<
"# ncp_alpha = " << m_ncp_alpha <<
'\n';
2781 if( m_wfsBeta == 0 )
2783 m_wfsBeta->dumpWFS( ios );
2785 atm.dumpAtmosphere( ios );
2792template <
typename realT,
class inputSpectT,
typename iosT>
2795 using namespace mx::app;
2798 config.
add(
"aosys.wfs",
2806 "The WFS type: idealWFS, unmodPyWFS, asympModPyWFS, shwfs, calculatedWFS" );
2807 config.
add(
"aosys.wfs_beta_p",
2815 "The beta_p file path for calcualtedWFS" );
2816 config.
add(
"aosys.wfs_beta_r",
2824 "The beta_r file path for calcualtedWFS" );
2825 config.
add(
"aosys.wfs_sensitivity",
2827 "aosys.wfs_sensitivity",
2833 "Flag indicating that beta_p/beta_r are sensitivities (inverse) [default false]" );
2835 "aosys.D",
"",
"aosys.D", argType::Required,
"aosys",
"D",
false,
"real",
"The telescope diameter [m]" );
2836 config.
add(
"aosys.d_min",
2844 "The minimum actuator spacing [m]" );
2845 config.
add(
"aosys.optd",
2853 "Whether or not the actuator spacing is optimized" );
2854 config.
add(
"aosys.optd_delta",
2862 "The fractional change from d_min used in optimization. Set to 1 (default) for integer binnings, > 1 "
2863 "for finer sampling." );
2864 config.
add(
"aosys.F0",
2872 "Zero-mag photon flux, [photons/sec]" );
2873 config.
add(
"aosys.lam_wfs",
2881 "WFS wavelength [m]" );
2882 config.
add(
"aosys.npix_wfs",
2890 "The number of pixels in the WFS" );
2891 config.
add(
"aosys.ron_wfs",
2899 "WFS readout noise [photons/read]" );
2900 config.
add(
"aosys.bin_npix",
2908 "Whether or not WFS pixels are re-binned along with actuator spacing optimization" );
2909 config.
add(
"aosys.Fbg",
2917 "Background counts, [counts/pix/sec]" );
2918 config.
add(
"aosys.tauWFS",
2926 "WFS integration time [s]" );
2927 config.
add(
"aosys.minTauWFS",
2935 "Minimum WFS integration time [s]" );
2936 config.
add(
"aosys.deltaTau",
2945 config.
add(
"aosys.optTau",
2953 "Whether or not the integration time is optimized" );
2954 config.
add(
"aosys.lam_sci",
2962 "Science wavelength [m]" );
2964 "aosys.zeta",
"",
"aosys.zeta", argType::Required,
"aosys",
"zeta",
false,
"real",
"Zenith distance [rad]" );
2965 config.
add(
"aosys.fit_mn_max",
2973 "Maximum spatial frequency index to use for analysis" );
2974 config.
add(
"aosys.circularLimit",
2976 "aosys.circularLimit",
2982 " Flag to indicate that the spatial frequency limit is circular, not square." );
2983 config.
add(
"aosys.spatialFilter_ku",
2985 "aosys.spatialFilter_ku",
2991 "Spatial filter cutoff frequency in u [m^-1]" );
2992 config.
add(
"aosys.spatialFilter_kv",
2994 "aosys.spatialFilter_kv",
3000 "Spatial filter cutoff frequency in v [m^-1]" );
3001 config.
add(
"aosys.ncp_wfe",
3009 "NCP WFE between 1 lambda/D and fit_mn_max [rad^2]" );
3010 config.
add(
"aosys.ncp_alpha",
3018 "PSD index for NCP WFE" );
3020 "aosys.starMag",
"",
"aosys.starMag", argType::Required,
"aosys",
"starMag",
false,
"real",
"Star magnitude" );
3021 config.
add(
"aosys.starMags",
3029 "A vector of star magnitudes" );
3031 atm.setupConfig( config );
3032 psd.setupConfig( config );
3035template <
typename realT,
class inputSpectT,
typename iosT>
3039 if( config.
isSet(
"aosys.wfs" ) )
3042 config( wfsStr,
"aosys.wfs" );
3044 if( wfsStr ==
"ideal" )
3046 wfsBeta<wfs<realT, iosT>>( nullptr );
3048 else if( wfsStr ==
"unmodPyWFS" )
3050 wfsBeta<pywfsUnmod<realT, iosT>>( nullptr );
3052 else if( wfsStr ==
"asympModPyWFS" )
3054 wfsBeta<pywfsModAsymptotic<realT>>( nullptr );
3056 else if( wfsStr ==
"SHWFS" )
3058 wfsBeta<shwfs<realT, iosT>>( nullptr );
3060 else if( wfsStr ==
"calculatedWFS" )
3062 wfsBeta<calculatedWFS<realT, iosT>>( nullptr );
3065 config( cwfs->m_beta_p_file,
"aosys.wfs_beta_p" );
3066 config( cwfs->m_beta_r_file,
"aosys.wfs_beta_r" );
3067 bool sens = cwfs->m_sensitivity;
3068 config( sens,
"aosys.wfs_sensitivity" );
3069 if( config.isSet(
"aosys.wfs_sensitivity" ) )
3071 cwfs->m_sensitivity = sens;
3085 config( nD,
"aosys.D" );
3086 if( config.
isSet(
"aosys.D" ) )
3090 std::vector<realT> nd_min = d_min();
3091 config( nd_min,
"aosys.d_min" );
3092 if( config.
isSet(
"aosys.d_min" ) )
3095 bool noptd = optd();
3096 config( noptd,
"aosys.optd" );
3097 if( config.
isSet(
"aosys.optd" ) )
3100 realT noptd_delta = optd_delta();
3101 config( noptd_delta,
"aosys.optd_delta" );
3102 if( config.
isSet(
"aosys.optd_delta" ) )
3103 optd_delta( noptd_delta );
3105 realT nlam_wfs = lam_wfs();
3106 config( nlam_wfs,
"aosys.lam_wfs" );
3107 if( config.
isSet(
"aosys.lam_wfs" ) )
3108 lam_wfs( nlam_wfs );
3111 std::vector<realT> nnpix_wfs = npix_wfs();
3112 config( nnpix_wfs,
"aosys.npix_wfs" );
3113 if( config.
isSet(
"aosys.npix_wfs" ) )
3114 npix_wfs( nnpix_wfs );
3117 std::vector<realT> nron_wfs = ron_wfs();
3118 config( nron_wfs,
"aosys.ron_wfs" );
3119 if( config.
isSet(
"aosys.ron_wfs" ) )
3120 ron_wfs( nron_wfs );
3123 std::vector<realT> nFbg = Fbg();
3124 config( nFbg,
"aosys.Fbg" );
3125 if( config.
isSet(
"aosys.Fbg" ) )
3129 std::vector<realT> nminTauWFS = minTauWFS();
3130 config( nminTauWFS,
"aosys.minTauWFS" );
3131 if( config.
isSet(
"aosys.minTauWFS" ) )
3132 minTauWFS( nminTauWFS );
3135 bool nbin_npix = bin_npix();
3136 config( nbin_npix,
"aosys.bin_npix" );
3137 if( config.
isSet(
"aosys.bin_npix" ) )
3138 bin_npix( nbin_npix );
3141 realT ntauWFS = tauWFS();
3142 config( ntauWFS,
"aosys.tauWFS" );
3143 if( config.
isSet(
"aosys.tauWFS" ) )
3147 realT ndeltaTau = deltaTau();
3148 config( ndeltaTau,
"aosys.deltaTau" );
3149 if( config.
isSet(
"aosys.deltaTau" ) )
3150 deltaTau( ndeltaTau );
3153 bool noptTau = optTau();
3154 config( noptTau,
"aosys.optTau" );
3155 if( config.
isSet(
"aosys.optTau" ) )
3159 realT nlam_sci = lam_sci();
3160 config( nlam_sci,
"aosys.lam_sci" );
3161 if( config.
isSet(
"aosys.lam_sci" ) )
3162 lam_sci( nlam_sci );
3165 realT nzeta = zeta();
3166 config( nzeta,
"aosys.zeta" );
3167 if( config.
isSet(
"aosys.zeta" ) )
3171 realT fmnm = fit_mn_max();
3172 config( fmnm,
"aosys.fit_mn_max" );
3173 if( config.
isSet(
"aosys.fit_mn_max" ) )
3177 bool cl = circularLimit();
3178 config( cl,
"aosys.circularLimit" );
3179 if( config.
isSet(
"aosys.circularLimit" ) )
3180 circularLimit( cl );
3183 realT ku = spatialFilter_ku();
3184 config( ku,
"aosys.spatialFilter_ku" );
3185 if( config.
isSet(
"aosys.spatialFilter_ku" ) )
3186 spatialFilter_ku( ku );
3189 realT kv = spatialFilter_kv();
3190 config( kv,
"aosys.spatialFilter_kv" );
3191 if( config.
isSet(
"aosys.spatialFilter_kv" ) )
3192 spatialFilter_kv( kv );
3195 realT nwfe = ncp_wfe();
3196 config( nwfe,
"aosys.ncp_wfe" );
3197 if( config.
isSet(
"aosys.ncp_wfe" ) )
3201 realT na = ncp_alpha();
3202 config( na,
"aosys.ncp_alpha" );
3203 if( config.
isSet(
"aosys.ncp_alpha" ) )
3208 config( nF0,
"aosys.F0" );
3209 if( config.
isSet(
"aosys.F0" ) )
3213 realT smag = starMag();
3214 config( smag,
"aosys.starMag" );
3215 if( config.
isSet(
"aosys.starMag" ) )
3218 atm.loadConfig( config );
3219 psd.loadConfig( config );
Provides a class to specify atmosphere parameters.
Calculate and provide constants related to adaptive optics.
Spatial power spectra used in adaptive optics.
Definitions of various analytic wavefront sensors.
A class to specify atmosphere parameters and perform related calculations.
Describes an analytic adaptive optics (AO) system.
bool circularLimit()
Get the value of the circularLimit flag.
realT m_ncp_wfe
Static WFE [m rms].
void loadMagAOX()
Load parameters corresponding to the MagAO-X system.
bool bin_npix()
Get the value of the pixel binngin flag.
void loadGuyon2005()
Load the default parameters from Guyon, 2005 .
bool optd()
Get the value of m_optd.
void C1Map(imageT &map, bool normStrehl)
Calculate a 2D map of contrast C1.
realT m_wfeNCP
Total WFE due to NCP errors [rad^2 at m_lam_sci].
realT F0()
Get the value of the 0 magnitude photon rate.
realT C5(realT m, realT n, bool normStrehl=true)
Calculate the contrast due to scintilation-amplitude chromaticity.
realT chromScintOPDErrorTotal()
Calculate the wavefront error due to scintillation chromaticity in the OPD over all spatial frequenci...
void C5Map(imageT &map, bool normStrehl)
Calculate a 2D map of contrast C5.
realT C1(realT m, realT n, bool normStrehl=true)
Calculate the contrast due to uncorrected amplitude, C1.
realT C0var(realT m, realT n)
Calculate the residual variance due to uncorrected phase at a spatial frequency.
realT C_(int m, int n, bool normStrehl, varFuncT varFunc, int doFittingError)
Worker function for raw contrast fuctions.
realT m_wfeVar
The WFE variance, in meters^2. Never use this directly, instead use wfeVar().
realT d_opt()
Calculate the optimum actuator spacing.
std::vector< realT > d_min()
Get the minimum subaperture sampling for all WFS modes.
realT ncpError()
Calculate the total NCP variance in rad^2.
realT m_opticalGain
The optical gain of the WFS, 0-1. Treated as a sensitivity reduction in measurement noise....
realT spatialFilter_kv()
Get the value of spatialFilter_kv.
bool m_specsChanged
Flag to indicate that a specification has changed.
bool m_circularLimit
Flag to indicate that the spatial frequency limit is circular, not square.
realT zeta()
Get the zenith angle.
realT Fg()
Get the photon rate at the current Star magnitude.
std::vector< realT > minTauWFS()
Get the values of the minimum WFS exposure time.
std::vector< realT > m_npix_wfs
Number of WFS pixels. One per WFS mode.
void calcStrehl()
Calculate the component WFE, total WFE, and Strehl ratio.
realT lam_sci()
Get the science wavelength.
realT m_wfeFitting
Total WFE due to fitting error [rad^2 at m_lam_sci].
realT m_wfeChromScintOPD
Total WFE due to the chromaticity of scintillation OPD [rad^2 at lam_sc].
realT m_strehl
Strehl ratio, a calculated quantity. Never use this directdy, instead use strehl().
realT deltaTau()
Get the value of m_deltaTau.
realT wfeVar()
Get the current value of the total WFE variance.
realT ncp_wfe()
Get the value of the non-common path WFE.
realT m_spatialFilter_ku
The spatial filter cutoff in u, [m^-1].
realT tauWFS()
Get the value of the minimum WFS exposure time.
std::vector< realT > m_ron_wfs
WFS readout noise [electrons/pix]. One per WFS mode.
bool m_ownWfsBeta
Flag indicating if the WFS beta_p pointer is owned by this instance.
realT m_secZeta
Secant of the Zenith angle (calculated)
realT m_starMag
The magnitude of the star.
realT C4(realT m, realT n, bool normStrehl=true)
Calculate the contrast due to scintilation-OPD chromaticity.
realT timeDelayError(realT m, realT n, realT d, int b)
Calculate the time delay at a spatial frequency at the optimum exposure time and the specified actuat...
realT chromIndexErrorTotal()
Calculate the wavefront error due to chromaticity in the index of refraction at a specific spatial fr...
realT chromIndexError(int m, int n)
Calculate the wavefront error due to chromaticity in the index of refraction at a given spatial frequ...
realT m_d_opt
Current optimum AO system actuator pitch [m].
realT C4var(realT m, realT n)
Calculate the residual variance due to scintilation-OPD chromaticity.
realT m_ncp_alpha
Power-law exponent for the NCP aberations. Default is 2.
realT beta_r(realT m, realT n)
Get the value of beta_r for a spatial frequency.
realT spatialFilter_ku()
Get the value of spatialFilter_ku.
realT m_spatialFilter_kv
The spatial filter cutoff in v, [m^-1].
void C7Map(imageT &map, bool normStrehl)
Calculate a 2D map of contrast C7.
realT C7var(realT m, realT n)
Calculate the residual variance due to dispersive anisoplanatism.
realT fittingErrorTotal()
Calculate the total fitting error over all uncorrected spatial frequencies.
bool m_bin_npix
Flag controlling whether or not to bin WFS pixels according to the actuator spacing.
void C0Map(imageT &map, bool normStrehl)
Calculate a 2D map of contrast C0.
bool optTau()
Get the value of m_optTau.
realT m_tauWFS
Actual WFS exposure time [sec].
realT beta_p(realT m, realT n)
Get the value of beta_p for a spatial frequency.
std::vector< realT > m_minTauWFS
Minimum WFS exposure time [sec]. One per WFS mode.
realT C5var(realT m, realT n)
Calculate the residual variance due to to scintilation-amplitude chromaticity.
wfs< realT, iosT > * m_wfsBeta
The WFS beta_p class.
realT secZeta()
Get the zecant of the zenith angle.
realT measurementError(realT m, realT n, realT d, int b)
Calculate the measurement noise at a spatial frequency and specified actuator spacing.
realT dispAnisoOPDErrorTotal()
Calculate the wavefront error due to dispersive anisoplanatism in the OPD over all specific spatial f...
realT m_lam_wfs
WFS wavelength [m].
void C3Map(imageT &map, bool normStrehl)
Calculate a 2D map of contrast C3.
realT m_F0
0 mag flux from star at WFS [photons/sec]
realT C2var(realT m, realT n)
Calculate the residual variance due to measurement and time delay errors in phase/OPD at a spatial fr...
bool m_dminChanged
Flag to indicate that d_min has changed.
std::vector< realT > Fbg()
Get the value of the background flux for all WFS modes.
realT timeDelayErrorTotal()
Calculate the time delay error over all corrected spatial frequencies.
realT dispAnisoOPDError(int m, int n)
Calculate the wavefront error due to dispersive anisoplanatism in the OPD at a given spatial frequenc...
realT m_zeta
Zenith angle [radians].
realT signal2Noise2(realT &Nph, realT tau_wfs, realT d, int b)
Calculate the terms of the signal to noise ratio squared (S/N)^2 for the WFS measurement.
realT C3var(realT m, realT n)
Calculate the residual variance due to measurement and time delay errors in amplitude at a spatial fr...
realT starMag()
Get the value of the Star's magnitude.
void loadGMagAOX()
Load parameters corresponding to the G-MagAO-X system.
realT m_D
Telescope diameter [m].
realT chromScintAmpError()
Calculate the wavefront error due to scintillation chromaticity in amplitude over all spatial frequen...
std::vector< realT > ron_wfs()
Get the value of the WFS readout noise for all WFS modes.
std::vector< realT > npix_wfs()
Get the number of pixels in the WFS for all WFS modes.
realT C7(realT m, realT n, bool normStrehl=true)
Calculate the contrast due to dispersive anisoplanatism.
realT measurementErrorTotal()
Calculate the total measurement error over all corrected spatial frequencies.
void setupConfig(app::appConfigurator &config)
Setup the configurator to configure this class.
realT strehl()
Get the current Strehl ratio.
realT C0(realT m, realT n, bool normStrehl=true)
Calculate the contrast due to uncorrected phase, C0.
realT C1var(realT m, realT n)
Calculate the residual variance due to uncorrected amplitude at a spatial frequency.
realT ncp_alpha()
Get the value of the non-common path WFE PSD index.
const Eigen::Array< int, -1, -1 > & controlledModes()
Access the array of controlledModes.
realT m_wfeTimeDelay
Total WFE due to time delay [rad^2 at m_lam_sci].
realT chromScintOPDError(int m, int n)
Calculate the wavefront error due to scintillation chromaticity in the OPD at a spatial frequency.
void C_Map(imageT &im, CfuncT Cfunc, bool normStrehl)
Worker function for the contrast-map functions.
int m_fit_mn_max
Maximum spatial frequency index to use for fitting error calculation.
iosT & dumpAOSystem(iosT &ios)
Output current parameters to a stream.
std::vector< realT > m_Fbg
Background flux, [photons/sec/pixel]. One per WFS mode.
void C4Map(imageT &map, bool normStrehl)
Calculate a 2D map of contrast C4.
realT C6var(realT m, realT n)
Calculate the residual variance due to chromaticity of the index of refraction of air.
realT C2(realT m, realT n, bool normStrehl=true)
Calculate the contrast due to measurement and time delay errors in phase/OPD at a spatial frequency.
realT m_wfeMeasurement
Total WFE due to measurement a error [rad^2 at m_lam_sci].
void C2Map(imageT &map, bool normStrehl)
Calculate a 2D map of contrast C2().
realT dispAnisoAmpError()
Calculate the wavefront error due to dispersive anisoplanatism in the amplitude at a specific spatial...
Eigen::Array< int, -1, -1 > m_controlledModes
Map of which modes are under control. Set by calcStrehl.
std::vector< realT > m_d_min
Minimum AO system actuator pitch [m]. One per WFS mode.
void loadConfig(app::appConfigurator &config)
Load the configuration of this class from a configurator.
realT C6(realT m, realT n, bool normStrehl=true)
Calculate the contrast due to chromaticity of the index of refraction of air.
int fit_mn_max()
Get the value of m_fit_mn_max.
realT opticalGain()
Get the value of the optical gain.
int bin_opt()
Get the value of the optimum binning factor/index.
realT m_wfeChromIndex
Total WFE due to the chromaticity of the index of refraction [rad^2 at lam_Sci].
realT m_lam_sci
Science wavelength [m].
realT optimumTauWFS(realT m, realT n, realT d, int b)
Calculate the optimum exposure time for a given spatial frequency at a specified actuator spacing.
realT m_deltaTau
Loop latency [sec].
void C6Map(imageT &map, bool normStrehl)
Calculate a 2D map of contrast C6.
realT lam_wfs()
Get the value of the WFS wavelength.
realT D()
Get the value of the primary mirror diamter.
realT m_wfeAnisoOPD
Total WFE due to dispersive anisoplanatism OPD.
realT C3(realT m, realT n, bool normStrehl=true)
Calculate the contrast due to measurement and time delay errors in amplitude at a spatial frequency.
realT fittingError(realT m, realT n)
Calculate the fitting error at a specific spatial frequency.
wfs< realT, iosT > * wfsBeta()
Get the WFS Beta pointer.
realT optd_delta()
Get the value of the fractional change in actuator spacing for optimization..
mxException for invalid config settings
mxException for parameters which aren't set
mxException for a size error
#define mxError(esrc, ecode, expl)
This reports an mxlib specific error.
#define mxThrowException(extype, src, expl)
Throw an exception. This macro takes care of the file and line.
void quarticRoots(std::vector< std::complex< realT > > &x, realT a, realT b, realT c, realT d, realT e)
Find the roots of the general quartic equation.
constexpr floatT six_fifths()
Return 6/5 in the specified precision.
#define MXE_PARAMNOTSET
A parameter was not set.
iosT & dumpGitStatus(iosT &ios, const std::string &repoName, const std::string &branch, const std::string &sha1, const bool &modified, const std::string §ion="")
Dump the git status of a repository to a stream.
The calculated WFS uses sensitivities provided by FITS files.
The ideal wavefront sensor sensitivity function.
Class to manage a set of configurable values, and read their values from config/ini files and the com...
void add(const configTarget &tgt)
Add a configTarget.
bool isSet(const std::string &name, std::unordered_map< std::string, configTarget > &targets)
Check if a target has been set by the configuration.