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 range entries with no backscatter data to NaN in output of echodata.compute_range() #547

Merged
merged 24 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d02b188
Add test_path fixture
lsetiawan Dec 17, 2021
9f006aa
Update echodata tests to use fixtures more
lsetiawan Dec 17, 2021
bd5276b
Update convert tests to use fixtures more
lsetiawan Dec 18, 2021
6c4e319
Clean up unecessary fixtures in ad2cp
lsetiawan Dec 18, 2021
5a7601f
Add convert test for all new EK80 files
lsetiawan Dec 18, 2021
4106452
Add es70 and fixturize
lsetiawan Jan 3, 2022
8e7a5ea
Add es80 convert tests
lsetiawan Jan 21, 2022
9959bfd
Fix multiple paths
lsetiawan Jan 21, 2022
41520f7
Fix convert open_raw to allow for es80
lsetiawan Jan 21, 2022
d16d2fb
Merge branch 'dev' of /~https://github.com/OSOceanAcoustics/echopype in…
lsetiawan Jan 28, 2022
62b0c29
Add EA640 and tweak test path
lsetiawan Jan 28, 2022
f326472
set range entries without corresponding backscatter data to NaN
leewujung Jan 31, 2022
bf51b20
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2022
36234d7
add docstring to make it clear what normal vs raw ad2cp files are
leewujung Jan 31, 2022
cbb179a
Merge branch 'update_tests' into fix-compute-range
leewujung Jan 31, 2022
4cc5cf7
add test for nan entries in echodata.compute_range output
leewujung Jan 31, 2022
0f7c4f3
add new EK60 test file in test_data/README.md
leewujung Jan 31, 2022
5d74d1e
dropna before checking range uniqueness in compute_MVBS
leewujung Jan 31, 2022
c02274d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2022
e76d689
Update ek80_file fixture to ek80_new_file
lsetiawan Jan 31, 2022
1ca6564
Change ec to echodata
lsetiawan Jan 31, 2022
5db7a7d
Consolidate test_convert.py and rename
lsetiawan Jan 31, 2022
a72547a
Merge branch 'update_tests' into fix-compute-range
leewujung Feb 1, 2022
e5ae984
Merge branch 'upstream-dev' into fix-compute-range
leewujung Feb 1, 2022
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
20 changes: 15 additions & 5 deletions echopype/echodata/echodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,15 @@ def squeeze_non_scalar(n):
beam.range_bin - tvg_correction_factor
) * sample_thickness # [frequency x range_bin]
elif waveform_mode == "BB":
beam = self.beam # always use the Beam group
# TODO: bug: right now only first ping_time has non-nan range
shift = self.beam[
shift = beam[
"transmit_duration_nominal"
] # based on Lar Anderson's Matlab code
# TODO: once we allow putting in arbitrary sound_speed,
# change below to use linearly-interpolated values
range_meter = (
(self.beam.range_bin * self.beam["sample_interval"] - shift)
* sound_speed
/ 2
(beam.range_bin * beam["sample_interval"] - shift) * sound_speed / 2
)
# TODO: Lar Anderson's code include a slicing by minRange with a default of 0.02 m,
# need to ask why and see if necessary here
Expand All @@ -360,7 +359,18 @@ def squeeze_non_scalar(n):
range_meter = range_meter.where(
range_meter > 0, 0
) # set negative ranges to 0
range_meter.name = "range" # add name to facilitate xr.merge

# set entries with NaN backscatter data to NaN
if "quadrant" in beam["backscatter_r"].dims:
valid_idx = (
~beam["backscatter_r"].isel(quadrant=0).drop("quadrant").isnull()
)
else:
valid_idx = ~beam["backscatter_r"].isnull()
range_meter = range_meter.where(valid_idx)

# add name to facilitate xr.merge
range_meter.name = "range"

return range_meter

Expand Down
5 changes: 4 additions & 1 deletion echopype/preprocess/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

def _check_range_uniqueness(ds):
"""Check if range changes across ping in a given frequency channel."""
return (ds["range"].isel(ping_time=0) == ds["range"]).all()
return (
ds["range"].isel(ping_time=0).dropna(dim="range_bin")
== ds["range"].dropna(dim="range_bin")
).all()


def compute_MVBS(ds_Sv, range_meter_bin=20, ping_time_bin="20S"):
Expand Down
1 change: 1 addition & 0 deletions echopype/test_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Most of these files are stored on Git LFS but the ones that aren't (due to file

### EK60
- DY1801_EK60-D20180211-T164025.raw: Standard test with constant ranges across ping times
- Winter2017-D20170115-T150122.raw: Contains a change of recording length in the middle of the file
- 2015843-D20151023-T190636.raw: Not used in tests but contains ranges are not constant across ping times
- SH1701_consecutive_files_w_range_change: Not used in tests. [Folder](https://drive.google.com/drive/u/1/folders/1PaDtL-xnG5EK3N3P1kGlXa5ub16Yic0f) on shared drive that contains seqential files with ranges that are not constant across ping times.

Expand Down
41 changes: 41 additions & 0 deletions echopype/tests/echodata/test_echodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,29 @@ def compute_range_samples(request, test_path):
)


@pytest.fixture(
params=[
{
"path_model": "EK60",
"raw_path": "Winter2017-D20170115-T150122.raw",
},
{
"path_model": "EK80",
"raw_path": "D20170912-T234910.raw",
},
],
ids=[
"ek60_winter2017",
"ek80_summer2017",
],
)
def range_check_files(request, test_path):
return (
request.param["path_model"],
test_path[request.param["path_model"]].joinpath(request.param['raw_path'])
)


@pytest.fixture(
params=[
{
Expand Down Expand Up @@ -308,6 +331,24 @@ def test_compute_range(compute_range_samples):
assert isinstance(range, xr.DataArray)


def test_nan_range_entries(range_check_files):
sonar_model, ek_file = range_check_files
echodata = echopype.open_raw(ek_file, sonar_model=sonar_model)
if sonar_model == "EK80":
ds_Sv = echopype.calibrate.compute_Sv(echodata, waveform_mode='BB', encode_mode='complex')
range_output = echodata.compute_range(env_params=[], ek_waveform_mode='BB')
nan_locs_backscatter_r = ~echodata.beam.backscatter_r.isel(quadrant=0).drop("quadrant").isnull()
else:
ds_Sv = echopype.calibrate.compute_Sv(echodata)
range_output = echodata.compute_range(env_params=[])
nan_locs_backscatter_r = ~echodata.beam.backscatter_r.isnull()

nan_locs_Sv_range = ~ds_Sv.range.isnull()
nan_locs_range = ~range_output.isnull()
assert xr.Dataset.equals(nan_locs_backscatter_r, nan_locs_range)
assert xr.Dataset.equals(nan_locs_backscatter_r, nan_locs_Sv_range)


def test_update_platform(update_platform_samples):
raw_file, extra_platform_data_file = update_platform_samples
extra_platform_data_file_name = extra_platform_data_file.name
Expand Down