seeing-things/track

Investigate `autofocus` `curve_fit` failures

Opened this issue · 2 comments

autofocus failed on one attempt on 8 March 2023, when other attempts had succeeded on the same evening. Unclear if the star was not in view or if the HFR data was too noisy or what. The first coarse pass seems to have worked, so my best guess is that noisy HFR data tripped it up. Relevant log output copied below.

I've seen this happen a couple times previously as well.

  • Investigate and try to determine root cause.
  • Determine if any adjustments can be made that could give the solver a better chance of succeeding with similar data. Consider solver parameters and spacing and number of HFR samples.
  • Implement a fallback strategy such that the focuser is left at the best position possible given the available information, perhaps the position found during the coarse pass, even if the solver fails.
[2023-03-09 04:16:50.671] [track.autofocus] [INFO] HFR   6.23 pixels at position 2828 (  1 of  20).
[2023-03-09 04:16:51.188] [track.autofocus] [INFO] HFR   5.66 pixels at position 2849 (  2 of  20).
[2023-03-09 04:16:51.693] [track.autofocus] [INFO] HFR   5.66 pixels at position 2870 (  3 of  20).
[2023-03-09 04:16:52.209] [track.autofocus] [INFO] HFR   5.78 pixels at position 2891 (  4 of  20).
[2023-03-09 04:16:52.723] [track.autofocus] [INFO] HFR   5.55 pixels at position 2912 (  5 of  20).
[2023-03-09 04:16:53.226] [track.autofocus] [INFO] HFR   5.44 pixels at position 2933 (  6 of  20).
[2023-03-09 04:16:53.736] [track.autofocus] [INFO] HFR   5.44 pixels at position 2954 (  7 of  20).
[2023-03-09 04:16:54.247] [track.autofocus] [INFO] HFR   5.61 pixels at position 2975 (  8 of  20).
[2023-03-09 04:16:54.748] [track.autofocus] [INFO] HFR   5.49 pixels at position 2996 (  9 of  20).
[2023-03-09 04:16:55.267] [track.autofocus] [INFO] HFR   5.55 pixels at position 3017 ( 10 of  20).
[2023-03-09 04:16:55.769] [track.autofocus] [INFO] HFR   5.21 pixels at position 3038 ( 11 of  20).
[2023-03-09 04:16:56.287] [track.autofocus] [INFO] HFR   5.21 pixels at position 3059 ( 12 of  20).
[2023-03-09 04:16:56.812] [track.autofocus] [INFO] HFR   5.38 pixels at position 3080 ( 13 of  20).
[2023-03-09 04:16:57.332] [track.autofocus] [INFO] HFR   5.21 pixels at position 3101 ( 14 of  20).
[2023-03-09 04:16:57.838] [track.autofocus] [INFO] HFR   5.32 pixels at position 3122 ( 15 of  20).
[2023-03-09 04:16:58.364] [track.autofocus] [INFO] HFR   5.44 pixels at position 3143 ( 16 of  20).
[2023-03-09 04:16:58.878] [track.autofocus] [INFO] HFR   5.55 pixels at position 3164 ( 17 of  20).
[2023-03-09 04:16:59.420] [track.autofocus] [INFO] HFR   5.66 pixels at position 3185 ( 18 of  20).
[2023-03-09 04:16:59.941] [track.autofocus] [INFO] HFR   6.00 pixels at position 3206 ( 19 of  20).
[2023-03-09 04:17:00.556] [track.autofocus] [INFO] HFR   5.95 pixels at position 3228 ( 20 of  20).
[2023-03-09 04:17:00.683] [track.autofocus] [ERROR] curve_fit failed.
Traceback (most recent call last):
  File "/home/rgottula/dev/track/track/autofocus.py", line 165, in estimate_ideal_focuser_position
    popt, _ = curve_fit(
  File "/home/rgottula/dev/venv/lib/python3.10/site-packages/scipy/optimize/_minpack_py.py", line 874, in curve_fit
    raise RuntimeError("Optimal parameters not found: " + res.message)
RuntimeError: Optimal parameters not found: The maximum number of function evaluations is exceeded.

Happened again on 15 March 2023. In this instance I was rushing to catch an ISS pass, but due to this and other issues I missed the pass. Log output from that run may be available.

Happened again on 25 March 2023. I noticed that the variation in the HFR values on the fine sweep was pretty small over the ±200 step range; even at the extreme ends the values were not much different than in the middle. I expanded the range to ±500 steps and was able to run autofocus three or four more times this evening without a problem. Maybe expanding the fine sweep range will be enough to solve the problem in most situations.