Skip to content

Commit

Permalink
Removed one instance of sonar_model conditions.
Browse files Browse the repository at this point in the history
This worked by finding a way to automate the parse type generation.
  • Loading branch information
spacetimeengineer committed Oct 23, 2024
1 parent a036fb6 commit e938737
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
17 changes: 10 additions & 7 deletions echopype/calibrate/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
from ..echodata import EchoData
from ..echodata.simrad import retrieve_correct_beam_group
from .env_params import harmonize_env_param_time
from ..core import SONAR_MODELS

DIMENSION_ORDER = ["channel", "ping_time", "range_sample"]

def range_meter_modification_handler(sonar_model):
return str(SONAR_MODELS[sonar_model]['parser']).split(".Parse")[1].split("'>")[0]

def compute_range_AZFP(echodata: EchoData, env_params: Dict, cal_type: str) -> xr.DataArray:
"""
Expand Down Expand Up @@ -147,17 +150,17 @@ def compute_range_EK(
similar to those recorded by EK60 echosounders (the "power/angle" format).
"""
# sound_speed should exist already
if echodata.sonar_model in ("EK60", "ES70"):
ek_str = "EK60"
elif echodata.sonar_model in ("EK80", "ES80", "EA640"):
ek_str = "EK80"
else:
raise ValueError("The specified sonar_model is not supported!")
#if echodata.sonar_model in ("EK60", "ES70"):
# ek_str = "EK60"
#elif echodata.sonar_model in ("EK80", "ES80", "EA640"):
# ek_str = "EK80"
#else:
# raise ValueError("The specified sonar_model is not supported!")

if "sound_speed" not in env_params:
raise RuntimeError(
"sounds_speed not included in env_params, "
f"use echopype.calibrate.env_params.get_env_params_{ek_str}() to compute env_params "
f"use echopype.calibrate.env_params.get_env_params_{range_meter_modification_handler(echodata.sonar_model)}() to compute env_params "
)
else:
sound_speed = env_params["sound_speed"]
Expand Down
21 changes: 8 additions & 13 deletions echopype/convert/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,19 +465,6 @@ def open_raw(
if not isinstance(raw_file, str):
raise TypeError("File path must be a string or Path")

<<<<<<< Updated upstream




#if sonar_model is None:
# raise ValueError("Sonar model must be specified.")
=======
if sonar_model is None:
#TODO : This is where we would implement logic to parse some object describing the sonar model.
raise ValueError("Sonar model must be specified.")
>>>>>>> Stashed changes

# Check inputs
if convert_params is None:
convert_params = {}
Expand All @@ -490,6 +477,14 @@ def open_raw(
if _is_EK60(raw_file, storage_options):
sonar_model = "EK60"


# Automatically determining the sonar model, is effective only if all potential sonar models are considered during data parsing.
# In this case, we only handle EK60 and EK80 models. However, by removing the requirement to explicitly specify the sonar model,
# the process generally works well. The sonar model is only necessary when the user provides data that isn't recognized by the automatic sonar model parser.

if sonar_model is None:
raise ValueError("Sonar model must be specified.")

# Uppercased model in case people use lowercase
sonar_model = sonar_model.upper() # type: ignore

Expand Down
2 changes: 2 additions & 0 deletions echopype/convert/set_groups_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def _nan_timestamp_handler(self, time_val) -> List:
"""
if len(time_val) == 1 and np.isnan(time_val[0]):
# set time_val to earliest ping_time among all channels


if self.sonar_model in ["EK60", "ES70", "EK80", "ES80", "EA640"]:
return [np.array([v[0] for v in self.parser_obj.ping_time.values()]).min()]
elif self.sonar_model in ["AZFP", "AZFP6"]:
Expand Down

0 comments on commit e938737

Please sign in to comment.