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 this example request 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.
Coverage decreased (-0.03%) to 83.474% when pulling 654fb20e17af8038d707922017639be514968d89 on tjgalvin:exceptions into 60bf55afc56f002d4d6ad82bc2fadc9ad48bb2ed on PaulHancock:main.
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 asaegean
correctly masks all NaNs in the data to begin with.Although one could capture the
ValueError
raised bylmfit
, aValueError
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 classAgeanError
class that we can subclass to better handle these strange errors.In this example request 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 insourcefinder.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.