Focus curve - clip the flat parts?

I don’t know if something changed with SGP focusing or if I have something set differently but focusing my SCT has been working well:

However, if I am a little off to start with I can get a curve like this:

What it did was then to extend the focus run and keep going inwards. I finally stopped it and told the focuser to go to the lowest point.

Is is possible to have the focus algorithm ignore the flat tails at the top of the graph? It’s otherwise a good focus curve but the tails throw off the slope and the intersection of the lines which I think caused it to keep going.


I too have seen this type of a curve with my SCT and it does seem to screw up the focus.

While I cannot speak for the shape of the A/F curve (I usually screen shot the curve, but have not for the last two nights), I believe my system is suffering from the same problem.

I’m running SGPro 2.4.0 r2260, and this is the first time I’ve noticed this problem. Two nights ago, the first auto-focus at the start of imaging fell out of focus and just kept going further out. I re-established the focuser to where good focus was and had it do another A/F. This time no problems.
Last night, the first A/F looked great. However, it was through the night where the focusing got really strange. There were normal AFpacks, shorted AFpacks, and AFpacks with extra images. Large donuts in some cases.
Interestingly, as bad as some of the AFpacks looked, focusing on the target images did not take a beating and came out reasonaby good. Scary, but no foul.

I’ve DropBoxed the AFpacks and SGPro log from last night.


My intention was not to call this a “problem” but to see if there could possibly be a refinement in how SGP deals with the curve. Jared and Ken have fully admitted that using autofocus in SGP with a long focal length SCT is very difficult. I was able to run all night last night with autofocus working quite well on my SCT though. What I have found is I have to start already focused. I use a Bahtinov mask on a bright star before starting to autofocus. The step size needs to be enough to get a curve but not enough to reach the flat tails. At that point the stars are large circles. If too out of focus, the curve will actually drop again as it starts detecting hot pixels instead of stars.

Since I had a good curve in the middle, I was hoping SGP could somehow ignore the flat parts.



I had the same problems and the same complaints about the new system during closed beta. The solution is to fix how large of an area you’re looking at for your focus points. Jared and Ken’s detection of stars just doesn’t work well when the HFR gets ‘too’ big. The numbers they gave me was find where your HFR is ‘3’ on each side of focus. Get the value between those steps and divide by the number of samples you want (I use 9). That tells you your step size. Make sure you’re roughly in focus when you start.

I haven’t had a single focus malfunction since I went to that method.

Good luck,

well that should be written up in the help manual.


1 Like

Chris, do you mean that if best focus is HFR of 2, we should shoot for max HFR of +3 from there? Meaning 5 on each end of the v-curve?



My HFR values are pretty tight… around 1 to 1.8. For my setup, I use HFR 3. Basically, take it to the step where you see the ‘plateau’ above on each side of focus, then generate your sample sizes from there.

Hope that helps,


For clarity, should I expect to see the plateaus as shown in Chris’ second image? Is this characteristic part of the auto focus properties now?



I’ve heard that method but that formula won’t work with my SCT. If you notice, my HFR never gets down to 3 at it’s lowest point. With my SCT I’ve had to do a lot of trial and error with step size. If I get too far out of focus, it fails completely. I try to keep it out of the flat parts of the curve.


I would do everything you can to avoid getting those plateaus. They can make the focus fail or be less accurate if not completely symmetrical. When it starts to see a flat curve, SGP seems to keep going until the stars are so out of focus it starts to detect hot pixels and the curve drops again. You need to find the correct step size so you stay just below those plateaus when starting from a good focus. That second curve of mine started with a rough eyeball focus only using BYEOS live view. So it was destined to be a bad result. But since the curve in the middle looks just like my good curve I was wondering if the algorithm could be tweaked to use just that. If I start with good focus, I get the first curve every time, step size on my EdgeHD SCT is 80. I’m not using backlash compensation but may try that at some point too.

Chris M (too many Chris’s here!)

