mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
aoAtmosphere_test.cpp
1/** \file fileAtmosphere_test.cpp
2 */
3#include "../../../catch2/catch.hpp"
4
5#define MX_NO_ERROR_REPORTS
6
7#include "../../../../include/ao/analysis/aoAtmosphere.hpp"
8
9typedef double realT;
10
11using namespace mx::app;
12using namespace mx::AO::analysis;
13
14/** Scenario: Loading aoAtmosphere config settings
15 *
16 * Verify parsing of config
17 *
18 * \anchor tests_ao_analysis_aoAtmosphere_config
19 */
20SCENARIO( "Loading aoAtmosphere config settings", "[ao::analysis::aoAtmosphere]" )
21{
22 GIVEN( "a valid config vile" )
23 {
24 aoAtmosphere<realT> atm; // This will be cumulative
25
26 WHEN( "all normal settings" )
27 {
28 appConfigurator config;
29
31 "aoAtmosphere.conf",
32 { "atm", "atm", "atm", "atm", "atm", "atm", "atm", "atm", "atm", "atm" },
33 { "r_0", "lam_0", "L_0", "l_0", "layer_z", "h_obs", "H", "layer_Cn2", "layer_v_wind", "layer_dir" },
34 { "0.25",
35 "0.4e-9",
36 "10,15,22.5",
37 "0.1,0.01,0.001",
38 "1000,2000,5000",
39 "3002",
40 "2.3",
41 "1,1,3.0",
42 "10.5,11.2,23.7",
43 "0.1,0.6,1.6" } );
44
45 atm.setupConfig( config );
46 config.readConfig( "aoAtmosphere.conf" );
47 atm.loadConfig( config );
48
49 REQUIRE( atm.r_0() == 0.25 );
50 REQUIRE( atm.lam_0() == 0.4e-9 );
51
52 REQUIRE( atm.L_0( 0 ) == 10 );
53 REQUIRE( atm.L_0( 1 ) == 15 );
54 REQUIRE( atm.L_0( 2 ) == 22.5 );
55
56 REQUIRE( atm.l_0( 0 ) == 0.1 );
57 REQUIRE( atm.l_0( 1 ) == 0.01 );
58 REQUIRE( atm.l_0( 2 ) == 0.001 );
59
60 REQUIRE( atm.layer_z( 0 ) == 1000 );
61 REQUIRE( atm.layer_z( 1 ) == 2000 );
62 REQUIRE( atm.layer_z( 2 ) == 5000 );
63
64 REQUIRE( atm.h_obs() == 3002 );
65
66 REQUIRE( atm.H() == 2.3 );
67
68 REQUIRE( atm.layer_Cn2( 0 ) == Approx( 0.2 ) );
69 REQUIRE( atm.layer_Cn2( 1 ) == Approx( 0.2 ) );
70 REQUIRE( atm.layer_Cn2( 2 ) == Approx( 0.6 ) );
71
72 REQUIRE( atm.layer_v_wind( 0 ) == Approx( 10.5 ) );
73 REQUIRE( atm.layer_v_wind( 1 ) == Approx( 11.2 ) );
74 REQUIRE( atm.layer_v_wind( 2 ) == Approx( 23.7 ) );
75
76 REQUIRE( atm.layer_dir( 0 ) == Approx( 0.1 ) );
77 REQUIRE( atm.layer_dir( 1 ) == Approx( 0.6 ) );
78 REQUIRE( atm.layer_dir( 2 ) == Approx( 1.6 ) );
79
80 REQUIRE( atm.v_wind() == Approx( 19.278644205193533 ) );
81 REQUIRE( atm.z_mean() == Approx( 3886.4496373530733 ) );
82
83 REQUIRE( atm.nonKolmogorov() == false );
84 }
85 WHEN( "setting v_wind and z_mean" )
86 {
87 appConfigurator config;
88
89 writeConfigFile( "aoAtmosphere.conf",
90 { "atm", "atm", "atm", "atm", "atm", "atm" },
91 { "layer_z", "layer_Cn2", "layer_v_wind", "layer_dir", "v_wind", "z_mean" },
92 { "1000,2000,5000", "1,1,3.0", "10.5,11.2,23.7", "0.1,0.6,1.6", "15.0", "5001.0" } );
93
94 atm.setupConfig( config );
95 config.readConfig( "aoAtmosphere.conf" );
96 atm.loadConfig( config );
97
98 REQUIRE( atm.v_wind() == Approx( 15.0 ) );
99 REQUIRE( atm.z_mean() == Approx( 5001.0 ) );
100
101 REQUIRE( atm.nonKolmogorov() == false );
102 }
103 WHEN( "setting nonKolmogorov to false" )
104 {
105 appConfigurator config;
106
107 writeConfigFile( "aoAtmosphere.conf", { "atm" }, { "nonKolmogorov" }, { "false" } );
108
109 atm.setupConfig( config );
110 config.readConfig( "aoAtmosphere.conf" );
111 atm.loadConfig( config );
112
113 REQUIRE( atm.nonKolmogorov() == false );
114 }
115 WHEN( "setting nonKolmogorov to true" )
116 {
117 appConfigurator config;
118
119 writeConfigFile( "aoAtmosphere.conf", { "atm" }, { "nonKolmogorov" }, { "true" } );
120
121 atm.setupConfig( config );
122 config.readConfig( "aoAtmosphere.conf" );
123 atm.loadConfig( config );
124
125 REQUIRE( atm.nonKolmogorov() == true );
126 }
127
128 WHEN( "setting nonKolmogorov alpha" )
129 {
130 atm.nonKolmogorov( false );
131 REQUIRE( atm.nonKolmogorov() == false );
132
133 appConfigurator config;
134
135 writeConfigFile( "aoAtmosphere.conf", { "atm" }, { "alpha" }, { "4.7" } );
136
137 atm.setupConfig( config );
138 config.readConfig( "aoAtmosphere.conf" );
139 atm.loadConfig( config );
140
141 REQUIRE( atm.alpha( 0 ) == Approx( 4.7 ) );
142 REQUIRE( atm.nonKolmogorov() == true );
143 }
144
145 WHEN( "setting nonKolmogorov beta" )
146 {
147 atm.nonKolmogorov( false );
148 REQUIRE( atm.nonKolmogorov() == false );
149
150 appConfigurator config;
151
152 writeConfigFile( "aoAtmosphere.conf", { "atm" }, { "beta" }, { "0.026" } );
153
154 atm.setupConfig( config );
155 config.readConfig( "aoAtmosphere.conf" );
156 atm.loadConfig( config );
157
158 REQUIRE( atm.beta( 0 ) == Approx( 0.026 ) );
159 REQUIRE( atm.nonKolmogorov() == true );
160 }
161
162 WHEN( "setting nonKolmogorov beta_0" )
163 {
164 atm.nonKolmogorov( false );
165 REQUIRE( atm.nonKolmogorov() == false );
166
167 appConfigurator config;
168
169 writeConfigFile( "aoAtmosphere.conf", { "atm" }, { "beta_0" }, { "1e-7" } );
170
171 atm.setupConfig( config );
172 config.readConfig( "aoAtmosphere.conf" );
173 atm.loadConfig( config );
174
175 REQUIRE( atm.beta_0( 0 ) == Approx( 1e-7 ) );
176 REQUIRE( atm.nonKolmogorov() == true );
177 }
178 }
179 GIVEN( "command line options" )
180 {
181 aoAtmosphere<realT> atm; // This will be cumulative
182
183 WHEN( "setting nonKolmogorov to true" )
184 {
185 appConfigurator config;
186 std::vector<std::string> argvs( 2 );
187
188 argvs[0] = "test";
189 argvs[1] = "--atm.nonKolmogorov=true";
190
191 char *argv[2];
192 argv[0] = (char *)argvs[0].data();
193 argv[1] = (char *)argvs[1].data();
194
195 REQUIRE( atm.nonKolmogorov() == false );
196 atm.setupConfig( config );
197 config.parseCommandLine( argvs.size(), argv );
198 atm.loadConfig( config );
199 REQUIRE( atm.nonKolmogorov() == true );
200 }
201
202 WHEN( "setting nonKolmogorov to true" )
203 {
204 appConfigurator config;
205 std::vector<std::string> argvs( 2 );
206
207 argvs[0] = "test";
208 argvs[1] = "--atm.nonKolmogorov=false";
209
210 char *argv[2];
211 argv[0] = (char *)argvs[0].data();
212 argv[1] = (char *)argvs[1].data();
213
214 atm.nonKolmogorov( true );
215 REQUIRE( atm.nonKolmogorov() == true );
216 atm.setupConfig( config );
217 config.parseCommandLine( argvs.size(), argv );
218 atm.loadConfig( config );
219 REQUIRE( atm.nonKolmogorov() == false );
220 }
221 }
222}
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.
A class to specify atmosphere parameters and perform related calculations.
realT lam_0()
Get the current value of the reference wavelength.
realT h_obs()
Get the height of the observatory.
realT l_0(const size_t &n)
Get the value of the inner scale for a single layer.
realT layer_dir(const int n)
Get the wind direction of a single layer.
realT L_0(const size_t &n)
Get the value of the outer scale for a single layer.
void nonKolmogorov(const bool &nk)
Set the value of m_nonKolmogorov.
void loadConfig(app::appConfigurator &config)
Load the configuration of this class from a configurator.
realT beta_0(const size_t &n)
Return the PSD constant for a single layer.
realT beta(const size_t &n)
Return the PSD normalization for a single layer.
void setupConfig(app::appConfigurator &config)
Setup the configurator to configure this class.
realT H()
Get the atmospheric scale height.
realT v_wind()
Get the 5/3 moment weighted mean wind speed.
realT layer_Cn2(const int n)
Get the strength of a single layer.
realT alpha(const size_t &n)
Return the PSD index for a single layer.
realT layer_v_wind(const int n)
Get the wind speed of a single layer.
realT z_mean()
Get the weighted mean layer height.
realT r_0()
Get the value of Fried's parameter r_0 at the reference wavelength lam_0.
realT layer_z(const size_t n)
Get the height of a single layer.
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.
void parseCommandLine(int argc, char **argv, const std::string &oneTarget="")
Parse the command line, updating the targets.