mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
aoSystem_test.cpp
Go to the documentation of this file.
1 /** \file aoSystem_test.cpp
2  */
3 #include "../../../catch2/catch.hpp"
4 
5 
6 #define MX_NO_ERROR_REPORTS
7 
8 #include "../../../../include/ao/analysis/aoSystem.hpp"
9 
10 typedef double realT;
11 
12 using namespace mx::app;
13 using namespace mx::AO::analysis;
14 
15 /** Scenario: Loading aoSystem config settings
16  *
17  * Verify parsing of config
18  * \anchor tests_ao_analysis_aoSystem_config
19  */
20 SCENARIO( "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 
72  writeConfigFile( "aoSystem.conf",
73  {"aosys"},
74  {"wfs"},
75  {"ideal"}
76  );
77 
78  aosys.setupConfig(config);
79  config.readConfig("aoSystem.conf");
80  aosys.loadConfig(config);
81 
82  REQUIRE(aosys.wfsBeta()->_id == "Ideal WFS");
83  }
84  WHEN("setting wfs to unmodPyWFS")
85  {
86  appConfigurator config;
87 
88 
89  writeConfigFile( "aoSystem.conf",
90  {"aosys"},
91  {"wfs"},
92  {"unmodPyWFS"}
93  );
94 
95  aosys.setupConfig(config);
96  config.readConfig("aoSystem.conf");
97 
98  aosys.loadConfig(config);
99 
100  REQUIRE(aosys.wfsBeta()->_id == "Unmodulated Pyramid");
101  }
102  WHEN("setting wfs to asympModPyWFS")
103  {
104  appConfigurator config;
105 
106 
107  writeConfigFile( "aoSystem.conf",
108  {"aosys"},
109  {"wfs"},
110  {"asympModPyWFS"}
111  );
112 
113  aosys.setupConfig(config);
114  config.readConfig("aoSystem.conf");
115  aosys.loadConfig(config);
116 
117  REQUIRE(aosys.wfsBeta()->_id == "Asymptotic Modulated Pyramid");
118  }
119  WHEN("setting wfs to SHWFS")
120  {
121  appConfigurator config;
122 
123 
124  writeConfigFile( "aoSystem.conf",
125  {"aosys"},
126  {"wfs"},
127  {"SHWFS"}
128  );
129 
130  aosys.setupConfig(config);
131  config.readConfig("aoSystem.conf");
132  aosys.loadConfig(config);
133 
134  REQUIRE(aosys.wfsBeta()->_id == "Shack Hartmann");
135  }
136  WHEN("typical settings part 1") //These are broken into parts just to keep things < 1 line
137  {
138  appConfigurator config;
139 
140 
141  writeConfigFile( "aoSystem.conf",
142  {"aosys","aosys","aosys","aosys","aosys"},
143  {"D","d_min","optd","optd_delta","lam_wfs"},
144  {"7.6","0.122","true","0.0037","800e-9"}
145  );
146 
147  aosys.setupConfig(config);
148  config.readConfig("aoSystem.conf");
149  aosys.loadConfig(config);
150 
151  REQUIRE(aosys.D() == Approx(7.6));
152  REQUIRE(aosys.d_min(0) == Approx(0.122));
153  REQUIRE(aosys.optd() == true);
154  REQUIRE(aosys.optd_delta() == Approx(0.0037));
155  REQUIRE(aosys.lam_wfs() == Approx(800e-9));
156  }
157  WHEN("typical settings part 2")
158  {
159  appConfigurator config;
160 
161  writeConfigFile( "aoSystem.conf",
162  {"aosys", "aosys", "aosys", "aosys", "aosys"},
163  {"npix_wfs", "ron_wfs", "Fbg", "minTauWFS", "bin_npix"},
164  {"100,1001", "0.5,0.25", "0.01,0.03", "0.0001,0.0005", "false"}
165  );
166 
167  aosys.setupConfig(config);
168  config.readConfig("aoSystem.conf");
169  aosys.loadConfig(config);
170 
171  REQUIRE(aosys.npix_wfs(0) == 100);
172  REQUIRE(aosys.npix_wfs(1) == 1001);
173  REQUIRE(aosys.ron_wfs(0) == 0.5);
174  REQUIRE(aosys.ron_wfs(1) == 0.25);
175  REQUIRE(aosys.Fbg(0) == 0.01);
176  REQUIRE(aosys.Fbg(1) == 0.03);
177  REQUIRE(aosys.minTauWFS(0) == 0.0001);
178  REQUIRE(aosys.minTauWFS(1) == 0.0005);
179  REQUIRE(aosys.bin_npix() == false);
180  }
181  WHEN("typical settings part 3")
182  {
183  appConfigurator config;
184 
185  writeConfigFile( "aoSystem.conf",
186  {"aosys", "aosys", "aosys", "aosys", "aosys", "aosys", "aosys", "aosys", "aosys"},
187  {"tauWFS", "deltaTau", "optTau", "lam_sci", "zeta", "fit_mn_max", "circularLimit", "spatialFilter_ku", "spatialFilter_kv"},
188  {"0.0007", "0.0001", "false", "802e-9", "0.15", "12", "true", "50", "53"}
189  );
190 
191  aosys.setupConfig(config);
192  config.readConfig("aoSystem.conf");
193  aosys.loadConfig(config);
194 
195  REQUIRE(aosys.tauWFS() == Approx(0.0007));
196  REQUIRE(aosys.deltaTau() == Approx(0.0001));
197  REQUIRE(aosys.optTau() == false);
198  REQUIRE(aosys.lam_sci() == Approx(802e-9));
199  REQUIRE(aosys.zeta() == Approx(0.15));
200  REQUIRE(aosys.secZeta() == Approx(1/cos(0.15)));
201  REQUIRE(aosys.fit_mn_max() == 12);
202  REQUIRE(aosys.circularLimit() == true);
203  REQUIRE(aosys.spatialFilter_ku() == 50);
204  REQUIRE(aosys.spatialFilter_kv() == 53);
205  }
206  WHEN("typical settings part 4")
207  {
208  appConfigurator config;
209 
210  writeConfigFile( "aoSystem.conf",
211  {"aosys", "aosys", "aosys", "aosys", "atm"}, //last one verifies that atm config gets processed
212  {"ncp_wfe", "ncp_alpha", "starMag", "F0", "r_0"},
213  {"30e-9", "2.34", "8.2", "5e9", "0.25"}
214  );
215 
216  aosys.setupConfig(config);
217  config.readConfig("aoSystem.conf");
218  aosys.loadConfig(config);
219 
220  REQUIRE(aosys.ncp_wfe() == Approx(30e-9));
221  REQUIRE(aosys.ncp_alpha() == Approx(2.34));
222  REQUIRE(aosys.F0() == Approx(5e9));
223  REQUIRE(aosys.starMag() == Approx(8.2));
224  REQUIRE(aosys.Fg() == Approx(5e9*pow(10, -0.4*8.2)));
225  REQUIRE(aosys.Fg(9.0) == Approx(5e9*pow(10, -0.4*9.0)));
226  REQUIRE(aosys.atm.r_0() == Approx(0.25));
227  }
228  }
229 }
230 
231 
SCENARIO("Loading aoSystem config settings", "[ao::analysis::aoSystem]")
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.
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:68
void optTau(bool ot)
Set the value of m_optTau.
Definition: aoSystem.hpp:1647
void optd_delta(realT odd)
Set the fractional change in actuator spacing for optimization.
Definition: aoSystem.hpp:1322
void starMag(realT nmag)
Set the value of the Star's magnitude.
Definition: aoSystem.hpp:1794
void wfsBeta(const wfsT &w)
Set the WFS Beta pointer.
Definition: aoSystem.hpp:1337
void circularLimit(bool cl)
Set the value of the circularLimit flag.
Definition: aoSystem.hpp:1710
void ncp_alpha(realT alpha)
Set the value of the non-common path WFE PSD index.
Definition: aoSystem.hpp:1766
realT d_opt()
Calculate the optimum actuator spacing.
Definition: aoSystem.hpp:2110
void tauWFS(realT ntau)
Set the value of the WFS exposure time.
Definition: aoSystem.hpp:1619
void deltaTau(realT ndel)
Set the value of m_deltaTau.
Definition: aoSystem.hpp:1633
void minTauWFS(const std::vector< realT > &ntau)
Set the value of the minimum WFS exposure times.
Definition: aoSystem.hpp:1548
void D(realT nD)
Set the value of the primary mirror diameter.
Definition: aoSystem.hpp:1251
void spatialFilter_ku(realT ku)
Set the value of spatialFilter_ku.
Definition: aoSystem.hpp:1724
void npix_wfs(const std::vector< realT > &npix)
Set the number of pixels in the WFS for each WFS mode.
Definition: aoSystem.hpp:1409
void optd(bool od)
Set whether or not the value of d is optimized or just set to m_d_min.
Definition: aoSystem.hpp:1308
realT secZeta()
Get the zecant of the zenith angle.
Definition: aoSystem.hpp:1691
void lam_wfs(realT nlam)
Set the value of the WFS wavelength.
Definition: aoSystem.hpp:1395
void bin_npix(bool bnp)
Set the value of the pixel binning flag.
Definition: aoSystem.hpp:1594
void ron_wfs(const std::vector< realT > &nron)
Set the value of the WFS readout noise for each WFS mode.
Definition: aoSystem.hpp:1455
realT Fg(realT mag)
The photon flux at a given star magnitude.
Definition: aoSystem.hpp:1808
void F0(realT nF0)
Set the value of the 0 magnitude photon rate.
Definition: aoSystem.hpp:1780
void d_min(const std::vector< realT > &nd)
Set the minimum subaperture sampling for each WFS mode.
Definition: aoSystem.hpp:1267
void setupConfig(app::appConfigurator &config)
Setup the configurator to configure this class.
Definition: aoSystem.hpp:2812
void lam_sci(realT nlam)
Set the science wavelength.
Definition: aoSystem.hpp:1661
void zeta(realT nz)
Set the zenith angle, and its secant.
Definition: aoSystem.hpp:1675
void fit_mn_max(int mnm)
Set the value of m_fit_mn_max.
Definition: aoSystem.hpp:1697
void ncp_wfe(realT nwfe)
Set the value of the non-common path WFE.
Definition: aoSystem.hpp:1752
void Fbg(const std::vector< realT > &fbg)
Set the value of the background fluxes.
Definition: aoSystem.hpp:1502
void spatialFilter_kv(realT kv)
Set the value of spatialFilter_kv.
Definition: aoSystem.hpp:1738
void loadConfig(app::appConfigurator &config)
Load the configuration of this class from a configurator.
Definition: aoSystem.hpp:2852
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.