mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
aoSystem_test.cpp
Go to the documentation of this file.
1/** \file aoSystem_test.cpp
2 * \brief Tests adaptive-optics system configuration.
3 */
4#include "../../../catch2/catch.hpp"
5
6#define MX_NO_ERROR_REPORTS
7
9
10typedef double realT;
11
12using namespace mx::app;
13using namespace mx::AO::analysis;
14
15/// Verify parsing of AO-system configuration settings.
16/** Exercises mx::AO::analysis::aoSystem::setupConfig and mx::AO::analysis::aoSystem::loadConfig. */
17/**
18 * \ingroup aoSystem_unit_tests
19 */
20TEST_CASE( "Loading aoSystem config settings", "[ao::analysis::aoSystem]" )
21{
22 GIVEN( "no config file" )
23 {
24 aoSystem<realT, mx::AO::analysis::vonKarmanSpectrum<realT>> aosys; // This will be cumulative
25 WHEN( "verifying the defaults" )
26 {
27
28 REQUIRE( aosys.D() == 0.0 );
29 REQUIRE( aosys.d_min( 0 ) == 0.0 );
30 REQUIRE( aosys.d_opt() == 1e-50 );
31 REQUIRE( aosys.optd() == false );
32 REQUIRE( aosys.optd_delta() == 1.0 );
33 REQUIRE( aosys.wfsBeta()->_id == "Ideal WFS" );
34 REQUIRE( aosys.lam_wfs() == 0 );
35 REQUIRE( aosys.npix_wfs().size() == 1 );
36 REQUIRE( aosys.npix_wfs( (size_t)0 ) == 0 );
37 REQUIRE( aosys.ron_wfs().size() == 1 );
38 REQUIRE( aosys.ron_wfs( (size_t)0 ) == 0 );
39 REQUIRE( aosys.Fbg().size() == 1 );
40 REQUIRE( aosys.Fbg( (size_t)0 ) == 0 );
41 REQUIRE( aosys.minTauWFS().size() == 1 );
42 REQUIRE( aosys.minTauWFS( (size_t)0 ) == 0 );
43 REQUIRE( aosys.bin_npix() == true );
44 REQUIRE( aosys.tauWFS() == 0 );
45 REQUIRE( aosys.deltaTau() == 0 );
46 REQUIRE( aosys.optTau() == true );
47 REQUIRE( aosys.lam_sci() == 0 );
48 REQUIRE( aosys.zeta() == 0 );
49 REQUIRE( aosys.secZeta() == 1.0 );
50 REQUIRE( aosys.fit_mn_max() == 100 );
51 REQUIRE( aosys.circularLimit() == false );
52 REQUIRE( aosys.spatialFilter_ku() == std::numeric_limits<realT>::max() );
53 REQUIRE( aosys.spatialFilter_kv() == std::numeric_limits<realT>::max() );
54 REQUIRE( aosys.ncp_wfe() == 0 );
55 REQUIRE( aosys.ncp_alpha() == 2.0 );
56 REQUIRE( aosys.F0() == 0.0 );
57 REQUIRE( aosys.starMag() == 0 );
58 REQUIRE( aosys.Fg() == 0 );
59 REQUIRE( aosys.Fg( 2.5 ) == 0 );
60 }
61 }
62
63 GIVEN( "a valid config file" )
64 {
65 aoSystem<realT, mx::AO::analysis::vonKarmanSpectrum<realT>> aosys; // This will be cumulative
66
67 WHEN( "setting wfs to ideal" )
68 {
69 appConfigurator config;
70
71 writeConfigFile( "aoSystem.conf", { "aosys" }, { "wfs" }, { "ideal" } );
72
73 aosys.setupConfig( config );
74 config.readConfig( "aoSystem.conf" );
75 aosys.loadConfig( config );
76
77 REQUIRE( aosys.wfsBeta()->_id == "Ideal WFS" );
78 }
79 WHEN( "setting wfs to unmodPyWFS" )
80 {
81 appConfigurator config;
82
83 writeConfigFile( "aoSystem.conf", { "aosys" }, { "wfs" }, { "unmodPyWFS" } );
84
85 aosys.setupConfig( config );
86 config.readConfig( "aoSystem.conf" );
87
88 aosys.loadConfig( config );
89
90 REQUIRE( aosys.wfsBeta()->_id == "Unmodulated Pyramid" );
91 }
92 WHEN( "setting wfs to asympModPyWFS" )
93 {
94 appConfigurator config;
95
96 writeConfigFile( "aoSystem.conf", { "aosys" }, { "wfs" }, { "asympModPyWFS" } );
97
98 aosys.setupConfig( config );
99 config.readConfig( "aoSystem.conf" );
100 aosys.loadConfig( config );
101
102 REQUIRE( aosys.wfsBeta()->_id == "Asymptotic Modulated Pyramid" );
103 }
104 WHEN( "setting wfs to SHWFS" )
105 {
106 appConfigurator config;
107
108 writeConfigFile( "aoSystem.conf", { "aosys" }, { "wfs" }, { "SHWFS" } );
109
110 aosys.setupConfig( config );
111 config.readConfig( "aoSystem.conf" );
112 aosys.loadConfig( config );
113
114 REQUIRE( aosys.wfsBeta()->_id == "Shack Hartmann" );
115 }
116 WHEN( "typical settings part 1" ) // These are broken into parts just to keep things < 1 line
117 {
118 appConfigurator config;
119
120 writeConfigFile( "aoSystem.conf",
121 { "aosys", "aosys", "aosys", "aosys", "aosys" },
122 { "D", "d_min", "optd", "optd_delta", "lam_wfs" },
123 { "7.6", "0.122", "true", "0.0037", "800e-9" } );
124
125 aosys.setupConfig( config );
126 config.readConfig( "aoSystem.conf" );
127 aosys.loadConfig( config );
128
129 REQUIRE( aosys.D() == Approx( 7.6 ) );
130 REQUIRE( aosys.d_min( 0 ) == Approx( 0.122 ) );
131 REQUIRE( aosys.optd() == true );
132 REQUIRE( aosys.optd_delta() == Approx( 0.0037 ) );
133 REQUIRE( aosys.lam_wfs() == Approx( 800e-9 ) );
134 }
135 WHEN( "typical settings part 2" )
136 {
137 appConfigurator config;
138
139 writeConfigFile( "aoSystem.conf",
140 { "aosys", "aosys", "aosys", "aosys", "aosys" },
141 { "npix_wfs", "ron_wfs", "Fbg", "minTauWFS", "bin_npix" },
142 { "100,1001", "0.5,0.25", "0.01,0.03", "0.0001,0.0005", "false" } );
143
144 aosys.setupConfig( config );
145 config.readConfig( "aoSystem.conf" );
146 aosys.loadConfig( config );
147
148 REQUIRE( aosys.npix_wfs( 0 ) == 100 );
149 REQUIRE( aosys.npix_wfs( 1 ) == 1001 );
150 REQUIRE( aosys.ron_wfs( 0 ) == 0.5 );
151 REQUIRE( aosys.ron_wfs( 1 ) == 0.25 );
152 REQUIRE( aosys.Fbg( 0 ) == 0.01 );
153 REQUIRE( aosys.Fbg( 1 ) == 0.03 );
154 REQUIRE( aosys.minTauWFS( 0 ) == 0.0001 );
155 REQUIRE( aosys.minTauWFS( 1 ) == 0.0005 );
156 REQUIRE( aosys.bin_npix() == false );
157 }
158 WHEN( "typical settings part 3" )
159 {
160 appConfigurator config;
161
162 writeConfigFile( "aoSystem.conf",
163 { "aosys", "aosys", "aosys", "aosys", "aosys", "aosys", "aosys", "aosys", "aosys" },
164 { "tauWFS",
165 "deltaTau",
166 "optTau",
167 "lam_sci",
168 "zeta",
169 "fit_mn_max",
170 "circularLimit",
171 "spatialFilter_ku",
172 "spatialFilter_kv" },
173 { "0.0007", "0.0001", "false", "802e-9", "0.15", "12", "true", "50", "53" } );
174
175 aosys.setupConfig( config );
176 config.readConfig( "aoSystem.conf" );
177 aosys.loadConfig( config );
178
179 REQUIRE( aosys.tauWFS() == Approx( 0.0007 ) );
180 REQUIRE( aosys.deltaTau() == Approx( 0.0001 ) );
181 REQUIRE( aosys.optTau() == false );
182 REQUIRE( aosys.lam_sci() == Approx( 802e-9 ) );
183 REQUIRE( aosys.zeta() == Approx( 0.15 ) );
184 REQUIRE( aosys.secZeta() == Approx( 1 / cos( 0.15 ) ) );
185 REQUIRE( aosys.fit_mn_max() == 12 );
186 REQUIRE( aosys.circularLimit() == true );
187 REQUIRE( aosys.spatialFilter_ku() == 50 );
188 REQUIRE( aosys.spatialFilter_kv() == 53 );
189 }
190 WHEN( "typical settings part 4" )
191 {
192 appConfigurator config;
193
195 "aoSystem.conf",
196 { "aosys", "aosys", "aosys", "aosys", "atm" }, // last one verifies that atm config gets processed
197 { "ncp_wfe", "ncp_alpha", "starMag", "F0", "r_0" },
198 { "30e-9", "2.34", "8.2", "5e9", "0.25" } );
199
200 aosys.setupConfig( config );
201 config.readConfig( "aoSystem.conf" );
202 aosys.loadConfig( config );
203
204 REQUIRE( aosys.ncp_wfe() == Approx( 30e-9 ) );
205 REQUIRE( aosys.ncp_alpha() == Approx( 2.34 ) );
206 REQUIRE( aosys.F0() == Approx( 5e9 ) );
207 REQUIRE( aosys.starMag() == Approx( 8.2 ) );
208 REQUIRE( aosys.Fg() == Approx( 5e9 * pow( 10, -0.4 * 8.2 ) ) );
209 REQUIRE( aosys.Fg( 9.0 ) == Approx( 5e9 * pow( 10, -0.4 * 9.0 ) ) );
210 REQUIRE( aosys.atm.r_0() == Approx( 0.25 ) );
211 }
212 }
213}
214
215/// Verify that AO-system configuration loading propagates atmosphere validity.
216/** Exercises mx::AO::analysis::aoSystem::loadConfig and mx::AO::analysis::aoAtmosphere::setSingleLayer. */
217/**
218 * \ingroup aoSystem_unit_tests
219 */
220TEST_CASE( "AO-system configuration reports atmosphere validity", "[ao::analysis::aoSystem]" )
221{
223 appConfigurator config;
224 aoSystem.setupConfig( config );
225
226 SECTION( "default atmosphere" )
227 {
228 REQUIRE( aoSystem.loadConfig( config ) == mx::error_t::sizeerr );
229 }
230
231 SECTION( "complete atmosphere" )
232 {
233 aoSystem.atm.setSingleLayer( 0.2, 0.5e-6, 25.0, 0.0, 0.0, 10.0, 0.0 );
234 REQUIRE( aoSystem.loadConfig( config ) == mx::error_t::noerror );
235 }
236}
Declares and defines an analytical AO system.
void writeConfigFile(const std::string &fname, const std::vector< std::string > &sections, const std::vector< std::string > &keywords, const std::vector< std::string > &values)
A simple config file writing function, useful for testing.
void setSingleLayer(realT r0, realT lam0, realT L0, realT l0, realT lz, realT vw, realT dir)
Set a single layer model.
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.
Definition aoSystem.hpp:64
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.
error_t loadConfig(app::appConfigurator &config)
Load the configuration of this class from a configurator.
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.
TEST_CASE("Loading aoSystem config settings", "[ao::analysis::aoSystem]")
Verify parsing of AO-system configuration settings.
@ noerror
No error has occurred.
Definition error_t.hpp:27
@ sizeerr
A size was invalid or calculated incorrectly.
Definition error_t.hpp:35
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.