spacetelescope / webbpsf

James Webb Space Telescope PSF simulation tool
https://webbpsf.readthedocs.io
BSD 3-Clause "New" or "Revised" License
119 stars 63 forks source link

Guidelines for using lists of grids? (all_detectors=True) #602

Closed keflavich closed 11 months ago

keflavich commented 2 years ago

Is there any practical way to use the list of grids from psf_grid on a dithered image?

grid = nrc.psf_grid(num_psfs=16, all_detectors=True)

There was some discussion in this issue, but I can't find any example use cases.

The documentation titled "Using PSF Grids" shows how to create and visualize the grids, but not how to use them in a practical context - i.e., for photometry.

I understand that the PSF models are not going to be perfect representations of the PSFs in the merged, dithered images. But since those are what the JWST pipeline delivers, and I suspect what most people will work with, it would be valuable to have some tools that generate the approximate average PSF for different default dither patterns.

I was unable to find any examples by searching through google & github; I hope this is as easy as pointing me to another notebook I just failed to search up!

mperrin commented 2 years ago

Hi @keflavich - (First, I was away on vacation last week; thanks for understanding about this delayed response.)

Have you seen the Photutils package documentation for PSF fitting? The PSF grid that's returned is designed to work as photutils.GriddedPSFModel for use with the PSF fitting photometry routines provided in photutils. That's the first place to start for how to use these.

That said, it turns out to be not straightforward to speak rigorously about PSFs in the merged dithered images (i.e. the level 3 "i2d" pipeline output product). The drizzle algorithm used to combine dithered images is flux conserving, but is not in any sense rigorously preserving of PSF properties. Further, since the PSF is field-position-dependent, it's not as simple as saying there's a well-defined average PSF for a particular dither pattern. For really rigorous work the state of the art approach has been to work on the set of all the individual images (i.e. the level 2 "cal" products), then combine the results of fits to each of those images, though yes that's more work of course.

Coming up with how to define an approximate PSF for a dithered drizzle-combined image, and assessing how useful or precise that would be for use with JWST pipeline level 3 products... sounds like an open research problem to me, rather than something that's easy in an existing notebook.

keflavich commented 2 years ago

Yes, I've read the photutils documentation and am using it extensively. It applies to grids, but not lists of grids - which makes some sense, since each GriddedPSFModel refers to an individual detector.

I get that a grid defined for post-drizzle data isn't well-defined. Nevertheless, averaging the PSFs for each visit would make a good starting point for that research project.

A simple use case I'd find very helpful, though I think I'll have to construct it myself, is to have a single PSF grid representing NRCA1-4, i.e., all of the short-wavelength detectors in one module.

Much as I would like to do the state-of-the-art thing, it's excessive for some projects and probably incompatible with mine, where I'm trying to separate stellar emission from extended backgrounds

obi-wan76 commented 11 months ago

Guidelines are in the photutils package documentation.