Chris (cmassa),
I agree about your minimum being a limit on the strict interpretation of the rule about “3”. If the plateaus show up at 6.8, then you should stay below that level. It’s interesting that for both curves’ min and max stepper count are 17640 and 18720. They both reach the approx. 6.8 HFR at those extensions. Apologies if you’ve already pointed this out.

I agree with your description of how the focus could wander off. I witnessed this two nights ago, and had to manually fix it. And review of the AFpacks from last night make me wonder how that focus ever came back.

My A/F settings for all of 2.3 and 2.4 have been 9 and 100, count and magnitude respectively. But the latest (r2260), run two nights ago, failed at initial startup. I changed the magnitude to 75 last night and still got some flaky looking AFpacks.

So, tonight, I will reduce the magnitude further, say 60, and watch for the plateaus.

Will let the group know how things come out.


This is already done (in 2.4).

As for the original intent of the post…

In terms of accommodating for this, curve analysis that excludes the “wings” is possible, but probably too invasive to be added into 2.4 at this point. So… we are considering 2 options that will likely not be permanent, but should suffice to meet most peoples needs:

  1. Provide an option in AF that forces the algorithm to use a weighted average of the 3 low points (this would effectively ignore the “wings”). Not checking this will use the newer best fit line method.
  2. Since focus runs start pretty close to focus, calculate the weighted average position (as above) and then also calculate the linear regression (best fit) position. Use the one closest to the original focus position. Not sure about this method at sequence start… while it would probably work OK from perfect focus, it might act strangely on initial focus (when you start from an area outside of CFZ). Possibly force use of the weighted average method for run 1 and then do this.

Using linear regression is nice because it allows for use of all of your data (this is crap when some of your data is bad due to central obstruction or other issue). Using the weighted average throws out bad stuff, but it also throws out data that should have valid input into final determination of the focuser’s position.

Other ideas are welcome (Temp ideas… 2.5 will see an overhaul of curve analysis to accommodate for these cases. We are looking for quick and low risk right now).

Thanks for the reply, Ken.

Exactly what I was asking about. I didn’t think it would be easy. Using an SCT certainly increases the chances of “crap” :smile: But lately my curves have been decent and it ran all night last night. The CEM60 even performed well, doing the meridian flip without problem.

Chris M

Hello Ken,
I for myself work on a project which involve precise focus with a step
cfz around 5 micron here, my dev team and image processing guys use at
first intention
a simple SNR evaluation and that works pretty well and efficiently.
maybe a combo between your algo and SNR could lead to something robust…

best regards


I would go for option 1 so that I can go to bed and not worry about monitoring my run to make sure it doesn’t defocus until it hits hot pixels.

This might not be as hard a problem as it appears. If you calculate the slope of the lines between adjacent points the slope of the “flat” areas is going to be significantly different than the U part of the curve. For a perfect U curve, the slope should increase as you move toward the center and then flatten out and change sign as you move back up the curve. For an ideal curve, the slopes should approximate the calculated linear fit slope within some reasonable error. The “flat” areas are also going to be at either end of the curve unless the initial focus is significantly off. Also, note in the second example graph, the intercept minimum is higher than two of the data points. This fact is a strong clue that the calculation is not right. By using these observations, I think you might able to apply some reasonable heuristics to eliminate bad data points at either end of the curve.

Lastly, on my SCT when auto-focus moves to the maximum, I have seen that the operation is already dead in the water because it is trying to do HFR on donuts. Perhaps the order of operations for auto-focus could be rearranged. Currently, it moves the focuser to the maximum position based on the parameters given and then steps toward the center. If however, you moved one step at a time toward the maximum, it would be possible to detect curve flattening and/or donut stars before they get too extreme. (Of course, backlash needs to be considered.) This approach might also permit adjusting the step size on the fly.

I know you guys are being inundated with suggestions and other data (good and bad) but please know that the community out here really appreciates your work.

Thanks for the suggestions. We have made our decision for 2.4 and will work to refactor a more universal curve analysis in version 2.5.

Closing as duplicate. We are looking at several more robust routines. For now, feel free to use the “Scope has central obstruction” option on AF settings (should be less bad).