PURIFY
Next-generation radio interferometric imaging
parser_test.cc
Go to the documentation of this file.
1 #include <cstdio>
2 #include <iostream>
3 #include <string>
4 #include <yaml-cpp/yaml.h>
5 #include "catch2/catch_all.hpp"
6 #include "purify/directories.h"
7 #include "purify/yaml-parser.h"
8 
9 using namespace purify;
10 
11 TEST_CASE("Yaml parser and setting variables test") {
12  std::string file_path = purify::data_filename("config/config.yaml");
13  YamlParser yaml_parser = YamlParser(file_path);
14  std::string file_path_m = purify::data_filename("config/test_measurements_config.yaml");
15  YamlParser yaml_parser_m = YamlParser(file_path_m);
16  SECTION("Check the GeneralConfiguration measurement input variables") {
17  REQUIRE(yaml_parser_m.source() == purify::utilities::vis_source::measurements);
18  std::vector<std::string> expected_measurements = {"/path/to/measurment/set"};
19  REQUIRE(yaml_parser_m.measurements() == expected_measurements);
20  REQUIRE(yaml_parser_m.measurements_polarization() == stokes::I);
21  REQUIRE(yaml_parser_m.measurements_units() == purify::utilities::vis_units::pixels);
22  REQUIRE(yaml_parser_m.measurements_sigma() == 0.1);
23  REQUIRE(yaml_parser_m.skymodel() == "");
24  REQUIRE(yaml_parser_m.signal_to_noise() == 30);
25  REQUIRE(yaml_parser_m.number_of_measurements() == 100000);
26  REQUIRE(yaml_parser_m.w_rms() == 100.);
27  REQUIRE(yaml_parser_m.warm_start() == "/path/to/warm/start/image");
28  }
29  SECTION("Check the GeneralConfiguration simulation input variables") {
30  std::string file_path_s = purify::data_filename("config/test_simulation_config.yaml");
31  YamlParser yaml_parser_s = YamlParser(file_path_s);
32  REQUIRE(yaml_parser_s.source() == purify::utilities::vis_source::simulation);
33  REQUIRE(yaml_parser_s.measurements() ==
34  std::vector<std::string>({"path/to/coverage/measurement/file"}));
35  REQUIRE(yaml_parser_s.measurements_polarization() == stokes::I);
36  REQUIRE(yaml_parser_s.measurements_units() == purify::utilities::vis_units::lambda);
37  REQUIRE(yaml_parser_s.measurements_sigma() == 1);
38  REQUIRE(yaml_parser_s.skymodel() == "/path/to/sky/image");
39  REQUIRE(yaml_parser_s.signal_to_noise() == 10);
40  REQUIRE(yaml_parser_s.sim_J() == 8);
41  }
42  SECTION("Check the rest of the GeneralConfiguration variables") {
43  REQUIRE(yaml_parser.filepath() == file_path);
44  REQUIRE(yaml_parser.logging() == "debug");
45  REQUIRE(yaml_parser.iterations() == 100);
46  REQUIRE(yaml_parser.epsilonScaling() == 1);
47  REQUIRE(yaml_parser.update_iters() == 0);
48  REQUIRE(yaml_parser.update_tolerance() == 1e-1);
49  REQUIRE(yaml_parser.output_prefix() == "/path/to/output/dir");
50  }
51  SECTION("Check the MeasureOperators node variables") {
52  REQUIRE(yaml_parser.kernel() == "kb");
53  REQUIRE(yaml_parser.oversampling() == 2);
54  REQUIRE(yaml_parser.powMethod_iter() == 100);
55  REQUIRE(yaml_parser.powMethod_tolerance() == float(1e-4));
56  REQUIRE(yaml_parser.cellsizex() == 1);
57  REQUIRE(yaml_parser.cellsizey() == 1);
58  REQUIRE(yaml_parser.height() == 1024);
59  REQUIRE(yaml_parser.width() == 1024);
60  REQUIRE(yaml_parser.Jx() == 4);
61  REQUIRE(yaml_parser.Jy() == 4);
62  REQUIRE(yaml_parser.Jw() == 30);
63  REQUIRE(yaml_parser.wprojection() == false);
64  REQUIRE(yaml_parser.mpi_wstacking() == false);
65  REQUIRE(yaml_parser.mpi_all_to_all() == false);
66  REQUIRE(yaml_parser.kmeans_iters() == 100);
67  REQUIRE(yaml_parser.gpu() == false);
68  }
69  SECTION("Check the SARA node variables") {
70  std::vector<std::string> expected_wavelets = {"Dirac", "DB1", "DB2", "DB3", "DB4",
71  "DB5", "DB6", "DB7", "DB8"};
72  REQUIRE(yaml_parser.wavelet_basis() == expected_wavelets);
73  REQUIRE(yaml_parser.wavelet_levels() == 4);
74  REQUIRE(yaml_parser.algorithm() == "primaldual");
75  }
76  SECTION("Check the AlgorithmOptions node variables") {
77  REQUIRE(yaml_parser.epsilonConvergenceScaling() == 1);
78  REQUIRE(yaml_parser.realValueConstraint() == true);
79  REQUIRE(yaml_parser.positiveValueConstraint() == true);
80  REQUIRE(yaml_parser.mpiAlgorithm() == factory::algo_distribution::mpi_serial);
81  REQUIRE(yaml_parser.relVarianceConvergence() == 1e-3);
82  }
83  SECTION("Check the writeOutput method") {
84  yaml_parser_m.writeOutput(); // This test config file has a relative path for output, for
85  // testing purposes
86  std::string file_path_save = yaml_parser_m.output_prefix() + "/output_" +
87  yaml_parser_m.timestamp() + "/test_measurements_config_save.yaml";
88  YamlParser yaml_parser_check(file_path_save);
89  REQUIRE(yaml_parser_check.filepath() == file_path_save);
90  REQUIRE(yaml_parser_check.logging() == yaml_parser_m.logging());
91  REQUIRE(yaml_parser_check.iterations() == yaml_parser_m.iterations());
92  REQUIRE(yaml_parser_check.epsilonScaling() == yaml_parser_m.epsilonScaling());
93  REQUIRE(yaml_parser_check.update_tolerance() == yaml_parser_m.update_tolerance());
94  REQUIRE(yaml_parser_check.update_iters() == yaml_parser_m.update_iters());
95  REQUIRE(yaml_parser_check.output_prefix() == yaml_parser_m.output_prefix());
96  REQUIRE(yaml_parser_check.source() == yaml_parser_m.source());
97  REQUIRE(yaml_parser_check.measurements() == yaml_parser_m.measurements());
98  REQUIRE(yaml_parser_check.measurements_polarization() ==
99  yaml_parser_m.measurements_polarization());
100  REQUIRE(yaml_parser_check.measurements_units() == yaml_parser_m.measurements_units());
101  REQUIRE(yaml_parser_check.measurements_sigma() == yaml_parser_m.measurements_sigma());
102  REQUIRE(yaml_parser_check.skymodel() == yaml_parser_m.skymodel());
103  REQUIRE(yaml_parser_check.signal_to_noise() == yaml_parser_m.signal_to_noise());
104  REQUIRE(yaml_parser_check.number_of_measurements() == yaml_parser_m.number_of_measurements());
105  REQUIRE(yaml_parser_check.w_rms() == yaml_parser_m.w_rms());
106  REQUIRE(yaml_parser_check.kernel() == yaml_parser_m.kernel());
107  REQUIRE(yaml_parser_check.oversampling() == yaml_parser_m.oversampling());
108  REQUIRE(yaml_parser_check.powMethod_iter() == yaml_parser_m.powMethod_iter());
109  REQUIRE(yaml_parser_check.powMethod_tolerance() == yaml_parser_m.powMethod_tolerance());
110  REQUIRE(yaml_parser_check.cellsizex() == yaml_parser_m.cellsizex());
111  REQUIRE(yaml_parser_check.cellsizey() == yaml_parser_m.cellsizey());
112  REQUIRE(yaml_parser_check.width() == yaml_parser_m.width());
113  REQUIRE(yaml_parser_check.mpi_all_to_all() == yaml_parser_m.mpi_all_to_all());
114  REQUIRE(yaml_parser_check.height() == yaml_parser_m.height());
115  REQUIRE(yaml_parser_check.Jx() == yaml_parser_m.Jx());
116  REQUIRE(yaml_parser_check.Jy() == yaml_parser_m.Jy());
117  REQUIRE(yaml_parser_check.gpu() == yaml_parser_m.gpu());
118  REQUIRE(yaml_parser.wavelet_basis() == yaml_parser_m.wavelet_basis());
119  REQUIRE(yaml_parser.wavelet_levels() == yaml_parser_m.wavelet_levels());
120  REQUIRE(yaml_parser.algorithm() == yaml_parser_m.algorithm());
121  REQUIRE(yaml_parser.epsilonConvergenceScaling() == yaml_parser_m.epsilonConvergenceScaling());
122  REQUIRE(yaml_parser.realValueConstraint() == yaml_parser_m.realValueConstraint());
123  REQUIRE(yaml_parser.positiveValueConstraint() == yaml_parser_m.positiveValueConstraint());
124  REQUIRE(yaml_parser.mpiAlgorithm() == yaml_parser_m.mpiAlgorithm());
125  REQUIRE(yaml_parser.relVarianceConvergence() == yaml_parser_m.relVarianceConvergence());
126  std::remove(file_path_save.c_str());
127  }
128  SECTION("test version") { CHECK(purify::version() == yaml_parser.version()); }
129 }
#define CHECK(CONDITION, ERROR)
Definition: casa.cc:6
std::string version()
Returns library version.
Definition: config.in.h:40
std::string data_filename(std::string const &filename)
Holds data and such.
TEST_CASE("Yaml parser and setting variables test")
Definition: parser_test.cc:11