PURIFY
Next-generation radio interferometric imaging
Enumerations | Functions
purify::read_measurements Namespace Reference

Enumerations

enum class  format { vis , h5 , uvfits , ms }
 

Functions

utilities::vis_params read_measurements (const std::string &name, const bool w_term=false, const stokes pol=stokes::I, const utilities::vis_units units=utilities::vis_units::lambda)
 read in single measurement file More...
 
utilities::vis_params read_measurements (const std::vector< std::string > &names, const bool w_term=false, const stokes pol=stokes::I, const utilities::vis_units units=utilities::vis_units::lambda)
 read in measurements from a vector of file names More...
 
bool file_exists (const std::string &path)
 check that file path exists More...
 
bool dir_exists (const std::string &path)
 check that directory path exists More...
 

Enumeration Type Documentation

◆ format

Function Documentation

◆ dir_exists()

bool purify::read_measurements::dir_exists ( const std::string &  path)

check that directory path exists

Definition at line 140 of file read_measurements.cc.

140  {
141  struct stat buf;
142  return (stat(path.c_str(), &buf) == 0 && S_ISDIR(buf.st_mode));
143 }

Referenced by purify::mkdir_recursive(), read_measurements(), and TEST_CASE().

◆ file_exists()

bool purify::read_measurements::file_exists ( const std::string &  path)

check that file path exists

Definition at line 135 of file read_measurements.cc.

135  {
136  struct stat buf;
137  return (stat(path.c_str(), &buf) == 0);
138 }

Referenced by read_measurements().

◆ read_measurements() [1/2]

utilities::vis_params purify::read_measurements::read_measurements ( const std::string &  name,
const bool  w_term,
const stokes  pol,
const utilities::vis_units  units 
)

read in single measurement file

Definition at line 17 of file read_measurements.cc.

18  {
19  return read_measurements(std::vector<std::string>{name}, w_term, pol, units);
20 }
utilities::vis_params read_measurements(const std::vector< std::string > &names, const bool w_term, const stokes pol, const utilities::vis_units units)
read in measurements from a vector of file names

Referenced by getInputData(), and TEST_CASE().

◆ read_measurements() [2/2]

utilities::vis_params purify::read_measurements::read_measurements ( const std::vector< std::string > &  names,
const bool  w_term,
const stokes  pol,
const utilities::vis_units  units 
)

read in measurements from a vector of file names

Definition at line 21 of file read_measurements.cc.

22  {
23  std::vector<std::string> found_files;
24  format format_type = format::uvfits;
25  for (t_int i = 0; i < names.size(); i++) {
26  const boost::filesystem::path file_path(names.at(i));
27  if (not file_exists(file_path.native())) {
28  PURIFY_HIGH_LOG("Missing file will be removed from list: {}", names.at(i));
29  } else {
30  found_files.emplace_back(names.at(i));
31  format format_check = format::uvfits;
32  // checking if reading measurement set or .vis file
33  std::size_t found = names.at(i).find_last_of(".");
34  std::string format_string = "." + names.at(i).substr(found + 1);
35  std::transform(format_string.begin(), format_string.end(), format_string.begin(), ::tolower);
36  if (format_string == ".ms") {
37  format_check = format::ms;
38  if (not dir_exists(file_path.native()))
39  throw std::runtime_error(names.at(i) +
40  " is not a directory, as expected for a measurement set.");
41  } else if (format_string == ".vis") {
42  format_check = format::vis;
43  if (not file_exists(file_path.native()))
44  throw std::runtime_error(names.at(i) + " is not a regular file.");
45  } else if (format_string == ".h5") {
46  format_check = format::h5;
47  if (not file_exists(file_path.native()))
48  throw std::runtime_error(names.at(i) + " is not a regular file.");
49  } else if (format_string == ".uvfits") {
50  format_check = format::uvfits;
51  if (not file_exists(file_path.native()))
52  throw std::runtime_error(names.at(i) + " is not a regular file.");
53  } else
54  throw std::runtime_error("File extension for " + names.at(i) +
55  " not recognised. Must be .vis, .h5, .uvfits, or .ms.");
56  if (i == 0) format_type = format_check;
57  if (i > 0 and (format_check != format_type))
58  throw std::runtime_error("File extension is not the same for " + names.at(i) + " " +
59  names.at(i - 1));
60  }
61  }
62 
63  if (found_files.size() == 0) throw std::runtime_error("No files found.");
64  switch (format_type) {
65  case (format::vis): {
66  if (pol != stokes::I)
67  throw std::runtime_error("Stokes I assumed for vis files, but a different type is chosen.");
68  auto measurements = utilities::read_visibility(found_files, w_term);
69  measurements.units = units;
70  return measurements;
71  break;
72  }
73  case (format::h5): {
74 #ifdef PURIFY_H5
75  if (pol != stokes::I)
76  throw std::runtime_error("Stokes I assumed for HDF5 files, but a different type is chosen.");
77  auto measurements = utilities::read_visibility(found_files, w_term);
78  measurements.units = units;
79  return measurements;
80  break;
81 #else
82  throw std::runtime_error("HDF5 interface required to read h5 files.");
83 #endif
84  }
85  case (format::uvfits): {
86  return pfitsio::read_uvfits(found_files, true, pol);
87  break;
88  }
89  case (format::ms): {
90 #ifdef PURIFY_CASACORE
91  return casa::read_measurementset(found_files, pol);
92  break;
93 #else
94  throw std::runtime_error("Casacore interface required to read a measurement set.");
95 #endif
96  }
97  default:
98  throw std::runtime_error("Format not recognised.");
99  }
100 }
#define PURIFY_HIGH_LOG(...)
High priority message.
Definition: logging.h:203
utilities::vis_params read_visibility(const std::string &vis_name, const bool w_term)
Reads an HDF5 file with u,v visibilities, constructs a vis_params object and returns it.
Definition: h5reader.h:166
utilities::vis_params read_measurementset(std::string const &filename, const stokes polarization, const std::vector< t_int > &channels_input, std::string const &filter)
Read measurement set into vis_params structure.
Definition: casacore.cc:147
utilities::vis_params read_uvfits(const std::vector< std::string > &names, const bool flag, const stokes pol)
Read uvfits files from name of vector.
Definition: uvfits.cc:12
bool dir_exists(const std::string &path)
check that directory path exists
bool file_exists(const std::string &path)
check that file path exists

References dir_exists(), file_exists(), h5, purify::I, ms, PURIFY_HIGH_LOG, purify::casa::read_measurementset(), purify::pfitsio::read_uvfits(), purify::utilities::read_visibility(), uvfits, and vis.