Skip to content

Add regrid mask functionality#1530

Merged
leewujung merged 42 commits intoOSOceanAcoustics:mainfrom
ctuguinay:regrid_mask
Apr 14, 2026
Merged

Add regrid mask functionality#1530
leewujung merged 42 commits intoOSOceanAcoustics:mainfrom
ctuguinay:regrid_mask

Conversation

@ctuguinay
Copy link
Copy Markdown
Collaborator

@ctuguinay ctuguinay commented Aug 13, 2025

This resolves #1516.

The ep.mask.regrid_mask function takes in a xr.DataArray and outputs a xr.DataArray. Regridding is done using flox xarray_reduce and has two aggregation options: logical-OR and strict logical-AND. These aggregations are not native to flox, so implement them, I turned 0/False into NaN and used flox built-in nanmean and mean aggregations.

@ctuguinay ctuguinay changed the title Add regrid mask functionality Add regrid mask functionality [all tests ci] Aug 13, 2025
@ctuguinay ctuguinay self-assigned this Aug 13, 2025
@ctuguinay ctuguinay added enhancement This makes echopype better feature request and removed enhancement This makes echopype better labels Aug 13, 2025
@ctuguinay ctuguinay added this to the v0.10.1 milestone Aug 13, 2025
@ctuguinay ctuguinay linked an issue Aug 13, 2025 that may be closed by this pull request
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Aug 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.73%. Comparing base (6cf6cee) to head (4d0946e).
⚠️ Report is 30 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1530      +/-   ##
==========================================
+ Coverage   85.58%   85.73%   +0.15%     
==========================================
  Files          79       78       -1     
  Lines        6998     7016      +18     
==========================================
+ Hits         5989     6015      +26     
+ Misses       1009     1001       -8     
Flag Coverage Δ
integration 80.92% <92.98%> (+0.29%) ⬆️
unit 60.13% <26.31%> (-0.29%) ⬇️
unittests 85.63% <100.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ctuguinay
Copy link
Copy Markdown
Collaborator Author

ctuguinay commented Aug 14, 2025

TODO: Try looking at using 1/0 with mean and if output strictly 1 and 0 for logical-AND then become 0 and if logical-OR then become 1.

@leewujung leewujung moved this to Backlog in VOTO echopype Sep 7, 2025
@leewujung leewujung removed this from VOTO echopype Sep 7, 2025
@leewujung leewujung moved this to Backlog in VOTO echopype Sep 8, 2025
@ctuguinay ctuguinay marked this pull request as draft September 10, 2025 03:20
@ctuguinay
Copy link
Copy Markdown
Collaborator Author

ctuguinay commented Sep 10, 2025

TODO: Add 2D range variable implementation and refactor the tests to work with it.

@ctuguinay ctuguinay closed this Nov 6, 2025
@ctuguinay ctuguinay reopened this Nov 6, 2025
Comment thread echopype/mask/api.py Outdated
Comment thread echopype/mask/api.py Outdated
Comment thread echopype/mask/api.py Outdated
Comment thread echopype/mask/api.py Outdated
Comment thread echopype/mask/api.py Outdated
Comment thread echopype/mask/api.py Outdated
Comment thread echopype/mask/api.py
Comment thread echopype/mask/api.py Outdated
Comment on lines +797 to +807
mask_regridded_da = xr.DataArray(
data=mask_regridded_da.data,
dims=[third_dim, "ping_time", range_da.name],
coords={
third_dim: mask_da[third_dim].values,
"ping_time": np.array([v.left for v in mask_regridded_da.ping_time_bins.values]),
range_da.name: np.array(
[v.left for v in mask_regridded_da[f"{range_da.name}_bins"].values]
),
},
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and also in the else case below, a new DataArray is constructed by taking the data in mask_regridded_da with new coordinates. I was wondering if it'll be more efficient to just rename the coordinates and update the values. But, looking at the I am not sure in practice if the underlying implementation - but it looks like a new object is created when rename is called anyway, so maybe it doesn't matter. Any thoughts here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree that it's cleaner to just rename and update values. I'll make that change.

Copy link
Copy Markdown
Member

@leewujung leewujung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ctuguinay : Thanks for the PR! I think it's about ready to go - my inline comments are mostly just wording changes.

One thing I think that may be useful is to separate out the tests from test_mask.py to something more descriptive, now that we have so many tests in that module. We should split out the tests for seafloor and swarm detection, but maybe we do that when we know where the functions themselves would go (@LOCEANlloydizard and I were thinking they should probably go somewhere else instead of sitting in echopype.mask.

ctuguinay and others added 15 commits April 13, 2026 13:27
Co-authored-by: Wu-Jung Lee <leewujung@gmail.com>
Co-authored-by: Wu-Jung Lee <leewujung@gmail.com>
Co-authored-by: Wu-Jung Lee <leewujung@gmail.com>
Co-authored-by: Wu-Jung Lee <leewujung@gmail.com>
Co-authored-by: Wu-Jung Lee <leewujung@gmail.com>
Co-authored-by: Wu-Jung Lee <leewujung@gmail.com>
Co-authored-by: Wu-Jung Lee <leewujung@gmail.com>
Co-authored-by: Wu-Jung Lee <leewujung@gmail.com>
…me bin parsing and conversion as own util function, and rename and edit variables instead of creating new data array
leewujung
leewujung previously approved these changes Apr 13, 2026
@leewujung
Copy link
Copy Markdown
Member

Thanks for the changes @ctuguinay! I'll merge this now.

@leewujung leewujung merged commit 41911fc into OSOceanAcoustics:main Apr 14, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done
Status: No status

Development

Successfully merging this pull request may close these issues.

Add functionality for mask regridding

4 participants