Skip to content

Comments

Improve flexibility and robustness of Acoustics Module#433

Merged
jmcvey3 merged 8 commits intoMHKiT-Software:developfrom
jmcvey3:acoustics-options
Feb 20, 2026
Merged

Improve flexibility and robustness of Acoustics Module#433
jmcvey3 merged 8 commits intoMHKiT-Software:developfrom
jmcvey3:acoustics-options

Conversation

@jmcvey3
Copy link
Contributor

@jmcvey3 jmcvey3 commented Jan 21, 2026

There are three main changes in this pull request:

  1. Added the option to determine the number of datapoints in each FFT when creating the sound pressure PSDs. This was currently hardcoded to the maximum FFT length, i.e. the total number of datapoints in each window, which might be more resolution and require more storage space than desired
  2. Changed names of bin and windowing related attributes on the PSDs to make them easier to understand
  3. Gain was improperly added - the sign has been corrected

Minor changes are refactoring some of the argument type checks to clean them up.

@jmcvey3
Copy link
Contributor Author

jmcvey3 commented Jan 21, 2026

Looks like some remaining dependency issues related to timestamps

@jmcvey3 jmcvey3 added enhancement New feature or request Clean Up Improve code consistency and readability acoustics Acoustics Module labels Jan 21, 2026
@akeeste akeeste self-assigned this Feb 3, 2026
@akeeste akeeste self-requested a review February 3, 2026 17:11
Copy link
Contributor

@akeeste akeeste left a comment

Choose a reason for hiding this comment

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

Thanks @jmcvey3! Just two small suggestions on the use of _check_numeric

@simmsa
Copy link
Contributor

simmsa commented Feb 18, 2026

@jmcvey3, from my perspective you are not obligated to have all of the tests passing here to merge this into develop. Do you have any thoughts/preferences here? I'm guessing all of the tests pass locally for you, so let us know what makes sense.

This is likely going to continue to be an issue moving forward with MHKiT, so I wonder if there is better way for the tests to only check "things that matter", and maybe only run pytest on the modules where the code has changed.

It is def appreciated to get the tests working here, but I think this is more of the tests are broken in general vs this PR's tests are not passing...

Happy to take any feedback here also. The actions have a lot of false positives IMO. I like the CI/CD idea in general, but there are also a lot of ways that this impedes actual development, so it seems like we need to find a balance...

@jmcvey3
Copy link
Contributor Author

jmcvey3 commented Feb 18, 2026

Well.... I tracked down the not-pretty bug in the cdip.py file and fixed that since it was a recurring issue.

In the process, I cleaned up the dependencies in the conda environment file, so now hopefully these tests will run faster now that they don't have to install dependencies twice each time. I most likely broke the pip installation because of the h5-related libraries, but we'll see whenever those tests finish.

@jmcvey3
Copy link
Contributor Author

jmcvey3 commented Feb 19, 2026

@jmcvey3, from my perspective you are not obligated to have all of the tests passing here to merge this into develop. Do you have any thoughts/preferences here? I'm guessing all of the tests pass locally for you, so let us know what makes sense.

This is likely going to continue to be an issue moving forward with MHKiT, so I wonder if there is better way for the tests to only check "things that matter", and maybe only run pytest on the modules where the code has changed.

It is def appreciated to get the tests working here, but I think this is more of the tests are broken in general vs this PR's tests are not passing...

Happy to take any feedback here also. The actions have a lot of false positives IMO. I like the CI/CD idea in general, but there are also a lot of ways that this impedes actual development, so it seems like we need to find a balance...

Perhaps, but these have been frustrating for a while now, and I need this PR merged. I'm realizing what I'm running through now may have been why the packaging was difficult for the 1.0 release

@simmsa
Copy link
Contributor

simmsa commented Feb 19, 2026

Perhaps, but these have been frustrating for a while now, and I need this PR merged. I'm realizing what I'm running through now may have been why the packaging was difficult for the 1.0 release.

Do you just need this merged into develop? I think if you are happy with Adam's review and your tests are passing locally it is fine to merge this?

I pulled your branch and all of the tests in the acoustics module pass locally for me in a fresh virtual environment:

 pytest -v mhkit/tests/acoustics
=============================================================================================== test session starts ================================================================================================
platform darwin -- Python 3.11.12, pytest-8.4.2, pluggy-1.6.0 -- /opt/homebrew/opt/python@3.11/bin/python3.11
cachedir: .pytest_cache
benchmark: 5.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /Users/asimms/Desktop/Programming/mcvey_mhkit/MHKiT-Python
configfile: pyproject.toml
plugins: benchmark-5.2.3, cov-6.0.0, anyio-4.11.0, asyncio-0.25.3, nbval-0.11.0, typeguard-4.4.2
asyncio: mode=Mode.STRICT, asyncio_default_fixture_loop_scope=function
collected 18 items

mhkit/tests/acoustics/test_analysis.py::TestAnalysis::test_apply_calibration PASSED                                                                                                                          [  5%]
mhkit/tests/acoustics/test_analysis.py::TestAnalysis::test_averaging PASSED                                                                                                                                  [ 11%]
mhkit/tests/acoustics/test_analysis.py::TestAnalysis::test_fmax_warning PASSED                                                                                                                               [ 16%]
mhkit/tests/acoustics/test_analysis.py::TestAnalysis::test_freq_loss PASSED                                                                                                                                  [ 22%]
mhkit/tests/acoustics/test_analysis.py::TestAnalysis::test_sound_pressure_spectral_density PASSED                                                                                                            [ 27%]
mhkit/tests/acoustics/test_analysis.py::TestAnalysis::test_spsdl PASSED                                                                                                                                      [ 33%]
mhkit/tests/acoustics/test_analysis.py::TestAnalysis::test_validate_method PASSED                                                                                                                            [ 38%]
mhkit/tests/acoustics/test_io.py::TestIO::test_audio_export PASSED                                                                                                                                           [ 44%]
mhkit/tests/acoustics/test_io.py::TestIO::test_calculate_voltage_and_time PASSED                                                                                                                             [ 50%]
mhkit/tests/acoustics/test_io.py::TestIO::test_calibration PASSED                                                                                                                                            [ 55%]
mhkit/tests/acoustics/test_io.py::TestIO::test_read_iclisten PASSED                                                                                                                                          [ 61%]
mhkit/tests/acoustics/test_io.py::TestIO::test_read_iclisten_metadata PASSED                                                                                                                                 [ 66%]
mhkit/tests/acoustics/test_io.py::TestIO::test_read_soundtrap PASSED                                                                                                                                         [ 72%]
mhkit/tests/acoustics/test_io.py::TestIO::test_read_wav_metadata PASSED                                                                                                                                      [ 77%]
mhkit/tests/acoustics/test_metrics.py::TestMetrics::test_nmfs_weighting PASSED                                                                                                                               [ 83%]
mhkit/tests/acoustics/test_metrics.py::TestMetrics::test_sel PASSED                                                                                                                                          [ 88%]
mhkit/tests/acoustics/test_metrics.py::TestMetrics::test_spl PASSED                                                                                                                                          [ 94%]
mhkit/tests/acoustics/test_metrics.py::TestMetrics::test_spl_vs_sel PASSED                                                                                                                                   [100%]

================================================================================================= warnings summary =================================================================================================
mhkit/tests/acoustics/test_analysis.py::TestAnalysis::test_averaging
  /Users/asimms/Desktop/Programming/mcvey_mhkit/MHKiT-Python/mhkit/acoustics/analysis.py:84: UserWarning: `fmax` = 100000 is greater than the Nyquist frequency. Settingfmax = 48000.0
    warnings.warn(

mhkit/tests/acoustics/test_analysis.py::TestAnalysis::test_fmax_warning
  /Users/asimms/Desktop/Programming/mcvey_mhkit/MHKiT-Python/mhkit/acoustics/analysis.py:84: UserWarning: `fmax` = 1500 is greater than the Nyquist frequency. Settingfmax = 1000
    warnings.warn(

mhkit/tests/acoustics/test_io.py::TestIO::test_audio_export
mhkit/tests/acoustics/test_io.py::TestIO::test_read_iclisten
  /Users/asimms/Desktop/Programming/mcvey_mhkit/MHKiT-Python/mhkit/acoustics/io.py:457: UserWarning: no explicit representation of timezones available for np.datetime64
    start_time = np.datetime64(metadata["icrd"])

mhkit/tests/acoustics/test_metrics.py::TestMetrics::test_sel
mhkit/tests/acoustics/test_metrics.py::TestMetrics::test_spl
mhkit/tests/acoustics/test_metrics.py::TestMetrics::test_spl_vs_sel
  /Users/asimms/Desktop/Programming/mcvey_mhkit/MHKiT-Python/mhkit/acoustics/analysis.py:84: UserWarning: `fmax` = 100000 is greater than the Nyquist frequency. Settingfmax = 48000
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================================= 18 passed, 7 warnings in 14.28s ==========================================================================================

What do you think? I don't want to set a bad precedent, but you are not merging this into main, you are merging into develop, and that seems like what the develop branch is for.

My own opinion is that some of the changes you are making in this PR are out of scope. That is fine and I get it, but I think we need to be careful about doing too many things to "appease the tests".

@jmcvey3
Copy link
Contributor Author

jmcvey3 commented Feb 19, 2026

What do you think? I don't want to set a bad precedent, but you are not merging this into main, you are merging into develop, and that seems like what the develop branch is for.

My own opinion is that some of the changes you are making in this PR are out of scope. That is fine and I get it, but I think we need to be careful about doing too many things to "appease the tests".

Sure sure. I can create a new branch and a new PR for these changes and then rebase this PR back to just the acoustics code. I'll redo the "black" commit too so it's just editing the acoustics files as well.

@akeeste
Copy link
Contributor

akeeste commented Feb 19, 2026

I agree with your first comment @simmsa , if the relevant tests are passing I think we should merge PRs as is to get that feature taken care of and then move to fixing the tests. Ideally, we'd do the test fixes first into develop and pull the updates into the feature PR (such as this one)--but none of us have the bandwidth to do so very quickly.

@jmcvey3 For this particular PR, I will support whatever will be most efficient, whether that's merging as is, putting another fix here for the last test, or rebasing the test fixes into a new PR

@jmcvey3
Copy link
Contributor Author

jmcvey3 commented Feb 19, 2026

I agree with your first comment @simmsa , if the relevant tests are passing I think we should merge PRs as is to get that feature taken care of and then move to fixing the tests. Ideally, we'd do the test fixes first into develop and pull the updates into the feature PR (such as this one)--but none of us have the bandwidth to do so very quickly.

@jmcvey3 For this particular PR, I will support whatever will be most efficient, whether that's merging as is, putting another fix here for the last test, or rebasing the test fixes into a new PR

Sounds good. I've rebased here and created a new PR for the other changes

@jmcvey3 jmcvey3 merged commit 6f806c8 into MHKiT-Software:develop Feb 20, 2026
36 of 58 checks passed
@jmcvey3 jmcvey3 deleted the acoustics-options branch February 20, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

acoustics Acoustics Module Clean Up Improve code consistency and readability enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants