Utilities
This section provides documentation on the various echoSMs utility functions and classes.
echosms.constants
Constants provided by echoSMs.
DATASTORE_URI = 'https://echosms-data-store-app-ogogm.ondigitalocean.app/'
module-attribute
The current URI to the echoSMs anatomical datastore.
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
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 | |
angle_as_dataframe()
Provide the angle benchmark dataset as a Pandas DataFrame.
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Dataframe containing the benchmark data. |
Source code in src/echosms/benchmarkdata.py
138 139 140 141 142 143 144 145 146 147 | |
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
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
angle_names()
Provide the model names for the angle benchmark data.
| RETURNS | DESCRIPTION |
|---|---|
list
|
List of model names. |
Source code in src/echosms/benchmarkdata.py
79 80 81 82 83 84 85 86 87 88 | |
freq_as_dataframe()
Provide the frequency benchmark dataset as a Pandas DataFrame.
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Dataframe containing the benchmark data. |
Source code in src/echosms/benchmarkdata.py
149 150 151 152 153 154 155 156 157 158 | |
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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
freq_names()
Provide the model names for the frequency benchmark data.
| RETURNS | DESCRIPTION |
|---|---|
list
|
List of model names. |
Source code in src/echosms/benchmarkdata.py
90 91 92 93 94 95 96 97 98 99 | |
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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
names()
Names of all model definitions.
| RETURNS | DESCRIPTION |
|---|---|
iterable of str
|
All model names in the |
Source code in src/echosms/referencemodels.py
68 69 70 71 72 73 74 75 76 77 | |
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
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
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
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
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
27 28 29 | |
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.
none = 'none'
class-attribute
instance-attribute
Used for testing.
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
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 | |
Neumann(m)
Neumann number.
| PARAMETER | DESCRIPTION |
|---|---|
m
|
The input integer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The Neumann number. |
Source code in src/echosms/utils.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
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
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
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
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
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
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 | |
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
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
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
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
as_dataarray(params, no_expand=None)
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
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
as_dataframe(params, no_expand=None)
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
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
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
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
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
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
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
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
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
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | |
names_from_aphia_id(aphia_id)
cached
Return species name information.
| PARAMETER | DESCRIPTION |
|---|---|
aphia_id
|
The World Register of Marine Species (WoRMS) aphia_id number.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Species name information 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
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
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. |
Source code in src/echosms/utils.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |