Skip to content

Commit 63c01d6

Browse files
committed
Merge branch 'htcleantest' into 'main'
Added a unit test for the libra_htclean.sh See merge request ardg/libra!108
2 parents 8967737 + 3e8a519 commit 63c01d6

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

apps/src/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ set(TEST_SOURCES
2323
test_dale.cc
2424
test_restore.cc
2525
test_dale.cc
26+
test_htclean.cc
2627
)
2728

2829
add_executable(LibRATests ${TEST_SOURCES})

apps/src/tests/gold_standard

Submodule gold_standard updated from e3aefd0 to 6eea0fb

apps/src/tests/test_htclean.cc

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include <filesystem>
2+
#include "gtest/gtest.h"
3+
4+
#include <cstdlib>
5+
#include <cstdio>
6+
#include <string>
7+
#include <fstream>
8+
#include <sys/stat.h>
9+
#include "Hummbee/hummbee.h"
10+
11+
using namespace std;
12+
using namespace std::filesystem;
13+
using namespace casacore;
14+
15+
namespace test{
16+
const path goldDir = current_path() / "gold_standard";
17+
18+
// Function to run the shell script
19+
std::string run_shell_script(const std::string& imagename) {
20+
// Ensure that the script is executable
21+
system("chmod +x ./libra_htclean.sh");
22+
system("chmod +x ./runapp.sh");
23+
24+
std::string command = "./libra_htclean.sh -i " + imagename + " -n 3 -p libra_htclean.def -L ../../../../install/bin/ -l LOGS";
25+
char buffer[128];
26+
std::string result = "";
27+
FILE* fp = popen(command.c_str(), "r");
28+
if (fp == nullptr) {
29+
return "Error running script";
30+
}
31+
while (fgets(buffer, sizeof(buffer), fp) != nullptr) {
32+
result += buffer;
33+
}
34+
fclose(fp);
35+
return result;
36+
}
37+
38+
39+
40+
TEST(HtcleanTest, Loops) {
41+
// Get the test name
42+
string testName = ::testing::UnitTest::GetInstance()->current_test_info()->name();
43+
44+
// Create a unique directory for this test case
45+
path testDir = current_path() / testName;
46+
47+
// create dir AppLevelSNRPSF
48+
std::filesystem::create_directory(testDir);
49+
50+
//copy over CYGTST.corespiral.ms from gold_standard to AppLevelSNRPSF
51+
std::filesystem::copy(goldDir/"CYGTST.corespiral.ms", testDir/"CYGTST.corespiral.ms", copy_options::recursive);
52+
//copy over 4k_nosquint.cfc from gold_standard to AppLevelSNRPSF
53+
std::filesystem::copy(goldDir/"4k_nosquint.cfc", testDir/"4k_nosquint.cfc", copy_options::recursive);
54+
// copy the input .def
55+
std::filesystem::copy(goldDir/"libra_htclean.def", testDir/"libra_htclean.def", copy_options::recursive);
56+
// copy htclean scripts
57+
std::filesystem::copy(goldDir/"../../../../frameworks/htclean/libra_htclean.sh", testDir/"libra_htclean.sh", copy_options::recursive);
58+
std::filesystem::copy(goldDir/"../../../../frameworks/htclean/runapp.sh", testDir/"runapp.sh", copy_options::recursive);
59+
//Step into test dir
60+
std::filesystem::current_path(testDir);
61+
62+
63+
64+
string imagename = "cygA";
65+
// Run the script
66+
string output = run_shell_script(imagename);
67+
68+
// Check that the images are generated
69+
path p1("cygA.psf");
70+
path p2("cygA.model");
71+
path p3("cygA.image");
72+
bool ans = exists(p1) && exists(p2) && exists(p3);
73+
74+
EXPECT_TRUE( ans );
75+
76+
PagedImage<casacore::Float> psfimage("cygA.model");
77+
float tol = 0.1;
78+
float goldValLoc0 = 0.095916;
79+
float goldValLoc1 = 0.0876324;
80+
81+
EXPECT_NEAR(psfimage(IPosition(4,2937,2352,0,0)), goldValLoc0, tol);
82+
EXPECT_NEAR(psfimage(IPosition(4,1076,1785,0,0)), goldValLoc1, tol);
83+
84+
85+
86+
//move to parent directory
87+
std::filesystem::current_path(testDir.parent_path());
88+
89+
remove_all(testDir);
90+
}
91+
92+
93+
94+
95+
};

frameworks/htclean/libra_htclean.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ do
216216
# run hummbee for updateModel deconvolution iterations
217217
${runApp} ${deconvolutionAPP} deconvolve ${imagename} ${input_file} ${logdir} -c ${i}
218218

219+
# Work around to fix the NOOP in dale. This should be removed when the real code fix is in.
220+
sed -i 's/SubType = normalized/SubType =/' ${imagename}.model/table.info
221+
219222
# run dale to divide model by weights
220223
${runApp} ${normalizationAPP} normalize ${imagename} ${input_file} ${logdir} -t model -c ${i}
221224

0 commit comments

Comments
 (0)