31 #include "../../math/constants.hpp"
32 #include "../../math/roots.hpp"
33 #include "../../mxError.hpp"
34 #include "../../mxException.hpp"
44 #define FITTING_ERROR_NO 0
45 #define FITTING_ERROR_ZERO 1
46 #define FITTING_ERROR_X 2
47 #define FITTING_ERROR_Y 3
66 template<
typename _realT,
class _inputSpectT,
typename iosT = std::ostream>
73 typedef _inputSpectT inputSpectT;
183 void d_min(
const std::vector<realT> & nd );
196 realT
d_min(
size_t idx );
202 std::vector<realT>
d_min();
207 void optd(
bool od );
231 template<
typename wfsT>
232 void wfsBeta(
const wfsT & w );
239 template<
typename wfsT>
240 void wfsBeta(
const wfsT * w );
280 void npix_wfs(
const std::vector<realT> & npix );
304 void ron_wfs(
const std::vector<realT> & nron );
328 void Fbg(
const std::vector<realT> & fbg );
341 realT
Fbg(
size_t idx );
347 std::vector<realT>
Fbg();
352 void minTauWFS(
const std::vector<realT> & ntau );
441 void zeta( realT nz );
546 realT
Fg( realT mag );
861 template<
typename varFuncT>
878 template<
typename imageT,
typename CfuncT>
879 void C_Map( imageT & im,
889 realT
C0var( realT m,
903 bool normStrehl =
true
910 template<
typename imageT>
911 void C0Map( imageT & map,
920 realT
C1var( realT m,
932 bool normStrehl =
true
942 template<
typename imageT>
943 void C1Map( imageT & map,
953 realT
C2var( realT m,
966 bool normStrehl =
true
976 template<
typename imageT>
977 void C2Map( imageT & map,
986 realT
C3var( realT m,
999 bool normStrehl =
true
1009 template<
typename imageT>
1010 void C3Map( imageT & map,
1020 realT
C4var( realT m,
1032 bool normStrehl =
true
1042 template<
typename imageT>
1043 void C4Map( imageT & map,
1055 realT
C5var( realT m,
1067 bool normStrehl =
true
1077 template<
typename imageT>
1078 void C5Map( imageT & map,
1088 realT
C6var( realT m,
1100 bool normStrehl =
true
1110 template<
typename imageT>
1111 void C6Map( imageT & map,
1121 realT
C7var( realT m,
1133 bool normStrehl =
true
1143 template<
typename imageT>
1144 void C7Map( imageT & map,
1173 template<
typename realT,
class inputSpectT,
typename iosT>
1176 wfsBeta<wfs<realT,iosT>>(
nullptr);
1179 template<
typename realT,
class inputSpectT,
typename iosT>
1182 if(m_wfsBeta && m_ownWfsBeta)
1188 template<
typename realT,
class inputSpectT,
typename iosT>
1191 atm.loadGuyon2005();
1193 F0(1.75e9*0.25*math::pi<realT>()*64.*0.18);
1200 npix_wfs(std::vector<realT>({12868}));
1201 ron_wfs(std::vector<realT>({0.0}));
1202 Fbg(std::vector<realT>({0.0}));
1205 minTauWFS( (realT) (1./1e9) );
1208 m_specsChanged =
true;
1209 m_dminChanged =
true;
1212 template<
typename realT,
class inputSpectT,
typename iosT>
1220 npix_wfs(std::vector<realT>({9024}));
1221 ron_wfs(std::vector<realT>({0.57}));
1222 Fbg(std::vector<realT>({0.22}));
1224 d_min(std::vector<realT>({6.5/48.0}));
1225 minTauWFS(std::vector<realT>({1./3622.}));
1230 m_specsChanged =
true;
1231 m_dminChanged =
true;
1235 template<
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;
1250 template<
typename realT,
class inputSpectT,
typename iosT>
1256 m_specsChanged =
true;
1257 m_dminChanged =
true;
1260 template<
typename realT,
class inputSpectT,
typename iosT>
1266 template<
typename realT,
class inputSpectT,
typename iosT>
1269 m_d_min.assign(nd.begin(), nd.end());
1270 m_specsChanged =
true;
1271 m_dminChanged =
true;
1274 template<
typename realT,
class inputSpectT,
typename iosT>
1279 if(m_d_min.size() < idx+1)
1281 mxThrowException(
err::sizeerr,
"aoSystem::d_min",
"idx larger than m_d_min");
1286 m_specsChanged =
true;
1287 m_dminChanged =
true;
1290 template<
typename realT,
class inputSpectT,
typename iosT>
1293 if(m_d_min.size() < idx+1)
1295 mxThrowException(
err::sizeerr,
"aoSystem::d_min",
"idx larger than m_d_min");
1298 return m_d_min[idx];
1301 template<
typename realT,
class inputSpectT,
typename iosT>
1307 template<
typename realT,
class inputSpectT,
typename iosT>
1311 m_specsChanged =
true;
1312 m_dminChanged =
true;
1315 template<
typename realT,
class inputSpectT,
typename iosT>
1321 template<
typename realT,
class inputSpectT,
typename iosT>
1325 m_specsChanged =
true;
1326 m_dminChanged =
true;
1329 template<
typename realT,
class inputSpectT,
typename iosT>
1332 return m_optd_delta;
1335 template<
typename realT,
class inputSpectT,
typename iosT>
1336 template<
typename wfsT>
1339 if(m_wfsBeta && m_ownWfsBeta)
1342 m_wfsBeta =
nullptr;
1346 m_ownWfsBeta =
false;
1349 template<
typename realT,
class inputSpectT,
typename iosT>
1350 template<
typename wfsT>
1353 if(m_wfsBeta && m_ownWfsBeta)
1356 m_wfsBeta =
nullptr;
1362 m_ownWfsBeta =
false;
1366 m_wfsBeta =
new wfsT;
1367 m_ownWfsBeta =
true;
1371 template<
typename realT,
class inputSpectT,
typename iosT>
1377 template<
typename realT,
class inputSpectT,
typename iosT>
1380 if( m_wfsBeta == 0) mxThrowException(
err::paramnotset,
"aoSystem::beta_p",
"The WFS is not assigned.");
1382 return m_wfsBeta->beta_p(m, n, m_D, d_opt(), atm.r_0(m_lam_sci) );
1385 template<
typename realT,
class inputSpectT,
typename iosT>
1388 if( m_wfsBeta == 0) mxThrowException(
err::paramnotset,
"aoSystem::beta_r",
"The WFS is not assigned.");
1390 return m_wfsBeta->beta_r(m, n, m_D, d_opt(), atm.r_0(m_lam_sci) );
1394 template<
typename realT,
class inputSpectT,
typename iosT>
1398 m_specsChanged =
true;
1399 m_dminChanged =
true;
1402 template<
typename realT,
class inputSpectT,
typename iosT>
1408 template<
typename realT,
class inputSpectT,
typename iosT>
1411 m_npix_wfs.resize(npix.size());
1412 for(
size_t n=0; n < npix.size(); ++n)
1414 m_npix_wfs[n] = npix[n];
1417 m_specsChanged =
true;
1418 m_dminChanged =
true;
1421 template<
typename realT,
class inputSpectT,
typename iosT>
1426 if(m_npix_wfs.size() < idx+1)
1428 mxThrowException(
err::sizeerr,
"aoSystem::npix_wfs",
"idx larger than m_npix_wfs");
1431 m_npix_wfs[idx] = npix;
1433 m_specsChanged =
true;
1434 m_dminChanged =
true;
1437 template<
typename realT,
class inputSpectT,
typename iosT>
1440 if(m_npix_wfs.size() < idx+1)
1442 mxThrowException(
err::sizeerr,
"aoSystem::npix_wfs",
"idx larger than m_npix_wfs");
1445 return m_npix_wfs[idx];
1448 template<
typename realT,
class inputSpectT,
typename iosT>
1454 template<
typename realT,
class inputSpectT,
typename iosT>
1457 m_ron_wfs.resize(nron.size());
1458 for(
size_t n=0; n < nron.size(); ++n)
1460 m_ron_wfs[n] = nron[n];
1463 m_specsChanged =
true;
1464 m_dminChanged =
true;
1467 template<
typename realT,
class inputSpectT,
typename iosT>
1472 if(m_ron_wfs.size() < idx+1)
1474 mxThrowException(
err::sizeerr,
"aoSystem::ron_wfs",
"idx larger than m_ron_wfs");
1477 m_ron_wfs[idx] = nron;
1479 m_specsChanged =
true;
1480 m_dminChanged =
true;
1484 template<
typename realT,
class inputSpectT,
typename iosT>
1487 if(m_ron_wfs.size() < idx+1)
1489 mxThrowException(
err::sizeerr,
"aoSystem::ron_wfs",
"idx larger than m_ron_wfs");
1492 return m_ron_wfs[idx];
1495 template<
typename realT,
class inputSpectT,
typename iosT>
1501 template<
typename realT,
class inputSpectT,
typename iosT>
1504 m_Fbg.resize(fbg.size());
1505 for(
size_t n=0; n < fbg.size(); ++n)
1510 m_specsChanged =
true;
1511 m_dminChanged =
true;
1514 template<
typename realT,
class inputSpectT,
typename iosT>
1519 if(m_Fbg.size() < idx+1)
1521 mxThrowException(
err::sizeerr,
"aoSyste,::Fbg",
"idx larger than m_Fbg");
1526 m_specsChanged =
true;
1527 m_dminChanged =
true;
1530 template<
typename realT,
class inputSpectT,
typename iosT>
1533 if(m_Fbg.size() < idx+1)
1535 mxThrowException(
err::sizeerr,
"aoSyste,::Fbg",
"idx larger than m_Fbg");
1541 template<
typename realT,
class inputSpectT,
typename iosT>
1547 template<
typename realT,
class inputSpectT,
typename iosT>
1550 m_minTauWFS.resize(ntau.size());
1551 for(
size_t n=0; n < ntau.size(); ++n)
1553 m_minTauWFS[n] = ntau[n];
1556 m_specsChanged =
true;
1557 m_dminChanged =
true;
1560 template<
typename realT,
class inputSpectT,
typename iosT>
1565 if(m_minTauWFS.size() < idx+1)
1567 mxThrowException(
err::sizeerr,
"aoSystem::minTauWFS",
"idx larger than m_ntau_wfs");
1570 m_minTauWFS[idx] = ntau;
1572 m_specsChanged =
true;
1573 m_dminChanged =
true;
1576 template<
typename realT,
class inputSpectT,
typename iosT>
1579 if(m_minTauWFS.size() < idx+1)
1581 mxThrowException(
err::sizeerr,
"aoSystem::minTauWFS",
"idx larger than m_ntau_wfs");
1584 return m_minTauWFS[idx];
1587 template<
typename realT,
class inputSpectT,
typename iosT>
1593 template<
typename realT,
class inputSpectT,
typename iosT>
1596 if(bnp != m_bin_npix)
1599 m_specsChanged =
true;
1600 m_dminChanged =
true;
1604 template<
typename realT,
class inputSpectT,
typename iosT>
1610 template<
typename realT,
class inputSpectT,
typename iosT>
1618 template<
typename realT,
class inputSpectT,
typename iosT>
1622 m_specsChanged =
true;
1623 m_dminChanged =
true;
1626 template<
typename realT,
class inputSpectT,
typename iosT>
1632 template<
typename realT,
class inputSpectT,
typename iosT>
1636 m_specsChanged =
true;
1637 m_dminChanged =
true;
1640 template<
typename realT,
class inputSpectT,
typename iosT>
1646 template<
typename realT,
class inputSpectT,
typename iosT>
1650 m_specsChanged =
true;
1651 m_dminChanged =
true;
1654 template<
typename realT,
class inputSpectT,
typename iosT>
1660 template<
typename realT,
class inputSpectT,
typename iosT>
1664 m_specsChanged =
true;
1665 m_dminChanged =
true;
1668 template<
typename realT,
class inputSpectT,
typename iosT>
1674 template<
typename realT,
class inputSpectT,
typename iosT>
1678 m_secZeta = 1/cos(m_zeta);
1680 m_specsChanged =
true;
1681 m_dminChanged =
true;
1684 template<
typename realT,
class inputSpectT,
typename iosT>
1690 template<
typename realT,
class inputSpectT,
typename iosT>
1696 template<
typename realT,
class inputSpectT,
typename iosT>
1699 if(mnm < 0) mnm = 0;
1703 template<
typename realT,
class inputSpectT,
typename iosT>
1706 return m_fit_mn_max;
1709 template<
typename realT,
class inputSpectT,
typename iosT>
1712 m_circularLimit = cl;
1713 m_specsChanged =
true;
1714 m_dminChanged =
true;
1717 template<
typename realT,
class inputSpectT,
typename iosT>
1720 return m_circularLimit;
1723 template<
typename realT,
class inputSpectT,
typename iosT>
1726 m_spatialFilter_ku = fabs(kx);
1727 m_specsChanged =
true;
1728 m_dminChanged =
true;
1731 template<
typename realT,
class inputSpectT,
typename iosT>
1734 return m_spatialFilter_ku;
1737 template<
typename realT,
class inputSpectT,
typename iosT>
1740 m_spatialFilter_kv = fabs(ky);
1741 m_specsChanged =
true;
1742 m_dminChanged =
true;
1745 template<
typename realT,
class inputSpectT,
typename iosT>
1748 return m_spatialFilter_kv;
1751 template<
typename realT,
class inputSpectT,
typename iosT>
1755 m_specsChanged =
true;
1756 m_dminChanged =
true;
1759 template<
typename realT,
class inputSpectT,
typename iosT>
1765 template<
typename realT,
class inputSpectT,
typename iosT>
1768 m_ncp_alpha = alpha;
1769 m_specsChanged =
true;
1770 m_dminChanged =
true;
1773 template<
typename realT,
class inputSpectT,
typename iosT>
1779 template<
typename realT,
class inputSpectT,
typename iosT>
1783 m_specsChanged =
true;
1784 m_dminChanged =
true;
1787 template<
typename realT,
class inputSpectT,
typename iosT>
1793 template<
typename realT,
class inputSpectT,
typename iosT>
1797 m_specsChanged =
true;
1798 m_dminChanged =
true;
1801 template<
typename realT,
class inputSpectT,
typename iosT>
1807 template<
typename realT,
class inputSpectT,
typename iosT>
1810 return m_F0*pow(10.0, -0.4*mag);
1813 template<
typename realT,
class inputSpectT,
typename iosT>
1816 return Fg(m_starMag);
1819 template<
typename realT,
class inputSpectT,
typename iosT>
1822 return m_controlledModes;
1825 template<
typename realT,
class inputSpectT,
typename iosT>
1834 double binfact = 1.0;
1838 if(m_npix_wfs.size() == 1)
1840 binfact = 1./pow((realT) b+1,2);
1845 return pow(Nph,2)/( m_npix_wfs[binidx]*binfact * ( m_Fbg[binidx]*tau_wfs + pow(m_ron_wfs[binidx],2)));
1848 template<
typename realT,
class inputSpectT,
typename iosT>
1855 if(m ==0 and n == 0)
return 0;
1859 if(m_optTau) tau_wfs = optimumTauWFS(m, n, d, b);
1860 else tau_wfs = m_tauWFS;
1862 if (m_wfsBeta == 0) mxThrowException(
err::paramnotset,
"aoSystem::measurementError",
"The WFS is not assigned.");
1864 realT beta_p = m_wfsBeta->beta_p(m,n,m_D, d, atm.r_0(m_lam_wfs));
1865 realT beta_r = m_wfsBeta->beta_r(m,n,m_D, d, atm.r_0(m_lam_wfs));
1867 realT snr2 = signal2Noise2( Nph, tau_wfs, d, b );
1869 return (pow(beta_r,2)/snr2 + pow(beta_p,2)/Nph) *pow(m_lam_wfs/m_lam_sci, 2);
1872 template<
typename realT,
class inputSpectT,
typename iosT>
1875 if(m_specsChanged || m_dminChanged ) calcStrehl();
1876 return m_wfeMeasurement;
1879 template<
typename realT,
class inputSpectT,
typename iosT>
1886 if(m ==0 and n == 0)
return 0;
1888 realT
k = sqrt(m*m + n*n)/m_D;
1892 if(m_optTau) tau_wfs = optimumTauWFS(m, n, d, b);
1893 else tau_wfs = m_tauWFS;
1895 realT tau = tau_wfs + m_deltaTau;
1898 return psd(atm, 0,
k, m_secZeta)/pow(m_D,2) * pow(atm.lam_0()/m_lam_sci, 2) * sqrt(atm.X(
k, m_lam_sci, m_secZeta)) * pow(math::two_pi<realT>()*atm.v_wind()*
k,2) * pow(tau,2);
1901 template<
typename realT,
class inputSpectT,
typename iosT>
1904 if(m_specsChanged || m_dminChanged ) calcStrehl();
1905 return m_wfeTimeDelay;
1909 template<
typename realT,
class inputSpectT,
typename iosT>
1913 realT
k = sqrt(m*m+n*n)/m_D;
1916 return psd(atm, 0,
k, m_secZeta)/pow(m_D,2) * pow(atm.lam_0()/m_lam_sci, 2);
1919 template<
typename realT,
class inputSpectT,
typename iosT>
1922 if(m_specsChanged || m_dminChanged ) calcStrehl();
1923 return m_wfeFitting;
1926 template<
typename realT,
class inputSpectT,
typename iosT>
1934 template<
typename realT,
class inputSpectT,
typename iosT>
1937 if(m_specsChanged || m_dminChanged ) calcStrehl();
1938 return m_wfeChromScintOPD;
1941 template<
typename realT,
class inputSpectT,
typename iosT>
1949 int mn_max = floor(0.5*m_D/d_opt());
1953 for(
int m = -mn_max; m <= mn_max; ++m)
1955 for(
int n = -mn_max; n <= mn_max; ++n)
1957 if(n == 0 && m == 0)
continue;
1967 template<
typename realT,
class inputSpectT,
typename iosT>
1975 template<
typename realT,
class inputSpectT,
typename iosT>
1978 if(m_specsChanged || m_dminChanged ) calcStrehl();
1979 return m_wfeChromIndex;
1982 template<
typename realT,
class inputSpectT,
typename iosT>
1990 template<
typename realT,
class inputSpectT,
typename iosT>
1993 if(m_specsChanged || m_dminChanged ) calcStrehl();
1994 return m_wfeAnisoOPD;
1997 template<
typename realT,
class inputSpectT,
typename iosT>
2003 int mn_max = floor(0.5*m_D/d_opt());
2007 for(
int m = -mn_max; m <= mn_max; ++m)
2009 for(
int n = -mn_max; n <= mn_max; ++n)
2011 if(n == 0 && m == 0)
continue;
2013 if( m_circularLimit )
2015 if( m*m + n*n > mn_max*mn_max )
continue;
2026 template<
typename realT,
class inputSpectT,
typename iosT>
2035 mxError(
"aoSystem::optimumTauWFS", MXE_PARAMNOTSET,
"Diameter (D) not set.");
2041 mxError(
"aoSystem::optimumTauWFS", MXE_PARAMNOTSET,
"0-mag photon flux (F0) not set.");
2045 double binfact = 1.0;
2049 if(m_npix_wfs.size() > 1)
2055 binfact = 1.0/pow((realT) (bbin+1),2);
2059 realT
k = sqrt(m*m + n*n)/m_D;
2063 if (m_wfsBeta == 0) mxThrowException(
err::paramnotset,
"aoSystem::beta_p",
"The WFS is not assigned.");
2065 realT beta_p = m_wfsBeta->beta_p(m,n,m_D, dact, atm.r_0(m_lam_wfs));
2066 realT beta_r = m_wfsBeta->beta_r(m,n,m_D, dact, atm.r_0(m_lam_wfs));
2069 realT a, b,
c, d, e;
2072 realT Atmp = 2*pow(atm.lam_0(),2)*psd(atm, 0,
k, m_secZeta)/pow(m_D,2)*(atm.X(
k, m_lam_wfs, m_secZeta))*pow(math::two_pi<realT>()*atm.v_wind()*
k,2);
2075 b = Atmp *m_deltaTau;
2077 d = -1*(pow(m_lam_wfs,2) / F) * ( (m_npix_wfs[binidx]*binfact*m_Fbg[binidx] / F)*pow(beta_r,2) + pow(beta_p,2));
2078 e = -2*pow(m_lam_wfs,2) * (m_npix_wfs[binidx]*binfact)*pow(m_ron_wfs[binidx],2) * pow(beta_r,2) / pow(F,2);
2080 std::vector<std::complex<realT> > x;
2088 for(
int i=0; i<4; i++)
2090 if( real(x[i]) > 0 && imag(x[i]) == 0 && real(x[i]) > tauopt) tauopt = real(x[i]);
2093 if(tauopt < m_minTauWFS[binidx]) tauopt = m_minTauWFS[binidx];
2100 template<
typename realT,
class inputSpectT,
typename iosT>
2105 return optimumTauWFS(m, n, m_d_opt, m_bin_opt);
2109 template<
typename realT,
class inputSpectT,
typename iosT>
2112 if(!m_dminChanged)
return m_d_opt;
2116 if(m_npix_wfs.size() < 1)
2118 mxThrowException(
err::sizeerr,
"aoSystem::d_opt",
"npix_wfs must have at least one entry");
2121 if(m_d_min.size() != m_npix_wfs.size())
2123 mxThrowException(
err::sizeerr,
"aoSystem::d_opt",
"d_min must be the same size as npix_wfs");
2126 if(m_ron_wfs.size() != m_npix_wfs.size())
2128 mxThrowException(
err::sizeerr,
"aoSystem::d_opt",
"ron_wfs must be the same size as npix_wfs");
2131 if(m_Fbg.size() != m_npix_wfs.size())
2133 mxThrowException(
err::sizeerr,
"aoSystem::d_opt",
"F_bg must be the same size as npix_wfs");
2136 if(m_minTauWFS.size() != m_npix_wfs.size())
2138 mxThrowException(
err::sizeerr,
"aoSystem::d_opt",
"minTauWFS must be the same size as npix_wfs");
2142 if( m_d_min.size() == 1 && m_d_min[0] == 0 )
2146 m_dminChanged =
false;
2152 m_d_opt = m_d_min[0];
2154 m_dminChanged =
false;
2164 if(m_npix_wfs.size() > 1)
2167 best_d = m_d_min[0];
2169 realT bestStrehlOverall = 0;
2171 for(
int b=0; b < m_npix_wfs.size(); ++b)
2173 realT d = m_d_min[b];
2174 realT s = strehl(d,b);
2175 realT bestStrehl = s;
2180 d += m_d_min[b]/m_optd_delta;
2185 d -= m_d_min[b]/m_optd_delta;
2188 else bestStrehl = s;
2192 if(bestStrehl >= bestStrehlOverall)
2194 bestStrehlOverall = bestStrehl;
2201 m_bin_opt = best_idx;
2205 realT d = m_d_min[0];
2208 realT s = strehl(d,m_bin_opt);
2209 realT bestStrehl = s;
2213 d += m_d_min[0]/m_optd_delta;
2214 m_bin_opt = d/m_d_min[0] - 1;
2215 if(m_bin_opt < 0) m_bin_opt = 0;
2217 s = strehl(d,m_bin_opt);
2221 d -= m_d_min[0]/m_optd_delta;
2222 m_bin_opt = d/m_d_min[0] - 1;
2223 if(m_bin_opt < 0) m_bin_opt = 0;
2226 else bestStrehl = s;
2233 realT d = m_d_min[0];
2236 realT s = strehl(d,m_bin_opt);
2237 realT bestStrehl = s;
2242 d += m_d_min[0]/m_optd_delta;
2244 s = strehl(d,m_bin_opt);
2247 d -= m_d_min[0]/m_optd_delta;
2250 else bestStrehl = s;
2256 m_dminChanged =
false;
2262 template<
typename realT,
class inputSpectT,
typename iosT>
2266 if(m ==0 and n == 0)
return 0;
2268 realT
k = sqrt(m*m + n*n)/m_D;
2270 return (m_ncp_alpha - 2)/(math::two_pi<realT>()) * pow(m_D, -m_ncp_alpha) * ncpError() * pow(
k, -m_ncp_alpha);
2273 template<
typename realT,
class inputSpectT,
typename iosT>
2276 return pow(m_ncp_wfe,2)*pow(math::two_pi<realT>()/m_lam_sci,2);
2279 template<
typename realT,
class inputSpectT,
typename iosT>
2285 int mn_max = floor(0.5*m_D/d);
2290 for(
int m = -m_fit_mn_max; m <= m_fit_mn_max; ++m)
2292 for(
int n = -m_fit_mn_max; n <= m_fit_mn_max; ++n)
2297 if( m*m + n*n <= mn_max*mn_max) controlled =
true;
2301 if( abs(m) <= mn_max && abs(n) <= mn_max) controlled =
true;
2306 realT wfeMeasurement = measurementError(m,n, d, b);
2307 realT wfeTimeDelay = timeDelayError(m,n,d, b);
2308 realT wfeChromScintOPD = chromScintOPDError(m,n);
2309 realT wfeChromIndex = chromIndexError(m,n);
2310 realT wfeAnisoOPD = dispAnisoOPDError(m,n);
2312 realT wfeFitting = fittingError(m,n);
2314 if(wfeFitting < wfeMeasurement + wfeTimeDelay + wfeChromScintOPD + wfeChromIndex + wfeAnisoOPD)
2316 wfeVar += wfeFitting;
2320 wfeVar += wfeMeasurement + wfeTimeDelay + wfeChromScintOPD + wfeChromIndex + wfeAnisoOPD;
2325 wfeVar += fittingError(m,n);
2328 realT wfeNCP = ncpError(m, n);
2333 return exp(-1 * wfeVar);
2337 template<
typename realT,
class inputSpectT,
typename iosT>
2343 int mn_max = floor(0.5*m_D/d);
2345 m_wfeMeasurement = 0;
2347 m_wfeChromScintOPD = 0;
2348 m_wfeChromIndex = 0;
2356 m_controlledModes.resize(2*m_fit_mn_max+1, 2*m_fit_mn_max+1);
2357 m_controlledModes.setZero();
2360 for(
int m = -m_fit_mn_max; m <= m_fit_mn_max; ++m)
2362 for(
int n = -m_fit_mn_max; n <= m_fit_mn_max; ++n)
2367 if( m*m + n*n <= mn_max*mn_max) controlled =
true;
2371 if( abs(m) <= mn_max && abs(n) <= mn_max) controlled =
true;
2376 realT wfeMeasurement = measurementError(m,n, d, b);
2377 realT wfeTimeDelay = timeDelayError(m,n,d, b);
2378 realT wfeChromScintOPD = chromScintOPDError(m,n);
2379 realT wfeChromIndex = chromIndexError(m,n);
2380 realT wfeAnisoOPD = dispAnisoOPDError(m,n);
2382 realT wfeFitting = fittingError(m,n);
2384 if(wfeFitting < wfeMeasurement + wfeTimeDelay + wfeChromScintOPD + wfeChromIndex + wfeAnisoOPD)
2386 m_wfeFitting += wfeFitting;
2390 m_wfeMeasurement += wfeMeasurement;
2391 m_wfeTimeDelay += wfeTimeDelay;
2392 m_wfeChromScintOPD += wfeChromScintOPD;
2393 m_wfeChromIndex += wfeChromIndex;
2394 m_wfeAnisoOPD += wfeAnisoOPD;
2395 m_controlledModes(m_fit_mn_max+m, m_fit_mn_max+n) = 1;
2400 m_wfeFitting += fittingError(m,n);
2403 m_wfeNCP += ncpError(m, n);
2407 m_wfeVar = m_wfeMeasurement + m_wfeTimeDelay + m_wfeFitting + m_wfeChromScintOPD +m_wfeChromIndex + m_wfeAnisoOPD + m_wfeNCP;
2409 m_strehl = exp(-1 * m_wfeVar);
2411 m_specsChanged =
false;
2414 template<
typename realT,
class inputSpectT,
typename iosT>
2417 if(m_specsChanged || m_dminChanged ) calcStrehl();
2422 template<
typename realT,
class inputSpectT,
typename iosT>
2425 if( m_specsChanged || m_dminChanged ) calcStrehl();
2430 template<
typename realT,
class inputSpectT,
typename iosT>
2431 template<
typename varFuncT>
2439 if(m ==0 && n == 0)
return 0;
2445 if(!normStrehl) S = 1;
2447 if( doFittingError != FITTING_ERROR_NO)
2449 int mn_max = m_D/(2.*d_opt());
2451 if( m_controlledModes(m_fit_mn_max+m, m_fit_mn_max+n) ==
false)
2453 if(doFittingError == FITTING_ERROR_ZERO)
return 0;
2455 realT fe = fittingError(m,n);
2457 realT
k = sqrt(m*m + n*n)/m_D;
2459 if(doFittingError == FITTING_ERROR_X) fe *= (atm.X(
k, m_lam_sci, m_secZeta));
2460 else if(doFittingError == FITTING_ERROR_Y) fe *= (atm.Y(
k, m_lam_sci, m_secZeta));
2463 std::cerr <<
"Unknown doFittingError\n";
2472 realT var = (this->*varFunc)(m, n);
2477 template<
typename realT,
class inputSpectT,
typename iosT>
2478 template<
typename imageT,
typename CfuncT>
2487 int mc = 0.5*(dim1-1);
2488 int nc = 0.5*(dim2-1);
2490 for(
int i=0; i< dim1; ++i)
2494 for(
int j=0; j< dim2; ++j)
2498 im(i,j) = (this->*Cfunc)(m, n, normStrehl);
2503 template<
typename realT,
class inputSpectT,
typename iosT>
2508 realT
k = sqrt(m*m + n*n)/m_D;
2510 return psd(atm, 0,
k, m_secZeta)/pow(m_D,2) * pow(atm.lam_0()/m_lam_sci, 2) * (atm.X(
k, m_lam_sci, m_secZeta));
2513 template<
typename realT,
class inputSpectT,
typename iosT>
2523 template<
typename realT,
class inputSpectT,
typename iosT>
2524 template<
typename imageT>
2532 template<
typename realT,
class inputSpectT,
typename iosT>
2537 realT
k = sqrt(m*m + n*n)/m_D;
2540 return psd(atm, 0,
k, m_secZeta)/pow(m_D,2) * pow(atm.lam_0()/m_lam_sci, 2) * (atm.Y(
k, m_lam_sci, m_secZeta));
2543 template<
typename realT,
class inputSpectT,
typename iosT>
2552 template<
typename realT,
class inputSpectT,
typename iosT>
2553 template<
typename imageT>
2561 template<
typename realT,
class inputSpectT,
typename iosT>
2567 return measurementError(m, n, d_opt(), m_bin_opt) + timeDelayError(m,n, d_opt(), m_bin_opt);
2570 template<
typename realT,
class inputSpectT,
typename iosT>
2579 template<
typename realT,
class inputSpectT,
typename iosT>
2580 template<
typename imageT>
2588 template<
typename realT,
class inputSpectT,
typename iosT>
2596 template<
typename realT,
class inputSpectT,
typename iosT>
2605 template<
typename realT,
class inputSpectT,
typename iosT>
2606 template<
typename imageT>
2614 template<
typename realT,
class inputSpectT,
typename iosT>
2619 realT
k = sqrt(m*m + n*n)/m_D;
2623 return psd(atm, 0,
k, m_secZeta)/pow(m_D,2) * pow(atm.lam_0()/m_lam_sci, 2) * atm.dX(
k, m_lam_sci, m_lam_wfs);
2627 template<
typename realT,
class inputSpectT,
typename iosT>
2636 template<
typename realT,
class inputSpectT,
typename iosT>
2637 template<
typename imageT>
2645 template<
typename realT,
class inputSpectT,
typename iosT>
2650 realT
k = sqrt(m*m + n*n)/m_D;
2654 return psd(atm, 0,
k, m_secZeta)/pow(m_D,2) * pow(atm.lam_0()/m_lam_sci, 2) * atm.dY(
k, m_lam_sci, m_lam_wfs);
2658 template<
typename realT,
class inputSpectT,
typename iosT>
2667 template<
typename realT,
class inputSpectT,
typename iosT>
2668 template<
typename imageT>
2676 template<
typename realT,
class inputSpectT,
typename iosT>
2681 realT ni = atm.n_air(m_lam_sci);
2682 realT nw = atm.n_air(m_lam_wfs);
2684 return C0var(m, n) * pow( (ni-nw)/(ni-1), 2);
2688 template<
typename realT,
class inputSpectT,
typename iosT>
2697 template<
typename realT,
class inputSpectT,
typename iosT>
2698 template<
typename imageT>
2706 template<
typename realT,
class inputSpectT,
typename iosT>
2711 realT
k = sqrt(m*m + n*n)/m_D;
2714 return psd(atm, 0,
k, m_secZeta)/pow(m_D,2) * pow(atm.lam_0()/m_lam_sci, 2) * atm.X_Z(
k, m_lam_wfs, m_lam_sci, m_secZeta);
2717 template<
typename realT,
class inputSpectT,
typename iosT>
2726 template<
typename realT,
class inputSpectT,
typename iosT>
2727 template<
typename imageT>
2735 template<
typename realT,
class inputSpectT,
typename iosT>
2738 ios <<
"# AO Params:\n";
2739 ios <<
"# D = " << D() <<
'\n';
2741 if(m_d_min.size() > 0)
2743 ios <<
"# d_min = " << d_min((
size_t) 0);
2744 for(
size_t n=1; n < m_d_min.size(); ++n) ios <<
',' << d_min(n);
2747 else ios <<
"# d_min = null\n";
2749 ios <<
"# optd = " << std::boolalpha << m_optd <<
'\n';
2750 ios <<
"# d_opt_delta = " << optd_delta() <<
'\n';
2751 ios <<
"# lam_sci = " << lam_sci() <<
'\n';
2752 ios <<
"# F0 = " << F0() <<
'\n';
2753 ios <<
"# starMag = " << starMag() <<
'\n';
2754 ios <<
"# lam_sci = " << lam_sci() <<
'\n';
2755 ios <<
"# zeta = " << zeta() <<
'\n';
2756 ios <<
"# lam_wfs = " << lam_wfs() <<
'\n';
2758 if(npix_wfs().size() > 0)
2760 ios <<
"# npix_wfs = " << npix_wfs((
size_t) 0);
2761 for(
size_t n=1; n < npix_wfs().size(); ++n) ios <<
',' << npix_wfs(n);
2764 else ios <<
"# npix_wfs = null\n";
2766 if(ron_wfs().size() > 0)
2768 ios <<
"# ron_wfs = " << ron_wfs((
size_t) 0);
2769 for(
size_t n=1; n < ron_wfs().size(); ++n) ios <<
',' << ron_wfs(n);
2772 else ios <<
"# ron_wfs = null\n";
2774 if(Fbg().size() > 0)
2776 ios <<
"# Fbg = " << Fbg((
size_t) 0);
2777 for(
size_t n=1; n < Fbg().size(); ++n) ios <<
',' << Fbg(n);
2780 else ios <<
"# Fbg = null\n";
2782 if(minTauWFS().size() > 0)
2784 ios <<
"# minTauWFS = " << minTauWFS((
size_t) 0);
2785 for(
size_t n=1; n < minTauWFS().size(); ++n) ios <<
',' << minTauWFS(n);
2788 else ios <<
"# minTauWFS = null\n";
2790 ios <<
"# bin_npix = " << std::boolalpha << m_bin_npix <<
'\n';
2791 ios <<
"# tauWFS = " << tauWFS() <<
'\n';
2792 ios <<
"# optTau = " << std::boolalpha << m_optTau <<
'\n';
2793 ios <<
"# deltaTau = " << deltaTau() <<
'\n';
2794 ios <<
"# fit_mn_max = " << m_fit_mn_max <<
'\n';
2795 ios <<
"# spatialFilter_ku = " << m_spatialFilter_ku <<
'\n';
2796 ios <<
"# spatialFilter_kv = " << m_spatialFilter_kv <<
'\n';
2797 ios <<
"# ncp_wfe = " << m_ncp_wfe <<
'\n';
2798 ios <<
"# ncp_alpha = " << m_ncp_alpha <<
'\n';
2801 if (m_wfsBeta == 0) mxThrowException(
err::paramnotset,
"aoSystem::beta_p",
"The WFS is not assigned.");
2802 m_wfsBeta->dumpWFS(ios);
2804 atm.dumpAtmosphere(ios);
2811 template<
typename realT,
class inputSpectT,
typename iosT>
2814 using namespace mx::app;
2817 config.
add(
"aosys.wfs" ,
"",
"aosys.wfs" , argType::Required,
"aosys",
"wfs",
false,
"string",
"The WFS type: idealWFS, unmodPyWFS, asympModPyWFS, shwfs, calculatedWFS");
2818 config.
add(
"aosys.wfs_beta_p" ,
"",
"aosys.wfs_beta_p" , argType::Required,
"aosys",
"wfs_beta_p",
false,
"string",
"The beta_p file path for calcualtedWFS");
2819 config.
add(
"aosys.wfs_beta_r" ,
"",
"aosys.wfs_beta_r" , argType::Required,
"aosys",
"wfs_beta_r",
false,
"string",
"The beta_r file path for calcualtedWFS");
2820 config.
add(
"aosys.wfs_sensitivity" ,
"",
"aosys.wfs_sensitivity" , argType::Required,
"aosys",
"wfs_sensitivity",
false,
"bool",
"Flag indicating that beta_p/beta_r are sensitivities (inverse) [default false]");
2821 config.
add(
"aosys.D" ,
"",
"aosys.D" , argType::Required,
"aosys",
"D",
false,
"real",
"The telescope diameter [m]");
2822 config.
add(
"aosys.d_min" ,
"",
"aosys.d_min" , argType::Required,
"aosys",
"d_min",
false,
"real",
"The minimum actuator spacing [m]");
2823 config.
add(
"aosys.optd" ,
"",
"aosys.optd" , argType::Optional,
"aosys",
"optd",
false,
"bool",
"Whether or not the actuator spacing is optimized");
2824 config.
add(
"aosys.optd_delta" ,
"",
"aosys.optd_delta" , argType::Required,
"aosys",
"optd_delta",
false,
"bool",
"The fractional change from d_min used in optimization. Set to 1 (default) for integer binnings, > 1 for finer sampling.");
2825 config.
add(
"aosys.F0" ,
"",
"aosys.F0" , argType::Required,
"aosys",
"F0",
false,
"real",
"Zero-mag photon flux, [photons/sec]");
2826 config.
add(
"aosys.lam_wfs" ,
"",
"aosys.lam_wfs" , argType::Required,
"aosys",
"lam_wfs",
false,
"real",
"WFS wavelength [m]" );
2827 config.
add(
"aosys.npix_wfs" ,
"",
"aosys.npix_wfs" , argType::Required,
"aosys",
"npix_wfs",
false,
"vector<real>",
"The number of pixels in the WFS");
2828 config.
add(
"aosys.ron_wfs" ,
"",
"aosys.ron_wfs" , argType::Required,
"aosys",
"ron_wfs",
false,
"vector<real>",
"WFS readout noise [photons/read]");
2829 config.
add(
"aosys.bin_npix" ,
"",
"aosys.bin_npix" , argType::Required,
"aosys",
"bin_npix",
false,
"bool",
"Whether or not WFS pixels are re-binned along with actuator spacing optimization");
2830 config.
add(
"aosys.Fbg" ,
"",
"aosys.Fbg" , argType::Required,
"aosys",
"Fbg",
false,
"vector<real>",
"Background counts, [counts/pix/sec]");\
2831 config.add(
"aosys.tauWFS" ,
"",
"aosys.tauWFS" , argType::Required,
"aosys",
"tauWFS",
false,
"real",
"WFS integration time [s]");
2832 config.
add(
"aosys.minTauWFS" ,
"",
"aosys.minTauWFS" , argType::Required,
"aosys",
"minTauWFS",
false,
"vector<real>",
"Minimum WFS integration time [s]");
2833 config.
add(
"aosys.deltaTau" ,
"",
"aosys.deltaTau" , argType::Required,
"aosys",
"deltaTau",
false,
"real",
"Loop delay [s]");
2834 config.
add(
"aosys.optTau" ,
"",
"aosys.optTau" , argType::Optional,
"aosys",
"optTau",
false,
"bool",
"Whether or not the integration time is optimized");
2835 config.
add(
"aosys.lam_sci" ,
"",
"aosys.lam_sci" , argType::Required,
"aosys",
"lam_sci",
false,
"real",
"Science wavelength [m]");
2836 config.
add(
"aosys.zeta" ,
"",
"aosys.zeta" , argType::Required,
"aosys",
"zeta",
false,
"real",
"Zenith distance [rad]");
2837 config.
add(
"aosys.fit_mn_max" ,
"",
"aosys.fit_mn_max" , argType::Required,
"aosys",
"fit_mn_max",
false,
"real",
"Maximum spatial frequency index to use for analysis");
2838 config.
add(
"aosys.circularLimit" ,
"",
"aosys.circularLimit" , argType::Optional,
"aosys",
"circularLimit",
false,
"bool",
" Flag to indicate that the spatial frequency limit is circular, not square.");
2839 config.
add(
"aosys.spatialFilter_ku",
"",
"aosys.spatialFilter_ku", argType::Required,
"aosys",
"spatialFilter_ku",
false,
"real",
"Spatial filter cutoff frequency in u [m^-1]");
2840 config.
add(
"aosys.spatialFilter_kv",
"",
"aosys.spatialFilter_kv", argType::Required,
"aosys",
"spatialFilter_kv",
false,
"real",
"Spatial filter cutoff frequency in v [m^-1]");
2841 config.
add(
"aosys.ncp_wfe" ,
"",
"aosys.ncp_wfe" , argType::Required,
"aosys",
"ncp_wfe",
false,
"real",
"NCP WFE between 1 lambda/D and fit_mn_max [rad^2]");
2842 config.
add(
"aosys.ncp_alpha" ,
"",
"aosys.ncp_alpha" , argType::Required,
"aosys",
"ncp_alpha",
false,
"real",
"PSD index for NCP WFE");
2843 config.
add(
"aosys.starMag" ,
"",
"aosys.starMag" , argType::Required,
"aosys",
"starMag",
false,
"real",
"Star magnitude");
2844 config.
add(
"aosys.starMags" ,
"",
"aosys.starMags" , argType::Required,
"aosys",
"starMags",
false,
"real vector",
"A vector of star magnitudes");
2846 atm.setupConfig(config);
2847 psd.setupConfig(config);
2851 template<
typename realT,
class inputSpectT,
typename iosT>
2855 if(config.
isSet(
"aosys.wfs"))
2858 config(wfsStr,
"aosys.wfs");
2860 if(wfsStr ==
"ideal")
2862 wfsBeta<wfs<realT,iosT>>(
nullptr);
2864 else if(wfsStr ==
"unmodPyWFS")
2866 wfsBeta<pywfsUnmod<realT,iosT>>(
nullptr);
2868 else if(wfsStr ==
"asympModPyWFS")
2870 wfsBeta<pywfsModAsymptotic<realT>>(
nullptr);
2872 else if(wfsStr ==
"SHWFS")
2874 wfsBeta<shwfs<realT,iosT>>(
nullptr);
2876 else if(wfsStr ==
"calculatedWFS")
2878 wfsBeta<calculatedWFS<realT,iosT>>(
nullptr);
2881 config(cwfs->m_beta_p_file,
"aosys.wfs_beta_p");
2882 config(cwfs->m_beta_r_file,
"aosys.wfs_beta_r");
2883 bool sens = cwfs->m_sensitivity;
2884 config(sens,
"aosys.wfs_sensitivity");
2885 if(config.isSet(
"aosys.wfs_sensitivity"))
2887 cwfs->m_sensitivity = sens;
2892 mxThrowException(
err::invalidconfig,
"aoSystem::loadConfig",
"unknown WFS " + wfsStr +
" specified");
2901 config(nD,
"aosys.D");
2902 if(config.
isSet(
"aosys.D") ) D(nD);
2905 std::vector<realT> nd_min = d_min();
2906 config(nd_min,
"aosys.d_min");
2907 if(config.
isSet(
"aosys.d_min")) d_min(nd_min);
2909 bool noptd = optd();
2910 config(noptd,
"aosys.optd");
2911 if(config.
isSet(
"aosys.optd")) optd(noptd);
2913 realT noptd_delta =optd_delta();
2914 config(noptd_delta,
"aosys.optd_delta");
2915 if(config.
isSet(
"aosys.optd_delta")) optd_delta(noptd_delta);
2917 realT nlam_wfs = lam_wfs();
2918 config(nlam_wfs,
"aosys.lam_wfs");
2919 if(config.
isSet(
"aosys.lam_wfs") ) lam_wfs(nlam_wfs);
2922 std::vector<realT> nnpix_wfs = npix_wfs();
2923 config(nnpix_wfs,
"aosys.npix_wfs");
2924 if(config.
isSet(
"aosys.npix_wfs")) npix_wfs(nnpix_wfs);
2927 std::vector<realT> nron_wfs = ron_wfs();
2928 config(nron_wfs,
"aosys.ron_wfs");
2929 if(config.
isSet(
"aosys.ron_wfs")) ron_wfs(nron_wfs);
2932 std::vector<realT> nFbg = Fbg();
2933 config(nFbg,
"aosys.Fbg");
2934 if(config.
isSet(
"aosys.Fbg")) Fbg(nFbg);
2937 std::vector<realT> nminTauWFS = minTauWFS();
2938 config(nminTauWFS,
"aosys.minTauWFS");
2939 if(config.
isSet(
"aosys.minTauWFS")) minTauWFS(nminTauWFS);
2942 bool nbin_npix = bin_npix();
2943 config(nbin_npix,
"aosys.bin_npix");
2944 if(config.
isSet(
"aosys.bin_npix")) bin_npix(nbin_npix);
2947 realT ntauWFS = tauWFS();
2948 config( ntauWFS,
"aosys.tauWFS");
2949 if(config.
isSet(
"aosys.tauWFS")) tauWFS(ntauWFS);
2952 realT ndeltaTau = deltaTau();
2953 config( ndeltaTau,
"aosys.deltaTau");
2954 if(config.
isSet(
"aosys.deltaTau")) deltaTau(ndeltaTau);
2957 bool noptTau = optTau();
2958 config(noptTau,
"aosys.optTau");
2959 if(config.
isSet(
"aosys.optTau")) optTau(noptTau);
2962 realT nlam_sci = lam_sci();
2963 config( nlam_sci,
"aosys.lam_sci");
2964 if(config.
isSet(
"aosys.lam_sci") ) lam_sci( nlam_sci );
2967 realT nzeta = zeta();
2968 config(nzeta ,
"aosys.zeta");
2969 if(config.
isSet(
"aosys.zeta") ) zeta(nzeta);
2972 realT fmnm = fit_mn_max();
2973 config( fmnm,
"aosys.fit_mn_max");
2974 if(config.
isSet(
"aosys.fit_mn_max") ) fit_mn_max(fmnm);
2977 bool cl = circularLimit();
2978 config(cl,
"aosys.circularLimit");
2979 if(config.
isSet(
"aosys.circularLimit") ) circularLimit(cl);
2982 realT ku = spatialFilter_ku();
2983 config( ku,
"aosys.spatialFilter_ku");
2984 if(config.
isSet(
"aosys.spatialFilter_ku") ) spatialFilter_ku(ku);
2987 realT kv = spatialFilter_kv();
2988 config( kv,
"aosys.spatialFilter_kv");
2989 if(config.
isSet(
"aosys.spatialFilter_kv") ) spatialFilter_kv(kv);
2992 realT nwfe = ncp_wfe();
2993 config( nwfe,
"aosys.ncp_wfe");
2994 if(config.
isSet(
"aosys.ncp_wfe") ) ncp_wfe(nwfe);
2997 realT na = ncp_alpha();
2998 config( na,
"aosys.ncp_alpha");
2999 if(config.
isSet(
"aosys.ncp_alpha") ) ncp_alpha( na );
3003 config(nF0,
"aosys.F0");
3004 if(config.
isSet(
"aosys.F0") ) F0(nF0);
3007 realT smag = starMag();
3008 config( smag,
"aosys.starMag");
3009 if(config.
isSet(
"aosys.starMag") ) starMag( smag );
3011 atm.loadConfig(config);
3012 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.
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 .
realT m_optd_delta
The fractional change from d_min used in optimization. Set to 1 for integer binnings,...
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.
const Eigen::Array< bool, -1, -1 > & controlledModes()
Access the array of controlledModes.
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.
bool m_optTau
Flag controlling whether optimum integration time is calculated (true) enforcing m_minTauWFS,...
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.
int m_bin_opt
The optimum binning factor. If WFS modes are used, this is the mode index (0 to N-1)....
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...
Eigen::Array< bool,-1,-1 > m_controlledModes
Map of which modes are under control. Set by calcStrehl.
bool m_dminChanged
Flag to indicate that d_min has changed.
bool m_optd
Flag controlling whether actuator pitch is optimized (true) or just uses m_d_min (false)....
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.
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...
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.
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
constexpr units::realT c()
The speed of light.
constexpr units::realT k()
Boltzmann Constant.
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.
iosT & dumpGitStatus(iosT &ios)
Dump the current git status of the library 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.