PURIFY
Next-generation radio interferometric imaging
Namespaces | Classes | Functions
purify::casa Namespace Reference

Namespaces

 details
 

Classes

class  MeasurementSet
 Interface around measurement sets. More...
 

Functions

utilities::vis_params read_measurementset (std::string const &filename, const stokes pol=stokes::I, const std::vector< t_int > &channels=std::vector< t_int >(), std::string const &filter="")
 Read measurement set into vis_params structure. More...
 
utilities::vis_params read_measurementset (std::string const &filename, const utilities::vis_params &uv1, const stokes pol, const std::vector< t_int > &channels, std::string const &filter)
 Read measurement set object then combine it with a uv_params structure. More...
 
utilities::vis_params read_measurementset (std::vector< std::string > const &filename, const stokes pol=stokes::I, const std::vector< t_int > &channels=std::vector< t_int >(), std::string const &filter="")
 Read multiple measurement sets into one vis_params structure. More...
 
utilities::vis_params read_measurementset (MeasurementSet const &ms_file, const stokes pol=stokes::I, const std::vector< t_int > &channels=std::vector< t_int >(), std::string const &filter="")
 Read measurement set object into vis_params structure. More...
 
std::vector< utilities::vis_paramsread_measurementset_channels (std::string const &filename, const stokes pol=stokes::I, const t_int &channel_width=1, std::string const &filter="")
 Read meassurement set into a vector of vis_params. More...
 
t_real average_frequency (const purify::casa::MeasurementSet &ms_file, std::string const &filter, const std::vector< t_int > &channels)
 Return average frequency over channels. More...
 
template<class T >
Matrix< T > table_column (::casacore::Table const &table, std::string const &column, std::string const &filter="")
 
MeasurementSet::const_iterator operator+ (MeasurementSet::const_iterator::difference_type n, MeasurementSet::const_iterator const &c)
 
MeasurementSet::const_iterator operator- (MeasurementSet::const_iterator::difference_type n, MeasurementSet::const_iterator const &c)
 

Function Documentation

◆ average_frequency()

t_real purify::casa::average_frequency ( const purify::casa::MeasurementSet ms_file,
std::string const &  filter,
const std::vector< t_int > &  channels 
)

Return average frequency over channels.

Definition at line 353 of file casacore.cc.

354  {
355  // calculate average frequency
356  t_real frequency_sum = 0;
357  t_real width_sum = 0.;
358  for (auto channel_number : channels) {
359  auto const channel = ms_file[channel_number];
360  auto const frequencies = channel.frequencies();
361  auto const width = channel.width();
362  frequency_sum += (frequencies.array() * width.array()).sum();
363  width_sum += width.sum();
364  }
365  return frequency_sum / width_sum / 1e6;
366 }

Referenced by read_measurementset().

◆ operator+()

Definition at line 388 of file casacore.h.

389  {
390  return c.operator+(n);
391 }
const t_real c
speed of light in vacuum
Definition: types.h:72

References purify::constant::c.

◆ operator-()

Definition at line 392 of file casacore.h.

393  {
394  return c.operator-(n);
395 }

References purify::constant::c.

◆ read_measurementset() [1/4]

utilities::vis_params purify::casa::read_measurementset ( MeasurementSet const &  ms_file,
const stokes  polarization,
const std::vector< t_int > &  channels_input,
std::string const &  filter 
)

Read measurement set object into vis_params structure.

Definition at line 191 of file casacore.cc.

