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

Acoustics SPL bugfix #379

Merged
merged 4 commits into from
Feb 18, 2025
Merged

Conversation

jmcvey3
Copy link
Contributor

@jmcvey3 jmcvey3 commented Feb 12, 2025

Fixes a bug where calculating SPLs in lower frequency bands was failing because the bandwidth resolution was on par with the frequency resolution, i.e. numpy.trapz was failing to calculate the integral because the input was only 1D over frequency. Also expanded testing to cover this particular case.

Copy link
Contributor

@ssolson ssolson left a comment

Choose a reason for hiding this comment

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

@jmcvey3 thanks for submitting this just a couple comments.

Comment on lines 831 to 835
# Interpolate between band frequencies if width is narrow
x = spsd["freq"].sel(freq=slice(*band_range))
if len(x) < 2:
spsd_slc = spsd.interp(freq=band_range)
x = band_range
Copy link
Contributor

Choose a reason for hiding this comment

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

If the dataset is large could this interp lead to performance issues where we would want to warn the user of what was slowing down the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question, I'm not sure.

This if statement should only happen at low frequencies, so in the next commit I'll slice the dataset down before interpolating. Should be faster.

@@ -473,6 +473,44 @@ def _validate_method(
return method_name, method_arg


def _create_frequency_bands(octave, fmin, fmax):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add some input checks?

if not isinstance(octave, int) or octave <= 0:
    raise TypeError("octave must be a positive integer.")
if not isinstance(fmin, int) or not isinstance(fmax, int):
    raise TypeError("fmin and fmax must be integers.")
if fmin <= 0:
    raise ValueError("fmin must be a positive integer greater than zero.")
if fmax <= fmin:
    raise ValueError("fmax must be greater than fmin.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add these because they're already checked in the respective functions that use this one

@jmcvey3 jmcvey3 merged commit 638876d into MHKiT-Software:develop Feb 18, 2025
15 of 16 checks passed
@jmcvey3 jmcvey3 deleted the acoustics-bugfix branch February 18, 2025 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants