Skip to content

Commit

Permalink
- absorption calculation
Browse files Browse the repository at this point in the history
- sound velocity calculation using gswteos-10
- amplitude range correction functions
- apply correction functions for wci
  • Loading branch information
peter-urban committed Sep 24, 2024
1 parent 54e4721 commit f33c6f1
Show file tree
Hide file tree
Showing 16 changed files with 543 additions and 166 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project(
'cpp',
license: 'MPL-2.0',

version: '0.8.1',
version: '0.8.2',
default_options: ['warning_level=2', 'buildtype=release', 'cpp_std=c++20'],
meson_version: '>=1.3.2' #first version with clang-cl openmp support
)
Expand Down
94 changes: 94 additions & 0 deletions src/pymodule/amplitudecorrection/functions/module.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-FileCopyrightText: 2022 - 2023 Peter Urban, Ghent University
//
// SPDX-License-Identifier: MPL-2.0

#include <pybind11/iostream.h>
#include <pybind11/pybind11.h>
#include <xtensor-python/pytensor.hpp>

#include <themachinethatgoesping/algorithms/amplitudecorrection/functions.hpp>

namespace themachinethatgoesping {
namespace algorithms {
namespace pymodule {
namespace py_amplitudecorrection {
namespace py_functions {

#define DOC_functions(ARG) \
DOC(themachinethatgoesping, algorithms, amplitudecorrection, functions, ARG)

void init_m_functions(pybind11::module& m)
{
namespace py = pybind11;

pybind11::module submodule = m.def_submodule("functions");

submodule.doc() = "Submodule that holds functions used for amplitude corrections";

using namespace amplitudecorrection::functions;

// sound velocity
submodule.def("calc_sound_velocity",
&calc_sound_velocity,
DOC_functions(calc_sound_velocity),
py::arg("depth_m"),
py::arg("temperature_c"),
py::arg("salinity_psu"),
py::arg("latitude") = 0.0,
py::arg("longitude") = 0.0);

// absorption
submodule.def("calc_absorption_coefficient_db_m",
&calc_absorption_coefficient_db_m,
DOC_functions(calc_absorption_coefficient_db_m),
py::arg("frequency_hz"),
py::arg("depth_m"),
py::arg("sound_velocity_m_s"),
py::arg("temperature_c"),
py::arg("salinity_psu"),
py::arg("pH") = 8);

// range correction
submodule.def("get_sample_numbers_plus_half",
&get_sample_numbers_plus_half<xt::pytensor, float, int64_t>,
DOC_functions(get_sample_numbers_plus_half),
py::arg("first_sample_nr"),
py::arg("last_sample_nr"),
py::arg("step") = 1);

submodule.def("approximate_range_factor",
&approximate_range_factor<float>,
DOC_functions(approximate_range_factor),
py::arg("sample_interval_s"),
py::arg("sound_velocity_m_s"));

submodule.def("approximate_ranges",
&approximate_ranges<xt::pytensor, float, int64_t>,
DOC_functions(approximate_ranges),
py::arg("sample_interval_s"),
py::arg("sound_velocity_m_s"),
py::arg("first_sample_nr"),
py::arg("last_sample_nr"),
py::arg("step") = 1);

submodule.def("compute_cw_range_correction",
&compute_cw_range_correction<xt::pytensor, float>,
DOC_functions(compute_cw_range_correction),
py::arg("ranges_m"),
py::arg("absorption_db_m"),
py::arg("tvg_factor"));

submodule.def("apply_wci_correction",
&apply_wci_correction<xt::pytensor, float>,
DOC_functions(apply_wci_correction),
py::arg("wci"),
py::arg("per_beam_offset"),
py::arg("per_sample_offset"),
py::arg("mp_cores") = 1);
}

} // namespace py_functions
} // namespace py_amplitudecorrection
} // namespace pymodule
} // namespace algorithms
} // namespace themachinethatgoesping
27 changes: 27 additions & 0 deletions src/pymodule/amplitudecorrection/module.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: 2022 - 2023 Peter Urban, Ghent University
//
// SPDX-License-Identifier: MPL-2.0

#include <pybind11/iostream.h>
#include <pybind11/pybind11.h>

#include "functions/module.hpp"

