3#include "../../../catch2/catch.hpp" 
    5#define MX_NO_ERROR_REPORTS 
    7#include "../../../../include/ao/analysis/aoSystem.hpp" 
   11using namespace mx::app;
 
   12using namespace mx::AO::analysis;
 
   19SCENARIO( 
"Loading aoSystem config settings", 
"[ao::analysis::aoSystem]" )
 
   21    GIVEN( 
"no config file" )
 
   24        WHEN( 
"verifying the defaults" )
 
   27            REQUIRE( aosys.
D() == 0.0 );
 
   28            REQUIRE( aosys.
d_min( 0 ) == 0.0 );
 
   29            REQUIRE( aosys.
d_opt() == 1e-50 );
 
   30            REQUIRE( aosys.
optd() == 
false );
 
   32            REQUIRE( aosys.
wfsBeta()->_id == 
"Ideal WFS" );
 
   33            REQUIRE( aosys.
lam_wfs() == 0 );
 
   34            REQUIRE( aosys.
npix_wfs().size() == 1 );
 
   35            REQUIRE( aosys.
npix_wfs( (
size_t)0 ) == 0 );
 
   36            REQUIRE( aosys.
ron_wfs().size() == 1 );
 
   37            REQUIRE( aosys.
ron_wfs( (
size_t)0 ) == 0 );
 
   38            REQUIRE( aosys.
Fbg().size() == 1 );
 
   39            REQUIRE( aosys.
Fbg( (
size_t)0 ) == 0 );
 
   41            REQUIRE( aosys.
minTauWFS( (
size_t)0 ) == 0 );
 
   43            REQUIRE( aosys.
tauWFS() == 0 );
 
   45            REQUIRE( aosys.
optTau() == 
true );
 
   46            REQUIRE( aosys.
lam_sci() == 0 );
 
   47            REQUIRE( aosys.
zeta() == 0 );
 
   48            REQUIRE( aosys.
secZeta() == 1.0 );
 
   53            REQUIRE( aosys.
ncp_wfe() == 0 );
 
   55            REQUIRE( aosys.
F0() == 0.0 );
 
   56            REQUIRE( aosys.
starMag() == 0 );
 
   57            REQUIRE( aosys.
Fg() == 0 );
 
   58            REQUIRE( aosys.
Fg( 2.5 ) == 0 );
 
   62    GIVEN( 
"a valid config file" )
 
   66        WHEN( 
"setting wfs to ideal" )
 
   70            writeConfigFile( 
"aoSystem.conf", { 
"aosys" }, { 
"wfs" }, { 
"ideal" } );
 
   76            REQUIRE( aosys.
wfsBeta()->_id == 
"Ideal WFS" );
 
   78        WHEN( 
"setting wfs to unmodPyWFS" )
 
   82            writeConfigFile( 
"aoSystem.conf", { 
"aosys" }, { 
"wfs" }, { 
"unmodPyWFS" } );
 
   89            REQUIRE( aosys.
wfsBeta()->_id == 
"Unmodulated Pyramid" );
 
   91        WHEN( 
"setting wfs to asympModPyWFS" )
 
   95            writeConfigFile( 
"aoSystem.conf", { 
"aosys" }, { 
"wfs" }, { 
"asympModPyWFS" } );
 
  101            REQUIRE( aosys.
wfsBeta()->_id == 
"Asymptotic Modulated Pyramid" );
 
  103        WHEN( 
"setting wfs to SHWFS" )
 
  107            writeConfigFile( 
"aoSystem.conf", { 
"aosys" }, { 
"wfs" }, { 
"SHWFS" } );
 
  113            REQUIRE( aosys.
wfsBeta()->_id == 
"Shack Hartmann" );
 
  115        WHEN( 
"typical settings part 1" ) 
 
  120                             { 
"aosys", 
"aosys", 
"aosys", 
"aosys", 
"aosys" },
 
  121                             { 
"D", 
"d_min", 
"optd", 
"optd_delta", 
"lam_wfs" },
 
  122                             { 
"7.6", 
"0.122", 
"true", 
"0.0037", 
"800e-9" } );
 
  128            REQUIRE( aosys.
D() == Approx( 7.6 ) );
 
  129            REQUIRE( aosys.
d_min( 0 ) == Approx( 0.122 ) );
 
  130            REQUIRE( aosys.
optd() == 
true );
 
  131            REQUIRE( aosys.
optd_delta() == Approx( 0.0037 ) );
 
  132            REQUIRE( aosys.
lam_wfs() == Approx( 800e-9 ) );
 
  134        WHEN( 
"typical settings part 2" )
 
  139                             { 
"aosys", 
"aosys", 
"aosys", 
"aosys", 
"aosys" },
 
  140                             { 
"npix_wfs", 
"ron_wfs", 
"Fbg", 
"minTauWFS", 
"bin_npix" },
 
  141                             { 
"100,1001", 
"0.5,0.25", 
"0.01,0.03", 
"0.0001,0.0005", 
"false" } );
 
  147            REQUIRE( aosys.
npix_wfs( 0 ) == 100 );
 
  148            REQUIRE( aosys.
npix_wfs( 1 ) == 1001 );
 
  149            REQUIRE( aosys.
ron_wfs( 0 ) == 0.5 );
 
  150            REQUIRE( aosys.
ron_wfs( 1 ) == 0.25 );
 
  151            REQUIRE( aosys.
Fbg( 0 ) == 0.01 );
 
  152            REQUIRE( aosys.
Fbg( 1 ) == 0.03 );
 
  153            REQUIRE( aosys.
minTauWFS( 0 ) == 0.0001 );
 
  154            REQUIRE( aosys.
minTauWFS( 1 ) == 0.0005 );
 
  155            REQUIRE( aosys.
bin_npix() == 
false );
 
  157        WHEN( 
"typical settings part 3" )
 
  162                             { 
"aosys", 
"aosys", 
"aosys", 
"aosys", 
"aosys", 
"aosys", 
"aosys", 
"aosys", 
"aosys" },
 
  171                               "spatialFilter_kv" },
 
  172                             { 
"0.0007", 
"0.0001", 
"false", 
"802e-9", 
"0.15", 
"12", 
"true", 
"50", 
"53" } );
 
  178            REQUIRE( aosys.
tauWFS() == Approx( 0.0007 ) );
 
  179            REQUIRE( aosys.
deltaTau() == Approx( 0.0001 ) );
 
  180            REQUIRE( aosys.
optTau() == 
false );
 
  181            REQUIRE( aosys.
lam_sci() == Approx( 802e-9 ) );
 
  182            REQUIRE( aosys.
zeta() == Approx( 0.15 ) );
 
  183            REQUIRE( aosys.
secZeta() == Approx( 1 / cos( 0.15 ) ) );
 
  189        WHEN( 
"typical settings part 4" )
 
  195                { 
"aosys", 
"aosys", 
"aosys", 
"aosys", 
"atm" }, 
 
  196                { 
"ncp_wfe", 
"ncp_alpha", 
"starMag", 
"F0", 
"r_0" },
 
  197                { 
"30e-9", 
"2.34", 
"8.2", 
"5e9", 
"0.25" } );
 
  203            REQUIRE( aosys.
ncp_wfe() == Approx( 30e-9 ) );
 
  204            REQUIRE( aosys.
ncp_alpha() == Approx( 2.34 ) );
 
  205            REQUIRE( aosys.
F0() == Approx( 5e9 ) );
 
  206            REQUIRE( aosys.
starMag() == Approx( 8.2 ) );
 
  207            REQUIRE( aosys.
Fg() == Approx( 5e9 * pow( 10, -0.4 * 8.2 ) ) );
 
  208            REQUIRE( aosys.
Fg( 9.0 ) == Approx( 5e9 * pow( 10, -0.4 * 9.0 ) ) );
 
  209            REQUIRE( aosys.atm.
r_0() == Approx( 0.25 ) );
 
 
SCENARIO("Loading aoSystem config settings", "[ao::analysis::aoSystem]")
void writeConfigFile(const std::string &fname, const std::vector< std::string > §ions, const std::vector< std::string > &keywords, const std::vector< std::string > &values)
A simple config file writing function, useful for testing.
realT r_0()
Get the value of Fried's parameter r_0 at the reference wavelength lam_0.
Describes an analytic adaptive optics (AO) system.
void optTau(bool ot)
Set the value of m_optTau.
void optd_delta(realT odd)
Set the fractional change in actuator spacing for optimization.
void starMag(realT nmag)
Set the value of the Star's magnitude.
void wfsBeta(const wfsT &w)
Set the WFS Beta pointer.
void circularLimit(bool cl)
Set the value of the circularLimit flag.
void ncp_alpha(realT alpha)
Set the value of the non-common path WFE PSD index.
realT d_opt()
Calculate the optimum actuator spacing.
void tauWFS(realT ntau)
Set the value of the WFS exposure time.
void deltaTau(realT ndel)
Set the value of m_deltaTau.
void minTauWFS(const std::vector< realT > &ntau)
Set the value of the minimum WFS exposure times.
void D(realT nD)
Set the value of the primary mirror diameter.
void spatialFilter_ku(realT ku)
Set the value of spatialFilter_ku.
void npix_wfs(const std::vector< realT > &npix)
Set the number of pixels in the WFS for each WFS mode.
void optd(bool od)
Set whether or not the value of d is optimized or just set to m_d_min.
realT secZeta()
Get the zecant of the zenith angle.
void lam_wfs(realT nlam)
Set the value of the WFS wavelength.
void bin_npix(bool bnp)
Set the value of the pixel binning flag.
void ron_wfs(const std::vector< realT > &nron)
Set the value of the WFS readout noise for each WFS mode.
realT Fg(realT mag)
The photon flux at a given star magnitude.
void F0(realT nF0)
Set the value of the 0 magnitude photon rate.
void d_min(const std::vector< realT > &nd)
Set the minimum subaperture sampling for each WFS mode.
void setupConfig(app::appConfigurator &config)
Setup the configurator to configure this class.
void lam_sci(realT nlam)
Set the science wavelength.
void zeta(realT nz)
Set the zenith angle, and its secant.
void fit_mn_max(int mnm)
Set the value of m_fit_mn_max.
void ncp_wfe(realT nwfe)
Set the value of the non-common path WFE.
void Fbg(const std::vector< realT > &fbg)
Set the value of the background fluxes.
void spatialFilter_kv(realT kv)
Set the value of spatialFilter_kv.
void loadConfig(app::appConfigurator &config)
Load the configuration of this class from a configurator.
Class to manage a set of configurable values, and read their values from config/ini files and the com...
int readConfig(const std::string &fname, bool reportFileNotFound=true)
Read and parse a config/ini file, updating the targets.