Utilities
This section provides documentation on the various echoSMs utility functions and classes. Miscellaneous utility code
echosms.BenchmarkData()
Convenient interface to the benchmark dataset.
This dataset contains the benchmark TS results from Jech et al. (2015).
Notes
The column names in the source benchmark files have been changed to be the same as those used in the ReferenceModels model definitions.
References
Jech, J.M., Horne, J.K., Chu, D., Demer, D.A., Francis, D.T.I., Gorska, N., Jones, B., Lavery, A.C., Stanton, T.K., Macaulay, G.J., Reeder, D.B., Sawada, K., 2015. Comparisons among ten models of acoustic backscattering used in aquatic ecosystem research. Journal of the Acoustical Society of America 138, 3742-3764. https://doi.org/10.1121/1.4937607
Source code in src/echosms/benchmarkdata.py
angle_as_dataframe()
Provide the angle benchmark dataset as a Pandas DataFrame.
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Dataframe containing the benchmark data. |
angle_data(name)
Provide the benchmark TS values verses angle for the name model.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the benchmark model (available from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
Tuple containing the angles (°) and TS (dB) for the requested benchmark model. |
Source code in src/echosms/benchmarkdata.py
angle_names()
Provide the model names for the angle benchmark data.
| RETURNS | DESCRIPTION |
|---|---|
list
|
List of model names. |
freq_as_dataframe()
Provide the frequency benchmark dataset as a Pandas DataFrame.
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Dataframe containing the benchmark data. |
freq_data(name)
Provide the benchmark TS values verses frequency for the name model.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the benchmark model (available from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
Tuple containing the frequencies (Hz) and TS (dB) for the requested benchmark model. |
Source code in src/echosms/benchmarkdata.py
freq_names()
Provide the model names for the frequency benchmark data.
| RETURNS | DESCRIPTION |
|---|---|
list
|
List of model names. |
echosms.ReferenceModels()
Provide access to reference scattering model parameters.
Reference models are the models and parameters defined in Jech et al. (2015). The parameters are stored in a TOML-formatted file in the echoSMs repository and this class provides easy access to the data in that file. Additional reference models may be defined in the future and added to the TOML file (for example, entries have been added for all known calibration sphere sizes).
| ATTRIBUTE | DESCRIPTION |
|---|---|
definitions |
A dict representation of the
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TOMLDecodeError
|
If the |
KeyError
|
If the |
References
Jech, J.M., Horne, J.K., Chu, D., Demer, D.A., Francis, D.T.I., Gorska, N., Jones, B., Lavery, A.C., Stanton, T.K., Macaulay, G.J., Reeder, D.B., Sawada, K., 2015. Comparisons among ten models of acoustic backscattering used in aquatic ecosystem research. Journal of the Acoustical Society of America 138, 3742–3764. https://doi.org/10.1121/1.4937607
Source code in src/echosms/referencemodels.py
names()
Names of all model definitions.
| RETURNS | DESCRIPTION |
|---|---|
iterable of str
|
All model names in the |
parameters(name)
Model parameters for a particular model.
Model parameters are a subset of the model specification where the metadata items have been removed.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of a model in the
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
The model parameters for the requested model or an empty dict if no model with that name. |
Source code in src/echosms/referencemodels.py
specification(name)
Model definitions for a particular model.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of a model in the
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
The model definitions for the requested model or an empty dict if no model with that name. |
Source code in src/echosms/referencemodels.py
echosms.JechEtAlData()
Simple access to all model results in Jech et al (2015).
| ATTRIBUTE | DESCRIPTION |
|---|---|
data |
One entry in the dict for each model results file.
TYPE:
|
data_directory |
The directory containing the model results files.
TYPE:
|
References
Jech, J.M., Horne, J.K., Chu, D., Demer, D.A., Francis, D.T.I., Gorska, N., Jones, B., Lavery, A.C., Stanton, T.K., Macaulay, G.J., Reeder, D.B., Sawada, K., 2015. Comparisons among ten models of acoustic backscattering used in aquatic ecosystem research. Journal of the Acoustical Society of America 138, 3742-3764. https://doi.org/10.1121/1.4937607
Source code in src/echosms/jechetaldata.py
echosms.utils
Miscellaneous utility functions.
boundary_type
Bases: StrEnum
Scattering model boundary types.
fixed_rigid = 'fixed-rigid'
class-attribute
instance-attribute
Fixed-rigid boundary condition, where the normal velocity is zero at the object's boundary.
pressure_release = 'pressure-release'
class-attribute
instance-attribute
Pressure-release boundary condition, where the acoustic pressure is zero at the object's boundary.
fluid_filled = 'fluid-filled'
class-attribute
instance-attribute
Fluid-filled boundary condition, where the acoustic pressure and normal velocity are both non-zero at the object's boundary.
elastic = 'elastic'
class-attribute
instance-attribute
The scattering object supports compressional and shear waves.
fluid_shell_fluid_interior = 'fluid shell fluid interior'
class-attribute
instance-attribute
The object has a fluid interior surrounded by a fluid shell.
fluid_shell_pressure_release_interior = 'fluid shell pressure release interior'
class-attribute
instance-attribute
The object has a pressure release interior surrounded by a fluid shell.
hard = 'fixed-rigid'
class-attribute
instance-attribute
A synonym for fixed_rigid.
soft = 'pressure-release'
class-attribute
instance-attribute
A synonym for pressure_release.
fluid = 'fluid-filled'
class-attribute
instance-attribute
A synonym for fluid_filled.
theoretical_Sa(ts, eba, r, nautical=False)
Theoretical area backscattering strength (Sₐ) of a target.
| PARAMETER | DESCRIPTION |
|---|---|
ts
|
The target strength of the object [dB re 1 m²].
TYPE:
|
eba
|
Ten times the logarithm to the base 10 of the transducer's equivalent two-way beam angle (ψ, sr). In formula form this is: eba = 10 log10(ψ) dB (re 1 sr).
TYPE:
|
r
|
The range from the transducer to the target [m]. Used for acoustic beam spreading.
TYPE:
|
nautical
|
If
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
float | ndarray
|
The theoretical Sₐ [dB re 1 m² m⁻²] or SA [dB re 1 m² nmi⁻²] of the input |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If an input value is out of bounds. |
Notes
While the calculation is valid for any target, the theoretical area strengths are most relevant when calibrating an echosounder using a sphere. The difference between the theoretical and measured can be used to calculate the calibration gain for an echosounder (when the sphere is on-axis).
Source code in src/echosms/utils.py
Neumann(m)
Neumann number.
| PARAMETER | DESCRIPTION |
|---|---|
m
|
The input integer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The Neumann number. |
wavenumber(c, f)
Calculate the acoustic wavenumber.
| PARAMETER | DESCRIPTION |
|---|---|
c
|
Sound speed [m/s]
TYPE:
|
f
|
Frequency [Hz]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The acoustic wavenumber [m⁻¹]. |
Source code in src/echosms/utils.py
wavelength(c, f)
Calculate the acoustic wavelength.
| PARAMETER | DESCRIPTION |
|---|---|
c
|
Sound speed [m/s]
TYPE:
|
f
|
Frequency [Hz]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The acoustic wavelength [m]. |
Source code in src/echosms/utils.py
h1(n, z, derivative=False)
Spherical Hankel function of the first kind or its' derivative.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Order (n ≥ 0).
TYPE:
|
z
|
Argument of the Hankel function.
TYPE:
|
derivative
|
if True, the value of the derivative (rather than the function itself) is returned.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
complex
|
Value of the spherical Hankel function |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
For negative n values. |
Notes
The value of the Hankel function is calculated from spherical Bessel functions [1].
The derivative is computed from spherical Hankel functions [2].
Source code in src/echosms/utils.py
spherical_jnpp(n, z)
Second derivative of the spherical Bessel function.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Order (n ≥ 0)
TYPE:
|
z
|
Argument of the Bessel function.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The second derivative of the spherical Bessel function. |
Source code in src/echosms/utils.py
split_dict(d, s)
Split a dict into two dicts based on a list of keys.
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Dict to be split.
TYPE:
|
s
|
List of dict keys to use for splitting
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple(dict, dict)
|
The |
Source code in src/echosms/utils.py
as_dataarray(params, no_expand=[])
Convert model parameters from dict form to a Xarray DataArray.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
The model parameters.
TYPE:
|
no_expand
|
Key values of the non-expandable model parameters in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataArray
|
Returns a multi-dimensional DataArray generated from the Cartesian product of all
expandable items in the input dict. Non-expandable items are added to the DataArray
attrs property. Expandable items are those that can be sensibly expanded into
DataArray coordinates. Not all models have non-expandable items.
The array is named |
Source code in src/echosms/utils.py
as_dataframe(params, no_expand=[])
Convert model parameters from dict form to a Pandas DataFrame.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
The model parameters.
TYPE:
|
no_expand
|
Key values of the non-expandable model parameters in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Returns a Pandas DataFrame generated from the Cartesian product of all expandable items in the input dict. DataFrame column names are obtained from the dict keys. Non-expandable items are added to the DataFrame attrs property. Expandable items are those that can be sensibly expanded into DataFrame columns. Not all models have non-expandable items. |
Source code in src/echosms/utils.py
as_dict(params)
Convert model parameters from DataFrame or DataArray to dict.
| PARAMETER | DESCRIPTION |
|---|---|
params
|
The model parameters
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError:
|
If the input data type is not supported. |
| RETURNS | DESCRIPTION |
|---|---|
dict
|
A dict containing the model parameters. |
Source code in src/echosms/utils.py
pro_ang1(m, n, c, eta, norm=False)
Prolate spheroidal angular function of the first kind and derivative.
Calculates the prolate spheroidal angular function of the first kind and its'
derivative with respect to eta.
| PARAMETER | DESCRIPTION |
|---|---|
m
|
The order parameter (≥ 0)
TYPE:
|
n
|
The degree parameter (≥
TYPE:
|
c
|
The size parameter.
TYPE:
|
eta
|
The angular coordinate, η, where |η| ≤ 1.
TYPE:
|
norm
|
If
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[float, float]
|
The value of the prolate spheroidal angular function and its' derivative. |
Notes
This method uses the prolate spheroidal wave function code for non complex
arguments (van Buren & Boisvert, 2002, and van Buren & Boisvert, 2024), available on
github. This code is in Fortran90
and was interfaced to Python using numpy.f2py then wrapped with the current method to
provide a similar calling convention as the Scipy function of the same name.
References
Van Buren, A. L., & Boisvert, J. E. (2002). Accurate calculation of prolate spheroidal radial functions of the first kind and their first derivatives. Quarterly of Applied Mathematics, 60(3), 589-599. https://doi.org/10.1090/qam/1914443
Van Buren, A. L., & Boisvert, J. E. (2004). Improved Calculation of Prolate Spheroidal Radial Functions of the Second Kind and Their First Derivatives. Quarterly of Applied Mathematics, 62(3), 493-507. https://doi.org/10.1090/qam/2086042
Source code in src/echosms/utils.py
pro_rad1(m, n, c, xi)
Prolate spheroidal radial function of the first kind and derivative.
Calculates the prolate spheroidal radial function of the first kind and its'
derivative with respect to xi.
| PARAMETER | DESCRIPTION |
|---|---|
m
|
The order parameter (≥ 0).
TYPE:
|
n
|
The degree parameter (≥
TYPE:
|
c
|
The size parameter.
TYPE:
|
xi
|
The radial coordinate, ξ, where ξ ≥ 1.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[float, float]
|
The value of the prolate spheroidal radial function and its' derivative. |
Notes
This method uses the prolate spheroidal wave function code for non complex
arguments (van Buren & Boisvert, 2002, and van Buren & Boisvert, 2024), available on
github. This code is in Fortran90
and was interfaced to Python using numpy.f2py then wrapped with the current method to
provide a similar calling convention as the Scipy function of the same name.
References
Van Buren, A. L., & Boisvert, J. E. (2002). Accurate calculation of prolate spheroidal radial functions of the first kind and their first derivatives. Quarterly of Applied Mathematics, 60(3), 589-599. https://doi.org/10.1090/qam/1914443
Van Buren, A. L., & Boisvert, J. E. (2004). Improved Calculation of Prolate Spheroidal Radial Functions of the Second Kind and Their First Derivatives. Quarterly of Applied Mathematics, 62(3), 493-507. https://doi.org/10.1090/qam/2086042
Source code in src/echosms/utils.py
pro_rad2(m, n, c, xi)
Prolate spheroidal radial function of the second kind and derivative.
Calculates the prolate spheroidal radial function of the second kind and its'
derivative with respect to xi.
| PARAMETER | DESCRIPTION |
|---|---|
m
|
The order parameter (≥ 0).
TYPE:
|
n
|
The degree parameter (≥
TYPE:
|
c
|
The size parameter.
TYPE:
|
xi
|
The radial coordinate, ξ, where ξ ≥ 1.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[float, float]
|
The value of the prolate spheroidal radial function and its' derivative. |
Notes
This method uses the prolate spheroidal wave function code for non complex
arguments (van Buren & Boisvert, 2002, and van Buren & Boisvert, 2024), available on
github. This code is in Fortran90
and was interfaced to Python using numpy.f2py then wrapped with the current method to
provide a similar calling convention as the Scipy function of the same name.
References
Van Buren, A. L., & Boisvert, J. E. (2002). Accurate calculation of prolate spheroidal radial functions of the first kind and their first derivatives. Quarterly of Applied Mathematics, 60(3), 589-599. https://doi.org/10.1090/qam/1914443
Van Buren, A. L., & Boisvert, J. E. (2004). Improved Calculation of Prolate Spheroidal Radial Functions of the Second Kind and Their First Derivatives. Quarterly of Applied Mathematics, 62(3), 493-507. https://doi.org/10.1090/qam/2086042
Source code in src/echosms/utils.py
echosms.shape_conversions
Functions that convert between different echoSMs datastore shape representations.
outline_to_surface(outline, num_pts=20, mesh_len=2.0)
Convert an outline shape to a surface shape.
| PARAMETER | DESCRIPTION |
|---|---|
outline
|
An echoSMs outline shape.
TYPE:
|
num_pts
|
The number of points to place on each cross-sectional ellipse.
TYPE:
|
mesh_len
|
The desired typical mesh length as a percentage of overall object size
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, list]
|
An echoSMs surface shape with shape metadata as per the input shape. |
Notes
Each outline cross-sectional ellipse is represented by a polygon with num_pts
vertices. Triangles are created that join the vertices on adjacent polygons.
The two ends are meshed using an ear slicing algorithm (using the mapbox_earcut package, a
Python binding to a C++ implementation of the
algorithm).
The mesh is then remeshed using the pymeshlab isotropic remeshing algorithm.
Source code in src/echosms/shape_conversions.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
surface_to_outline(shape, slice_thickness=0.005)
Convert a surface shape to an outline shape.
| PARAMETER | DESCRIPTION |
|---|---|
shape
|
An echoSMs surface shape.
TYPE:
|
slice_thickness
|
The slice thickness [m] used when generating the outline.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
An echoSMs outline shape with shape metadata as per the input shape. |
Notes
The conversion projects the surface shape to get dorsal and lateral outlines and then slices along the x-axis at a configurable resolution to produce the outline shape.
Source code in src/echosms/shape_conversions.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |