Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion echopype/calibrate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

from ..core import SONAR_MODELS
from ..echodata import EchoData
from ..echodata.simrad import check_input_args_combination, retrieve_correct_beam_group
from ..echodata.simrad import retrieve_correct_beam_group
from ..utils.prov import echopype_prov_attrs, source_files_vars
from .calibrate_azfp import CalibrateAZFP
from .calibrate_ek import CalibrateEK60, CalibrateEK80
from .utils import check_input_args_combination

CALIBRATOR = {
"EK60": CalibrateEK60,
Expand Down
24 changes: 24 additions & 0 deletions echopype/calibrate/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Utilities shared by calibration workflows."""


def check_input_args_combination(
waveform_mode: str, encode_mode: str, pulse_compression: bool = None
) -> None:
"""Validate waveform, encoding, and pulse-compression options."""
if waveform_mode not in ["CW", "BB"]:
raise ValueError("The input waveform_mode must be either 'CW' or 'BB'!")

if encode_mode not in ["complex", "power"]:
raise ValueError("The input encode_mode must be either 'complex' or 'power'!")

if waveform_mode == "BB" and encode_mode == "power":
raise ValueError(
"Data from broadband ('BB') transmission must be recorded as complex samples"
)

if pulse_compression is not None:
if pulse_compression and ((waveform_mode != "BB") or (encode_mode != "complex")):
raise RuntimeError(
"Pulse compression can only be used with "
"waveform_mode='BB' and encode_mode='complex'"
)
40 changes: 2 additions & 38 deletions echopype/echodata/simrad.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,11 @@

import numpy as np

from ..calibrate.utils import check_input_args_combination
from ..core import SONAR_MODELS
from .echodata import EchoData


def check_input_args_combination(
waveform_mode: str, encode_mode: str, pulse_compression: bool = None
) -> None:
"""
Checks that the ``waveform_mode`` and ``encode_mode`` have
the correct values and that the combination of input arguments are valid, without
considering the actual data.

Parameters
----------
waveform_mode: str
Type of transmit waveform
encode_mode: str
Type of encoded return echo data
pulse_compression: bool
States whether pulse compression should be used
"""

if waveform_mode not in ["CW", "BB"]:
raise ValueError("The input waveform_mode must be either 'CW' or 'BB'!")

if encode_mode not in ["complex", "power"]:
raise ValueError("The input encode_mode must be either 'complex' or 'power'!")

# BB has complex data only, but CW can have complex or power data
if (waveform_mode == "BB") and (encode_mode == "power"):
raise ValueError(
"Data from broadband ('BB') transmission must be recorded as complex samples"
)

# make sure that we have BB and complex inputs, if pulse compression is selected
if pulse_compression is not None:
if pulse_compression and ((waveform_mode != "BB") or (encode_mode != "complex")):
raise RuntimeError(
"Pulse compression can only be used with "
"waveform_mode='BB' and encode_mode='complex'"
)
__all__ = ["check_input_args_combination", "retrieve_correct_beam_group"]


def _retrieve_correct_beam_group_EK60(
Expand Down
25 changes: 25 additions & 0 deletions echopype/tests/calibrate/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest

from echopype.calibrate.utils import check_input_args_combination


@pytest.mark.parametrize(
("waveform_mode", "encode_mode"),
[("CW", "power"), ("CW", "complex"), ("BB", "complex")],
)
def test_check_input_args_combination_accepts_valid_modes(waveform_mode, encode_mode):
check_input_args_combination(waveform_mode, encode_mode)


@pytest.mark.parametrize(
("waveform_mode", "encode_mode"),
[("FM", "complex"), ("CW", "raw"), ("BB", "power")],
)
def test_check_input_args_combination_rejects_invalid_modes(waveform_mode, encode_mode):
with pytest.raises(ValueError):
check_input_args_combination(waveform_mode, encode_mode)


def test_check_input_args_combination_rejects_invalid_pulse_compression():
with pytest.raises(RuntimeError, match="Pulse compression"):
check_input_args_combination("CW", "complex", pulse_compression=True)