Skip to content
Snippets Groups Projects
Commit b442bdc9 authored by Mark de Wever's avatar Mark de Wever
Browse files

AST-940 Prints WorkTable configuration

parent 14dfd849
No related branches found
No related tags found
1 merge request!58AST-940 Prints WorkTable configuration
Pipeline #32058 passed
...@@ -90,5 +90,44 @@ BOOST_AUTO_TEST_CASE(add_entries) { ...@@ -90,5 +90,44 @@ BOOST_AUTO_TEST_CASE(add_entries) {
BOOST_TEST(table.Size() == entries.size()); BOOST_TEST(table.Size() == entries.size());
} }
BOOST_AUTO_TEST_CASE(print_empty) {
WorkTable table(0, 0);
std::stringstream output;
output << table;
BOOST_CHECK_EQUAL(output.str(),
R"(=== IMAGING TABLE ===
Original groups 1
Deconvolution groups 1
Channel index 0
)");
}
BOOST_AUTO_TEST_CASE(print_not_empty) {
WorkTable table(3, 1);
table.AddEntry(std::make_unique<WorkTableEntry>(
WorkTableEntry{0, 5'000'000.0, 10'000'000.0,
aocommon::PolarizationEnum::StokesQ, 0, 4, 1.234}));
table.AddEntry(std::make_unique<WorkTableEntry>(
WorkTableEntry{1, 1'000'000.0, 2'000'000.0,
aocommon::PolarizationEnum::StokesI, 1, 8, 1.01}));
table.AddEntry(std::make_unique<WorkTableEntry>(
WorkTableEntry{1, 100'000'000.0, 200'000'000.0,
aocommon::PolarizationEnum::StokesU, 0, 16, 1.1}));
std::stringstream output;
output << table;
BOOST_CHECK_EQUAL(output.str(),
R"(=== IMAGING TABLE ===
Original groups 3
Deconvolution groups 1
Channel index 0
# Pol Ch Interval Weight Freq(MHz)
0 Q 0 4 1.234 10-10
1 I 1 8 1.01 2-2
2 U 0 16 1.1 200-200
)");
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} // namespace radler } // namespace radler
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <ostream>
#include <vector> #include <vector>
namespace radler { namespace radler {
...@@ -166,6 +167,25 @@ class WorkTable { ...@@ -166,6 +167,25 @@ class WorkTable {
} }
friend EntryIteratorLite end(const WorkTable& table) { return table.End(); } friend EntryIteratorLite end(const WorkTable& table) { return table.End(); }
/** @} */ /** @} */
friend std::ostream& operator<<(std::ostream& output,
const WorkTable& work_table) {
output << "=== IMAGING TABLE ==="
<< "\nOriginal groups " << work_table.original_groups_.size()
<< "\nDeconvolution groups "
<< work_table.deconvolution_groups_.size()
<< "\nChannel index " << work_table.channel_index_offset_
<< '\n';
if (!work_table.entries_.empty()) {
output << " # Pol Ch Interval Weight Freq(MHz)\n";
for (const auto& entry : work_table.entries_) {
output << *entry;
}
}
return output;
}
}; };
} // namespace radler } // namespace radler
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
#ifndef RADLER_WORK_TABLE_ENTRY_H_ #ifndef RADLER_WORK_TABLE_ENTRY_H_
#define RADLER_WORK_TABLE_ENTRY_H_ #define RADLER_WORK_TABLE_ENTRY_H_
#include <iomanip>
#include <memory> #include <memory>
#include <ostream>
#include <vector> #include <vector>
#include <aocommon/imageaccessor.h> #include <aocommon/imageaccessor.h>
...@@ -61,6 +63,18 @@ struct WorkTableEntry { ...@@ -61,6 +63,18 @@ struct WorkTableEntry {
* Image accessor for the residual image for this entry. * Image accessor for the residual image for this entry.
*/ */
std::unique_ptr<aocommon::ImageAccessor> residual_accessor; std::unique_ptr<aocommon::ImageAccessor> residual_accessor;
friend std::ostream& operator<<(std::ostream& output,
const WorkTableEntry& entry) {
return output << " " << std::setw(2) << entry.index << " " << std::setw(3)
<< aocommon::Polarization::TypeToShortString(
entry.polarization)
<< " " << std::setw(2) << entry.original_channel_index << " "
<< std::setw(8) << entry.original_interval_index << " "
<< std::setw(6) << entry.image_weight << " "
<< round(entry.band_end_frequency * 1e-6) << "-"
<< round(entry.band_end_frequency * 1e-6) << '\n';
}
}; };
} // namespace radler } // namespace radler
#endif #endif
...@@ -56,6 +56,12 @@ void init_work_table(py::module& m) { ...@@ -56,6 +56,12 @@ void init_work_table(py::module& m) {
.def_property_readonly("deconvolution_groups", .def_property_readonly("deconvolution_groups",
&radler::WorkTable::DeconvolutionGroups) &radler::WorkTable::DeconvolutionGroups)
.def("__len__", &radler::WorkTable::Size) .def("__len__", &radler::WorkTable::Size)
.def("__str__",
[](const radler::WorkTable& self) {
std::stringstream result;
result << self;
return result.str();
})
.def_property_readonly("channel_index_offset", .def_property_readonly("channel_index_offset",
&radler::WorkTable::GetChannelIndexOffset) &radler::WorkTable::GetChannelIndexOffset)
.def( .def(
......
...@@ -186,3 +186,42 @@ def test_add_entries(): ...@@ -186,3 +186,42 @@ def test_add_entries():
for (i, entry) in enumerate(work_table): for (i, entry) in enumerate(work_table):
assert entry.image_weight == i assert entry.image_weight == i
assert entry.central_frequency == (0.5 * float(i + 1) * 1e6) assert entry.central_frequency == (0.5 * float(i + 1) * 1e6)
def test_str(capsys):
"""
Check the WorkTable.__str__().
Both str(WorkTable) and print(WorkTable) use the __str__ member function
and are tested to validate they work as intended.
"""
work_table = rd.WorkTable(0, 0)
assert (
work_table.__str__()
== """=== IMAGING TABLE ===
Original groups 1
Deconvolution groups 1
Channel index 0
"""
)
assert (
str(work_table)
== """=== IMAGING TABLE ===
Original groups 1
Deconvolution groups 1
Channel index 0
"""
)
print(work_table)
captured = capsys.readouterr()
assert (
captured.out
== """=== IMAGING TABLE ===
Original groups 1
Deconvolution groups 1
Channel index 0
"""
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment