QUADRATIC best fit Focus routine TESTING - SEND LOGS

A couple of observations about this data. If you go back to the original FocusMax papers, they found that the slopes of the curve are linear except at the very bottom and that the slopes of each side are not necessarily the same. That would suggest that doing a quadratic fit might not be the best idea because a quadradic curve is not linear on the wings and it is a symmetrical curve. Looking at the samples #1,#6, and #7 it does appear (by eyeball) that if one where to do a better linear fit of the wings, you would also get a better focus result than SGP achieved. I also note that for those three examples, the difference between the S and Q result is not very large (60 steps in one case, 30 for the others). On my setup that difference would be almost identical focus. Thus I don’t find the argument for quadratic fit to be compelling.

It is true that the SGP approach needs some help but I think the effort should be directed toward getting a better linear fit for each side and calculating a “goodness” value to determine if the result is valid. As another poster has suggested, you can calculate the sigma of the HFR values for each exposure and use those values as a weighting factor for a linear fit. Perhaps the sigma value could be used to determine if a particular exposure should be redone.

While using a quadradic fit is tempting, it is not supported by the basic physics of the situation. With the treasure trove of data you are gathering, perhaps you could look for better linear fit algorithms. The SGP approach seems to work well with good data but falls apart with marginal data. Unfortunately, I imagine your data only includes the mean HFR value for each exposure and not the sigma so you won’t be able to test that approach.

The actual step difference given in these examples is not normalized, ie. not meaningful without comparing it to the step increment. In our analysis we are working with the difference as a percentage of the step increment. This 30 or 60 steps might correspond to 300 to 600 steps on your rig. What is your step increment? In the case of my example, my step increment is 30, so the difference is 100% to 200% of the step increment, a really big difference. Definitely significantly worse focus.

Actually a quadratic curve (which is a parabola) rapidly approaches a straight line as you go up the curve. That is why the FocusMax papers refer to straight lines. The lack of symmetry that can occur with our curves is definitely a potential issue that will need to be dealt with. And we can easily deal with it. A straight line approach would have the exact same problem to deal with. One of the reasons we need a lot of sample log files. Can you send us some that are asymmetrical?

The big problem with this approach is demonstrated well by the current SGP implementation. Trying to work with two linear sides involves tricky and arbitrary choices of which points to put in each line. In every example, quadratic does a much better job.

Not true. The basic physics is a parabola. Particularly around the bottom of the curve. What good are your straight lines?

This is a misunderstanding. We have and are using all the data, which is all the focus data points of hfr at each position. We are calculating the full quadratic formula. I am not displaying the rest of the best fit quadratic formula on the graphs because these graphs are the graphs SGP created. I just plotted the only point we need, which is the center best fit position. This shows the improved focus point compared with what SGP now produces. It works perfectly as my examples show. If you doubt it will work as well with your data, and far better than the current routine, send me your logs and we will see.

Quoting from https://focusmax.org/Documents_V4/Statistical%20view%20on%20FocusMax_00.pdf
“Outside focus star diameters vary linearly with the focuser position”

I’m suggesting taking a clue from the actual nature of the data and find better fitting algorithms. The data is not a parabola particularly when the two sides are not the same slope. The fact that there is a small curve at the bottom does not make it a parabola.

In some cases, the SGP algorithm tries to do too much with too little data. Fitting a parabola to the data does not fix the problems with the data. It only gives the illusion of fixing it.

I’ve not used FocusMax but by all accounts it works quite well. Before attempting to focus you have to do a run to determine the slopes of each side of the curve and the delta between the lines intersection and the bottom of the curve. During a focusing run, FocusMax does not have to plot both sides of the curve. It interpolates the result after taking a few points and using the predetermined slopes. FocusMax only uses one bright star for focus which is both a blessing and a curse. A single bright star is subject to less seeing issues and you can do fast subframe exposures, however, it often requires slewing away from the target to a bright star. So my point is FocusMax works quite well using the linear slopes knowledge.

I don’t pretend to know the best way to fix SGP but I am suggesting that fitting a parabola is fighting the nature of the data.

The physics is that the light cone - which is what these plots show - is a hyperbola. I provided references in another thread. But if fitting to a parabola is easier then it won’t do much harm.

The main thing I’d take away from this analysis is that reporting the HFR as zero for images where no stars are detected is not a good idea. Reporting a high HFR or, better, not using that point would be more useful.

The second of the failed example plots doesn’t show anything that can be used to determine focus, one point with a high HFR with the rest showing more or less the same HFR varying apparently randomly.

The last failed graph shows a situation which is part of the problem, the SGP HFR detection falls apart if slightly out of focus. In this case the left hand point should have a HFR of about 9 but it’s 3.2. The first failed graph also shows this where the two zero points should be about 13 and 15.

I think the essential is to detect that the HFR determination is giving bad data and to manage this in a better way.

But what I think is really needed is to be able to get star sizes reliably even when well out of focus. We can see star discs or doughnuts when a long way out of focus so there’s a prospect that a different algorithm could do this.

As for using the variance in HFR as a measure of quality I think that the main influence on HFR will be star brightness. Bright stars will be larger. Experimenting will be needed, is the data on star brightness, HFR and ideally position in the frame for each star available?

DesertSky and Chris,

I think that your comments on the quadratic fit method are out of place here, they would have been much more suitable in the original thread, Proposal of a "Quadratic Fit" Auto Focus evaluation method . Please post your comments regarding the method there, and not here.

The purpose of Jerry’s request is to motivate users who are discontent with the currently used algorithm of finding best focus in SGP to send some logfiles in which the best focus obviously was not found in spite of half-decent focus curves. He would feed the data measured by SGP (i.e. focus position and HFR values of the focus frames and best focus determined by SGP) to our algorithm and send back a detailed report to the sender that contains the result determined by our algorithm. This approach is completely transparent: each sender can get an idea of whether an improvement would be achieved or not.

Jerry did not intend to open a new thread in which the pros and cons of a quadratic fit are discussed in detail.

Therefore I am somewhat disappointed. I think it is a pity if users are deterred from sending logfiles by your comments. The telescopes that are used by SGP users differ strongly (e.g. type, focal length). How shall we be able to test our algorithm without having data that cover the whole spectrum of telescopes?

I want to stress further advantages of our algorithm which Jerry forgot to mention:

  • the recommended AF step size for the quadratic fit algorithm will be reduced most likely (estimated: to 60 - 70 %), so the donut issue will be less severe (important for long focal length),

  • automatical rerun with corrected starting focus position when the first AF run was not performed near best focus (point 5 in the list of tasks of the AF routine; this would profit considerably from the quality criterion).

I hope that the response to this request will increase. I did not expect and cannot understand such reservations about sending logfiles.

Bernd

This and your other points are spot on. Yes, the physics is one arm of a hyperbola, but at our use near the vertex they are very close so fitting to a parabola gives very similar results. Telescopic focus data is not precise enough to show a difference. Proof is presented above. It works, and it works perfectly. What’s not to like?

And our quadratic routine accomplishes this perfectly.

Also and most importantly, it is programmed and ready to go. (Well, it will be if you folks that are complaining about focus not working for you would send me your logs).

I have 1539 focusing runs on my C drive. They are all from an iDK 14.5" and OPTEC TCF-S3i focuser.
I’m one of those that have experienced very few failures of the SGP focusing routine and, when they DO happen, it’s usually because of cloud! So, the overwhelming majority of these runs will be flat out, boring repeats of the better examples already seen here but with min. HFRs of 0.6-0.8. The Focus Log folder runs to 2.86GB! It is at this link: https://www.dropbox.com/sh/pl0el7giz77cbjq/AACsS9YU2Jr4ch44QUlkcVfxa?dl=0

Could you provide that reference again? Thanks

Thanks Terry for sending the focus packs. I unpacked them and you have a lot of fine examples here. Do you have the Log files for those nights? The Log files are what we need because they contain all the data for the focus data points and the resulting best focus value determined by SGP. The focus data points are displayed on the graphs, but we can’t import that data into our program.

Sorry to report that I have no saved log files. Not sure why I
set and then entirely forgot I was saving AF packs in the first
place…

The various discussions about parabolic or hyperbolic curves ignores the fact that these are symmetric curves and that focus curves are known to be, in general, asymmetric. Both the SGP and FocusMax use linear fit algorithms that handle the asymmetry. Anyone doing research in this area would be well advised to take this asymmetry into account and not indiscriminately apply a symmetric curve to the data.

I am, in fact, just today refining our logic to deal effectively with asymmetric curves. Curves that are asymmetrical require an adjustment based on the degree of asymmetry. I can determine that degree of asymmetry and make an effective adjustment. I can do this within the quadratic framework, and will post examples shortly. I have some but not many asymmetric curves to test on, so again, please send Logs, particularly if they have asymmetric curves. Do you have any @DesertSky?

Nope, gave up on SGP focusing a long time ago. A bahtinov mask works just fine and my setup does not seem to be very temperature sensitive.

I’ll be interested to see how you plan to coerce a symmetric curve unto asymmetric data.

Hi Jerry,

good to hear of this new development.

I have sent you one file (the only one currently available) and posted your request and a link to this thread on two Dutch astronomy forums:

http://www.starry-night.nl/forums/topic/sgp-autofocus-logfiles/
https://www.astroforum.nl/forum/astrofotografie/astrofoto-s-deepsky/1425461-sgp-autofocus-logfiles

So hopefully this will result in more data.

Nicolàs

1 Like

Thank you Nicolàs, and all the other folks who have sent me logs directly via email. These are proving very helpful, particularly by providing great examples of problematic curves.

NOTE: when you send me your logs, it is very helpful if you include this data on your rig: telescope type, focal length, pixel scale.

Simply bad curves due to factors like weather are already handled really well by quadratic. They always have a bad R^2 and will trigger a rerun.

The major category of problematic curves is Asymmetric curves, as several folks have mentioned.
Asymmetric curves are of two types:

  1. best focus point is very off center
  2. best focus point is centered, but the wings consistently have very different slopes

A strictly applied quadratic fit will not return optimum values in these cases, because a parabola is symmetric but our data is asymmetric. SGP generally solves 1) by just selecting the low point of the curve, in other words, special treatment.

Quadratic will also need special approaches to effectively handle these special cases. I have come up with elegant approaches to accomplish this, and I am now in the process of implementing these. I would guess a couple of days at the most. After which I will be sending results to the folks who have sent me logs.

Hi Jerry,
my rig consists of a SkyWatcher Esprit 150ED of 1050 focal length and a ZWO ASI1600MM Cool with a pixel size of 3.8micron and 0.74". The focuser has a home-made 1:16 geared planetary drive.

Nicolàs

@jmacon

Its great to see your work on improving the algorithm to better fit the HFR data points but we need to keep in mind that the best algorithm in the world still relies on the quality of the underlying data it is trying to fit. The varied shapes of the HFR plots clearly show how difficult it is to scan a pixel array to identify stars, calculate accurate HFRs, discard blobs of nebulosity, eliminate backgrounds and ignore hot pixels. Then its necessary to analyze the resulting data set to come up with an accurate HFR value that truly represents the entire image. It is my personal opinion that what Ken and Jared have accomplished is pretty impressive. So, it might be equally important to work on an algorithm that can do a better job of producing those initial HFR calculations.

Charlie

@jmacon
I did some searching on the internet for asymmetric parabolas and the best idea I found was joining two curves at some inflection point. That sparked an idea that you might apply to your data sets. It’s likely that each side of the focus curve can be fit to a parabola just not necessarily the same one. It’s pretty easy to determine the minimum point and bifurcate the data and do separate curve fits with each side. You would then have two minimum points would you would need to resolve to a single minimum. There might be some fit test you could apply to decide whether the best fit is one or two curves.

As @chasmiller46 points out, curve fitting is probably the least of the problems. If a data set is robust, linear fit seem to work just fine. Using a more advance fitting algorithm is not going to fix bad data.

www.mainsequencesoftware.com