Utilities
This section provides documentation on the various echoSMs utility functions and classes.
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
names_from_aphia_id(aphia_id)
cached
Returns species name information.
| PARAMETER | DESCRIPTION |
|---|---|
aphia_id
|
The World Register of Marine Species (WoRMS) aphia_id number.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Species name infomation as used by the echoSMs anatomical datastore or an empty dict if no species data found. |
Notes
Queries the WoRMS web service and caches the results to reduce queries to WoRMS.
Source code in src/echosms/utils.py
datastore_schema(schema_file=None)
cached
Get the echoSMs datastore schema.
| PARAMETER | DESCRIPTION |
|---|---|
schema_file
|
The schema filename. If None, the schema will be downloaded from the echoSMs github repository
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
The datastore schema in JSON Schema form or an empty string if no schema was found. |