Skip to content

Commit

Permalink
Fix test values (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruxandra-valcu authored Nov 24, 2023
1 parent 977ff37 commit d6167e0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
4 changes: 2 additions & 2 deletions oceanstream/L3_regridded_data/shoal_detection_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"thr": -70,
"maxvgap": 5,
"maxhgap": 5,
"minvlen": 0,
"minhlen": 0,
"minvlen": 5,
"minhlen": 5,
"dask_chunking": {"ping_time": 1000, "range_sample": 1000},
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_applying_masks_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ def test_apply_mask_organisms_in_order(enriched_ek60_Sv):
}

ds_processed = apply_mask_organisms_in_order(ds_Sv_with_shoal_combined_mask, process_parameters)
assert np.nanmean(ds_processed["Sv"].values) == pytest.approx(-56.85248587691882, 0.0001)
assert np.nanmean(ds_processed["Sv"].values) == pytest.approx(-63.41369478688135, 0.0001)
with pytest.raises(ValueError, match="Unexpected mask"):
apply_selected_noise_masks_and_or_noise_removal(ds_processed, "invalid_parameters")
10 changes: 5 additions & 5 deletions tests/test_nasc_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from oceanstream.L3_regridded_data.csv_export_nasc import *

@pytest.mark.ignore
# @pytest.mark.ignore
def test_compute_per_dataset_nasc(ek_60_Sv_full_denoised):
dataset = ek_60_Sv_full_denoised
nasc = base_nasc_data(dataset)
Expand All @@ -12,15 +12,15 @@ def test_compute_per_dataset_nasc(ek_60_Sv_full_denoised):
assert len(short_nasc) == 3
assert "fish_NASC_38000.0" in short_nasc

@pytest.mark.ignore
# @pytest.mark.ignore
def test_compute_masked_nasc(ek_60_Sv_shoal):
dataset = ek_60_Sv_shoal
fish_nasc = mask_nasc_data(dataset, {"mask_shoal": False}, True, "fish_NASC")
assert fish_nasc['fish_NASC_38000.0'] == pytest.approx(130821359, 0.0001)
assert fish_nasc['fish_NASC_38000.0'] == pytest.approx(103252307.9526562, 0.0001)

@pytest.mark.ignore
# @pytest.mark.ignore
def test_compute_full_nasc(ek_60_Sv_shoal):
dataset = ek_60_Sv_shoal
nasc = full_nasc_data(dataset, BASE_NASC_PARAMETERS)
assert len(nasc) == 24
assert nasc['fish_NASC_38000.0'] == pytest.approx(130821359, 0.0001)
assert nasc['fish_NASC_38000.0'] == pytest.approx(103252307.9526562, 0.0001)
4 changes: 2 additions & 2 deletions tests/test_shoal_detection_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def shoal_masks(ek_60_Sv_denoised):
@pytest.mark.ignore
def test_create_shoal_mask_multichannel(ek_60_Sv_denoised):
mask = create_shoal_mask_multichannel(ek_60_Sv_denoised)
assert _count_false_values(mask) == 4873071
assert _count_false_values(mask) == 4471604


@pytest.mark.ignore
Expand All @@ -33,5 +33,5 @@ def test_attach_shoal_mask_to_ds(ek_60_Sv_denoised):
ds_Sv_shoal_combined, ds_Sv_shoal_combined["mask_shoal"]
)
assert np.nanmean(ds_Sv_shoal_combined["Sv"].values) == pytest.approx(
-56.46381852479049, 0.0001
-61.21094022368077, 0.0001
)
35 changes: 17 additions & 18 deletions tests/test_shoal_process.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from oceanstream.L3_regridded_data.shoal_detection_handler import attach_shoal_mask_to_ds, WEILL_DEFAULT_PARAMETERS
import pytest

from oceanstream.L3_regridded_data.shoal_detection_handler import attach_shoal_mask_to_ds

from oceanstream.L3_regridded_data.shoal_process import (
process_shoals,
Expand All @@ -9,9 +7,17 @@
)
from oceanstream.utils import tfc

@pytest.mark.ignore
WEILL_DEFAULT_PARAMETERS = {
"thr": -55,
"maxvgap": 5,
"maxhgap": 5,
"minvlen": 5,
"minhlen": 5,
"dask_chunking": {"ping_time": 1000, "range_sample": 1000},
}

# @pytest.mark.ignore
def prep_dataset(Sv):
# parameters = {"thr": -55, "maxvgap": -5, "maxhgap": 0, "minvlen": 5, "minhlen": 5}
parameters = WEILL_DEFAULT_PARAMETERS
shoal_dataset = attach_shoal_mask_to_ds(Sv, parameters=parameters, method="will")
shoal_dataset["mask_shoal"][:, :, 0:25] = False
Expand All @@ -20,34 +26,27 @@ def prep_dataset(Sv):
shoal_dataset["mask_shoal"][:, 800:, :] = False
return shoal_dataset

@pytest.mark.ignore
# @pytest.mark.ignore
def test_split_shoal(ek_60_Sv_denoised):
expected_results = [
(10362, 6104418),
(11155, 6103625),
(44, 6114736),
(21, 6114759),
(21, 6114759),
(20, 6114760),
]
expected_results = [(13671, 6101109), (13465, 6101315), (30, 6114750)]
shoal_dataset = prep_dataset(ek_60_Sv_denoised)
res = split_shoal_mask(shoal_dataset)
res_tfc = [tfc(r) for r in res]
assert res_tfc == expected_results

@pytest.mark.ignore
# @pytest.mark.ignore
def test_single_shoal(ek_60_Sv_denoised):
shoal_dataset = prep_dataset(ek_60_Sv_denoised)
mask = split_shoal_mask(shoal_dataset)[0]
res = process_single_shoal(shoal_dataset, mask)
assert len(res) == 3
assert len(res[0]) == 24
assert res[0]["area"] == 4252
assert res[0]["area"] == 6017

@pytest.mark.ignore
# @pytest.mark.ignore
def test_shoals(ek_60_Sv_denoised):
shoal_dataset = prep_dataset(ek_60_Sv_denoised)
res = process_shoals(shoal_dataset)
none_res = [r for r in res if r is None]
assert len(res) == 10
assert len(res) == 7
assert len(none_res) == 0

0 comments on commit d6167e0

Please sign in to comment.