Auto Focus uses bogus data points

Under most circumstances, the auto focus routine does a great job focusing.
There are, however, circumstances when it fails to find focus, and this can easily result in the entire remainder of the night being lost with all images out of focus.

Some, what I think should be easy, fixes can mostly prevent these failures.

The circumstances I frequently run into that can trigger these failures are:
—intermittent clouds
—focusing with narrow band filters

I have a 12" newtonian and a 5" refractor. Both give absolutely perfect V shaped curves with clear weather and LRGB filters. However, with either clouds or NB filters, the following sequence of curves is very common.
This sequence occured last night with clear weather, and a NB filter was being focused.

These were 4 sequential focus runs on my AG12 imaging Newtonian. The first one followed 7 other perfect focus runs. Starting with the next focus run, all focus runs for the remaining 8 hours were badly out of focus. Focus was never restored. Same for the piggy backed SV NP127is 5 inch refractor.

0 0 0 0
The first image is typical of the first 7 focuses of the night. The following ones were the next 3 focus runs, all images taken on all three badly out of focus. The good focus runs were the first 4 hours, followed by 8 hours of out of focus images.

The option for “Disable smart focus” was CHECKED for both scopes. I have tried both checked and unchecked for this option in an effort to prevent this behavior, and neither one solves the problem.

What is clearly happening in images 2, 3, and 4 is that the focus routine is accepting a value of 0 as a legitimate data point, when it should clearly be ignored. Accepting the 0 data points causes the routine to shift the range out of the valid focus range. Forever after it can never find focus.

Unchecking “Disable smart focus” sometimes allows focus to be reestablished, but not always. It has a particular problem with clouds causing completely random data points, which it happily considers legitimate and comes up with a fairly arbitrary new focus point. Example follows:

I would love to see the focus routine follow the medical motto of “do no harm”. I have lobbied for years for the focus routine to incorporate some simple standard of evaluating the quality of the focus curve, and just doing nothing if the quality is not satisfactory. It could even perform a rerun x times to hopefully achieve a satisfactory run. A simple version of a quality metric could be the sum of the deviations of the data points from the least square fit lines on each side. Ignoring data points of 0 and/or ignoring the entire run if there are some inner 0 data points would be very easy.

If fixes are made to the focus routine, it would also be a good idea to try to solve the focus failures that many folks encounter with long focal length scopes and large central image features. This has not been a problem for me. A possible easy solution to this one is to only consider the smaller stars in any calculation.

Another problem I have noticed with the routine is that it does not use the same set of stars in all the images. The more it does this, the less valid the data points. I think this is only significant if there are very few stars in the image, ie. smaller fields of view, or star poor regions.

Focus files:


Using the same strategy as autoguiding, where SGpro uses PHD2 for this, it would be great if SGpro could use FocusMax (FM). FM uses a pre-defined V curve for the optical system and then samples a given star(s) to establish the focus. In other words, the shape of the V curve does not change with weather as it is only determined by the optical system, which has not changed. The focus is just this V curve sliding up or down the scale and samples are used to determine where this is. FM is fast and is not affected by weather as much as other algorithms.

It would be too much to expect the guys at SGPro to write their own version of this algorithm, but like autoguiding, it would be nice if SGPro could talk to FM. Yes, it would be additional cost, but at least we would get better focusing, especially for telescopes that have a central obstruction.

I have compared SGPro focusing many times with my copy of FM and like you say, when the sky is settled and clear I get good agreement between them. But when there are weather changes and even some random events I have not been able to determine why, FM almost always gives the correct focus.


I’m not sure that this would entirely fix things. Apart from the previous decision to not implement a FM-like routine, FM still needs a few data points to work. These too can be interrupted by clouds.

If however a V / U curve can be recognized by humans, it may also be recognized by a computer and modeled with a quadratic or cubic equation (I think I shared one a few years ago). With a model, it could then determine if the points were a good fit or not and using correlation coefficients, decide to abort/retry or discard some points. Far more advanced modeling and rejection occurs with things like TPoint.

Standing back from the problem, we have to be realistic on how much imaging we can get done with intermittent clouds too.

Interesting thread as my main issue with this kind of focus issue has been when trying to focus on a Globular Cluster. I would love to see an improved system.
My two thoughts about this post are: as Buzz suggests, imaging when there is cloud around is ‘a waste of time’, the data generated for the target is not going to be good, so autofocus isn’t even needed until the clouds pass! See future release of ‘restart on safe again’ functionality.
Secondly, I agree that focus with narrowband filters can be nigh on impossible, especially in star poor fields of view. The solution is to use focus offsets - focus with the luminance filter and adjust by the predetermined amount for the actual filter to be used. Works a treat if you take time and care to work out the offset value.
Clear skies!

@Buzz I think you are missing the real point here.

My 8 hours of lost imaging was on a perfectly clear night. Once focus was lost, it never recovered for the rest of the night.

What is so frustrating is that with very minor tweaks to the focus algorithm, it would have given me perfect focus for the entire night. And I generally have good focus results with NB filters. This type of failure happens with LRGB filters too.

@PhotoGav you are so right about using focus offsets. I have tried them extensively over the past several months and for the moment have abandoned them because of serious bugs using them, i.e. they don’t always work correctly, such as at times adding the backlash then not subtracting it. I will post another thread detailing those failures.

