PURIFY
Next-generation radio interferometric imaging
casa.cc
Go to the documentation of this file.
1 #include "purify/config.h"
2 #include "purify/casacore.h"
3 #include "purify/directories.h"
4 #include "purify/logging.h"
5 
6 #define CHECK(CONDITION, ERROR) \
7  if (not(CONDITION)) throw std::runtime_error(ERROR);
8 #define CHECK_THROWS(STATEMENT, ERROR) \
9  { \
10  bool did_throw = false; \
11  try { \
12  STATEMENT; \
13  } catch (...) { \
14  did_throw = true; \
15  } \
16  if (not did_throw) throw std::runtime_error(ERROR); \
17  }
18 
19 int main(int, char **) {
21  // Loads a measurement set
22  auto const ngc3256_filename = purify::ngc3256_ms();
23  auto const ngc3256 = purify::casa::MeasurementSet(ngc3256_filename);
24 
25  try {
26  // Gets the number of channels
27  CHECK(ngc3256.size() == 128, "Not the number of channels I expected");
28  // some of these channels are invalid
29  // in which case, the different vectors are empty
30  auto const channel0 = ngc3256[0];
31  CHECK(channel0.is_valid() == false, "Expected channel to be invalid");
32  CHECK(channel0.raw_u().size() == 0, "Expected raw u to be empty");
33  CHECK(channel0.lambda_u().size() == 0, "Expected frequencies to be empty");
34  CHECK(channel0.I().size() == 0, "Expected I component to be empty");
35  CHECK(channel0.wI().size() == 0, "Expected weights associated with I to be empty");
36 
37  // other channels will have data
38  auto const channel17 = ngc3256[17];
39  CHECK(channel17.is_valid(), "Channel should be valid");
40  CHECK(channel17.frequencies().size() == 141059, "Incorrect channel size");
41  CHECK(channel17.width().size() == 141059, "Incorrect channel-width size");
42  CHECK(channel17.raw_w().size() == 141059, "Incorrect channel size");
43  CHECK(channel17.wQ().size() == 141059, "Incorrect channel size");
44 
45  // valid channels have access to RA, DEC
46  CHECK(std::abs(channel17.right_ascension() - 2.7395560603928995) < 1e-8, "Right Ascension");
47  CHECK(std::abs(channel17.declination() + 0.76628680808811045) < 1e-8, "Declination");
48  // invalid channels do not
49  CHECK_THROWS(channel0.declination(), "Can't figure out direction of empty channel");
50 
51  // It is also possible to loop over channels
52  for (auto const &channel : ngc3256) {
53  if (not channel.is_valid()) continue;
54  // although we will stop at the first one
55  CHECK(channel.channel() == 17, "First valid channel is #17");
56  break;
57  }
58 
59  // Finally, it is possible to filter down some components
60  // Note that the filter "all(NOT FLAG[i,])" has already been applied, where
61  // i the channel index
62  auto const filter = "OBSERVATION_ID=1 AND DATA_DESC_ID=0";
63  auto const filtered = ngc3256[std::make_pair(17, filter)];
64  CHECK(filtered.lambda_w().size() == 6300, "Incorrect size for filtered data");
65  // Loops can also be filtered
66  for (auto i_first = ngc3256.begin(filter); i_first != ngc3256.end(filter); ++i_first) {
67  if (not i_first->is_valid()) continue;
68  CHECK(i_first->channel() == 17, "First valid channel is #17");
69  CHECK(i_first->V().size() == 6300, "Incorrect size for the filtered V Stokes component");
70  break;
71  }
72  } catch (std::runtime_error const &e) {
73  std::cerr << "Example did not run as expected:\n" << e.what() << "\n";
74  return 1;
75  }
76  return 0;
77 }
78 #undef CHECK
79 #undef CHECK_THROWS
int main(int, char **)
Definition: casa.cc:19
#define CHECK(CONDITION, ERROR)
Definition: casa.cc:6
#define CHECK_THROWS(STATEMENT, ERROR)
Definition: casa.cc:8
Interface around measurement sets.
Definition: casacore.h:27
void set_level(const std::string &level)
Method to set the logging level of the default Log object.
Definition: logging.h:137
std::string default_logging_level()
Default logging level.
Definition: config.in.h:51
std::string ngc3256_ms()