#include "SDDoubleCircleGainCalImpl.h"
#include <casacore/casa/Arrays/Vector.h>
#include <casacore/casa/Arrays/ArrayMath.h>
#include <casacore/casa/Arrays/ArrayIO.h>
#include <casacore/scimath/Functionals/Interpolate1D.h>
#include <casacore/scimath/Functionals/ScalarSampledFunctional.h>
#include <casacore/casa/BasicSL/Constants.h>
#include <casacore/casa/Logging/LogIO.h>
#include <casacore/casa/Quanta/Quantum.h>
#include <casacore/casa/Utilities/Sort.h>
using namespace casacore;
#define LOG logger_ << LogOrigin("SDDoubleCircleGainCal", __FUNCTION__, WHERE)
#define POSTLOG LogIO::POST
inline Double getPrimaryBeamSize(Double const observing_frequency,
Double const antenna_diameter) {
constexpr Double kFactorALMA = 1.13;
Double const speed_of_light = C::c;
if (observing_frequency <= 0.0 || antenna_diameter <= 0.0) {
beam_size = kFactorALMA * speed_of_light
/ (antenna_diameter * observing_frequency);
inline Int getDefaultSmoothingSize(Double const radius) {
auto const radius_in_arcsec = Quantity(radius, "rad").getValue("arcsec");
return 2 * static_cast<Int>(round(radius_in_arcsec / 1.5)) + 1;
inline Double average(size_t const index_from, size_t const index_to,
Vector<Double> const &data) {
assert(index_from <= index_to);
for (size_t i = index_from; i < index_to; ++i) {
return sum / static_cast<Double>(index_to - index_from);
inline Double average(size_t const index_from, size_t const index_to,
Vector<Double> const &data, Vector<Bool> const &flag) {
assert(index_from <= index_to);
for (size_t i = index_from; i < index_to; ++i) {
return sum / static_cast<Double>(count);
inline void smooth(Int const smooth_size, Vector<Double> const &data,
Vector<Double> &smoothed_data) {
assert(data.nelements() == smoothed_data.nelements());