Skip to content

Commit

Permalink
PingSampleSelection:
Browse files Browse the repository at this point in the history
    - select transmit_sectors by beam_angle or by number
  • Loading branch information
peter-urban committed Oct 23, 2024
1 parent bc55e7d commit f349cf9
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 13 deletions.
31 changes: 29 additions & 2 deletions src/pymodule/py_pingtools/c_pingsampleselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ void init_c_pingsampleselector(pybind11::module& m)

// --- main interface ---
.def("apply_selection",
py::overload_cast<filetemplates::datatypes::I_PingWatercolumn&>(&PingSampleSelector::apply_selection),
py::overload_cast<filetemplates::datatypes::I_PingWatercolumn&>(
&PingSampleSelector::apply_selection),
DOC_PingSampleSelector(apply_selection),
py::arg("ping_watercolumn"))
.def("apply_selection",
py::overload_cast<filetemplates::datatypes::I_PingBottom&>(&PingSampleSelector::apply_selection),
py::overload_cast<filetemplates::datatypes::I_PingBottom&>(
&PingSampleSelector::apply_selection),
DOC_PingSampleSelector(apply_selection),
py::arg("ping_bottom"))

Expand Down Expand Up @@ -63,6 +65,15 @@ void init_c_pingsampleselector(pybind11::module& m)
.def("get_max_sample_range",
&PingSampleSelector::get_max_sample_range,
DOC_PingSampleSelector(max_sample_range))
.def("get_transmit_sectors",
&PingSampleSelector::get_transmit_sectors,
DOC_PingSampleSelector(transmit_sectors))
.def("get_transmit_sector_min_beam_angle",
&PingSampleSelector::get_transmit_sector_min_beam_angle,
DOC_PingSampleSelector(transmit_sector_min_beam_angle))
.def("get_transmit_sector_max_beam_angle",
&PingSampleSelector::get_transmit_sector_max_beam_angle,
DOC_PingSampleSelector(transmit_sector_max_beam_angle))
.def("get_beam_step", &PingSampleSelector::get_beam_step, DOC_PingSampleSelector(beam_step))
.def("get_sample_step",
&PingSampleSelector::get_sample_step,
Expand All @@ -81,6 +92,12 @@ void init_c_pingsampleselector(pybind11::module& m)
.def("clear_sample_range_range",
&PingSampleSelector::clear_sample_range_range,
DOC_PingSampleSelector(clear_sample_range_range))
.def("clear_transmit_sectors",
&PingSampleSelector::clear_transmit_sectors,
DOC_PingSampleSelector(clear_transmit_sectors))
.def("clear_transmit_sector_beam_angle_range",
&PingSampleSelector::clear_transmit_sector_beam_angle_range,
DOC_PingSampleSelector(clear_transmit_sector_beam_angle_range))
.def("clear_beam_step",
&PingSampleSelector::clear_beam_step,
DOC_PingSampleSelector(clear_beam_step))
Expand Down Expand Up @@ -114,6 +131,16 @@ void init_c_pingsampleselector(pybind11::module& m)
py::arg("min_sample_range"),
py::arg("max_sample_range"),
py::arg("sample_step") = std::nullopt)
.def("select_transmit_sectors",
&PingSampleSelector::select_transmit_sectors,
DOC_PingSampleSelector(select_transmit_sectors),
py::arg("transmit_sectors"))
.def("select_transmit_sectors_by_beam_angles",
&PingSampleSelector::select_transmit_sectors_by_beam_angles,
DOC_PingSampleSelector(select_transmit_sectors_by_beam_angles),
py::arg("transmit_sector_min_beam_angle") = std::nullopt,
py::arg("transmit_sector_max_beam_angle") = std::nullopt)

