Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #71 from ICRAR/cgray_refactor_phaserotate
Browse files Browse the repository at this point in the history
  • Loading branch information
calgray authored Nov 12, 2020
2 parents 2bc263a + e077174 commit f49ed89
Show file tree
Hide file tree
Showing 23 changed files with 897 additions and 791 deletions.
2 changes: 1 addition & 1 deletion deploy/submit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#
# examples:
# sbatch ./bin/submit.sh --help
# sbatch ./bin/submit.sh -f ~/leap-accelerate/testdata/1197638568-32.ms -s 126 -i cuda -d
# sbatch ./bin/submit.sh -f ~/leap-accelerate/testdata/mwa/1197638568-32.ms -s 126 -i cuda -d
#[[-0.4606549305661674,-0.29719233792392513],[-0.753231018062671,-0.44387635324622354],[-0.6207547100721282,-0.2539086572881469],[-0.41958660604621867,-0.03677626900108552],[-0.41108685258900596,-0.08638012622791202],[-0.7782459495668798,-0.4887860989684432],[-0.17001324965728973,-0.28595644149463484],[-0.7129444556035118,-0.365286407171852],[-0.1512764129166089,-0.21161026349648748]]
#

Expand Down
2 changes: 1 addition & 1 deletion src/icrar/leap-accelerate-cli/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int main(int argc, char** argv)
app.add_option("-s,--stations", rawArgs.stations, "Override number of stations to use in the specified measurement set");
app.add_option("-i,--implementation", rawArgs.computeImplementation, "Compute implementation type (casa, cpu, cuda)");
//TODO: app.add_option("-m,--mwa-support", rawArgs.mwaSupport, "MWA data support by negating baselines");
app.add_option("-a,--autocorrelations", rawArgs.readAutocorrelations, "True if measurement set rows store autocorrelations");
app.add_option("-a,--autocorrelations", rawArgs.readAutocorrelations, "Set to true if measurement set rows store autocorrelations");
app.add_option("-v,--verbosity", rawArgs.verbosity, "Verbosity (0=fatal, 1=error, 2=warn, 3=info, 4=debug, 5=trace), defaults to info");