193  {
194  utilities::vis_params uv_data;
195  t_uint rows = 0;
196  std::vector<t_int> channels = channels_input;
197  if (channels.empty()) {
198  PURIFY_LOW_LOG("All Channels = {}", ms_file.size());
199  Vector<t_int> temp_vector = Vector<t_int>::LinSpaced(ms_file.size(), 0, ms_file.size());
200  if (temp_vector.size() == 1) // fixing unwanted behavior of LinSpaced when ms_file.size() = 1
201  temp_vector(0) = 0;
202  channels = std::vector<t_int>(temp_vector.data(), temp_vector.data() + temp_vector.size());
203  }
204 
205  // counting number of rows
206  for (auto channel_number : channels) {
207  rows += ms_file[channel_number].size();
208  }
209 
210  PURIFY_LOW_LOG("Visibilities = {}", rows);
211  uv_data.u = Vector<t_real>::Zero(rows);
212  uv_data.v = Vector<t_real>::Zero(rows);
213  uv_data.w = Vector<t_real>::Zero(rows);
214  uv_data.vis = Vector<t_complex>::Zero(rows);
215  uv_data.weights = Vector<t_complex>::Zero(rows);
216  uv_data.ra =
217  ms_file[channels[0]].right_ascension(); // convert directions from radians to degrees
218  uv_data.dec = ms_file[channels[0]].declination();
219  // calculate average frequency
220  uv_data.average_frequency = average_frequency(ms_file, filter, channels);
221 
222  // add data to channel
223  t_uint row = 0;
224 
225  for (auto channel_number : channels) {
226  PURIFY_DEBUG("Adding channel {} to plane...", channel_number);
227  if (channel_number < ms_file.size()) {
228  auto const channel = ms_file[channel_number];
229  if (channel.size() > 0) {
230  if (uv_data.ra != channel.right_ascension() or uv_data.dec != channel.declination())
231  throw std::runtime_error("Channels contain multiple pointings.");
232  Vector<t_real> const frequencies = channel.frequencies();
233  uv_data.u.segment(row, channel.size()) = channel.lambda_u();
234  uv_data.v.segment(row, channel.size()) = -channel.lambda_v();
235  uv_data.w.segment(row, channel.size()) = channel.lambda_w();
236  t_real const the_casa_factor = 2;
237  switch (polarization) {
238  case stokes::I:
239  uv_data.vis.segment(row, channel.size()) = channel.I("DATA") * 0.5;
240  uv_data.weights.segment(row, channel.size()).real() =
241  channel.wI(MeasurementSet::ChannelWrapper::Sigma::OVERALL) *
242  the_casa_factor; // go for sigma rather than sigma_spectrum
243  break;
244  case stokes::Q:
245  uv_data.vis.segment(row, channel.size()) = channel.Q("DATA") * 0.5;
246  uv_data.weights.segment(row, channel.size()).real() =
247  channel.wQ(MeasurementSet::ChannelWrapper::Sigma::OVERALL) *
248  the_casa_factor; // go for sigma rather than sigma_spectrum
249  break;
250  case stokes::U:
251  uv_data.vis.segment(row, channel.size()) = channel.U("DATA") * 0.5;
252  uv_data.weights.segment(row, channel.size()).real() =
253  channel.wU(MeasurementSet::ChannelWrapper::Sigma::OVERALL) *
254  the_casa_factor; // go for sigma rather than sigma_spectrum
255  break;
256  case stokes::V:
257  uv_data.vis.segment(row, channel.size()) = channel.V("DATA") * 0.5;
258  uv_data.weights.segment(row, channel.size()).real() =
259  channel.wV(MeasurementSet::ChannelWrapper::Sigma::OVERALL) *
260  the_casa_factor; // go for sigma rather than sigma_spectrum
261  break;
262  case stokes::LL:
263  uv_data.vis.segment(row, channel.size()) = channel.LL("DATA");
264  uv_data.weights.segment(row, channel.size()).real() = channel.wLL(
265  MeasurementSet::ChannelWrapper::Sigma::OVERALL); // go for sigma rather than
266  // sigma_spectrum
267  break;
268  case stokes::LR:
269  uv_data.vis.segment(row, channel.size()) = channel.LR("DATA");
270  uv_data.weights.segment(row, channel.size()).real() = channel.wRL(
271  MeasurementSet::ChannelWrapper::Sigma::OVERALL); // go for sigma rather than
272  // sigma_spectrum
273  break;
274  case stokes::RL:
275  uv_data.vis.segment(row, channel.size()) = channel.RL("DATA");
276  uv_data.weights.segment(row, channel.size()).real() = channel.wRL(
277  MeasurementSet::ChannelWrapper::Sigma::OVERALL); // go for sigma rather than
278  // sigma_spectrum
279  break;
280  case stokes::RR:
281  uv_data.vis.segment(row, channel.size()) = channel.RR("DATA");
282  uv_data.weights.segment(row, channel.size()).real() = channel.wRR(
283  MeasurementSet::ChannelWrapper::Sigma::OVERALL); // go for sigma rather than
284  // sigma_spectrum
285  break;
286  case stokes::XX:
287  uv_data.vis.segment(row, channel.size()) = channel.XX("DATA");
288  uv_data.weights.segment(row, channel.size()).real() = channel.wXX(
289  MeasurementSet::ChannelWrapper::Sigma::OVERALL); // go for sigma rather than
290  // sigma_spectrum
291  break;
292  case stokes::XY:
293  uv_data.vis.segment(row, channel.size()) = channel.XY("DATA");
294  uv_data.weights.segment(row, channel.size()).real() = channel.wXY(
295  MeasurementSet::ChannelWrapper::Sigma::OVERALL); // go for sigma rather than
296  // sigma_spectrum
297  break;
298  case stokes::YX:
299  uv_data.vis.segment(row, channel.size()) = channel.YX("DATA");
300  uv_data.weights.segment(row, channel.size()).real() = channel.wYX(
301  MeasurementSet::ChannelWrapper::Sigma::OVERALL); // go for sigma rather than
302  // sigma_spectrum
303  break;
304  case stokes::YY:
305  uv_data.vis.segment(row, channel.size()) = channel.YY("DATA");
306  uv_data.weights.segment(row, channel.size()).real() = channel.wYY(
307  MeasurementSet::ChannelWrapper::Sigma::OVERALL); // go for sigma rather than
308  // sigma_spectrum
309  break;
310  case stokes::P:
311  t_complex I(0., 1.);
312  uv_data.vis.segment(row, channel.size()) = channel.Q("DATA") + I * channel.U("DATA");
313  uv_data.weights.segment(row, channel.size()).real() =
314  (channel.wQ(MeasurementSet::ChannelWrapper::Sigma::OVERALL).array() *
315  channel.wQ(MeasurementSet::ChannelWrapper::Sigma::OVERALL).array() +
316  channel.wU(MeasurementSet::ChannelWrapper::Sigma::OVERALL).array() *
317  channel.wU(MeasurementSet::ChannelWrapper::Sigma::OVERALL).array())
318  .sqrt(); // go for sigma rather than
319  // sigma_spectrum
320  break;
321  }
322  row += channel.size();
323  }
324  }
325  }
326  // make consistent with vis file format exported from casa
327  uv_data.weights = 1. / uv_data.weights.array();
328  uv_data.units = utilities::vis_units::lambda;
329  return uv_data;
330 }
#define PURIFY_LOW_LOG(...)
Low priority message.
Definition: logging.h:207
#define PURIFY_DEBUG(...)
\macro Output some debugging
Definition: logging.h:197
t_real average_frequency(const purify::casa::MeasurementSet &ms_file, std::string const &filter, const std::vector< t_int > &channels)
Return average frequency over channels.
Definition: casacore.cc:353