.def("set_sample_step",
&PingSampleSelector::set_sample_step,
DOC_PingSampleSelector(set_sample_step),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TEST_CASE("WaterColumnCalibration should support common functions", TESTTAG)

// test hash (should be stable if class is not changed)
CHECK(obj.binary_hash() == 14297201401130263458ULL);
CHECK(obj2.binary_hash() == 13359915444826610029ULL);
CHECK(obj2.binary_hash() == 5753520697174627545ULL);

// test equality
// test inequality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST_CASE("KongsbergAllWaterColumnCalibration should support common functions",
auto obj2 = KongsbergAllWaterColumnCalibration();

// test hash (should be stable if class is not changed)
CHECK(obj.binary_hash() == 4129550967388344509ULL);
CHECK(obj.binary_hash() == 3596872097889454741ULL);
CHECK(obj2.binary_hash() == 770061992534893794ULL);

// test equality
Expand Down
26 changes: 25 additions & 1 deletion src/tests/pingtools/pingsampleselector.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,63 @@ TEST_CASE("PingSampleselector should support common functions", TESTTAG)
// initialize class structure
auto obj = PingSampleSelector();

// make sure binary_hash is stable for empty object
// the hash tests need to be updated in case the object structure changes
CHECK(obj.binary_hash() == 564375710488919660ULL);

// set some variables
obj.select_beam_range_by_numbers(1, -1, 1);
REQUIRE(obj.get_min_beam_number() == 1);
REQUIRE(obj.get_max_beam_number() == -1);
REQUIRE(obj.get_beam_step() == 1);

// test binary (inbetween)
REQUIRE(obj == PingSampleSelector(obj.from_binary(obj.to_binary())));
obj.select_sample_range_by_numbers(-2, 2, 2);
REQUIRE(obj.get_min_sample_number() == -2);
REQUIRE(obj.get_max_sample_number() == 2);
REQUIRE(obj.get_sample_step() == 2);

// test binary (inbetween)
REQUIRE(obj == PingSampleSelector(obj.from_binary(obj.to_binary())));
obj.select_beam_range_by_angles(-3.3, 4.4, 10);
REQUIRE(obj.get_min_beam_angle() == Catch::Approx(-3.3));
REQUIRE(obj.get_max_beam_angle() == Catch::Approx(4.4));
REQUIRE(obj.get_beam_step() == 10);

// test binary (inbetween)
REQUIRE(obj == PingSampleSelector(obj.from_binary(obj.to_binary())));
obj.select_sample_range_by_ranges(4.3, -5.4, 20);
REQUIRE(obj.get_min_sample_range() == Catch::Approx(4.3));
REQUIRE(obj.get_max_sample_range() == Catch::Approx(-5.4));
REQUIRE(obj.get_sample_step() == 20);

// test binary (inbetween)
REQUIRE(obj == PingSampleSelector(obj.from_binary(obj.to_binary())));
obj.select_transmit_sectors({ 3, 1 });
REQUIRE(obj.get_transmit_sectors().value().at(0) == 3);
REQUIRE(obj.get_transmit_sectors().value().at(1) == 1);

// test binary (inbetween)
REQUIRE(obj == PingSampleSelector(obj.from_binary(obj.to_binary())));
obj.select_transmit_sectors_by_beam_angles(-2.3, 6.4);
REQUIRE(obj.get_transmit_sector_min_beam_angle() == Catch::Approx(-2.3));
REQUIRE(obj.get_transmit_sector_max_beam_angle() == Catch::Approx(6.4));

obj.set_sample_step(12);
REQUIRE(obj.get_sample_step() == 12);
obj.set_beam_step(13);
REQUIRE(obj.get_beam_step() == 13);

CHECK(obj.binary_hash() == 3607378432970521986ULL);

// test inequality
REQUIRE(obj != PingSampleSelector());

// test copy
REQUIRE(obj == PingSampleSelector(obj));

// test binary
// test binary (inbetween)
REQUIRE(obj == PingSampleSelector(obj.from_binary(obj.to_binary())));

// test stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,8 +1052,8 @@ TEST_CASE("SimradRawWaterColumnCalibration should support common functions", TES
{
// test hash (should be stable if class is not changed)
CHECK(cal0.binary_hash() == 17881936019455399031ULL);
CHECK(cal_power.binary_hash() == 17028420629437399240ULL);
CHECK(cal_cmplx.binary_hash() == 11449725189696852697ULL);
CHECK(cal_power.binary_hash() == 7583670336073361441ULL);
CHECK(cal_cmplx.binary_hash() == 4293420015706961800ULL);

// test equality
CHECK(cal0 == cal0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: 6a27ca0a4b841c5c3c12e8d6c28fdfe7a6e0be954e3d8901ae63d74d3ee9fd6e
//sourcehash: d806933ede2881d41e86e3edf9ee9093d4afbdbe28369bed9e6c3e4041ac2302

/*
This file contains docstrings for use in the Python bindings.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: 4951ef14139d3a86a9820d23d4058f579dd5b1a51a17c400154496eb15f3214b
//sourcehash: 762f19736a2115c1023633e93f6cc81621d8cf6fdeb49b703343e684bc983dae

/*
This file contains docstrings for use in the Python bindings.
Expand Down Expand Up @@ -62,6 +62,10 @@ static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampl

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_clear_sample_step = R"doc()doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_clear_transmit_sector_beam_angle_range = R"doc()doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_clear_transmit_sectors = R"doc()doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_from_stream =
R"doc(Return a PingSampleSelector read from a binary stream
Expand Down Expand Up @@ -91,6 +95,12 @@ static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampl

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_get_sample_step = R"doc()doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_get_transmit_sector_max_beam_angle = R"doc()doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_get_transmit_sector_min_beam_angle = R"doc()doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_get_transmit_sectors = R"doc()doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_max_beam_angle = R"doc(< max beam angle to select (°))doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_max_beam_number = R"doc(< max beam number to select)doc";
Expand Down Expand Up @@ -129,6 +139,10 @@ static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampl

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_select_sample_range_by_ranges = R"doc()doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_select_transmit_sectors = R"doc()doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_select_transmit_sectors_by_beam_angles = R"doc()doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_set_beam_step = R"doc()doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_set_sample_step = R"doc()doc";
Expand All @@ -139,6 +153,16 @@ R"doc(Write a PingSampleSelector to a binary stream
Parameter ``os``:
output stream)doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_transmit_sector_max_beam_angle =
R"doc(< select transmit sectors with angles < <=
_transmit_sector_max_beam_angle)doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_transmit_sector_min_beam_angle =
R"doc(< select transmit sectors with angles < >=
_transmit_sector_min_beam_angle)doc";

static const char *__doc_themachinethatgoesping_echosounders_pingtools_PingSampleSelector_transmit_sectors = R"doc(< transmit_sectors to select)doc";

#if defined(__GNUG__)
#pragma GCC diagnostic pop
#endif
Expand Down
Loading

0 comments on commit f349cf9

Please sign in to comment.