Skip to content

Commit

Permalink
Fixed reshape bug in pad_shorter_ping and added test for EK80 missi…
Browse files Browse the repository at this point in the history
…ng `receiver_sampling_freq` error [all tests ci] (#1234)

* fixed bug in pad_shorter_ping and added test for issue#1217

* fix nask shape in pad_shorter_ping

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update echopype/tests/calibrate/test_calibrate_ek80.py

Co-authored-by: Wu-Jung Lee <leewujung@gmail.com>

* Update echopype/tests/calibrate/test_calibrate_ek80.py

Co-authored-by: Wu-Jung Lee <leewujung@gmail.com>

* fix spacing in echopype/tests/calibrate/test_calibrate_ek80.py

---------

Co-authored-by: Wu-Jung Lee <leewujung@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 3, 2023
1 parent 87fd9af commit 63547fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
10 changes: 8 additions & 2 deletions echopype/convert/parse_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,14 @@ def pad_shorter_ping(data_list) -> np.ndarray:
lens = np.array([len(item) for item in data_list])
if np.unique(lens).size != 1: # if some pings have different lengths along range
if data_list[0].ndim == 2:
# Angle data have an extra dimension for alongship and athwartship samples
mask = lens[:, None, None] > np.array([np.arange(lens.max())] * 2).T
# Data may have an extra dimension:
# - Angle data have an extra dimension for alongship and athwartship samples
# - Complex data have an extra dimension for different transducer sectors
mask = (
lens[:, None, None]
> np.array([np.arange(lens.max())] * data_list[0].shape[1]).T
)

else:
mask = lens[:, None] > np.arange(lens.max())

Expand Down
19 changes: 18 additions & 1 deletion echopype/tests/calibrate/test_calibrate_ek80.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,21 @@ def test_ek80_BB_power_echoview(ek80_path):
ev_vals = df_real.values[:, :]
ep_vals = pc_mean.values.real[:, :]
assert np.allclose(ev_vals[:, 69:8284], ep_vals[:, 69:], atol=1e-4)
assert np.allclose(ev_vals[:, 90:8284], ep_vals[:, 90:], atol=1e-5)
assert np.allclose(ev_vals[:, 90:8284], ep_vals[:, 90:], atol=1e-5)


def test_ek80_CW_complex_Sv_receiver_sampling_freq(ek80_path):
ek80_raw_path = str(ek80_path.joinpath("D20230804-T083032.raw"))
ed = ep.open_raw(ek80_raw_path, sonar_model="EK80")
# Parsed receiver_sampling_frequency is 0
assert ed["Vendor_specific"]["receiver_sampling_frequency"] == 0
# Calibration object
waveform_mode = "CW"
encode_mode = "complex"
ds_Sv = ep.calibrate.compute_Sv(
ed, waveform_mode=waveform_mode, encode_mode=encode_mode
)

# receiver_sampling_frequency substituted with default value in compute_Sv
assert ds_Sv["receiver_sampling_frequency"] is not None
assert np.allclose(ds_Sv["receiver_sampling_frequency"].data, 1500000)

0 comments on commit 63547fc

Please sign in to comment.