From 21acf860ec4e6d2a290fccc1e881b1cbdcf0e03a Mon Sep 17 00:00:00 2001 From: praneethratna Date: Sat, 25 Nov 2023 17:08:10 +0530 Subject: [PATCH 1/6] fixed bug in pad_shorter_ping and added test for issue#1217 --- echopype/convert/parse_base.py | 3 ++- echopype/tests/calibrate/test_calibrate_ek80.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/echopype/convert/parse_base.py b/echopype/convert/parse_base.py index 8bd585503..d33215f5d 100644 --- a/echopype/convert/parse_base.py +++ b/echopype/convert/parse_base.py @@ -614,7 +614,8 @@ def pad_shorter_ping(data_list) -> np.ndarray: out_array = out_array.astype(arr_dtype) # Fill in values - out_array[mask] = np.concatenate(data_list).reshape(-1) # reshape in case data > 1D + if data_list[0].ndim == 1: + out_array[mask] = np.concatenate(data_list).reshape(-1) # reshape in case data > 1D else: out_array = np.array(data_list) return out_array diff --git a/echopype/tests/calibrate/test_calibrate_ek80.py b/echopype/tests/calibrate/test_calibrate_ek80.py index 8e544b5f5..cc6f9323e 100644 --- a/echopype/tests/calibrate/test_calibrate_ek80.py +++ b/echopype/tests/calibrate/test_calibrate_ek80.py @@ -251,4 +251,19 @@ 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) \ No newline at end of file + 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") + + # Calibration object + waveform_mode = "CW" + encode_mode = "complex" + ds_Sv = ep.calibrate.compute_Sv( + ed, waveform_mode=waveform_mode, encode_mode=encode_mode + ) + + assert ds_Sv["receiver_sampling_frequency"] is not None + assert np.allclose(ds_Sv["receiver_sampling_frequency"].data, 1500000) From 63a489631e19d65e7d9cf1ab07f21d16d8420e77 Mon Sep 17 00:00:00 2001 From: Wu-Jung Lee Date: Thu, 30 Nov 2023 20:27:44 -0500 Subject: [PATCH 2/6] fix nask shape in pad_shorter_ping --- echopype/convert/parse_base.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/echopype/convert/parse_base.py b/echopype/convert/parse_base.py index d33215f5d..575b2ddd2 100644 --- a/echopype/convert/parse_base.py +++ b/echopype/convert/parse_base.py @@ -600,8 +600,11 @@ 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()) @@ -614,8 +617,7 @@ def pad_shorter_ping(data_list) -> np.ndarray: out_array = out_array.astype(arr_dtype) # Fill in values - if data_list[0].ndim == 1: - out_array[mask] = np.concatenate(data_list).reshape(-1) # reshape in case data > 1D + out_array[mask] = np.concatenate(data_list).reshape(-1) # reshape in case data > 1D else: out_array = np.array(data_list) return out_array From c05bfc2281154b343314bf1482daed6537f35090 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Dec 2023 01:27:59 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- echopype/convert/parse_base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/echopype/convert/parse_base.py b/echopype/convert/parse_base.py index 575b2ddd2..23a08d52f 100644 --- a/echopype/convert/parse_base.py +++ b/echopype/convert/parse_base.py @@ -603,7 +603,10 @@ def pad_shorter_ping(data_list) -> np.ndarray: # 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 + mask = ( + lens[:, None, None] + > np.array([np.arange(lens.max())] * data_list[0].shape[1]).T + ) else: mask = lens[:, None] > np.arange(lens.max()) From 51df0fa217f22962ece1e8a67926144d0c1c7f29 Mon Sep 17 00:00:00 2001 From: Praneeth Ratna <63547155+praneethratna@users.noreply.github.com> Date: Mon, 4 Dec 2023 00:35:40 +0530 Subject: [PATCH 4/6] Update echopype/tests/calibrate/test_calibrate_ek80.py Co-authored-by: Wu-Jung Lee --- echopype/tests/calibrate/test_calibrate_ek80.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/echopype/tests/calibrate/test_calibrate_ek80.py b/echopype/tests/calibrate/test_calibrate_ek80.py index cc6f9323e..4318ad99c 100644 --- a/echopype/tests/calibrate/test_calibrate_ek80.py +++ b/echopype/tests/calibrate/test_calibrate_ek80.py @@ -257,7 +257,8 @@ def test_ek80_BB_power_echoview(ek80_path): 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" From 28162272f7bb822d95c4977e493afb8bf01efa86 Mon Sep 17 00:00:00 2001 From: Praneeth Ratna <63547155+praneethratna@users.noreply.github.com> Date: Mon, 4 Dec 2023 00:35:46 +0530 Subject: [PATCH 5/6] Update echopype/tests/calibrate/test_calibrate_ek80.py Co-authored-by: Wu-Jung Lee --- echopype/tests/calibrate/test_calibrate_ek80.py | 1 + 1 file changed, 1 insertion(+) diff --git a/echopype/tests/calibrate/test_calibrate_ek80.py b/echopype/tests/calibrate/test_calibrate_ek80.py index 4318ad99c..198c1df7e 100644 --- a/echopype/tests/calibrate/test_calibrate_ek80.py +++ b/echopype/tests/calibrate/test_calibrate_ek80.py @@ -266,5 +266,6 @@ def test_ek80_CW_complex_Sv_receiver_sampling_freq(ek80_path): 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) From 660ee070b510aceff4d0581ce03e150d5a2e503a Mon Sep 17 00:00:00 2001 From: Wu-Jung Lee Date: Sun, 3 Dec 2023 14:03:45 -0800 Subject: [PATCH 6/6] fix spacing in echopype/tests/calibrate/test_calibrate_ek80.py --- echopype/tests/calibrate/test_calibrate_ek80.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/echopype/tests/calibrate/test_calibrate_ek80.py b/echopype/tests/calibrate/test_calibrate_ek80.py index 198c1df7e..36fe4ca3a 100644 --- a/echopype/tests/calibrate/test_calibrate_ek80.py +++ b/echopype/tests/calibrate/test_calibrate_ek80.py @@ -257,8 +257,8 @@ def test_ek80_BB_power_echoview(ek80_path): 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 + # Parsed receiver_sampling_frequency is 0 + assert ed["Vendor_specific"]["receiver_sampling_frequency"] == 0 # Calibration object waveform_mode = "CW" encode_mode = "complex"