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

Catch runtime errors when smoothing spectra #65

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

krisvanneste
Copy link
Collaborator

Small fix to avoid program ending when a runtime error occurs during smoothing of a spectrum.
I ran into this problem when running sourcespec on > 200 earthquakes.
It should be easy to propagate this fix to v2 as well.

@claudiodsf
Copy link
Member

Hi Kris, thanks for this PR.

One of my future goals is to replace all generic except Exception with specific exception handling. Do you know which kind of exception is raised in this case?

If it is a RuntimeError, I would prefer to handle it as except RuntimeError.

Thanks 😉

@krisvanneste
Copy link
Collaborator Author

Claudio,
It was one of the ValueErrors that can be raised in the smooth() function in ssp_util.py, more specifically:

ValueError('Input vector needs to be bigger than window size.')

If you want, I can try running it again on one of the problematic cases to see if it gets caught with except ValueError.

@claudiodsf
Copy link
Member

Yes, please. In principle, that should work with except ValueError.

The idea behind handling specific errors is to more easily discover unexpected ones when they occur 😉

@krisvanneste
Copy link
Collaborator Author

OK, I will test.

@krisvanneste
Copy link
Collaborator Author

It works, the exception gets caught. Shall I commit or are you going to replace generic exceptions in a separate branch?

@claudiodsf
Copy link
Member

Please commit!

@krisvanneste
Copy link
Collaborator Author

Done!

@claudiodsf claudiodsf merged commit de6e6bb into SeismicSource:main Jan 15, 2025
2 checks passed
@claudiodsf
Copy link
Member

Merged! Also, rebased v2 on this commit 😉

claudiodsf pushed a commit that referenced this pull request Jan 27, 2025
* Catch runtime errors when smoothing spectrum in _build_spectrum function.

* Replaced generic Exception with ValueError when catching smoothing errors in _build_spectrum function.
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