namespace themachinethatgoesping {
namespace algorithms {
namespace pymodule {
namespace py_amplitudecorrection {

void init_m_amplitudecorrection(pybind11::module& m)
{
pybind11::module submodule = m.def_submodule("amplitudecorrection");

submodule.doc() = "Submodule for amplitudecorrection (absorption, tvg, calibration factors, etc.)";

py_functions::init_m_functions(submodule);
}

} // namespace py_amplitudecorrection
} // namespace pymodule
} // namespace algorithms
} // namespace themachinethatgoesping
1 change: 1 addition & 0 deletions src/pymodule/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ py_algorithms = pymod.extension_module(
dependencies : [
tools_pybind_dep,
algorithms_dep,
gswteos_10_dep,
pybind11_dep,
python3_dep],
link_language : 'cpp',
Expand Down
8 changes: 5 additions & 3 deletions src/pymodule/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
//
// SPDX-License-Identifier: MPL-2.0

#define FORCE_IMPORT_ARRAY // this is needed for xtensor-python but must only be included once
#include <xtensor-python/pyarray.hpp> // Numpy bindings

#include <pybind11/iostream.h>
#include <pybind11/pybind11.h>

#include "amplitudecorrection/module.hpp"
#include "geoprocessing/module.hpp"
#include "signalprocessing/module.hpp"

#define FORCE_IMPORT_ARRAY // this is needed for xtensor-python but must only be included once
#include <xtensor-python/pyarray.hpp> // Numpy bindings

namespace themachinethatgoesping {
namespace algorithms {
namespace pymodule {
Expand All @@ -26,6 +27,7 @@ PYBIND11_MODULE(MODULE_NAME, m)
"range/depth, raytrace ...";
m.attr("__version__") = MODULE_VERSION;

py_amplitudecorrection::init_m_amplitudecorrection(m);
py_geoprocessing::init_m_geoprocessing(m);
py_signalprocessing::init_m_signalprocessing(m);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: fe33432f6337ae8971ac01f79910fbd6f7a7cf3746aa10ae1a41ce8176476dc9
//sourcehash: 5c8188cb5f1b2d240c72954adc6430e13d22062d6b400c11476baed51945113c

/*
This file contains docstrings for use in the Python bindings.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2024 Peter Urban, Ghent University
// SPDX-FileCopyrightText: 2022 GEOMAR Helmholtz Centre for Ocean Research Kiel
//
// SPDX-License-Identifier: MPL-2.0

#pragma once

/* generated doc strings */
#include ".docstrings/functions.doc.hpp"

#include "functions/absorption.hpp"
#include "functions/rangecorrection.hpp"
#include "functions/wcicorrection.hpp"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: f832ca529d511eb1355e2ffa7576b496727810220ef0c08ce75b8943910b56b5
//sourcehash: 50c3a9bed6dffaec83b931b6cf30653eaca9ebfdce0e73ee940aea068eac54b6

/*
This file contains docstrings for use in the Python bindings.
Expand Down Expand Up @@ -38,22 +38,22 @@
#endif


static const char *__doc_themachinethatgoesping_algorithms_rangecorrection_functions_calc_absorption_coefficient_db_m =
static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_calc_absorption_coefficient_db_m =
R"doc(Compute the logarithmic absorption coefficient in dB/m based on
Francois and Garrison (1982) [taken from Fisheries Acoustics Theory
and Practice, 2nd Edition, Simmonds and MacLennan, 2005]
Parameter ``frequency``:
// Frequency in Hz
Parameter ``frequency_hz``:
// Frequency_hz in Hz
Parameter ``depth``:
// Depth in m
Parameter ``depth_m``:
// Depth_m in m
Parameter ``speedOfSound``:
Parameter ``sound_velocity_m_s``:
// Speed of sound in m/s
Parameter ``temperature``:
// ITS-90 temperature in degrees Celsius
Parameter ``temperature_c``:
// ITS-90 temperature_c in degrees Celsius
Parameter ``salinity_psu``:
// Salinity in PSU
Expand All @@ -64,8 +64,22 @@ Parameter ``pH``:
Returns:
double)doc";

static const char *__doc_themachinethatgoesping_algorithms_rangecorrection_functions_its90_to_its68 =
R"doc(Convert temperature from ITS-68 to ITS-90
static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_calc_sound_velocity =
R"doc(Compute the speed of sound in seawater using the TEOS-10 library
Parameter ``depth_m``:
$Parameter ``temperature_c``:
Parameter ``salinity_psu``:
$Parameter ``latitude``:
Parameter ``longitude``:
$Returns:
double)doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_its90_to_its68 =
R"doc(Convert temperature_c from ITS-68 to ITS-90
Parameter ``T90``:
$Returns:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//sourcehash: fd3765d68f5b2a0a54c3a4057bfde38c84b4a141f4eaacb1862ef398989d077a

/*
This file contains docstrings for use in the Python bindings.
Do not edit! They were automatically extracted by pybind11_mkdoc.
This is a modified version which allows for more than 8 arguments and includes def-guard
*/

#pragma once

#ifndef __DOCSTRINGS_HPP__

#define __EXPAND(x) x
#define __COUNT(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, COUNT, ...) COUNT
#define __VA_SIZE(...) __EXPAND(__COUNT(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1))
#define __CAT1(a, b) a##b
#define __CAT2(a, b) __CAT1(a, b)
#define __DOC1(n1) __doc_##n1
#define __DOC2(n1, n2) __doc_##n1##_##n2
#define __DOC3(n1, n2, n3) __doc_##n1##_##n2##_##n3
#define __DOC4(n1, n2, n3, n4) __doc_##n1##_##n2##_##n3##_##n4
#define __DOC5(n1, n2, n3, n4, n5) __doc_##n1##_##n2##_##n3##_##n4##_##n5
#define __DOC6(n1, n2, n3, n4, n5, n6) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6
#define __DOC7(n1, n2, n3, n4, n5, n6, n7) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7
#define __DOC8(n1, n2, n3, n4, n5, n6, n7, n8) \
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7##_##n8
#define __DOC9(n1, n2, n3, n4, n5, n6, n7, n8, n9) \
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7##_##n8##_##n9
#define __DOC10(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10) \
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7##_##n8##_##n9##_##n10
#define DOC(...) __EXPAND(__EXPAND(__CAT2(__DOC, __VA_SIZE(__VA_ARGS__)))(__VA_ARGS__))

#endif // NEW_DOC_HEADER_HPP
#if defined(__GNUG__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif


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

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

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

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

#if defined(__GNUG__)
#pragma GCC diagnostic pop
#endif


Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//sourcehash: 1ae8666ee5111ec85d545eb0598565f91fc501c9641654802e5948d424bae907

/*
This file contains docstrings for use in the Python bindings.
Do not edit! They were automatically extracted by pybind11_mkdoc.
This is a modified version which allows for more than 8 arguments and includes def-guard
*/

#pragma once

#ifndef __DOCSTRINGS_HPP__

#define __EXPAND(x) x
#define __COUNT(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, COUNT, ...) COUNT
#define __VA_SIZE(...) __EXPAND(__COUNT(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1))
#define __CAT1(a, b) a##b
#define __CAT2(a, b) __CAT1(a, b)
#define __DOC1(n1) __doc_##n1
#define __DOC2(n1, n2) __doc_##n1##_##n2
#define __DOC3(n1, n2, n3) __doc_##n1##_##n2##_##n3
#define __DOC4(n1, n2, n3, n4) __doc_##n1##_##n2##_##n3##_##n4
#define __DOC5(n1, n2, n3, n4, n5) __doc_##n1##_##n2##_##n3##_##n4##_##n5
#define __DOC6(n1, n2, n3, n4, n5, n6) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6
#define __DOC7(n1, n2, n3, n4, n5, n6, n7) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7
#define __DOC8(n1, n2, n3, n4, n5, n6, n7, n8) \
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7##_##n8
#define __DOC9(n1, n2, n3, n4, n5, n6, n7, n8, n9) \
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7##_##n8##_##n9
#define __DOC10(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10) \
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7##_##n8##_##n9##_##n10
#define DOC(...) __EXPAND(__EXPAND(__CAT2(__DOC, __VA_SIZE(__VA_ARGS__)))(__VA_ARGS__))

#endif // NEW_DOC_HEADER_HPP
#if defined(__GNUG__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif


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

#if defined(__GNUG__)
#pragma GCC diagnostic pop
#endif


Loading

0 comments on commit f33c6f1

Please sign in to comment.