Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differences in KRM implementations #30

Open
gavinmacaulay opened this issue Dec 18, 2024 · 5 comments
Open

Differences in KRM implementations #30

gavinmacaulay opened this issue Dec 18, 2024 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@gavinmacaulay
Copy link
Collaborator

The Clay & Horne (1994) paper, in the line immediately after equation 13, says

and $k_b \approx k$ at low contrast.

Setting $k_b$ to $k$ gives TS results that differ by around 1 dB compared to not setting $k_b$ to be $k$ for some example datasets. It is not clear why this approximation is necessary (it doesn't simplify the calculations at all) and it perhaps leads to less accurate TS results. Some other implementations of the KRM that echoSMs has been compared against set $k_b$ to $k$, so echoSMs currently does the same.

To allow for testing and comparison of other KRM implementations, the fish shapes from the online KRM TS calculator (https://www.fisheries.noaa.gov/data-tools/krm-model) have been included in echoSMs in a toml-formatted file (or use the KRMorganism Python class for easy access).

The TS for the sardine shape from there can be calculated and compared to the online results with:

from echosms import KRMModel, KRMdata
import matplotlib.pyplot as plt
import numpy as np

mod = KRMModel()

fish = KRMdata().model('Sardine')

p = {'medium_c': 1490, 'medium_rho': 1030, 'organism': fish, 'theta': 90,
     'f': np.arange(12, 121, 1)*1e3}

krm_ts = mod.calculate_ts(p)

noaa_ts = KRMdata.ts('Sardine')

d = np.mean(np.abs(np.array(krm_ts) - np.array(noaa_ts[' TS (dB).1'])))
print(f'Mean difference in results is {d:.2f} dB')

plt.plot(fish.body.x, fish.body.z_U, fish.body.x, fish.body.z_L, c='black')
for s in fish.inclusions:
    plt.plot(s.x, s.z_U, s.x, s.z_L, c='C0' if s.boundary == 'fluid' else 'C1')
plt.gca().set_aspect('equal')
plt.show()
@gavinmacaulay gavinmacaulay added the help wanted Extra attention is needed label Dec 18, 2024
@jmjech
Copy link
Collaborator

jmjech commented Jan 13, 2025

I've gone through some old KRM code of mine and Clay's and here is what I've found so far:

  • I've attached hard-copy versions of Clay's BASIC code from 1992
    Clay-KRM_10-3-1992_highlight.pdf
    Clay-KRM_10-3-1992.pdf
    The _highlight version highlights in orange where g and h are set for calculating scatter from the swimbladder. In his version, both g and h are relative to water, not the fish body. This is for both low, breathing mode, and Kirchhoff approximation.
    It would be nice to post the non-highlighted version on the site for historical purposes.

  • I am still looking to get the electronic copies of Clay's code off of 3.5" Apple/Mac-formatted floppy drives. When I do that, I will confirm that the electronic code match the hard copy and I will try to actually run Clay's code.

  • I've also gone over my KRM code and it has gone through several transitions over the years. I am working on organizing the different versions, but it seems that I started with Clay's version of g and h relative to water, then g and h for low mode relative to water and g and h relative to the fish body for Kirchhoff, then g and h relative to the fish body for both low mode and Kirchhoff. In the appendix of Horne and Jech (https://doi.org/10.1006/jmsc.1998.0432) we state we use g and h relative to water for the low mode and relative to the fish body for Kirchhoff. It seems that was done during one of our transitions.

  • I think John Horne ran the KRM model for the benchmark paper, so I will contact him (I asked if he has a github handle) and have him join in this discussion so that we can determine what was done for that paper. I will also rectify my versions with his.

  • I will run your example code next and look at comparisons of your, mine, and the on-line versions. From first inspection, it seems you define a "medium", which the user can select as the water or the fish body. It will be useful to make this explicit, if you haven't already, in the documentation.

@jmjech
Copy link
Collaborator

jmjech commented Jan 13, 2025

I'm adding @phishdoc - John Horne - to the string.

@gavinmacaulay
Copy link
Collaborator Author

The scan of the Basic code has been added to the echoSMs documentation (in a Historical notes section) We can add more historical things there as we find them.

The values of sound speed and density for the "medium" are entirely up the user, but the model takes these to be the surrounding water. The model code doesn't offer an option to select the water or body as the medium that the swimbladder is in, but this can be added if we want.

@jmjech
Copy link
Collaborator

jmjech commented Jan 13, 2025

Thanks for adding Clays' code!

I think we should have the option of setting the medium to water or the body. I've gone with using the body as the medium for the embedded target, such as a swimbladder, but to compare to historical analyses or for whatever reason, the user should have control of that. We can discuss more at our telecon.

@gavinmacaulay
Copy link
Collaborator Author

Options to select whether the swimbladder backscatter is calculated relative to the water or the body have been added to release v0.6.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants