OSOceanAcoustics / echopype

Enabling interoperability and scalability in ocean sonar data analysis
https://echopype.readthedocs.io/
Apache License 2.0
95 stars 73 forks source link

Patch/nasc #1150

Closed simedroniraluca closed 12 months ago

simedroniraluca commented 1 year ago

NASC (Nautical Area Scattering Coefficient) Computation Correction

This PR is opened to propose a solution for https://github.com/OSOceanAcoustics/echopype/pull/1136

Changes Made:

  1. Conversion Factors: Conversion factors have been incorporated to facilitate the conversion from backscattering cross-section to scattering cross-section and from meters to nautical miles (nmi).

  2. Computation Approach:

    • Cells Selection: Cells are chosen based on their depth and distance. The distance calculation is based on latitude and longitude coordinates.
    • NASC Calculation: For each channel and cell, the NASC is computed using the following steps:
      • Multiply the Sv (in linear units) with the height of the samples. The sample height is determined as the difference between consecutive depth values.
      • Compute the mean of the obtained values.
      • Multiply the mean value by the number of samples within the selected cell per the number of pings in the same cell.
      • Further multiply the result by $4 \times \pi \times 1852^2$
      • Finally, divide the obtained result by the percentage of non-NaN samples present in the analysis.
leewujung commented 12 months ago

Hey @simedroniraluca : Thanks very much for pointing out the bug and sending in the above! I did some investigation and comparison and put the results in this gist. In it I compare the echopy implementation with the Echoview one, and an adaption that we'll use in echopype using flox.

For the bug in #1136 and the different implementations, it boils down to:

To make compute_NASC more efficient we are moving away from the looping approach (#1127). I'll send in a separate and incomplete PR in a moment that has the barebone stuff using flox, which @lsetiawan will carry forward to finish it.

leewujung commented 12 months ago

For visibility, here I copy-paste some notes from the gist:

Regarding echopy implementation

The implementation in echopy integrated Sv between the range limits r0 and r1.

There are a few specifics to note:

  • if method="mean", the function takes the mean of sv*sh and multiply that by the number of vertical samples, and treat this number as the integration output
  • if method=""sum, the function just takes the sum of sv*sh to be the integration output
  • the resulting integrated output is "corrected" by scaling according to the number of valid samples in each column (distance_nmi). For example, if there are only 2 non-NaN samples out of 3 total samples along depth, then the integrated output NASC_raw is scaled by 3/2: NASC_corrected = NASC_raw / (2/3)
  • the code also assumes that the "height" of the samples are conserved across ping, which may not be the case unless the Sv data has been regridded

I am not sure about the final correction of the NASC based on the missing non-NaN values. This would result in inflating the NASC number if there are a lot of NaNs in sv, and would not be accurate if the goal is to obtain NASC from masked Sv dataset.

Regarding echopy vs Echoview differences

  • the Echoview implementation computes NASC in a sense of a mean across multiple pings
  • the Echopy implementation computes ping-by-ping NASC with some scaling to compensate for potential NaN samples along depth in some pings
leewujung commented 12 months ago

Hey @simedroniraluca: I think we can close this issue and move our discussions to #1167, so that everything is in one place. Thanks again for your contribution!!