try
Expand Down
8 changes: 4 additions & 4 deletions src/icrar/leap-accelerate-cli/tests/CommandLineTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace icrar
void TestSimpleRun()
{
std::string command = m_binDir + "LeapAccelerateCLI";
command += " -f " + m_srcDir + "testdata/1197638568-32.ms";
command += " -f " + m_srcDir + "testdata/mwa/1197638568-32.ms";
command += " -s 126";
command += " -d [[1.0,0.0]]";

Expand All @@ -77,7 +77,7 @@ namespace icrar
void TestMultipleCasa()
{
std::string command = m_binDir + "LeapAccelerateCLI";
command += " -f " + m_srcDir + "testdata/1197638568-32.ms";
command += " -f " + m_srcDir + "testdata/mwa/1197638568-32.ms";
command += " -s 126";
command += " -i casa";
command += " -d ["
Expand All @@ -99,7 +99,7 @@ namespace icrar
void TestMultipleCpu()
{
std::string command = m_binDir + "LeapAccelerateCLI";
command += " -f " + m_srcDir + "testdata/1197638568-32.ms";
command += " -f " + m_srcDir + "testdata/mwa/1197638568-32.ms";
command += " -s 126";
command += " -i eigen";
command += " -d ["
Expand All @@ -121,7 +121,7 @@ namespace icrar
void TestMultipleCuda()
{
std::string command = m_binDir + "LeapAccelerateCLI";
command += " -f " + m_srcDir + "testdata/1197638568-32.ms";
command += " -f " + m_srcDir + "testdata/mwa/1197638568-32.ms";
command += " -s 126";
command += " -i cuda";
command += " -d ["
Expand Down
14 changes: 7 additions & 7 deletions src/icrar/leap-accelerate-cli/tests/E2EPerformanceTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ namespace icrar
}
};

TEST_F(E2EPerformanceTests, MultiDirectionTestCasa) { MultiDirectionTest(ComputeImplementation::casa, "/1197638568-32.ms", 126, true); }
TEST_F(E2EPerformanceTests, MultiDirectionTestCpu) { MultiDirectionTest(ComputeImplementation::cpu, "/1197638568-32.ms", 126, true); }
TEST_F(E2EPerformanceTests, MultiDirectionTestCuda) { MultiDirectionTest(ComputeImplementation::cuda, "/1197638568-32.ms", 126, true); }
TEST_F(E2EPerformanceTests, MultiDirectionTestCasa) { MultiDirectionTest(ComputeImplementation::casa, "/mwa/1197638568-32.ms", 126, true); }
TEST_F(E2EPerformanceTests, MultiDirectionTestCpu) { MultiDirectionTest(ComputeImplementation::cpu, "/mwa/1197638568-32.ms", 126, true); }
TEST_F(E2EPerformanceTests, MultiDirectionTestCuda) { MultiDirectionTest(ComputeImplementation::cuda, "/mwa/1197638568-32.ms", 126, true); }

// These measurements have flagged data removed and complete data for each timestep
TEST_F(E2EPerformanceTests, MWACleanTestCpu) { MultiDirectionTest(ComputeImplementation::cpu, "/1197638568-split.ms", 126, true); }
TEST_F(E2EPerformanceTests, MWACleanTestCuda) { MultiDirectionTest(ComputeImplementation::cuda, "/1197638568-split.ms", 126, true); }
TEST_F(E2EPerformanceTests, MWACleanTestCpu) { MultiDirectionTest(ComputeImplementation::cpu, "/mwa/1197638568-split.ms", 126, true); }
TEST_F(E2EPerformanceTests, MWACleanTestCuda) { MultiDirectionTest(ComputeImplementation::cuda, "/mwa/1197638568-split.ms", 126, true); }

// These measurements are clean and use a single timestep
TEST_F(E2EPerformanceTests, SKACleanTestCpu) { MultiDirectionTest(ComputeImplementation::cpu, "/SKA_LOW_SIM_short_EoR0_ionosphere_off_GLEAM.0001.ms", boost::none, false); }
TEST_F(E2EPerformanceTests, SKACleanTestCuda) { MultiDirectionTest(ComputeImplementation::cuda, "/SKA_LOW_SIM_short_EoR0_ionosphere_off_GLEAM.0001.ms", boost::none, false); }
TEST_F(E2EPerformanceTests, SKACleanTestCpu) { MultiDirectionTest(ComputeImplementation::cpu, "/ska/SKA_LOW_SIM_short_EoR0_ionosphere_off_GLEAM.0001.ms", boost::none, false); }
TEST_F(E2EPerformanceTests, SKACleanTestCuda) { MultiDirectionTest(ComputeImplementation::cuda, "/ska/SKA_LOW_SIM_short_EoR0_ionosphere_off_GLEAM.0001.ms", boost::none, false); }
}
2 changes: 2 additions & 0 deletions src/icrar/leap-accelerate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ set(sources

common/MVDirection.cc

algorithm/casa/PhaseMatrixFunction.cc
algorithm/casa/PhaseRotate.cc
algorithm/cpu/PhaseMatrixFunction.cc
algorithm/cpu/PhaseRotate.cc
)

Expand Down
102 changes: 102 additions & 0 deletions src/icrar/leap-accelerate/algorithm/casa/PhaseMatrixFunction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* ICRAR - International Centre for Radio Astronomy Research
* (c) UWA - The University of Western Australia
* Copyright by UWA(in the framework of the ICRAR)
* All rights reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111 - 1307 USA
*/

#include "PhaseMatrixFunction.h"

#include <icrar/leap-accelerate/math/math.h>
#include <icrar/leap-accelerate/math/cpu/vector.h>
#include <icrar/leap-accelerate/math/casacore_helper.h>
#include <icrar/leap-accelerate/math/casa/matrix.h>

#include <casacore/casa/Arrays/Matrix.h>
#include <casacore/casa/Arrays/Vector.h>

#include <set>

using namespace casacore;

namespace icrar
{
namespace casalib
{
std::pair<casacore::Matrix<double>, casacore::Vector<std::int32_t>> PhaseMatrixFunction(
const casacore::Vector<std::int32_t>& a1,
const casacore::Vector<std::int32_t>& a2,
int refAnt)
{
if(a1.size() != a2.size())
{
throw std::invalid_argument("a1 and a2 must be equal size");
}

auto unique = std::set<std::int32_t>(a1.cbegin(), a1.cend());
unique.insert(a2.cbegin(), a2.cend());
int nAnt = unique.size();
if(refAnt >= nAnt - 1)
{
throw std::invalid_argument("RefAnt out of bounds");
}

Matrix<double> A = Matrix<double>(a1.size() + 1, std::max(icrar::ArrayMax(a1), icrar::ArrayMax(a2)) + 1);
A = 0.0;

Vector<int> I = Vector<int>(a1.size() + 1);
I = -1;

int STATIONS = A.shape()[1]; //TODO verify correctness
int k = 0;

for(size_t n = 0; n < a1.size(); n++)
{
if(a1(n) != a2(n))
{
if((refAnt < 0) || ((refAnt >= 0) && ((a1(n) == refAnt) || (a2(n) == refAnt))))
{
A(k, a1(n)) = 1.0; // set scalear
A(k, a2(n)) = -1.0; // set scalear
I(k) = n; //set scalear
k++;
}
}
}
if(refAnt < 0)
{
refAnt = 0;
}

A(k, refAnt) = 1;
k++;

auto Atemp = casacore::Matrix<double>(k, STATIONS);
Atemp = A(Slice(0, k), Slice(0, STATIONS));
A.resize(0,0);
A = Atemp;

auto Itemp = casacore::Vector<int>(k);
Itemp = I(Slice(0, k));
I.resize(0);
I = Itemp;

return std::make_pair(A, I);
}
}
}
51 changes: 51 additions & 0 deletions src/icrar/leap-accelerate/algorithm/casa/PhaseMatrixFunction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* ICRAR - International Centre for Radio Astronomy Research
* (c) UWA - The University of Western Australia
* Copyright by UWA(in the framework of the ICRAR)
* All rights reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111 - 1307 USA
*/

#pragma once

#include <casacore/casa/Arrays/Matrix.h>
#include <casacore/casa/Arrays/Vector.h>

#include <utility>

namespace icrar
{
namespace casalib
{
/**
* @brief Form Phase Matrix
* Given the antenna lists from MS and (optionally) RefAnt & Map:
* If non-negative RefAnt is provided it only forms the matrix for baselines with that antenna.
* If True Map is provided it returns the index map for the matrix (only useful if RefAnt set).
*
* This function generates and returns the linear matrix for the phase calibration (only)
* @param a1 indexes of 1st antenna of each baselines
* @param a2 indexes of 2nd antenna of each baselines
* @param refAnt the reference antenna (0, 1), -1
* @return std::pair<casacore::Matrix<double>, casacore::Vector<std::int32_t>>
*/
std::pair<casacore::Matrix<double>, casacore::Vector<std::int32_t>> PhaseMatrixFunction(
const casacore::Vector<std::int32_t>& a1,
const casacore::Vector<std::int32_t>& a2,
int refAnt);
}
}
63 changes: 2 additions & 61 deletions src/icrar/leap-accelerate/algorithm/casa/PhaseRotate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "PhaseRotate.h"

#include <icrar/leap-accelerate/algorithm/casa/PhaseMatrixFunction.h>

#include <icrar/leap-accelerate/math/math.h>
#include <icrar/leap-accelerate/math/cpu/vector.h>
#include <icrar/leap-accelerate/math/casacore_helper.h>
Expand Down Expand Up @@ -274,66 +276,5 @@ namespace casalib
}
}
}

std::pair<casacore::Matrix<double>, casacore::Vector<std::int32_t>> PhaseMatrixFunction(
const casacore::Vector<std::int32_t>& a1,
const casacore::Vector<std::int32_t>& a2,
int refAnt)
{
if(a1.size() != a2.size())
{
throw std::invalid_argument("a1 and a2 must be equal size");
}

auto unique = std::set<std::int32_t>(a1.cbegin(), a1.cend());
unique.insert(a2.cbegin(), a2.cend());
int nAnt = unique.size();
if(refAnt >= nAnt - 1)
{
throw std::invalid_argument("RefAnt out of bounds");
}

Matrix<double> A = Matrix<double>(a1.size() + 1, std::max(icrar::ArrayMax(a1), icrar::ArrayMax(a2)) + 1);
A = 0.0;

Vector<int> I = Vector<int>(a1.size() + 1);
I = -1;

int STATIONS = A.shape()[1]; //TODO verify correctness
int k = 0;

for(size_t n = 0; n < a1.size(); n++)
{
if(a1(n) != a2(n))
{
if((refAnt < 0) || ((refAnt >= 0) && ((a1(n) == refAnt) || (a2(n) == refAnt))))
{
A(k, a1(n)) = 1.0; // set scalear
A(k, a2(n)) = -1.0; // set scalear
I(k) = n; //set scalear
k++;
}
}
}
if(refAnt < 0)
{
refAnt = 0;
}

A(k, refAnt) = 1;
k++;

auto Atemp = casacore::Matrix<double>(k, STATIONS);
Atemp = A(Slice(0, k), Slice(0, STATIONS));
A.resize(0,0);
A = Atemp;

auto Itemp = casacore::Vector<int>(k);
Itemp = I(Slice(0, k));
I.resize(0);
I = Itemp;

return std::make_pair(A, I);
}
}
}
17 changes: 0 additions & 17 deletions src/icrar/leap-accelerate/algorithm/casa/PhaseRotate.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,5 @@ namespace casalib
* @param direction
*/
void RotateVisibilities(Integration& integration, MetaData& metadata, const casacore::MVDirection& direction);

/**
* @brief Form Phase Matrix
* Given the antenna lists from MS and (optionally) RefAnt & Map:
* If non-negative RefAnt is provided it only forms the matrix for baselines with that antenna.
* If True Map is provided it returns the index map for the matrix (only useful if RefAnt set).
*
* This function generates and returns the linear matrix for the phase calibration (only)
* @param a1 antenna vector of size nStations
* @param a2 antenna vector of size nStations
* @param refAnt the reference antenna e.g. (0, 1). -1 if no reference.
* @return std::pair<Matrixd, Matrixi>
*/
std::pair<casacore::Matrix<double>, casacore::Vector<std::int32_t>> PhaseMatrixFunction(
const casacore::Vector<std::int32_t>& a1,
const casacore::Vector<std::int32_t>& a2,
int refAnt=-1);
}
}
Loading

0 comments on commit f49ed89

Please sign in to comment.