Skip to content

Commit

Permalink
EK60 Conversion: Drop channels that don't have power data (#1383)
Browse files Browse the repository at this point in the history
* init commit

* simplify test
  • Loading branch information
ctuguinay authored Sep 3, 2024
1 parent 64cde5b commit 3378133
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions echopype/convert/set_groups_ek60.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def __init__(self, *args, **kwargs):
# In some examples the channels may not be ordered, thus sorting is required
self.sorted_channel = dict(sorted(channel_ids.items(), key=lambda item: item[1]))

# Select channels where parser `power` is not empty
self.sorted_channel = {
key: value
for key, value in self.sorted_channel.items()
if len(self.parser_obj.ping_data_dict["power"][key]) != 0
}

# obtain corresponding frequency dict from sorted channels
self.freq = [
self.parser_obj.config_datagram["transceivers"][ch]["frequency"]
Expand Down
28 changes: 28 additions & 0 deletions echopype/tests/convert/test_convert_ek60.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

from echopype import open_raw
from echopype.convert import ParseEK60


@pytest.fixture
Expand Down Expand Up @@ -236,3 +237,30 @@ def test_convert_ek60_different_num_channel_mode_values(file_path, ek60_path):
ed["Sonar/Beam_group1"]["channel_mode"].data.dtype,
np.float32
)

@pytest.mark.test
@pytest.mark.integration
def test_converting_ek60_raw_with_missing_channel_power():
"""
Tests that we can convert a EK60 RAW file that has missing power data for a
specific channel.
"""
# Parse RAW
raw_path = "echopype/test_data/ek60_missing_channel_power/Summer2017-D20170807-T171736.raw"
ek60_parser = ParseEK60(raw_path)
ek60_parser.parse_raw()

# Open RAW
ed = open_raw(raw_path, sonar_model="EK60")

# Get channels that have empty `power`
channels = list(ek60_parser.config_datagram["transceivers"].keys())
empty_power_chs = {
ch: ek60_parser.config_datagram["transceivers"][ch]["channel_id"]
for ch in channels
if len(ek60_parser.ping_data_dict["power"][ch]) == 0
}

# Check that all empty power channels do not exist in the EchoData Beam group
for _, empty_power_channel_name in empty_power_chs.items():
assert empty_power_channel_name not in ed["Sonar/Beam_group1"]["channel"]

0 comments on commit 3378133

Please sign in to comment.