Skip to content

Commit

Permalink
Noise test fix (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruxandra-valcu authored Nov 8, 2023
1 parent 0622fdf commit 73292e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
22 changes: 11 additions & 11 deletions oceanstream/L2_calibrated_data/noise_masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pathlib
from typing import Union

import xarray
import xarray as xr
from echopype.clean.api import (
get_attenuation_mask_multichannel,
Expand All @@ -28,7 +27,8 @@
# "n": 5,
"thr": 20,
"excludeabove": 250,
"operation": "percentile15",
"dask_chunking": {"ping_time": 100},
"operation": "mean",
},
},
"attenuation": {
Expand Down Expand Up @@ -83,7 +83,8 @@
# "n": 5,
"thr": 20,
"excludeabove": 250,
"operation": "percentile15",
"dask_chunking": {"ping_time": 100},
"operation": "mean",
},
},
"attenuation": {
Expand Down Expand Up @@ -140,6 +141,7 @@
"n": 5,
"thr": 20,
"excludeabove": 250,
"dask_chunking": {"ping_time": 100},
"operation": "mean",
},
},
Expand Down Expand Up @@ -307,7 +309,7 @@ def create_seabed_mask(Sv, parameters, method):
return mask


def create_mask(source_Sv: xarray.Dataset, mask_type="impulse", params=MASK_PARAMETERS):
def create_mask(source_Sv: xr.Dataset, mask_type="impulse", params=MASK_PARAMETERS):
"""
A function that creates a single noise mask for a given dataset
Expand Down Expand Up @@ -341,7 +343,7 @@ def create_mask(source_Sv: xarray.Dataset, mask_type="impulse", params=MASK_PARA
return mask


def create_multiple_masks(source_Sv: xarray.Dataset, params=TEST_MASK_PARAMETERS):
def create_multiple_masks(source_Sv: xr.Dataset, params=TEST_MASK_PARAMETERS):
"""
A function that creates multiple noise masks for a given Sv dataset
Expand All @@ -366,7 +368,7 @@ def create_multiple_masks(source_Sv: xarray.Dataset, params=TEST_MASK_PARAMETERS
return Sv_mask


def create_noise_masks_rapidkrill(source_Sv: xarray.Dataset, params=RAPIDKRILL_MASK_PARAMETERS):
def create_noise_masks_rapidkrill(source_Sv: xr.Dataset, params=RAPIDKRILL_MASK_PARAMETERS):
"""
A function that creates noise masks for a given Sv dataset according to
rapidkrill processing needs
Expand All @@ -391,7 +393,7 @@ def create_noise_masks_rapidkrill(source_Sv: xarray.Dataset, params=RAPIDKRILL_M


def create_default_noise_masks_oceanstream(
source_Sv: xarray.Dataset, params=OCEANSTREAM_MASK_PARAMETERS
source_Sv: xr.Dataset, params=OCEANSTREAM_MASK_PARAMETERS
):
"""
A function that creates noise masks for a given Sv dataset using default methods for oceanstream
Expand All @@ -416,7 +418,7 @@ def create_default_noise_masks_oceanstream(


def create_seabed_masks_oceanstream(
source_Sv: xarray.Dataset, params=OCEANSTREAM_SEABED_MASK_PARAMETERS
source_Sv: xr.Dataset, params=OCEANSTREAM_SEABED_MASK_PARAMETERS
):
"""
A function that creates seabed masks for a given Sv dataset using default methods for oceanstream
Expand All @@ -434,9 +436,7 @@ def create_seabed_masks_oceanstream(
return Sv_mask


def create_noise_masks_oceanstream(
source_Sv: xarray.Dataset, params=OCEANSTREAM_NOISE_MASK_PARAMETERS
):
def create_noise_masks_oceanstream(source_Sv: xr.Dataset, params=OCEANSTREAM_NOISE_MASK_PARAMETERS):
"""
A function that creates noise masks for a given Sv dataset using default methods for oceanstream
Expand Down
29 changes: 7 additions & 22 deletions tests/test_noise_mask.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from oceanstream.L2_calibrated_data.noise_masks import OCEANSTREAM_MASK_PARAMETERS

from oceanstream.L2_calibrated_data.noise_masks import (
create_attenuation_mask,
Expand All @@ -13,46 +14,29 @@

def test_impulse(enriched_ek60_Sv):
source_Sv = enriched_ek60_Sv
RYAN_DEFAULT_PARAMS = {"thr": 10, "m": 5, "n": 1}
RYAN_DEFAULT_PARAMS = OCEANSTREAM_MASK_PARAMETERS["impulse"]["params"]
mask = create_impulse_mask(source_Sv, parameters=RYAN_DEFAULT_PARAMS)
assert mask["channel"].shape == (3,)


def test_transient(enriched_ek60_Sv):
source_Sv = enriched_ek60_Sv
RYAN_DEFAULT_PARAMS = {
# "m": 5,
# "n": 20,
"m": 5,
"n": 5,
"thr": 20,
"excludeabove": 250,
"operation": "mean",
}
RYAN_DEFAULT_PARAMS = OCEANSTREAM_MASK_PARAMETERS["transient"]["params"]
mask_ryan = create_transient_mask(
source_Sv, parameters=RYAN_DEFAULT_PARAMS, method="ryan"
)
assert mask_ryan["channel"].shape == (3,)


def test_attenuation(enriched_ek60_Sv):
DEFAULT_RYAN_PARAMS = {"r0": 180, "r1": 280, "n": 30, "thr": -6, "start": 0}
DEFAULT_RYAN_PARAMS = OCEANSTREAM_MASK_PARAMETERS["attenuation"]["params"]
source_Sv = enriched_ek60_Sv
mask = create_attenuation_mask(source_Sv, parameters=DEFAULT_RYAN_PARAMS)
assert mask["channel"].shape == (3,)


def test_seabed(enriched_ek60_Sv):
ARIZA_DEFAULT_PARAMS = {
"r0": 10,
"r1": 1000,
"roff": 0,
"thr": -40,
"ec": 1,
"ek": (1, 3),
"dc": 10,
"dk": (3, 7),
}
ARIZA_DEFAULT_PARAMS = OCEANSTREAM_MASK_PARAMETERS["seabed"]["params"]
source_Sv = enriched_ek60_Sv
mask = create_seabed_mask(
source_Sv,
Expand All @@ -66,4 +50,5 @@ def test_create_masks(enriched_ek60_Sv):
enriched_Sv = enriched_ek60_Sv
Sv_mask = create_multiple_masks(enriched_Sv)
assert Sv_mask["mask_seabed"].attrs["mask_type"] == "seabed"
assert Sv_mask["mask_impulse"].attrs["parameters"] == ["thr=10", "m=5", "n=1"]
assert Sv_mask["mask_impulse"].attrs["parameters"] == ["thr=3", "m=3", "n=1"]

0 comments on commit 73292e4

Please sign in to comment.