Author Topic: PSFEstimation script  (Read 63836 times)

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
PSFEstimation script
« on: 2012 March 17 18:07:15 »
I'd like to share a new script. Something like this may already exist, but I am new to PI and easily may have missed it.

PSFEstimation provides a simple way to estimate the point spread function (PSF) and other parameters of a target image.

Stars are detected automatically by StarAlignment's star detector. You can specify parameters to that process. The script generates a map of detected stars so you can double check your settings. The script then applies the DynamicPSF process to the detected stars and reports the medians and median deviations of the results.

In contrast to running DynamicPSF manually, you loose the ability to be selective in your choice of stars to fit, but you gain the ability to quickly analyze subexposures, calibrations, registrations and integrations.

Strictly speaking, the script should only be applied to linear images. But it does seem to provide some useful information for nonlinear images as well. RGB images are converted to Grayscale prior to PSF estimation.

When you click OK, the script runs its process and then opens a second dialog with the results, and optionally an additional window with visualizations. The result fields have tool tips that provide helpful information.

Comments welcome.

The script dialog.



Results dialog.



Visualization (generated when the Mosaic size parameter is 3 or larger):



Thanks,
Mike

Known bugs:
- Due to a previously reported issue, StarAlignment will abort PSFEstimation if it finds no stars. After clicking OK to dismiss the error dialog, try again with more permissive star detection parameters.

0.2 changes:
Added source view to dialog.
Added AvgDev eccentricity to results.
Decreased default detection sensitivity value.

0.3 changes:
Fixed non 32-bit floating point sample bug.
Increased limit on maximum number of stars fitted.
Changed fitted star map to Grayscale.
Improved performance.

0.4 changes:
Fixed zero fitted stars bug.

0.5 changes:
Increased default detection sensitivity value.
Fixed StarAlignment stars view id bug.
Cleanup code.

0.6 changes:
Added new instance button to parameters dialog.

0.7 changes:
Added new instance button to results dialogs.

0.8 changes:
Allow dialog to open with no active view.

0.9 changes:
Fixed fitted star map bug.

0.10 changes:
Fixed no target view bug.
Preserve STF in star map views.
Removed duplicate fits.

0.11 changes:
Added Save As.. CSV file button.

0.12 changes:
Fixed missing directory bug.

0.13 changes:
Handle 'Execute in the global context' command.

0.14 - 0.18 changes:
Many improvements.

0.19 - 0.28 changes:
Many improvements.

0.29 changes:
Fix MacOS dialog layout bugs.
Impose maximum per panel and total fitted star limits.

0.30 - 0.32 changes:
Use MedDev rather than AvgDev for robustness.
Set defaults to Moffat4 and Eccentricity.
Add MRS Noise and SNR Weight.
Remove Median (background) visualization.

0.33 changes:
Added per star PSF information to the .csv file.

« Last Edit: 2012 September 21 11:57:26 by mschuster »

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: PSFEstimation script
« Reply #1 on: 2012 March 17 18:40:27 »
Impressive! Do you feed the star locations to the PSF process or do you calculate the PSF yourself? I realize I could review your code but maybe you'll humor me and tell us :)
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: PSFEstimation script
« Reply #2 on: 2012 March 17 18:46:06 »
Oh yes I use DynamicPSF. I then calculate the median and avgdev across its output table myself. I was hoping to use its synthetic export to avoid having to do my own reduction but I can't find a way to force it to export via pjsr.

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: PSFEstimation script
« Reply #3 on: 2012 March 17 18:50:09 »
Excellent! I'll give it a try and let you know how it goes. Capturing some subs right now.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: PSFEstimation script
« Reply #4 on: 2012 March 22 13:00:18 »
Another note of a script update above, I hope you don't mind again. There are a lot of bug fixes and new features, including the ability to create an icon that you can drag to a view for a quick analysis.

I am finding the tool useful for evaluating the star quality on subs. It provides a quick way to check the roundness of your stars across the field. Just create a preview of your area of interest and drag the icon into the preview. Then check the aspect ratio and eccentricity values. You can also evaluate star FWHM differences across the field easily. You can also save the result as a CSV file for documentation or post-processing purposes.

Some suggestions for usage. You will want to double check the detected star map to see just which stars are being detected. On noisier subs you may need to increase the sensitivity parameter to avoid false star detection on noise structures. On smoother integrations you may want to decrease sensitivity to help detect enough stars. The script fits at most 1000 of the detected stars, so if you have detected more than this number you can double check the fitted star map to see just which stars were fitted.

The script works best when there are a fair number of stars detected. The median values are usually robust and reliable. However, StarAlignment's star detector and DynamicPSF's star fitter can sometimes provide bad results on fields containing lots of noise or large scale nebular and galactic structures. If you see relatively large average deviation values try fitting regions that do not contain these structures.

Finally, this tool is intended only for quick analysis. If you need to be selective on the set of stars analyzed then please use the DynamicPSF process directly.


Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: PSFEstimation script
« Reply #5 on: 2012 March 24 19:16:32 »
Here is more analysis of the collimation problem that motivated my work on this script. I divided the subexposure into a 5x5 grid and ran the script on each cell to detect stars and estimate PSF FWH, aspect ratio and azimuth parameters. I then used Mathematica to plot the arrays as height/vector fields. See the attachments. The contour plots turned out to be a nice way to visualize the data.
« Last Edit: 2012 March 24 20:50:59 by mschuster »

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: PSFEstimation script
« Reply #6 on: 2012 April 12 14:27:59 »
I made some improvements to the script. It now creates visualizations of FWHM and other parameters, so you can easily see how the PSF parameters vary across your subs and integrations. I posted the updates in this thread's head post.

As before the script uses StarAlignment for star detection and DynamicPSF for PSF fitting. The visualizations are created using Resample, PixelMath and custom scripts that do the layout and labeling. The visualizations are similar to the Mathemetica generated versions.

I recommend running the script with Mosaic size set to 1 first to verify that stars are being detected properly and that PSF medians for the whole view seem reasonable. You can modify the detection and fitting parameters if necessary. If things look good rerun with Mosaic size set to 5 or 7. You will then get the visualizations that show how the PSF parameters vary across your view. The labeling makes it easy to see what is going on.

Thanks,
Mike

PS: I have not figured out an easy way to visualize vector fields. I would like to match what Mathematica does for azimuth. If anybody has a suggestion please let me know.



Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: PSFEstimation script
« Reply #7 on: 2012 April 13 00:16:55 »
Very good script, thank you.  It is interesting to see the corelation between FWMH and gradient in the image.
I have attached an image with a (strongly stretched) gradient and the result of PSF estimator
Now I have to test if the fwmh measured after background equalization is better or worse... and understand the meaning.

-- bitli

Offline NKV

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 677
Re: PSFEstimation script
« Reply #8 on: 2012 April 13 01:42:11 »
The visualizations are created using Resample
Good job and excellent idea!

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Re: PSFEstimation script
« Reply #9 on: 2012 April 13 03:14:04 »
Thank you Mike. This a very useful script.

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PSFEstimation script
« Reply #10 on: 2012 April 13 04:39:02 »
Hi Mike,

Very nice work. Can we distribute this script as an official one through the update system?
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: PSFEstimation script
« Reply #11 on: 2012 April 13 09:42:59 »
Thank you Juan, that would be great. Please go ahead.

Andres, NKV, bitli, thank you also for you kind comments.

NKV, yes, I was happy when I found that Resample's excellent results were exactly what I needed. Credit goes to PixelMath also, it is helpful to say the least. I had actually had started a custom implementation of all of this and then realized that these tools could do a better, faster job with much less work.

bitli I would like to hear your conclusions.

Mike

Hans Pleijsier

  • Guest
Re: PSFEstimation script
« Reply #12 on: 2012 April 13 10:45:09 »
Hi Mike,
I am impressed by your slick programming and the result.
At the same time: In evaluating one sub the screen of my macbook is cluttered by the many windows this script is producing.
Is this the way to go or do you suggest another workflow to assess the starquality of many subs in one set?

I expect that your script have the potential to make my ccdinspectorsoftware (my current tool for subselection) obsolete.
But for now I must say that the ease of work of ccdinspector beats yours.
It would be nice if the script could pick the files from a given directory and produce some sort of list with scorings per sub.

I know ...  I am ungrateful and selfish but since you are obviously a great javascriptguru I take my chance  ... ;-)

But again, many thanks for the effort and result sofar: I will certainly use this script many times.

Hans

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: PSFEstimation script
« Reply #13 on: 2012 April 13 14:41:55 »
Hi Hans,
Thank you for your comments and feedback. I agree, reducing the number of windows and adding a workflow for multiple subs would be big improvements. What sort of scoring per sub would you find most useful? A basic one of course might be per sub FWHM information (median, minimum, maximum). Beyond that what would you like to see?
Thanks,
Mike

Hans Pleijsier

  • Guest
Re: PSFEstimation script
« Reply #14 on: 2012 April 14 06:38:52 »
Hi Mike,

I agree: FWHM is essential.
The evaluation mechanism could be further enhanced by:
(1) aspect ratio (roundness)
(2) background level
(3 , optional) contrast (brightest star pixels versus background).

The ultimate prizewinning tool would be that the user is able to give these four criteria a weight. Something along the way of 1 being important and -1 unimportant. The script calculates an overall score. A maximum score of 100 represents the best theoretical values like when the FWHM equals the seeing, stars are completely round etc ...

The report ... maybe a list with columns: subnr/  evaluated total score / fwhm / aspectratio & weight / bckgrndlevel & weight / contrast & weight //


Hans