Oh I see - in which case it would be helpful to have an equivalent to the ‘guider star lost’ notification so at least we can intervene. It should be possible to measure the goodness of the V-curve fit and decide whether to proceed without changing the focus position until next time. Thinking about it, I have had the same issue, where a single rogue AF routine messed up the entire night. I have temperature triggers for AF, but the night was stable within 1C.
I limited my problem by introducing a second AF trigger based on exposure count. Any issues are short lived.

I use focus offsets, focusing only with Lum filters. I set up the offsets with a Goldfocus mask and have never looked back. I started using SGP backlash controls, which worked just fine. I occasionally use TSX for T-Point modelling but as TSX does not implement a simple backlash control for ASCOM focusers, I disabled the backlash control in SGP and asked my focus module supplier to pop the backlash feature into the firmware. It just works.

There are good arguments for working on “error detection” in the SGP auto focus routine. There is also merit in SGP being able to interface with the very advanced algorithms of Focus Max since, once setup (not trivial), FM can provide much faster focusing than the current SGP routines.

Being notified that the just completed AF run failed to produce acceptable results (user defined) would be a good first step. I would rather be awakened at 3AM than to loose the rest of the night. But how often do clouds ruin a run only to disappear an hour later? Automation is a bottomless pit of needs.

I image with both a fast APO and a 12" f/8 Meade ACF and the current AF routines always seem to do a good job with these scopes. @jmacon – perhaps some more twiddling with the AF parameters could help SGP not “go out of range” and produce such strange results. However, I also see the AF routines not work as well when seeing is marginal but perhaps that is just a fact of life.


One other point – if SGP becomes integrated with FM, then the two software packages will need to be able to share the interface with the same imaging camera. I believe this could be done if the camera has a robust ASCOM interface but many cameras don’t.


I wish this worked reliably. My additional regular focus runs for the rest of the night failed to restore good focus. So I was doing the equivalent of what you suggest here, to no avail. Once it is out of valid focus range, it never returns.
I must get to the bottom of why the offsets fail for me. That seems to be my only option.

Here is a link to an article providing a detailed description of a focusing algorithm similar to what FocusMax uses:

In my case, the central obstruction limitation of the SGPro focusing algorithm results in a narrow V curve range resulting in reduced accuracy and miscalculations. The algorithm above is tolerant of the central obstruction as shown in the article. The algorithm described in the paper does requires a V curve defined for the optical system before commencing autofocusing, but this is done only once and takes only a few minutes.


I just received a note from Steve at CCDware about adding SGPro support to FocusMax. He wrote that they reached out to the SGP team over a week ago and no response thus far. So it looks like the team at CCDware would like to work with SGP guys.


I don’t have anything from them so maybe it got lost in a tube somewhere. Sounds like you have a contact there. Feel free to forward along the following email which will get directly to us

We’ll take the other points into consideration. Auto focus is one of those things we’re pretty much always tweaking.


The linear fit result needs have to opposite slopes that are similar.

Why not fix this ?

I would love to see improvement in the SGP AF routine. Support for external options, but also improvements to the internal options, additional outlier checks to determine if a run was bad, the ability to re-try a run in the event of issues like those presented in the original post. I wonder if it would be possible to acquire multiple samples per focus step for improved measurement, and to help detect and reject outlier samples.

I have been having a really tough time with AF in SGP lately, and it is mostly because of the kind of issues shown in the original post here. I have spent quite a lot of time modeling my backlash and it is modeled very accurately now, but there are often strange readings during the AF routine, or two reads that are exactly the same when they should not be (you can see the stars tighten up, but the HFD remains the same)…or very noisy reads (like the last example in the OP) which just throw things all out of whack.

SGP’s AF really needs some love! :sparkling_heart:

1 Like

In my posts above I mentioned that I could not use the “Auto adjust focus per filter” which would allow me to auto focus only L and use this feature to apply the offsets for the other filters. This hopefully will make a big improvement in my auto focus reliability.

The reason I cannot use it is because if you are using a backlash setting, there are frequent conditions (at least for me) under which the backlash amount is applied but not removed, causing all filter positions from that point forward to be high by the backlash amount. Hopefully this will get fixed soon.

I have documented this behavior in another thread. See “Auto adjust focus per filter - fails to work”.

+1 for supporting external options. Similarly some folks would prefer sub frame focusing where they can select an ROI, or have one auto selected. With the smaller ROI doing multiple samples per point becomes easier and faster.

I set up my offsets using @focus3 in Sky X and copied those over to SGP. Working great and using the L filter for focusing everything is much faster, although could still improve based on comments already made in this thread.

I use focus offsets myself. It does not appear to have any impact on the overall unreliability of the AF routine itself. I have also found that focus offsets and backlash compensation adjustments do not seem to be consistent with temperature with some scopes, and SGP offers no way to handle that. An offset that may work during summer may not work during spring/fall or winter.

I have found that focusing with L is indeed faster. I have tried to reduce the ROI that the focus routine uses to just the central 30% of the frame, however it also appears as though SGP always downloads the full frame regardless, and does not seem capable of using hardware ROI features to actually speed up the download of the focus frames.

It would be really nice if SGP could use hardware ROI to download smaller portions of the sensor for focus, perform multiple sample readings per focus step (to help it reject outlier or just downright bad samples), and perform some more in-depth analysis of the slopes generated by the AF routine. It would also be nice if the chosen focus point is suspect after an AF run, SGP could be configured to automatically retry a configurable number of times. That should help to improve the speed and reliability of the AF process, which is desperately needed.

Of all the features of SGP, most of which I think are fine, I spend most of my time fighting with focus. It is my most loathed feature of the program. Really wish it would get some attention.


I so totally agree!