PaulHancock / Aegean

The Aegean source finding program and associated tools
http://aegeantools.rtfd.io/
Other
47 stars 14 forks source link

Aegean Exception class #169

Closed tjgalvin closed 2 years ago

tjgalvin commented 2 years ago

I had an instance recently where lmfit was raising exceptions to highlight NaNs in either the data or model output when performing optimisation. It turned out that sometimes during optimisation that parameters were set to NaN as they were passed to the residual function, which in turn generates a model made up of all NaNs. This was a little bit of a pain to track down as aegean correctly masks all NaNs in the data to begin with.

Although one could capture the ValueError raised by lmfit, a ValueError is an awfully broad exception and might be a little painful to test against during the exception handling, I thought the better approach would be to have a class AgeanError class that we can subclass to better handle these strange errors.

In #168 I have made an AegeanNaNModelError that is raised in the residual function if there are any NaNs, and is capture in the non-priorised fitting routine in sourcefinder.py. This, I think, lets us better handle the cases where there are errors we do not care about, and still correctly raise new ones we don't currently know about.

Happy to discuss further