Focus routine needs QUALITY control factor

Issue #557 resolved
Jerry Macon created an issue

I have serious issues with the focus routine. I am a 6+ year user of SGP which has improved lots in the last year. I wrote the new quadratic focus routine in SGP. The hyperbolic in NINA is superior and works great and focusing is 2x faster than in SGP because of NINA's fast image processing. The biggest problem with focusing in NINA is lack of quality control. The 25% rule for accepting a focus run and moving focuser to that pos works fine in good conditions, a disaster if clouds/wind come in. It will accept a run that looks and is terrible as long as the 25% is satisfied. Last night I started with perfect focus on both scopes, clouds came for a short time then went, one focuser went from perfect focus at 17700 and ended the night at 23000, no good images. We need a quality control factor, which SGP has. Also great would be use of intercept/slope with a maximum allowable deviation. That would prevent the focuser from ever deviating significantly from good focus.

Comments (11)

  1. Yannick Dutertre

    Could you detail the logic you are thinking about for that quality control factor? E.g. what it would do and how it would work? Same for the intercept/slope logic.

    For your particular session, it is weird that it would have moved so much (assuming “small” step sizes), as AF abandons after significant HFR differences cannot be found for more than x steps (unless there is a bug). Have you tried checking the JSON files related to the AF runs to try and see what happened (you can drag and drop them to the NINA Discord channel to check them)?

  2. Jerry Macon reporter

    Here is an example of NINA focus with completely random results (clouds) which just happened to meet the 25% rule. The quality control factor I implemented in SGP computes a least squares fit for the run (LSF). This will range from 0 to 100% and SGP assigns a required minimum of 90% to accept the run. The user can set any value, I set mine at 95% because almost all my runs on both scopes return an average of 99%, which is common for good equipment and clear weather. My quadratic fit algorithm throws away one bad data point, if there is one, then uses the remaining data points to compute the LSF. It is working perfectly, very effective.

    I have tried for years to get SGP to implement what I will call a linear focus plot validation routine. (Linear Focus Formula?) Most scope/camera setups will follow a very linear plot relating temperature with focus position. This may not be true for portable rigs but generally is for fixed. Attached shows the plots for my Televue NP127is with attached ASI183mm. All filters are shown, and from the plots it is easy to calculate the filter offsets relative to L. This makes possible to use the best focusing approach of only focusing on L, then NINA applies the correct offset for the other filters. This is working great with NINA. The focus plot for each filter has an intercept on the vertical POSITION axis at T=0, and a slope, which is the position change for each degree of T change. Example for my UK AG12/ASI183mm: Intercept = 17469, Slope = -67.5. NINA would require 3 values from user: Intercept, Slope, MaximumDeviation. MaximumDeviation would be the maximum number of steps off the calculated focus position that NINA would ever move the focuser to for a focus end result. Obviously the focuser would likely be moved far outside this range on the wings of the focus run. Couple this with the Quality Control Factor and you would never have a bad focus result, regardless of weather.

    The Linear Focus Formula would only be provided for a single filter, most likely the L. The formula looks like this: POSITION = INTERCEPT + SLOPE * T

    An added benefit of implementing this feature is NINA can then set the starting focus position at the beginning of a night’s imaging session using the formula.

  3. Jerry Macon reporter

    Notes on FocusFilterOffsets plot: This plot is produced by a program written by Mikael Afzelius mtafzelius@gmail.com which reads the SGP log files which contain all the focus run details. We should try to get Mikael to write a version for NINA. It is sooo nice!

    Calculating filter offsets is easy when you have this plot. Choose a temperature near the middle of the night’s temperature range, calculate the POSITION for each filter at that same T value, then calculate the differences. It is best to take as many focus runs during a single night as possible using all filters. However, with well behaved equipment you can merge many nights of focus runs. My example plot is from one night.

    Attached are examples of SGP focus runs with different Quality factors.

  4. Dale Ghent

    The JSON files, 1 generated for each focus run, are the exact values on the curve that were found by NINA. You can find them in %LOCALAPPDATA%\NINA\AutoFocus. If you drag and drop one of them into the NINA Discord chat, we have a bot that will take it and automatically reconstruct the graph for you.

  5. Jerry Macon reporter

    This zip contains all the JSON files for my TV NP127is that went from a starting good focus around 17000 and ended up at 23000 at the end of the night. It gradually worked its way up there over the course of the evening. I have posted a start and finish on Discord General.

  6. Jerry Macon reporter

    My actual quality control factor is the R value for the quadratic fit function. I think it better to use R and not R^2 because R is more sensitive, not being squared.

  7. Log in to comment