diff --git a/echopype/convert/set_groups_ek60.py b/echopype/convert/set_groups_ek60.py index cc5290cfe..21c4aced5 100644 --- a/echopype/convert/set_groups_ek60.py +++ b/echopype/convert/set_groups_ek60.py @@ -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"] diff --git a/echopype/tests/convert/test_convert_ek60.py b/echopype/tests/convert/test_convert_ek60.py index 195a46d1b..a77481380 100644 --- a/echopype/tests/convert/test_convert_ek60.py +++ b/echopype/tests/convert/test_convert_ek60.py @@ -6,6 +6,7 @@ import pytest from echopype import open_raw +from echopype.convert import ParseEK60 @pytest.fixture @@ -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"]