Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set EK60/80 Platform and NMEA nan timestamp to first ping_time value [all tests ci] #1154

Merged
merged 5 commits into from
Sep 2, 2023
Merged
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
13 changes: 10 additions & 3 deletions echopype/convert/set_groups_azfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,22 @@ def set_platform(self) -> xr.Dataset:
"""Set the Platform group."""
platform_dict = {"platform_name": "", "platform_type": "", "platform_code_ICES": ""}
unpacked_data = self.parser_obj.unpacked_data
time2 = self.parser_obj.ping_time
time1 = [time2[0]]

# Create nan time coordinate for lat/lon (lat/lon do not exist in AZFP 01A data)
time1 = [np.nan]

# If tilt_x and/or tilt_y are all nan, create single-value time2 dimension
# and single-value (np.nan) tilt_x and tilt_y
tilt_x = [np.nan] if np.isnan(unpacked_data["tilt_x"]).all() else unpacked_data["tilt_x"]
tilt_y = [np.nan] if np.isnan(unpacked_data["tilt_y"]).all() else unpacked_data["tilt_y"]
if (len(tilt_x) == 1 and np.isnan(tilt_x)) and (len(tilt_y) == 1 and np.isnan(tilt_y)):
time2 = [time2[0]]
time2 = [self.parser_obj.ping_time[0]]
else:
time2 = self.parser_obj.ping_time

# Handle potential nan timestamp for time1 and time2
time1 = self._nan_timestamp_handler(time1)
time2 = self._nan_timestamp_handler(time2) # should not be nan; but add for completeness

ds = xr.Dataset(
{
Expand Down
20 changes: 20 additions & 0 deletions echopype/convert/set_groups_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ def set_platform(self) -> xr.Dataset:
"""Set the Platform group."""
raise NotImplementedError

def _nan_timestamp_handler(self, time_val) -> List:
"""
Replace nan in time coordinate to avoid xarray warning.
"""
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 == "AZFP":
return [self.parser_obj.ping_time[0]]
else:
return NotImplementedError(
f"Nan timestamp handling has not been implemented for {self.sonar_model}!"
)
else:
return time_val

def set_nmea(self) -> xr.Dataset:
"""Set the Platform/NMEA group."""
# Save nan if nmea data is not encoded in the raw file
Expand All @@ -126,6 +143,9 @@ def set_nmea(self) -> xr.Dataset:
time = [np.nan]
raw_nmea = [np.nan]

# Handle potential nan timestamp for time
time = self._nan_timestamp_handler(time)

ds = xr.Dataset(
{
"NMEA_datagram": (
Expand Down
7 changes: 6 additions & 1 deletion echopype/convert/set_groups_ek60.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ def set_platform(self) -> xr.Dataset:

# NMEA dataset: variables filled with np.nan if they do not exist
platform_dict = {"platform_name": "", "platform_type": "", "platform_code_ICES": ""}
# Values for the variables below having a channel (ch) dependence

# Values for the variables in ds below having a channel (ch) dependence
# are identical across channels
ch = list(self.sorted_channel.keys())[0]

# Handle potential nan timestamp for time1 and time2
time1 = self._nan_timestamp_handler(time1)

ds = xr.Dataset(
{
"latitude": (
Expand Down
4 changes: 4 additions & 0 deletions echopype/convert/set_groups_ek80.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ def set_platform(self) -> xr.Dataset:
time2 = self.parser_obj.mru.get("timestamp", None)
time2 = np.array(time2) if time2 is not None else [np.nan]

# Handle potential nan timestamp for time1 and time2
time1 = self._nan_timestamp_handler(time1)
time2 = self._nan_timestamp_handler(time2)

# Assemble variables into a dataset: variables filled with nan if do not exist
platform_dict = {"platform_name": "", "platform_type": "", "platform_code_ICES": ""}
ds = xr.Dataset(
Expand Down