Skip to content

Commit

Permalink
Handling problematic NMEA messages when setting lat/lon in Platform g…
Browse files Browse the repository at this point in the history
…roup (#1067)

* add handling of problematic NMEA strings

* fix bug re no lat/lon scenario

* add warning for problematic lat/lon entry

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix dimension mismatches

* remove conversion to numpy array for msg_type

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
leewujung and pre-commit-ci[bot] authored Jul 5, 2023
1 parent 8145693 commit 90d3630
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions echopype/convert/set_groups_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
import warnings
from typing import List, Set, Tuple

import dask.array
Expand Down Expand Up @@ -173,18 +174,29 @@ def _extract_NMEA_latlon(self):
pynmea2.ParseError,
):
nmea_msg.append(None)
lat = (
np.array([x.latitude if hasattr(x, "latitude") else np.nan for x in nmea_msg])
if nmea_msg
else [np.nan]
)
lon = (
np.array([x.longitude if hasattr(x, "longitude") else np.nan for x in nmea_msg])
if nmea_msg
else [np.nan]
)
if nmea_msg:
lat, lon = [], []
for x in nmea_msg:
try:
lat.append(x.latitude if hasattr(x, "latitude") else np.nan)
except ValueError as ve:
lat.append(np.nan)
warnings.warn(
"At least one latitude entry is problematic and "
f"are assigned None in the converted data: {str(ve)}"
)
try:
lon.append(x.longitude if hasattr(x, "longitude") else np.nan)
except ValueError as ve:
lon.append(np.nan)
warnings.warn(
f"At least one longitude entry is problematic and "
f"are assigned None in the converted data: {str(ve)}"
)
else:
lat, lon = [np.nan], [np.nan]
msg_type = (
np.array([x.sentence_type if hasattr(x, "sentence_type") else np.nan for x in nmea_msg])
[x.sentence_type if hasattr(x, "sentence_type") else np.nan for x in nmea_msg]
if nmea_msg
else [np.nan]
)
Expand Down

0 comments on commit 90d3630

Please sign in to comment.