File: tcommandline.cpp

package info (click to toggle)
wsclean 3.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,296 kB
  • sloc: cpp: 129,246; python: 22,066; sh: 360; ansic: 230; makefile: 185
file content (195 lines) | stat: -rw-r--r-- 6,908 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include <boost/test/unit_test.hpp>

#include "../../main/commandline.h"
#include "../../main/wsclean.h"
#include "../../structures/primarybeam.h"

namespace wsclean {

namespace {
const char* kMWA_MS = "test_data/MWA_MOCK.ms/";
const char* kMWA_BDA_MS = "test_data/MWA_BDA_MOCK.ms/";
const char* kFacetFile2Facets = FACET_DEFINITION_FILE_2FACETS;
const char* kFacetFile4Facets = FACET_DEFINITION_FILE_4FACETS;
const char* kFacetSolutionFile = "test_data/mock_soltab_2pol.h5";

// Include sizes ending in "k", "m", which should yield kilobytes / megabytes.
std::vector<const char*> baseArgs() {
  return {"wsclean", "-quiet", "-size",           "1k",     "512",
          "-scale",  "1amin",  "-multiscale",     "-niter", "2m",
          "-mgain",  "0.8",    "-auto-threshold", "1",      "-auto-mask",
          "4"};
}

std::vector<const char*> baseArgsBda() {
  return {"wsclean", "-quiet", "-size",    "1024",      "1024",
          "-scale",  "1amin",  "-use-idg", "-idg-mode", "cpu"};
}
}  // namespace

/**
 * @brief Collection of tests to check the parsing of
 * command line input.
 */
BOOST_AUTO_TEST_SUITE(commandline)

BOOST_AUTO_TEST_CASE(pb_grid_size) {
  BOOST_REQUIRE(boost::filesystem::is_directory(kMWA_MS));

  WSClean wsclean;
  CommandLine commandLine;
  std::vector<const char*> args1 = baseArgs();
  args1.push_back("-apply-primary-beam");
  args1.push_back(kMWA_MS);
  commandLine.Parse(wsclean, args1.size(), args1.data(), false);
  const Settings settings1 = wsclean.GetSettings();
  BOOST_CHECK_EQUAL(settings1.trimmedImageWidth, 1024);
  BOOST_CHECK_EQUAL(settings1.trimmedImageHeight, 512);
  BOOST_CHECK_EQUAL(settings1.deconvolutionIterationCount, 2 * 1024 * 1024);
  BOOST_CHECK_EQUAL(settings1.primaryBeamGridSize, 32u);
  PrimaryBeam primaryBeam1(settings1);
  BOOST_CHECK_EQUAL(primaryBeam1.GetUndersamplingFactor(), 16u);
  BOOST_CHECK_EQUAL(primaryBeam1.GetBeamUpdateTime(), 1800u);
  BOOST_CHECK_EQUAL(settings1.maxMpiMessageSize,
                    std::numeric_limits<std::int32_t>::max());

  std::vector<const char*> args2 = baseArgs();
  args2.push_back("-apply-primary-beam");
  args2.push_back("-pb-grid-size");
  args2.push_back("64");
  args2.push_back("-beam-aterm-update");
  args2.push_back("900");
  args2.push_back("-max-mpi-message-size");
  args2.push_back("1g");  // Test that a "g" suffix yields gigabytes.
  args2.push_back(kMWA_MS);
  commandLine.Parse(wsclean, args2.size(), args2.data(), false);
  const Settings settings2 = wsclean.GetSettings();
  BOOST_CHECK_EQUAL(settings2.primaryBeamGridSize, 64u);
  PrimaryBeam primaryBeam2(settings2);
  BOOST_CHECK_EQUAL(primaryBeam2.GetUndersamplingFactor(), 8u);
  BOOST_CHECK_EQUAL(primaryBeam2.GetBeamUpdateTime(), 900u);
  BOOST_CHECK_EQUAL(settings2.maxMpiMessageSize, 1024 * 1024 * 1024);
}

BOOST_AUTO_TEST_CASE(h5parm_basics) {
  BOOST_REQUIRE(boost::filesystem::is_directory(kMWA_MS));
  BOOST_REQUIRE(boost::filesystem::is_regular_file(kFacetFile2Facets));
  BOOST_REQUIRE(boost::filesystem::is_regular_file(kFacetFile4Facets));
  BOOST_REQUIRE(boost::filesystem::is_regular_file(kFacetSolutionFile));
}

BOOST_AUTO_TEST_CASE(h5parm_one_file) {
  CommandLine commandLine;
  WSClean wsclean;
  Settings settings;

  // One solution file, one MSet
  std::vector<const char*> args = baseArgs();
  args.push_back("-facet-regions");
  args.push_back(kFacetFile4Facets);
  args.push_back("-apply-facet-solutions");
  args.push_back(kFacetSolutionFile);
  args.push_back("amplitude000,phase000");
  args.push_back(kMWA_MS);
  commandLine.Parse(wsclean, args.size(), args.data(), false);
  settings = wsclean.GetSettings();
  BOOST_CHECK_EQUAL(settings.facetSolutionFiles.size(), 1u);
  BOOST_CHECK_EQUAL(settings.facetSolutionFiles[0], kFacetSolutionFile);

  // One solution file, two MSets
  wsclean.ResetSettings();
  args.push_back(kMWA_MS);
  commandLine.Parse(wsclean, args.size(), args.data(), false);
  settings = wsclean.GetSettings();
  BOOST_CHECK_EQUAL(settings.filenames.size(), 2u);
  BOOST_CHECK_EQUAL(settings.facetSolutionFiles.size(), 1u);
  BOOST_CHECK_EQUAL(settings.facetSolutionFiles[0], kFacetSolutionFile);
}

BOOST_AUTO_TEST_CASE(h5parm_multiple_files) {
  CommandLine commandLine;
  WSClean wsclean;
  Settings settings;

  // Two solution files, one MSet
  std::vector<const char*> args = baseArgs();
  args.push_back("-facet-regions");
  args.push_back(kFacetFile4Facets);
  args.push_back("-apply-facet-solutions");
  const std::string facet_solutions_str =
      std::string(kFacetSolutionFile) + "," + std::string(kFacetSolutionFile);
  const char* facet_solutions_char = facet_solutions_str.c_str();
  args.push_back(facet_solutions_char);
  args.push_back("amplitude000,phase000");
  args.push_back(kMWA_MS);
  BOOST_CHECK_THROW(commandLine.Parse(wsclean, args.size(), args.data(), false),
                    std::runtime_error);

  // Two solution files, two MSets
  wsclean.ResetSettings();
  args.push_back(kMWA_MS);
  commandLine.Parse(wsclean, args.size(), args.data(), false);
  settings = wsclean.GetSettings();
  BOOST_CHECK_EQUAL(settings.filenames.size(), 2u);
  BOOST_CHECK_EQUAL(settings.facetSolutionFiles.size(), 2u);
  BOOST_CHECK_EQUAL(settings.facetSolutionFiles[0], kFacetSolutionFile);
  BOOST_CHECK_EQUAL(settings.facetSolutionFiles[1], kFacetSolutionFile);
}

BOOST_AUTO_TEST_CASE(h5parm_inconsistent) {
  WSClean wsclean;
  CommandLine commandLine;

  std::vector<const char*> args = baseArgs();
  args.push_back("-facet-regions");
  args.push_back(kFacetFile2Facets);
  args.push_back("-apply-facet-solutions");
  args.push_back(kFacetSolutionFile);
  args.push_back("amplitude000,phase000");
  args.push_back(kMWA_MS);
  BOOST_CHECK_THROW(commandLine.Parse(wsclean, args.size(), args.data(), false),
                    std::runtime_error);
}

BOOST_AUTO_TEST_CASE(idg_bda_averaging) {
  BOOST_REQUIRE(boost::filesystem::is_directory(kMWA_MS));

  WSClean wsclean;
  CommandLine commandLine;

  std::vector<const char*> args = baseArgsBda();

  args.push_back("-baseline-averaging");
  args.push_back("10.0");
  args.push_back(kMWA_MS);

  BOOST_CHECK_THROW(commandLine.Parse(wsclean, args.size(), args.data(), false),
                    std::runtime_error);
}

BOOST_AUTO_TEST_CASE(idg_bda_mset) {
  BOOST_REQUIRE(boost::filesystem::is_directory(kMWA_BDA_MS));

  WSClean wsclean;
  CommandLine commandLine;

  std::vector<const char*> args = baseArgsBda();
  args.push_back(kMWA_BDA_MS);

  BOOST_CHECK_THROW(commandLine.Parse(wsclean, args.size(), args.data(), false),
                    std::runtime_error);
}

BOOST_AUTO_TEST_CASE(incomplete_commandline) {
  WSClean wsclean;
  CommandLine commandLine;

  std::vector<const char*> args{"wsclean", "-name"};

  BOOST_CHECK_THROW(commandLine.Parse(wsclean, args.size(), args.data(), false),
                    std::runtime_error);
}

BOOST_AUTO_TEST_SUITE_END()

}  // namespace wsclean