References average_frequency(), purify::utilities::vis_params::average_frequency, purify::utilities::vis_params::dec, purify::casa::MeasurementSet::declination(), purify::I, purify::utilities::lambda, purify::LL, purify::LR, purify::casa::MeasurementSet::ChannelWrapper::OVERALL, purify::P, PURIFY_DEBUG, PURIFY_LOW_LOG, purify::Q, purify::utilities::vis_params::ra, purify::casa::MeasurementSet::right_ascension(), purify::RL, purify::RR, purify::casa::MeasurementSet::size(), purify::U, purify::utilities::vis_params::u, purify::utilities::vis_params::units, purify::V, purify::utilities::vis_params::v, purify::utilities::vis_params::vis, purify::utilities::vis_params::w, purify::utilities::vis_params::weights, purify::XX, purify::XY, purify::YX, and purify::YY.

◆ read_measurementset() [2/4]

utilities::vis_params purify::casa::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 at line 147 of file casacore.cc.

149  {
150  auto const ms_file = purify::casa::MeasurementSet(filename);
151  return read_measurementset(ms_file, polarization, channels_input, filter);
152 };
Interface around measurement sets.
Definition: casacore.h:27
utilities::vis_params read_measurementset(MeasurementSet const &ms_file, const stokes polarization, const std::vector< t_int > &channels_input, std::string const &filter)
Read measurement set object into vis_params structure.
Definition: casacore.cc:191

References purify::casa::MeasurementSet::filename().

Referenced by purify::read_measurements::read_measurements(), read_measurementset(), and read_measurementset_channels().

◆ read_measurementset() [3/4]

utilities::vis_params purify::casa::read_measurementset ( std::string const &  filename,
const utilities::vis_params uv1,
const stokes  pol,
const std::vector< t_int > &  channels,
std::string const &  filter 
)

Read measurement set object then combine it with a uv_params structure.

Definition at line 153 of file casacore.cc.

