Skip to content

Commit

Permalink
Fix False masks (#103)
Browse files Browse the repository at this point in the history
* Fix False masks

* Deliver True masks instead of negate False one
  • Loading branch information
simedroniraluca committed Oct 31, 2023
1 parent a8d6354 commit 9c9ea4b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
7 changes: 5 additions & 2 deletions echopype/clean/signal_attenuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ def _ryan(source_Sv: xr.DataArray, desired_channel: str, parameters=DEFAULT_RYAN
if r0 > r1:
raise Exception("Minimum range has to be shorter than maximum range")

# return empty mask if searching range is outside the echosounder range
# give empty mask if searching range is outside the echosounder range
if (r0 > r[-1]) or (r1 < r[0]):
warnings.warn("Searching range is outside the echosounder range. Returning empty mask.")
warnings.warn(
"Searching range is outside the echosounder range."
"Returning a default mask with all True values."
)
mask = np.zeros_like(Sv, dtype=bool)
mask_ = np.zeros_like(Sv, dtype=bool)

Expand Down
17 changes: 7 additions & 10 deletions echopype/clean/transient_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"Mihai Boldeanu", # adapted the mask transient noise algorithms to echopype
]


import warnings

import numpy as np
Expand Down Expand Up @@ -54,6 +53,7 @@ def _ryan(source_Sv: xr.DataArray, desired_channel: str, parameters: dict = RYAN
transient noise. Sv values are removed if exceed a threshold. Masking is
excluded above 250 m by default to avoid the removal of aggregated biota.
Args:
Args:
source_Sv (xr.DataArray): Sv array
selected_channel (str): name of the channel to process
Expand Down Expand Up @@ -115,7 +115,6 @@ def _ryan(source_Sv: xr.DataArray, desired_channel: str, parameters: dict = RYAN
)
)
mask[i, j] = sample - block > thr

mask = np.logical_not(mask)
return_mask = xr.DataArray(
mask,
Expand Down Expand Up @@ -189,21 +188,19 @@ def _fielding(
if r0 > r1:
raise Exception("Minimum range has to be shorter than maximum range")

# In the case where the searching range is outside the echosounder range:
# return a default mask with all True values
# if searching range is outside the echosounder range
if (r0 > r[-1]) or (r1 < r[0]):
mask = np.zeros_like(Sv, dtype=bool)
mask_ = np.zeros_like(Sv, dtype=bool)

# Raise a warning to inform the user
warnings.warn(
"The searching range is outside the echosounder range. "
"A default mask with all False values is returned, "
"A default mask with all True values is returned, "
"which won't mask any data points in the dataset."
)

combined_mask = mask
mask = np.ones_like(Sv, dtype=bool)
mask_ = np.ones_like(Sv, dtype=bool)
return xr.DataArray(
combined_mask,
mask,
dims=("ping_time", "range_sample"),
coords={"ping_time": source_Sv.ping_time, "range_sample": source_Sv.range_sample},
)
Expand Down
34 changes: 24 additions & 10 deletions echopype/mask/seabed.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,12 @@ def _blackwell(Sv_ds: xr.DataArray, desired_channel: str, parameters: dict = MAX
below = np.zeros((len(r) - r1, maskchunk.shape[1]), dtype=bool)
mask = np.r_[above, maskchunk, below]

# return empty mask if aliased-seabed was not detected in Theta & Phi
# give empty mask if aliased-seabed was not detected in Theta & Phi
else:
warnings.warn("No aliased seabed detected in Theta & Phi. Returning empty mask.")
warnings.warn(
"No aliased seabed detected in Theta & Phi. "
"A default mask with all True values is returned."
)
mask = np.zeros_like(Sv, dtype=bool)

mask = np.logical_not(mask.T)
Expand Down Expand Up @@ -423,9 +426,12 @@ def _blackwell_mod(
if r0 > r1:
raise Exception("Minimum range has to be shorter than maximum range")

# return empty mask if searching range is outside the echosounder range
# give empty mask if searching range is outside the echosounder range
if (r0 > r[-1]) or (r1 < r[0]):
warnings.warn("Search range is outside the echosounder range. Returning empty mask.")
warnings.warn(
"Search range is outside the echosounder range."
"A default mask with all True values is returned."
)
mask = np.zeros_like(Sv, dtype=bool)

# delimit the analysis within user-defined range limits
Expand Down Expand Up @@ -485,9 +491,12 @@ def _blackwell_mod(
below = np.zeros((len(r) - i1, maskchunk.shape[1]), dtype=bool)
mask = np.r_[above, maskchunk, below]

# return empty mask if aliased-seabed was not detected in Theta & Phi
# give empty mask if aliased-seabed was not detected in Theta & Phi
else:
warnings.warn("Aliased seabed not detected in Theta & Phi. Returning empty mask.")
warnings.warn(
"Aliased seabed not detected in Theta & Phi."
"A default mask with all True values is returned."
)
mask = np.zeros_like(Sv, dtype=bool)

mask = np.logical_not(mask.T)
Expand Down Expand Up @@ -708,9 +717,12 @@ def _ariza(Sv_ds: xr.DataArray, desired_channel: str, parameters: dict = MAX_SV_
if r0 > r1:
raise Exception("Minimum range has to be shorter than maximum range")

# return empty mask if searching range is outside the echosounder range
# give empty mask if searching range is outside the echosounder range
if (r0 > r[-1]) or (r1 < r[0]):
warnings.warn("Search range is outside the echosounder range. Returning empty mask.")
warnings.warn(
"Search range is outside the echosounder range. "
"A default mask with all True values is returned."
)
mask = np.zeros_like(Sv, dtype=bool)

# get indexes for range offset and range limits
Expand All @@ -723,9 +735,11 @@ def _ariza(Sv_ds: xr.DataArray, desired_channel: str, parameters: dict = MAX_SV_
Sv_[0:r0, :] = -999
Sv_[r1:, :] = -999

# return empty mask if there is nothing above threshold
# give empty mask if there is nothing above threshold
if not (Sv_ > thr).any():
warnings.warn("Nothing found above the threshold. Returning empty mask.")
warnings.warn(
"Nothing found above the threshold. " "A default mask with all True values is returned."
)
mask = np.zeros_like(Sv_, dtype=bool)

# search for seabed otherwise
Expand Down

0 comments on commit 9c9ea4b

Please sign in to comment.