30#include "../../mxlib.hpp"
31#include "../../math/constants.hpp"
32#include "../../math/roots.hpp"
40#define FITTING_ERROR_NO 0
41#define FITTING_ERROR_ZERO 1
42#define FITTING_ERROR_X 2
43#define FITTING_ERROR_Y 3
62template <
typename _realT,
class _inputSpectT,
typename iosT = std::ostream>
69 typedef _inputSpectT inputSpectT;
185 void d_min(
const std::vector<realT> &nd );
198 realT
d_min(
size_t idx );
204 std::vector<realT>
d_min();
209 void optd(
bool od );
233 template <
typename wfsT>
241 template<
typename wfsT>
242 void wfsBeta(
const wfsT * w );
294 void npix_wfs(
const std::vector<realT> &npix );
318 void ron_wfs(
const std::vector<realT> &nron );
342 void Fbg(
const std::vector<realT> &fbg );
355 realT
Fbg(
size_t idx );
361 std::vector<realT>
Fbg();
366 void minTauWFS(
const std::vector<realT> &ntau );
410 void tauWFS( realT ntau );
454 void zeta( realT nz );
536 void F0( realT nF0 );
559 realT
Fg( realT mag );
876 template <
typename varFuncT>
894 template <
typename imageT,
typename CfuncT>
895 void C_Map( imageT &im,
905 realT
C0var( realT m,
919 bool normStrehl =
true
926 template <
typename imageT>
927 void C0Map( imageT &map,
935 realT
C1var( realT m,
947 bool normStrehl =
true
957 template <
typename imageT>
958 void C1Map( imageT &map,
966 realT
C2var( realT m,
979 bool normStrehl =
true
989 template <
typename imageT>
990 void C2Map( imageT &map,
998 realT
C3var( realT m,
1011 bool normStrehl =
true
1021 template <
typename imageT>
1022 void C3Map( imageT &map,
1030 realT
C4var( realT m,
1043 bool normStrehl =
true
1053 template <
typename imageT>
1054 void C4Map( imageT &map,
1064 realT
C5var( realT m,
1077 bool normStrehl =
true
1087 template <
typename imageT>
1088 void C5Map( imageT &map,
1096 realT
C6var( realT m,
1109 bool normStrehl =
true
1119 template <
typename imageT>
1120 void C6Map( imageT &map,
1128 realT
C7var( realT m,
1140 bool normStrehl =
true
1150 template <
typename imageT>
1151 void C7Map( imageT &map,
1175template <
typename realT,
class inputSpectT,
typename iosT>
1178 wfsBeta<wfs<realT, iosT>>( nullptr );
1181template <
typename realT,
class inputSpectT,
typename iosT>
1184 if( m_wfsBeta && m_ownWfsBeta )
1190template <
typename realT,
class inputSpectT,
typename iosT>
1193 atm.loadGuyon2005();
1202 npix_wfs( std::vector<realT>( { 12868 } ) );
1203 ron_wfs( std::vector<realT>( { 0.0 } ) );
1204 Fbg( std::vector<realT>( { 0.0 } ) );
1207 minTauWFS( (realT)( 1. / 1e9 ) );
1210 m_specsChanged =
true;
1211 m_dminChanged =
true;
1214template <
typename realT,
class inputSpectT,
typename iosT>
1219 lam_wfs( 0.791e-6 );
1220 lam_sci( 0.656e-6 );
1222 npix_wfs( std::vector<realT>( { 9024 } ) );
1223 ron_wfs( std::vector<realT>( { 0.57 } ) );
1224 Fbg( std::vector<realT>( { 0.22 } ) );
1226 d_min( std::vector<realT>( { 6.5 / 48.0 } ) );
1227 minTauWFS( std::vector<realT>( { 1. / 3622. } ) );
1228 tauWFS( 1. / 3622. );
1232 m_specsChanged =
true;
1233 m_dminChanged =
true;
1236template <
typename realT,
class inputSpectT,
typename iosT>
1242 F0( 7.6e10 * 368.0 / ( 0.25 *
math::pi<realT>() * 6.5 * 6.5 * ( 1. - 0.29 * 0.29 ) ) );
1246 m_specsChanged =
true;
1247 m_dminChanged =
true;
1250template <
typename realT,
class inputSpectT,
typename iosT>
1256 m_specsChanged =
true;
1257 m_dminChanged =
true;
1260template <
typename realT,
class inputSpectT,
typename iosT>
1266template <
typename realT,
class inputSpectT,
typename iosT>
1269 m_d_min.assign( nd.begin(), nd.end() );
1270 m_specsChanged =
true;
1271 m_dminChanged =
true;
1274template <
typename realT,
class inputSpectT,
typename iosT>
1277 if( m_d_min.size() < idx + 1 )
1284 m_specsChanged =
true;
1285 m_dminChanged =
true;
1288template <
typename realT,
class inputSpectT,
typename iosT>
1291 if( m_d_min.size() < idx + 1 )
1296 return m_d_min[idx];
1299template <
typename realT,
class inputSpectT,
typename iosT>
1305template <
typename realT,
class inputSpectT,
typename iosT>
1309 m_specsChanged =
true;
1310 m_dminChanged =
true;
1313template <
typename realT,
class inputSpectT,
typename iosT>
1319template <
typename realT,
class inputSpectT,
typename iosT>
1323 m_specsChanged =
true;
1324 m_dminChanged =
true;
1327template <
typename realT,
class inputSpectT,
typename iosT>
1330 return m_optd_delta;
1333template <
typename realT,
class inputSpectT,
typename iosT>
1334template <
typename wfsT>
1337 if( m_wfsBeta && m_ownWfsBeta )
1340 m_wfsBeta =
nullptr;
1344 m_ownWfsBeta =
false;
1347template <
typename realT,
class inputSpectT,
typename iosT>
1348template <
typename wfsT>
1351 if( m_wfsBeta && m_ownWfsBeta )
1354 m_wfsBeta =
nullptr;
1360 m_ownWfsBeta =
false;
1364 m_wfsBeta =
new wfsT;
1365 m_ownWfsBeta =
true;
1369template <
typename realT,
class inputSpectT,
typename iosT>
1375template <
typename realT,
class inputSpectT,
typename iosT>
1378 if( m_wfsBeta == 0 )
1383 return m_wfsBeta->
beta_p( m, n, m_D, d_opt(), atm.r_0( m_lam_sci ) );
1386template <
typename realT,
class inputSpectT,
typename iosT>
1389 if( m_wfsBeta == 0 )
1393 return m_wfsBeta->beta_r( m, n, m_D, d_opt(), atm.r_0( m_lam_sci ) );
1396template <
typename realT,
class inputSpectT,
typename iosT>
1400 m_specsChanged =
true;
1401 m_dminChanged =
true;
1404template <
typename realT,
class inputSpectT,
typename iosT>
1407 return m_opticalGain;
1410template <
typename realT,
class inputSpectT,
typename iosT>
1414 m_specsChanged =
true;
1415 m_dminChanged =
true;
1418template <
typename realT,
class inputSpectT,
typename iosT>
1424template <
typename realT,
class inputSpectT,
typename iosT>
1427 m_npix_wfs.resize( npix.size() );
1428 for(
size_t n = 0; n < npix.size(); ++n )
1430 m_npix_wfs[n] = npix[n];
1433 m_specsChanged =
true;
1434 m_dminChanged =
true;
1437template <
typename realT,
class inputSpectT,
typename iosT>
1440 if( m_npix_wfs.size() < idx + 1 )
1445 m_npix_wfs[idx] = npix;
1447 m_specsChanged =
true;
1448 m_dminChanged =
true;
1451template <
typename realT,
class inputSpectT,
typename iosT>
1454 if( m_npix_wfs.size() < idx + 1 )
1459 return m_npix_wfs[idx];
1462template <
typename realT,
class inputSpectT,
typename iosT>
1468template <
typename realT,
class inputSpectT,
typename iosT>
1471 m_ron_wfs.resize( nron.size() );
1472 for(
size_t n = 0; n < nron.size(); ++n )
1474 m_ron_wfs[n] = nron[n];
1477 m_specsChanged =
true;
1478 m_dminChanged =
true;
1481template <
typename realT,
class inputSpectT,
typename iosT>
1484 if( m_ron_wfs.size() < idx + 1 )
1489 m_ron_wfs[idx] = nron;
1491 m_specsChanged =
true;
1492 m_dminChanged =
true;
1495template <
typename realT,
class inputSpectT,
typename iosT>
1498 if( m_ron_wfs.size() < idx + 1 )
1503 return m_ron_wfs[idx];
1506template <
typename realT,
class inputSpectT,
typename iosT>
1512template <
typename realT,
class inputSpectT,
typename iosT>
1515 m_Fbg.resize( fbg.size() );
1516 for(
size_t n = 0; n < fbg.size(); ++n )
1521 m_specsChanged =
true;
1522 m_dminChanged =
true;
1525template <
typename realT,
class inputSpectT,
typename iosT>
1528 if( m_Fbg.size() < idx + 1 )
1535 m_specsChanged =
true;
1536 m_dminChanged =
true;
1539template <
typename realT,
class inputSpectT,
typename iosT>
1542 if( m_Fbg.size() < idx + 1 )
1550template <
typename realT,
class inputSpectT,
typename iosT>
1556template <
typename realT,
class inputSpectT,
typename iosT>
1559 m_minTauWFS.resize( ntau.size() );
1560 for(
size_t n = 0; n < ntau.size(); ++n )
1562 m_minTauWFS[n] = ntau[n];
1565 m_specsChanged =
true;
1566 m_dminChanged =
true;
1569template <
typename realT,
class inputSpectT,
typename iosT>
1572 if( m_minTauWFS.size() < idx + 1 )
1577 m_minTauWFS[idx] = ntau;
1579 m_specsChanged =
true;
1580 m_dminChanged =
true;
1583template <
typename realT,
class inputSpectT,
typename iosT>
1586 if( m_minTauWFS.size() < idx + 1 )
1591 return m_minTauWFS[idx];
1594template <
typename realT,
class inputSpectT,
typename iosT>
1600template <
typename realT,
class inputSpectT,
typename iosT>
1603 if( bnp != m_bin_npix )
1606 m_specsChanged =
true;
1607 m_dminChanged =
true;
1611template <
typename realT,
class inputSpectT,
typename iosT>
1617template <
typename realT,
class inputSpectT,
typename iosT>
1624template <
typename realT,
class inputSpectT,
typename iosT>
1628 m_specsChanged =
true;
1629 m_dminChanged =
true;
1632template <
typename realT,
class inputSpectT,
typename iosT>
1638template <
typename realT,
class inputSpectT,
typename iosT>
1642 m_specsChanged =
true;
1643 m_dminChanged =
true;
1646template <
typename realT,
class inputSpectT,
typename iosT>
1652template <
typename realT,
class inputSpectT,
typename iosT>
1656 m_specsChanged =
true;
1657 m_dminChanged =
true;
1660template <
typename realT,
class inputSpectT,
typename iosT>
1666template <
typename realT,
class inputSpectT,
typename iosT>
1670 m_specsChanged =
true;
1671 m_dminChanged =
true;
1674template <
typename realT,
class inputSpectT,
typename iosT>
1680template <
typename realT,
class inputSpectT,
typename iosT>
1684 m_secZeta = 1 / cos( m_zeta );
1686 m_specsChanged =
true;
1687 m_dminChanged =
true;
1690template <
typename realT,
class inputSpectT,
typename iosT>
1696template <
typename realT,
class inputSpectT,
typename iosT>
1702template <
typename realT,
class inputSpectT,
typename iosT>
1710template <
typename realT,
class inputSpectT,
typename iosT>
1713 return m_fit_mn_max;
1716template <
typename realT,
class inputSpectT,
typename iosT>
1719 m_circularLimit = cl;
1720 m_specsChanged =
true;
1721 m_dminChanged =
true;
1724template <
typename realT,
class inputSpectT,
typename iosT>
1727 return m_circularLimit;
1730template <
typename realT,
class inputSpectT,
typename iosT>
1733 m_spatialFilter_ku = fabs( kx );
1734 m_specsChanged =
true;
1735 m_dminChanged =
true;
1738template <
typename realT,
class inputSpectT,
typename iosT>
1741 return m_spatialFilter_ku;
1744template <
typename realT,
class inputSpectT,
typename iosT>
1747 m_spatialFilter_kv = fabs( ky );
1748 m_specsChanged =
true;
1749 m_dminChanged =
true;
1752template <
typename realT,
class inputSpectT,
typename iosT>
1755 return m_spatialFilter_kv;
1758template <
typename realT,
class inputSpectT,
typename iosT>
1762 m_specsChanged =
true;
1763 m_dminChanged =
true;
1766template <
typename realT,
class inputSpectT,
typename iosT>
1772template <
typename realT,
class inputSpectT,
typename iosT>
1775 m_ncp_alpha = alpha;
1776 m_specsChanged =
true;
1777 m_dminChanged =
true;
1780template <
typename realT,
class inputSpectT,
typename iosT>
1786template <
typename realT,
class inputSpectT,
typename iosT>
1790 m_specsChanged =
true;
1791 m_dminChanged =
true;
1794template <
typename realT,
class inputSpectT,
typename iosT>
1800template <
typename realT,
class inputSpectT,
typename iosT>
1804 m_specsChanged =
true;
1805 m_dminChanged =
true;
1808template <
typename realT,
class inputSpectT,
typename iosT>
1814template <
typename realT,
class inputSpectT,
typename iosT>
1817 return m_F0 * pow( 10.0, -0.4 * mag );
1820template <
typename realT,
class inputSpectT,
typename iosT>
1823 return Fg( m_starMag );
1826template <
typename realT,
class inputSpectT,
typename iosT>
1829 if( m_specsChanged || m_dminChanged )
1832 return m_controlledModes;
1835template <
typename realT,
class inputSpectT,
typename iosT>
1838 Nph = Fg() * tau_wfs;
1840 double binfact = 1.0;
1844 if( m_npix_wfs.size() == 1 )
1846 binfact = 1. / pow( (realT)b + 1, 2 );
1852 return pow( Nph, 2 ) / ( m_npix_wfs[binidx] * binfact * ( m_Fbg[binidx] * tau_wfs + pow( m_ron_wfs[binidx], 2 ) ) );
1855template <
typename realT,
class inputSpectT,
typename iosT>
1858 if( m == 0 and n == 0 )
1864 tau_wfs = optimumTauWFS( m, n, d, b );
1868 if( m_wfsBeta == 0 )
1873 realT beta_p = m_wfsBeta->beta_p( m, n, m_D, d, atm.r_0( m_lam_wfs ) ) / sqrt( m_opticalGain );
1874 realT beta_r = m_wfsBeta->beta_r( m, n, m_D, d, atm.r_0( m_lam_wfs ) );
1876 realT snr2 = signal2Noise2( Nph, tau_wfs, d, b );
1878 return ( pow( beta_r, 2 ) / snr2 + pow( beta_p, 2 ) / Nph ) * pow( m_lam_wfs / m_lam_sci, 2 );
1881template <
typename realT,
class inputSpectT,
typename iosT>
1884 if( m_specsChanged || m_dminChanged )
1886 return m_wfeMeasurement;
1889template <
typename realT,
class inputSpectT,
typename iosT>
1892 if( m == 0 and n == 0 )
1895 realT k = sqrt( m * m + n * n ) / m_D;
1900 tau_wfs = optimumTauWFS( m, n, d, b );
1904 realT tau = tau_wfs + m_deltaTau;
1907 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
1908 sqrt( atm.X( k, m_lam_sci, m_secZeta ) ) * pow(
math::two_pi<realT>() * atm.v_wind() * k, 2 ) *
1912template <
typename realT,
class inputSpectT,
typename iosT>
1915 if( m_specsChanged || m_dminChanged )
1917 return m_wfeTimeDelay;
1920template <
typename realT,
class inputSpectT,
typename iosT>
1923 realT k = sqrt( m * m + n * n ) / m_D;
1926 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 );
1929template <
typename realT,
class inputSpectT,
typename iosT>
1932 if( m_specsChanged || m_dminChanged )
1934 return m_wfeFitting;
1937template <
typename realT,
class inputSpectT,
typename iosT>
1940 return C4var( m, n );
1943template <
typename realT,
class inputSpectT,
typename iosT>
1946 if( m_specsChanged || m_dminChanged )
1948 return m_wfeChromScintOPD;
1951template <
typename realT,
class inputSpectT,
typename iosT>
1954 return C5var( m, n );
1957 int mn_max = floor(0.5*m_D/d_opt());
1961 for(
int m = -mn_max; m <= mn_max; ++m)
1963 for(
int n = -mn_max; n <= mn_max; ++n)
1965 if(n == 0 && m == 0)
continue;
1975template <
typename realT,
class inputSpectT,
typename iosT>
1978 return C6var( m, n );
1981template <
typename realT,
class inputSpectT,
typename iosT>
1984 if( m_specsChanged || m_dminChanged )
1986 return m_wfeChromIndex;
1989template <
typename realT,
class inputSpectT,
typename iosT>
1992 return C7var( m, n );
1995template <
typename realT,
class inputSpectT,
typename iosT>
1998 if( m_specsChanged || m_dminChanged )
2000 return m_wfeAnisoOPD;
2003template <
typename realT,
class inputSpectT,
typename iosT>
2009 int mn_max = floor(0.5*m_D/d_opt());
2013 for(
int m = -mn_max; m <= mn_max; ++m)
2015 for(
int n = -mn_max; n <= mn_max; ++n)
2017 if(n == 0 && m == 0)
continue;
2019 if( m_circularLimit )
2021 if( m*m + n*n > mn_max*mn_max )
continue;
2032template <
typename realT,
class inputSpectT,
typename iosT>
2051 double binfact = 1.0;
2055 if( m_npix_wfs.size() > 1 )
2061 binfact = 1.0 / pow( (realT)( bbin + 1 ), 2 );
2065 realT k = sqrt( m * m + n * n ) / m_D;
2069 if( m_wfsBeta == 0 )
2074 realT beta_p = m_wfsBeta->beta_p( m, n, m_D, dact, atm.r_0( m_lam_wfs ) ) / sqrt( m_opticalGain );
2075 realT beta_r = m_wfsBeta->beta_r( m, n, m_D, dact, atm.r_0( m_lam_wfs ) ) / sqrt( m_opticalGain );
2078 realT a, b, c, d, e;
2081 realT Atmp = 2 * pow( atm.lam_0(), 2 ) * psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) *
2082 ( atm.X( k, m_lam_wfs, m_secZeta ) ) * pow(
math::two_pi<realT>() * atm.v_wind() * k, 2 );
2085 b = Atmp * m_deltaTau;
2087 d = -1 * ( pow( m_lam_wfs, 2 ) / F ) *
2088 ( ( m_npix_wfs[binidx] * binfact * m_Fbg[binidx] / F ) * pow( beta_r, 2 ) + pow( beta_p, 2 ) );
2089 e = -2 * pow( m_lam_wfs, 2 ) * ( m_npix_wfs[binidx] * binfact ) * pow( m_ron_wfs[binidx], 2 ) * pow( beta_r, 2 ) /
2092 std::vector<std::complex<realT>> x;
2100 for(
int i = 0; i < 4; i++ )
2102 if( real( x[i] ) > 0 && imag( x[i] ) == 0 && real( x[i] ) > tauopt )
2103 tauopt = real( x[i] );
2106 if( tauopt < m_minTauWFS[binidx] )
2107 tauopt = m_minTauWFS[binidx];
2112template <
typename realT,
class inputSpectT,
typename iosT>
2116 return optimumTauWFS( m, n, m_d_opt, m_bin_opt );
2119template <
typename realT,
class inputSpectT,
typename iosT>
2122 if( !m_dminChanged )
2127 if( m_npix_wfs.size() < 1 )
2132 if( m_d_min.size() != m_npix_wfs.size() )
2137 if( m_ron_wfs.size() != m_npix_wfs.size() )
2142 if( m_Fbg.size() != m_npix_wfs.size() )
2147 if( m_minTauWFS.size() != m_npix_wfs.size() )
2153 if( m_d_min.size() == 1 && m_d_min[0] == 0 )
2157 m_dminChanged =
false;
2163 m_d_opt = m_d_min[0];
2165 m_dminChanged =
false;
2174 if( m_npix_wfs.size() > 1 )
2177 best_d = m_d_min[0];
2179 realT bestStrehlOverall = 0;
2181 for(
int b = 0; b < m_npix_wfs.size(); ++b )
2183 realT d = m_d_min[b];
2184 realT s = strehl( d, b );
2185 realT bestStrehl = s;
2188 while( d < m_D / 2 )
2190 d += m_d_min[b] / m_optd_delta;
2193 if( s < bestStrehl )
2196 d -= m_d_min[b] / m_optd_delta;
2204 if( bestStrehl >= bestStrehlOverall )
2206 bestStrehlOverall = bestStrehl;
2212 m_bin_opt = best_idx;
2216 realT d = m_d_min[0];
2219 realT s = strehl( d, m_bin_opt );
2220 realT bestStrehl = s;
2222 while( d < m_D / 2 )
2224 d += m_d_min[0] / m_optd_delta;
2225 m_bin_opt = d / m_d_min[0] - 1;
2229 s = strehl( d, m_bin_opt );
2231 if( s < bestStrehl )
2234 d -= m_d_min[0] / m_optd_delta;
2235 m_bin_opt = d / m_d_min[0] - 1;
2248 realT d = m_d_min[0];
2251 realT s = strehl( d, m_bin_opt );
2252 realT bestStrehl = s;
2255 while( d < m_D / 2 )
2257 d += m_d_min[0] / m_optd_delta;
2259 s = strehl( d, m_bin_opt );
2260 if( s < bestStrehl )
2262 d -= m_d_min[0] / m_optd_delta;
2272 m_dminChanged =
false;
2277template <
typename realT,
class inputSpectT,
typename iosT>
2280 if( m == 0 and n == 0 )
2283 realT k = sqrt( m * m + n * n ) / m_D;
2285 realT kmax = m_fit_mn_max / m_D;
2286 realT kmin = 1. / m_D;
2289 if( m_ncp_alpha != 2 )
2292 ( pow( kmin, -m_ncp_alpha + 2 ) - pow( kmax, -m_ncp_alpha + 2 ) );
2298 return beta * ncpError() * pow( k, -m_ncp_alpha ) * pow( kmin, 2 );
2301template <
typename realT,
class inputSpectT,
typename iosT>
2307template <
typename realT,
class inputSpectT,
typename iosT>
2311 int mn_max = floor( 0.5 * m_D / d );
2316 for(
int m = -m_fit_mn_max; m <= m_fit_mn_max; ++m )
2318 for(
int n = -m_fit_mn_max; n <= m_fit_mn_max; ++n )
2321 if( m_circularLimit )
2323 if( m * m + n * n <= mn_max * mn_max )
2328 if( abs( m ) <= mn_max && abs( n ) <= mn_max )
2334 realT wfeMeasurement = measurementError( m, n, d, b );
2335 realT wfeTimeDelay = timeDelayError( m, n, d, b );
2336 realT wfeChromScintOPD = chromScintOPDError( m, n );
2337 realT wfeChromIndex = chromIndexError( m, n );
2338 realT wfeAnisoOPD = dispAnisoOPDError( m, n );
2340 realT wfeFitting = fittingError( m, n );
2342 if( wfeFitting < wfeMeasurement + wfeTimeDelay + wfeChromScintOPD + wfeChromIndex + wfeAnisoOPD )
2344 wfeVar += wfeFitting;
2348 wfeVar += wfeMeasurement + wfeTimeDelay + wfeChromScintOPD + wfeChromIndex + wfeAnisoOPD;
2353 wfeVar += fittingError( m, n );
2358 wfeVar += ncpError();
2359 return exp( -1 * wfeVar );
2362template <
typename realT,
class inputSpectT,
typename iosT>
2368 int mn_max = floor( 0.5 * m_D / d );
2370 m_wfeMeasurement = 0;
2372 m_wfeChromScintOPD = 0;
2373 m_wfeChromIndex = 0;
2380 m_controlledModes.resize( 2 * m_fit_mn_max + 1, 2 * m_fit_mn_max + 1 );
2381 m_controlledModes.setZero();
2384 for(
int m = -m_fit_mn_max; m <= m_fit_mn_max; ++m )
2386 for(
int n = -m_fit_mn_max; n <= m_fit_mn_max; ++n )
2388 if( m == 0 && n == 0 )
2394 if( m_circularLimit )
2396 if( m * m + n * n <= mn_max * mn_max )
2401 if( abs( m ) <= mn_max && abs( n ) <= mn_max )
2407 realT wfeMeasurement = measurementError( m, n, d, b );
2408 realT wfeTimeDelay = timeDelayError( m, n, d, b );
2409 realT wfeChromScintOPD = chromScintOPDError( m, n );
2410 realT wfeChromIndex = chromIndexError( m, n );
2411 realT wfeAnisoOPD = dispAnisoOPDError( m, n );
2413 realT wfeFitting = fittingError( m, n );
2415 if( wfeFitting < wfeMeasurement + wfeTimeDelay + wfeChromScintOPD + wfeChromIndex + wfeAnisoOPD )
2417 m_wfeFitting += wfeFitting;
2421 m_wfeMeasurement += wfeMeasurement;
2422 m_wfeTimeDelay += wfeTimeDelay;
2423 m_wfeChromScintOPD += wfeChromScintOPD;
2424 m_wfeChromIndex += wfeChromIndex;
2425 m_wfeAnisoOPD += wfeAnisoOPD;
2426 m_controlledModes( m_fit_mn_max + m, m_fit_mn_max + n ) = 1;
2431 m_wfeFitting += fittingError( m, n );
2436 m_wfeNCP = ncpError();
2438 m_wfeVar = m_wfeMeasurement + m_wfeTimeDelay + m_wfeFitting + m_wfeChromScintOPD + m_wfeChromIndex + m_wfeAnisoOPD +
2441 m_strehl = exp( -1 * m_wfeVar );
2443 m_specsChanged =
false;
2446template <
typename realT,
class inputSpectT,
typename iosT>
2449 if( m_specsChanged || m_dminChanged )
2455template <
typename realT,
class inputSpectT,
typename iosT>
2458 if( m_specsChanged || m_dminChanged )
2464template <
typename realT,
class inputSpectT,
typename iosT>
2465template <
typename varFuncT>
2468 if( m == 0 && n == 0 )
2478 if( doFittingError != FITTING_ERROR_NO )
2480 int mn_max = m_D / ( 2. * d_opt() );
2482 if( m_controlledModes( m_fit_mn_max + m, m_fit_mn_max + n ) == false )
2484 if( doFittingError == FITTING_ERROR_ZERO )
2487 realT fe = fittingError( m, n );
2489 realT k = sqrt( m * m + n * n ) / m_D;
2491 if( doFittingError == FITTING_ERROR_X )
2492 fe *= ( atm.X( k, m_lam_sci, m_secZeta ) );
2493 else if( doFittingError == FITTING_ERROR_Y )
2494 fe *= ( atm.Y( k, m_lam_sci, m_secZeta ) );
2497 std::cerr <<
"Unknown doFittingError\n";
2506 realT var = ( this->*varFunc )( m, n );
2511template <
typename realT,
class inputSpectT,
typename iosT>
2512template <
typename imageT,
typename CfuncT>
2515 int dim1 = im.rows();
2516 int dim2 = im.cols();
2518 int mc = 0.5 * ( dim1 - 1 );
2519 int nc = 0.5 * ( dim2 - 1 );
2521 for(
int i = 0; i < dim1; ++i )
2525 for(
int j = 0; j < dim2; ++j )
2529 im( i, j ) = ( this->*Cfunc )( m, n, normStrehl );
2534template <
typename realT,
class inputSpectT,
typename iosT>
2537 realT k = sqrt( m * m + n * n ) / m_D;
2539 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
2540 ( atm.X( k, m_lam_sci, m_secZeta ) );
2543template <
typename realT,
class inputSpectT,
typename iosT>
2550template <
typename realT,
class inputSpectT,
typename iosT>
2551template <
typename imageT>
2557template <
typename realT,
class inputSpectT,
typename iosT>
2560 realT k = sqrt( m * m + n * n ) / m_D;
2563 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
2564 ( atm.Y( k, m_lam_sci, m_secZeta ) );
2567template <
typename realT,
class inputSpectT,
typename iosT>
2573template <
typename realT,
class inputSpectT,
typename iosT>
2574template <
typename imageT>
2580template <
typename realT,
class inputSpectT,
typename iosT>
2584 return measurementError( m, n, d_opt(), m_bin_opt ) + timeDelayError( m, n, d_opt(), m_bin_opt );
2587template <
typename realT,
class inputSpectT,
typename iosT>
2593template <
typename realT,
class inputSpectT,
typename iosT>
2594template <
typename imageT>
2600template <
typename realT,
class inputSpectT,
typename iosT>
2606template <
typename realT,
class inputSpectT,
typename iosT>
2612template <
typename realT,
class inputSpectT,
typename iosT>
2613template <
typename imageT>
2619template <
typename realT,
class inputSpectT,
typename iosT>
2622 realT k = sqrt( m * m + n * n ) / m_D;
2626 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
2627 atm.dX( k, m_lam_sci, m_lam_wfs );
2630template <
typename realT,
class inputSpectT,
typename iosT>
2636template <
typename realT,
class inputSpectT,
typename iosT>
2637template <
typename imageT>
2643template <
typename realT,
class inputSpectT,
typename iosT>
2646 realT k = sqrt( m * m + n * n ) / m_D;
2650 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
2651 atm.dY( k, m_lam_sci, m_lam_wfs );
2654template <
typename realT,
class inputSpectT,
typename iosT>
2660template <
typename realT,
class inputSpectT,
typename iosT>
2661template <
typename imageT>
2667template <
typename realT,
class inputSpectT,
typename iosT>
2670 realT ni = atm.n_air( m_lam_sci );
2671 realT nw = atm.n_air( m_lam_wfs );
2673 return C0var( m, n ) * pow( ( ni - nw ) / ( ni - 1 ), 2 );
2676template <
typename realT,
class inputSpectT,
typename iosT>
2682template <
typename realT,
class inputSpectT,
typename iosT>
2683template <
typename imageT>
2689template <
typename realT,
class inputSpectT,
typename iosT>
2692 realT k = sqrt( m * m + n * n ) / m_D;
2695 return psd( atm, 0, k, m_secZeta ) / pow( m_D, 2 ) * pow( atm.lam_0() / m_lam_sci, 2 ) *
2696 atm.X_Z( k, m_lam_wfs, m_lam_sci, m_secZeta );
2699template <
typename realT,
class inputSpectT,
typename iosT>
2705template <
typename realT,
class inputSpectT,
typename iosT>
2706template <
typename imageT>
2712template <
typename realT,
class inputSpectT,
typename iosT>
2715 ios <<
"# AO Params:\n";
2716 ios <<
"# D = " << D() <<
'\n';
2718 if( m_d_min.size() > 0 )
2720 ios <<
"# d_min = " << d_min( (
size_t)0 );
2721 for(
size_t n = 1; n < m_d_min.size(); ++n )
2722 ios <<
',' << d_min( n );
2726 ios <<
"# d_min = null\n";
2728 ios <<
"# optd = " << std::boolalpha << m_optd <<
'\n';
2729 ios <<
"# d_opt_delta = " << optd_delta() <<
'\n';
2730 ios <<
"# lam_sci = " << lam_sci() <<
'\n';
2731 ios <<
"# F0 = " << F0() <<
'\n';
2732 ios <<
"# starMag = " << starMag() <<
'\n';
2733 ios <<
"# lam_sci = " << lam_sci() <<
'\n';
2734 ios <<
"# zeta = " << zeta() <<
'\n';
2735 ios <<
"# lam_wfs = " << lam_wfs() <<
'\n';
2737 if( npix_wfs().size() > 0 )
2739 ios <<
"# npix_wfs = " << npix_wfs( (
size_t)0 );
2740 for(
size_t n = 1; n < npix_wfs().size(); ++n )
2741 ios <<
',' << npix_wfs( n );
2745 ios <<
"# npix_wfs = null\n";
2747 if( ron_wfs().size() > 0 )
2749 ios <<
"# ron_wfs = " << ron_wfs( (
size_t)0 );
2750 for(
size_t n = 1; n < ron_wfs().size(); ++n )
2751 ios <<
',' << ron_wfs( n );
2755 ios <<
"# ron_wfs = null\n";
2757 if( Fbg().size() > 0 )
2759 ios <<
"# Fbg = " << Fbg( (
size_t)0 );
2760 for(
size_t n = 1; n < Fbg().size(); ++n )
2761 ios <<
',' << Fbg( n );
2765 ios <<
"# Fbg = null\n";
2767 if( minTauWFS().size() > 0 )
2769 ios <<
"# minTauWFS = " << minTauWFS( (
size_t)0 );
2770 for(
size_t n = 1; n < minTauWFS().size(); ++n )
2771 ios <<
',' << minTauWFS( n );
2775 ios <<
"# minTauWFS = null\n";
2777 ios <<
"# bin_npix = " << std::boolalpha << m_bin_npix <<
'\n';
2778 ios <<
"# tauWFS = " << tauWFS() <<
'\n';
2779 ios <<
"# optTau = " << std::boolalpha << m_optTau <<
'\n';
2780 ios <<
"# deltaTau = " << deltaTau() <<
'\n';
2781 ios <<
"# fit_mn_max = " << m_fit_mn_max <<
'\n';
2782 ios <<
"# spatialFilter_ku = " << m_spatialFilter_ku <<
'\n';
2783 ios <<
"# spatialFilter_kv = " << m_spatialFilter_kv <<
'\n';
2784 ios <<
"# ncp_wfe = " << m_ncp_wfe <<
'\n';
2785 ios <<
"# ncp_alpha = " << m_ncp_alpha <<
'\n';
2787 if( m_wfsBeta == 0 )
2792 m_wfsBeta->dumpWFS( ios );
2794 atm.dumpAtmosphere( ios );
2801template <
typename realT,
class inputSpectT,
typename iosT>
2804 using namespace mx::app;
2807 config.
add(
"aosys.wfs",
2815 "The WFS type: idealWFS, unmodPyWFS, asympModPyWFS, shwfs, calculatedWFS" );
2816 config.
add(
"aosys.wfs_beta_p",
2824 "The beta_p file path for calcualtedWFS" );
2825 config.
add(
"aosys.wfs_beta_r",
2833 "The beta_r file path for calcualtedWFS" );
2834 config.
add(
"aosys.wfs_sensitivity",
2836 "aosys.wfs_sensitivity",
2842 "Flag indicating that beta_p/beta_r are sensitivities (inverse) [default false]" );
2844 .
add(
"aosys.D",
"",
"aosys.D", argType::Required,
"aosys",
"D",
false,
"real",
"The telescope diameter [m]" );
2845 config.
add(
"aosys.d_min",
2853 "The minimum actuator spacing [m]" );
2854 config.
add(
"aosys.optd",
2862 "Whether or not the actuator spacing is optimized" );
2863 config.
add(
"aosys.optd_delta",
2871 "The fractional change from d_min used in optimization. Set to 1 (default) for integer binnings, > 1 "
2872 "for finer sampling." );
2873 config.
add(
"aosys.F0",
2881 "Zero-mag photon flux, [photons/sec]" );
2882 config.
add(
"aosys.lam_wfs",
2890 "WFS wavelength [m]" );
2891 config.
add(
"aosys.npix_wfs",
2899 "The number of pixels in the WFS" );
2900 config.
add(
"aosys.ron_wfs",
2908 "WFS readout noise [photons/read]" );
2909 config.
add(
"aosys.bin_npix",
2917 "Whether or not WFS pixels are re-binned along with actuator spacing optimization" );
2918 config.
add(
"aosys.Fbg",
2926 "Background counts, [counts/pix/sec]" );
2927 config.
add(
"aosys.tauWFS",
2935 "WFS integration time [s]" );
2936 config.
add(
"aosys.minTauWFS",
2944 "Minimum WFS integration time [s]" );
2945 config.
add(
"aosys.deltaTau",
2954 config.
add(
"aosys.optTau",
2962 "Whether or not the integration time is optimized" );
2963 config.
add(
"aosys.lam_sci",
2971 "Science wavelength [m]" );
2972 config.
add(
"aosys.zeta",
2980 "Zenith distance [rad]" );
2981 config.
add(
"aosys.fit_mn_max",
2989 "Maximum spatial frequency index to use for analysis" );
2990 config.
add(
"aosys.circularLimit",
2992 "aosys.circularLimit",
2998 " Flag to indicate that the spatial frequency limit is circular, not square." );
2999 config.
add(
"aosys.spatialFilter_ku",
3001 "aosys.spatialFilter_ku",
3007 "Spatial filter cutoff frequency in u [m^-1]" );
3008 config.
add(
"aosys.spatialFilter_kv",
3010 "aosys.spatialFilter_kv",
3016 "Spatial filter cutoff frequency in v [m^-1]" );
3017 config.
add(
"aosys.ncp_wfe",
3025 "NCP WFE between 1 lambda/D and fit_mn_max [rad^2]" );
3026 config.
add(
"aosys.ncp_alpha",
3034 "PSD index for NCP WFE" );
3035 config.
add(
"aosys.starMag",
3044 config.
add(
"aosys.starMags",
3052 "A vector of star magnitudes" );
3054 atm.setupConfig( config );
3055 psd.setupConfig( config );
3058template <
typename realT,
class inputSpectT,
typename iosT>
3062 if( config.
isSet(
"aosys.wfs" ) )
3065 config( wfsStr,
"aosys.wfs" );
3067 if( wfsStr ==
"ideal" )
3069 wfsBeta<wfs<realT, iosT>>( nullptr );
3071 else if( wfsStr ==
"unmodPyWFS" )
3073 wfsBeta<pywfsUnmod<realT, iosT>>( nullptr );
3075 else if( wfsStr ==
"asympModPyWFS" )
3077 wfsBeta<pywfsModAsymptotic<realT>>( nullptr );
3079 else if( wfsStr ==
"SHWFS" )
3081 wfsBeta<shwfs<realT, iosT>>( nullptr );
3083 else if( wfsStr ==
"calculatedWFS" )
3085 wfsBeta<calculatedWFS<realT, iosT>>( nullptr );
3088 config( cwfs->m_beta_p_file,
"aosys.wfs_beta_p" );
3089 config( cwfs->m_beta_r_file,
"aosys.wfs_beta_r" );
3090 bool sens = cwfs->m_sensitivity;
3091 config( sens,
"aosys.wfs_sensitivity" );
3092 if( config.isSet(
"aosys.wfs_sensitivity" ) )
3094 cwfs->m_sensitivity = sens;
3108 config( nD,
"aosys.D" );
3109 if( config.
isSet(
"aosys.D" ) )
3113 std::vector<realT> nd_min = d_min();
3114 config( nd_min,
"aosys.d_min" );
3115 if( config.
isSet(
"aosys.d_min" ) )
3118 bool noptd = optd();
3119 config( noptd,
"aosys.optd" );
3120 if( config.
isSet(
"aosys.optd" ) )
3123 realT noptd_delta = optd_delta();
3124 config( noptd_delta,
"aosys.optd_delta" );
3125 if( config.
isSet(
"aosys.optd_delta" ) )
3126 optd_delta( noptd_delta );
3128 realT nlam_wfs = lam_wfs();
3129 config( nlam_wfs,
"aosys.lam_wfs" );
3130 if( config.
isSet(
"aosys.lam_wfs" ) )
3131 lam_wfs( nlam_wfs );
3134 std::vector<realT> nnpix_wfs = npix_wfs();
3135 config( nnpix_wfs,
"aosys.npix_wfs" );
3136 if( config.
isSet(
"aosys.npix_wfs" ) )
3137 npix_wfs( nnpix_wfs );
3140 std::vector<realT> nron_wfs = ron_wfs();
3141 config( nron_wfs,
"aosys.ron_wfs" );
3142 if( config.
isSet(
"aosys.ron_wfs" ) )
3143 ron_wfs( nron_wfs );
3146 std::vector<realT> nFbg = Fbg();
3147 config( nFbg,
"aosys.Fbg" );
3148 if( config.
isSet(
"aosys.Fbg" ) )
3152 std::vector<realT> nminTauWFS = minTauWFS();
3153 config( nminTauWFS,
"aosys.minTauWFS" );
3154 if( config.
isSet(
"aosys.minTauWFS" ) )
3155 minTauWFS( nminTauWFS );
3158 bool nbin_npix = bin_npix();
3159 config( nbin_npix,
"aosys.bin_npix" );
3160 if( config.
isSet(
"aosys.bin_npix" ) )
3161 bin_npix( nbin_npix );
3164 realT ntauWFS = tauWFS();
3165 config( ntauWFS,
"aosys.tauWFS" );
3166 if( config.
isSet(
"aosys.tauWFS" ) )
3170 realT ndeltaTau = deltaTau();
3171 config( ndeltaTau,
"aosys.deltaTau" );
3172 if( config.
isSet(
"aosys.deltaTau" ) )
3173 deltaTau( ndeltaTau );
3176 bool noptTau = optTau();
3177 config( noptTau,
"aosys.optTau" );
3178 if( config.
isSet(
"aosys.optTau" ) )
3182 realT nlam_sci = lam_sci();
3183 config( nlam_sci,
"aosys.lam_sci" );
3184 if( config.
isSet(
"aosys.lam_sci" ) )
3185 lam_sci( nlam_sci );
3188 realT nzeta = zeta();
3189 config( nzeta,
"aosys.zeta" );
3190 if( config.
isSet(
"aosys.zeta" ) )
3194 realT fmnm = fit_mn_max();
3195 config( fmnm,
"aosys.fit_mn_max" );
3196 if( config.
isSet(
"aosys.fit_mn_max" ) )
3200 bool cl = circularLimit();
3201 config( cl,
"aosys.circularLimit" );
3202 if( config.
isSet(
"aosys.circularLimit" ) )
3203 circularLimit( cl );
3206 realT ku = spatialFilter_ku();
3207 config( ku,
"aosys.spatialFilter_ku" );
3208 if( config.
isSet(
"aosys.spatialFilter_ku" ) )
3209 spatialFilter_ku( ku );
3212 realT kv = spatialFilter_kv();
3213 config( kv,
"aosys.spatialFilter_kv" );
3214 if( config.
isSet(
"aosys.spatialFilter_kv" ) )
3215 spatialFilter_kv( kv );
3218 realT nwfe = ncp_wfe();
3219 config( nwfe,
"aosys.ncp_wfe" );
3220 if( config.
isSet(
"aosys.ncp_wfe" ) )
3224 realT na = ncp_alpha();
3225 config( na,
"aosys.ncp_alpha" );
3226 if( config.
isSet(
"aosys.ncp_alpha" ) )
3231 config( nF0,
"aosys.F0" );
3232 if( config.
isSet(
"aosys.F0" ) )
3236 realT smag = starMag();
3237 config( smag,
"aosys.starMag" );
3238 if( config.
isSet(
"aosys.starMag" ) )
3241 atm.loadConfig( config );
3242 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 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..
Augments an exception with the source file and line.
@ sizeerr
A size was invalid or calculated incorrectly.
@ paramnotset
A parameter was not set.
@ invalidarg
An argument was invalid.
error_t mxlib_error_report(const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
Print a report to stderr given an mxlib error_t code and explanation and return the code.
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.
MXLIB_DEFAULT_VERBOSITY d
The default verbosity.
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.
virtual realT beta_p(int m, int n, realT D, realT d, realT r0)
Get the photon noise sensitivity at a spatial frequency.
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.