156  {
157  utilities::vis_params uv;
158  const auto uv2 = read_measurementset(filename, pol, channels, filter);
159  if (std::abs(uv1.ra - uv2.ra) > 1e-6)
160  throw std::runtime_error(filename + ": wrong RA in pointing.");
161  if (std::abs(uv1.dec - uv2.dec) > 1e-6)
162  throw std::runtime_error(filename + ": wrong DEC in pointing.");
163  uv.ra = uv1.ra;
164  uv.dec = uv1.dec;
165  uv.u = Vector<t_real>::Zero(uv1.size() + uv2.size());
166  uv.v = Vector<t_real>::Zero(uv1.size() + uv2.size());
167  uv.w = Vector<t_real>::Zero(uv1.size() + uv2.size());
168  uv.vis = Vector<t_complex>::Zero(uv1.size() + uv2.size());
169  uv.weights = Vector<t_complex>::Zero(uv1.size() + uv2.size());
170  uv.u.segment(0, uv1.size()) = uv1.u;
171  uv.v.segment(0, uv1.size()) = uv1.v;
172  uv.w.segment(0, uv1.size()) = uv1.w;
173  uv.vis.segment(0, uv1.size()) = uv1.vis;
174  uv.weights.segment(0, uv1.size()) = uv1.weights;
175  uv.u.segment(uv1.size(), uv2.size()) = uv2.u;
176  uv.v.segment(uv1.size(), uv2.size()) = uv2.v;
177  uv.w.segment(uv1.size(), uv2.size()) = uv2.w;
178  uv.vis.segment(uv1.size(), uv2.size()) = uv2.vis;
179  uv.weights.segment(uv1.size(), uv2.size()) = uv2.weights;
180  return uv;
181 }

References purify::utilities::vis_params::dec, purify::casa::MeasurementSet::filename(), purify::utilities::vis_params::ra, read_measurementset(), purify::utilities::vis_params::size(), purify::utilities::vis_params::u, purify::utilities::vis_params::v, purify::utilities::vis_params::vis, purify::utilities::vis_params::w, and purify::utilities::vis_params::weights.

◆ read_measurementset() [4/4]

utilities::vis_params purify::casa::read_measurementset ( std::vector< std::string > const &  filename,
const stokes  pol,
const std::vector< t_int > &  channel,
std::string const &  filter 
)

Read multiple measurement sets into one vis_params structure.

Definition at line 182 of file casacore.cc.

184  {
185  utilities::vis_params output = read_measurementset(filename.at(0), pol, channel, filter);
186  if (filename.size() == 1) return output;
187  for (int i = 1; i < filename.size(); i++)
188  output = read_measurementset(filename.at(i), output, pol, channel, filter);
189  return output;
190 }

References purify::casa::MeasurementSet::filename(), and read_measurementset().

◆ read_measurementset_channels()

std::vector< utilities::vis_params > purify::casa::read_measurementset_channels ( std::string const &  filename,
const stokes  pol,
const t_int &  channel_width,
std::string const &  filter 
)

Read meassurement set into a vector of vis_params.

Definition at line 332 of file casacore.cc.

335  {
336  // Read and average the channels into a vector of vis_params
337  std::vector<utilities::vis_params> channels_vis;
338  auto const ms_file = purify::casa::MeasurementSet(filename);
339  t_int const total_channels = ms_file.size();
340  t_int const planes = (channel_width == 0) ? 1 : std::floor(total_channels / channel_width);
341  PURIFY_DEBUG("Number of planes {} ...", planes);
342  for (int i = 0; i < planes; i++) {
343  PURIFY_DEBUG("Reading plane {} ...", i);
344  t_int const end = std::min((i + 1) * channel_width, total_channels);
345  Vector<t_int> temp_block = Vector<t_int>::LinSpaced(channel_width, i * channel_width, end);
346  if (channel_width == 1 or total_channels == i) temp_block(0) = i;
347  auto const block = std::vector<t_int>(temp_block.data(), temp_block.data() + temp_block.size());
348  channels_vis.push_back(read_measurementset(ms_file, pol, block, filter));
349  }
350  return channels_vis;
351 };

References purify::casa::MeasurementSet::end(), purify::casa::MeasurementSet::filename(), PURIFY_DEBUG, and read_measurementset().

◆ table_column()

template<class T >
Matrix< T > purify::casa::table_column ( ::casacore::Table const &  table,
std::string const &  column,
std::string const &  filter = "" 
)

Definition at line 203 of file casacore.h.

204  {
205  return details::table_column<T>(table, column, filter,
206  std::integral_constant<bool, sopt::is_complex<T>::value>());
207 }