-
-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map out parameter choices where EPSFBuilder fails, document it clearly, and give heuristic warnings #960
Comments
Thanks for the summary, @eteq. I have started looking into this in more quantitative detail, using @larrybradley's notebook as the foundation. So far I have extended my parameter space to several Gaussian sigma values (0.5, 1, and 3 pixels, which hopefully represent roughly under, critically, and oversampled PSFs), and different inputs for So far Re: my previous comment about why the residuals change 'magically fix' things... It turns out there are two-fold easy changes that can be made: the first is the assignment of star samplings to residual grid points. Currently, the assigning of a star sample to a residual (star normalised flux minus ePSF evaluated at its x, y, to then be sigma-clipped and the mean added to the ePSF grid data points) is done on a nearest neighbour scheme, via I will also follow this up with more rigorous testing, but it appears that it is the total number of iterations that matter (i.e., However, in terms of preliminary guesses as to what causes failures at "random":
|
(See the bottom of this long post for questions I would like clarifications to; everything before that is mostly context, details, and record keeping) My test suite now is a bit more complex, but also set up to more or less probe any of these issues in any combination now. I hadn't bothered reporting back on any intermediate steps until I was reasonably convinced of where the issue could lie, and now I've kinda hit a dead end. For context, I am running I have run a bunch of combinations of star density, dither patterns (needing a relatively sensible pattern to ensure that my fake WCSs make sense and are easily createable), and PSF size, but for this update I mostly am focusing on a pretty hard case: 1 star per square oversampling (so an average of 1 sampling per ePSF grid point), no dithers (or a dither of 1x1...), and a Gaussian PSF with The things to vary, which are different between the original, non-normalised-but-non-blowing-up v0.6 code and the new, normalised-but-sometimes-falls-over v0.7 code:
This produces 5 unique tests, rather than 8, as the 'update the samplings' recenter method doesn't actually do anything on the final update-and-smooth inner loop, as you go immediately into star fitting which updates the positions anyway, removing 1 combination; and option (3) doesn't, as far as I have understood it, really make any sense (at least without serious code overhaul) for the 'update the samplings' recentering, removing from the combinations cases where the recentering would be done by sampling shift. We thus have: For each dataset/algorithm combination, we can also test how much poor initial positions change things by initially updating the star For tests 1+2, with the iterative centroiding, the final recentering doesn't matter too much, although not including it gives slightly worse residuals (except when Tests 3+4: for the same tests, except without the 'random walk' to a fully centered ePSF during the residual-subtract-smooth loop, the results are worse than the v0.6 case (with a small fraction of the tests producing horrible ePSFs, and occasionally producing the banding pattern seen previously). Whether the final recentering is better or not is unclear, but Test 5: changing the recentering to the case where the samples are shifted avoids any major 'blow up' issues, but the ePSFs seem to sometimes be offset slightly (i.e., the residuals are positive on one side and negative on the other). This could be a simple code error on my part, since this was a new addition to the test after combing AK00 for any details that I may have missed previously. Other than that, this gives residual values of the order those of the v0.6 code version. Given what a terrible set up this test is (randomly placed low number of stars, no dither, small PSF relative to pixel size, plus a, hopefully, "healthy" amount of image noise) it would seem that the issue could most likely be the recentering. It appears the current version is a 'halfway house' of two algorithms that work, unfortunately. The v0.6 code option which iterates (either a 2nd or 3rd loop, depending on if you still include I guess the question now (for those who are still with me) is one of how closely this code should actually follow AK00. The 'inner loop' of residual fitting, smoothing, and centering is from the original paper, but in the WFC3 ISR it appears that this loop is dropped, and for each outer loop star average positions are computed (to remove pixel phase from the undersampled images, etc.), one iteration of residuals -> smoothing -> centering is performed, and then the stars are fit with the new ePSF (and repeat). This more closely agrees with the v0.6 version (plus the, then second, inner loop of 'random walks' to fit the centroid, which is different than the ISR's small steps of shifts & compute asymmetry criterion, but could spiritually be similar). Thus the old v0.6 code had split from its cited paper, and perhaps I without realising this, naively putting the algorithm back as close as possible to its quoted reference without making too large a code upheaval, undid some changes that were made for some reasons. Thus my questions now are: START HERE FOR CLARIFICATION QUESTIONS
In summary: I now have too many fitting combinations which seem to produce decent ePSFs (well, good under the circumstances) for a rubbish dataset (no dithers, 16 stars, random placings, noise in the image), but am now slightly confused on details between different versions of the ePSF fitting algorithm in the literature and would appreciate some clarifications from people (I'm guessing @larrybradley and @eteq, possibly Jay) who were involved in the v0.6 code writing to correct what could just be a half-and-half mix of two apparently incompatible algorithm flows. If the WFC3 ISR represents an update to the algorithm overall (and certainly with hindsight a single centroiding shift acceptance seems a little silly given that we don't blindly trust the centroids of the star positions in the first place) then I'll just put the recentering part of the code back to its v0.6 state (single loop, iterate over centroid position), but if it's worth looking at the sampling shift within an inner residual loop I can continue to work on that too. If the |
After a quick chat to @eteq it appears this is a case of missing history of the code project resulting in some unforeseen bugs that got past review. I reduced the number of recentering combinations to 3 by assuming that PSF evaluation recenterings should always have a final recenter (because it doesn't make much sense that they don't, unlike the sampling shift recenter), which reduced the test to evaluation+iterative centroid, evaluation+single centroid, and sampling shift loop. Assuming that the sampling shift loop (the (1) loop in AK00 Figure 8) is itself a form of recentering refinement, similarities then become fairly obvious between the two algorithms. Thus, following @eteq's information that the changes to the loop structure came from Jay I can therefore only assume that the ISR is (obviously) an update to the algorithm; I therefore will put the The current metrics are still fairly useful for 'goodness of fit vs input parameter' studies so I'll keep going with the tests and condense the information into some more easily digestible forms (currently just a load of residual plots near one another...). There just remains the issue of the centroiding algorithm itself. The v0.6 code just used To summarise again: with hindsight and context, it appears I did indeed halfway code between two algorithms, producing unexpected results; I will therefore concede to the newer algorithm and change the recentering to closer match that flow. I will continue to test the precision/accuracy of the fits for test Gaussians as well. |
This is the follow-on issue I promised in #951 (comment)
One of the results to come out of that was that, regardless of whether there's an actual bug in the algorithm, more guidance needs to be available to users about how to set the parameters, how many PSF stars there need to be, etc. So to rectify this (and provide concrete answers to some of the speculation mentioned in #951), I propose the following experiment:
Build a notebook that builds a dataset that's a cross between the existing example and @larrybradley's example from #951 (https://nbviewer.jupyter.org/gist/larrybradley/57371f860741e7d0189a48e085b32e63). That is, it would do something like this:
Use a relatively small image/set of stars for reasonable speed i.e. more like @larrybradley's example than what's in the docs, using a gaussian PSF (to make "truth" easier) but also with a background w/noise and not be right on the pixel grid, to make it slightly more realistic. Then try building the psf varying all of these parameters:
For each of the various cases, build the psf and then compare the result to the true PSF. Once we have that, we will have actual data-driven answers to the assertions in #951. Then with that in hand, the notebook can be translated into a sphinx document (
nbconvert
is helpful here), which we will add to thephotutils
docs (and implicitly then also the tests).With that documentation available, we can add some heuristic checks to the top of the psf builder that raise warnings when some of the "danger zones" are met. E.g.:
That then leads the user to something helpful while still warning them that it probably isn't going to work out for their particular dataset.
The text was updated successfully, but these errors were encountered: