Skip to content

Refactor DOLfYN PSD Scripts to use Scipy.Signal.Welch#452

Open
jmcvey3 wants to merge 45 commits into
MHKiT-Software:developfrom
jmcvey3:pwelch
Open

Refactor DOLfYN PSD Scripts to use Scipy.Signal.Welch#452
jmcvey3 wants to merge 45 commits into
MHKiT-Software:developfrom
jmcvey3:pwelch

Conversation

@jmcvey3

@jmcvey3 jmcvey3 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Big refactor I'd been intending to finish for a while.

This refactor solves a DOLfYN structural problem between its binning architecture and the traditional sliding-window architecture of Welch's algorithm. Because DOLfYN was using slices of bins to compute each PSD segment, it was impossible to ensure data overlap between one bin and the next, meaning the industry-standard 50% overlap cannot be accomplished. This PR removes the bin structure from the PSD computation and ensures overlap using a "step" argument, which is also now built into the bin structure to properly average dimensions for the PSD.

In doing this, DOLfYN's custom PSD code, which was a custom implementation of Welch's algorithm without the ability to overlap FFT segments, has been replaced with scipy.signal.welch. This has one breaking change, in that NaN's are no longer tolerated in the PSD calculation.

To avoid breaking changes, the DOLfYN code will default to an overlap of 0%. This ensures array shapes will remain the same. On the other hand, since it's new, the Acoustics module will default to 50%.

The second breaking change is that the PSD code now renames the input time dimension to "time_psd". In this way, if a different overlap is used, and the PSD is saved into dataset with an averaged "time" dimension, the PSD will not follow the xarray default and go to nan.

Finally, I removed the float32 datatypes in certain functions since sometimes we do need float64 precision. Removing custom code means fft.py no longer exists, and tools/misc.py was renamed to tools.py

jmcvey3 added 30 commits May 29, 2026 14:41
…y vector weighting for calculating band-averaged SPLs
…ed, fix missing step input, set acoustics default to use 50% overlap
jmcvey3 added 3 commits July 1, 2026 11:05
…ons to interpolate to the same timestamps (this does intro nan's, unlike previously when assuming timestamps were the same)
…d time size is the same as the other variables
@jmcvey3 jmcvey3 requested review from akeeste and simmsa July 1, 2026 18:35
@jmcvey3 jmcvey3 added bug Something isn't working dolfyn module acoustics Acoustics Module labels Jul 1, 2026
@jmcvey3

jmcvey3 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Apologies for a mess of repeat commits from a previous PR, and I'll update the tests when I have another moment

@akeeste akeeste left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @jmcvey3 . A couple minor comments and one question around the ADCP_example.ipynb

Comment thread mhkit/tests/dolfyn/test_analysis.py
Comment thread mhkit/dolfyn/binned.py Outdated
Comment thread mhkit/dolfyn/binned.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are a lot of changes to this file here and in #448 but I don't see any conflicts. Are these changes merged together to include the plots from the MATLAB notebook that @browniea added in #448?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh shoot no I think those got lost

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

K, that notebook is updated based on 448

@jmcvey3

jmcvey3 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Okay, @akeeste @simmsa, I believe this is completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

acoustics Acoustics Module bug Something isn't working dolfyn module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants