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

Bug fixes to snr module and related C++ code #598

Merged
merged 6 commits into from
Jan 23, 2025
Merged

Bug fixes to snr module and related C++ code #598

merged 6 commits into from
Jan 23, 2025

Conversation

pavlis
Copy link
Collaborator

@pavlis pavlis commented Jan 19, 2025

This branch implements bug fixes I found in more extensive testing of the snr module function broadband_snr_QC with more marginal signal to noise ratio data. Testing uncovered a few problems this branch fixes:

  1. broadband_snr_QC was aborting with some kinds of invalid returns from the EstimateBandwidth function. I added some error handlers in both functions that seem to resolve that problem.
  2. There was problem in the MTPowerSpectrum engine C++ code in handling the situation where it was given an array of all 0s. It has a small section of code that normalizes the spectrum level to match the input using Parseval' theorem (a standard time series analysis formula). Problem was it returned a NaN with the algorithm used because the L2 norm of both the data and spectrum were zero and the normalzation uses a ratio of the two. Resolved by trapping the all 0 condition and not trying to do scaling in that situation.
  3. There was an older bug in the C++ code I had worked around in the srn module earlier. The BandwidthData class has a bandwidth method that would return an NaN in certain error conditions that needed to be trapped (e.g. invalid input with the low frequency corner greater than the high frequency corner). This revision should resolve that bug.

I haven't run testing on this because the changes to the C++ code could conceivably have broader impacts, but I don't really think so. I'm going to see if the github push works here. If it does we should merge this commit after I also do some tidying of snr.py with black.

@pavlis
Copy link
Collaborator Author

pavlis commented Jan 19, 2025

@wangyinz looks like this runs clean. Assuming black didn't do something weird the tests should again pass. I would urge you to quickly review what I did and merge this branch once you have a feel for what I did.

@pavlis
Copy link
Collaborator Author

pavlis commented Jan 19, 2025

@wangyinz one other detail. I intentionally left some debug scaffolding in snr.py. It is commented out here. I might need to quickly resurrect the debugging stuff if I something else goes wrong so don't worry about that for now. Help me remember to clear it out, however, when I finish this current round of testing with a full up extended usarray data set.

Copy link

codecov bot commented Jan 19, 2025

Codecov Report

Attention: Patch coverage is 57.57576% with 14 lines in your changes missing coverage. Please review.

Project coverage is 58.70%. Comparing base (68d5410) to head (e628ea8).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
python/mspasspy/algorithms/snr.py 59.25% 11 Missing ⚠️
cxx/include/mspass/algorithms/amplitudes.h 0.00% 2 Missing ⚠️
.../algorithms/deconvolution/MTPowerSpectrumEngine.cc 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #598      +/-   ##
==========================================
+ Coverage   58.66%   58.70%   +0.03%     
==========================================
  Files         156      156              
  Lines       25392    25419      +27     
  Branches     1518     1519       +1     
==========================================
+ Hits        14897    14921      +24     
- Misses      10028    10031       +3     
  Partials      467      467              

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

@pavlis
Copy link
Collaborator Author

pavlis commented Jan 19, 2025

I don't know why codecov complained on this last push and not the one before is a mystery. snr.py actually needs a lot of work to improve the pytest module and these are picky compared to the bigger sections not being currently covered. @wangyinz let me know how you want to resolve this.

@wangyinz wangyinz merged commit e19b122 into master Jan 23, 2025
11 of 12 checks passed
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