Autostronomy / AstroPhot

A fast, flexible, automated, and differentiable astronomical image 2D forward modelling tool for precise parallel multi-wavelength photometry
https://astrophot.readthedocs.io
GNU General Public License v3.0
78 stars 9 forks source link

2D PSF models? #198

Open entaylor opened 1 month ago

entaylor commented 1 month ago

I'm not sure if this is more a request for guidance or a real feature request.

I'm interested in trialing a 2D PSF model, but not (yet) brave enough to try coding my own class.

I think my biggest question is, before i dive into this, whether/how feasible it is? Is there anything in the code to prefer/require 1D (parametric) PSF models?

Alternatively, this might be a good candidate for a new set of PSF models; i.e. Gaussian2d, Moffat2d.

ConnorStoneAstro commented 1 month ago

You can certainly create 2D PSF models. I have wanted to make something like a diffraction spike model for a long time now, but I just don't really know what the correct mathematical representation would be.

It is also possible to make composite models where instead of a group model you make a psf group model. There are some extra considerations for a composite model. In regular PSF models, the "center" is fixed to (0,0) in an arbitrary coordinate system (which aligns with the image coordinate system), and any flux parameters are fixed to some constant value. When a PSF model is generated it evaluates the model then just normalizes the total flux to 1. If you are making a composite PSF model, then you will want to relax some of these constraints. Certainly the flux parameters would no longer be locked, they should be unlocked so they can encode the relative flux in different components. You can also allow some of the models to have a variable center, although that would be a very odd PSF.

Would it be helpful if I made a custom psf tutorial like how I have the custom model tutorial?

For something like a gaussian2d or moffat2d, that would be relatively easy to put together if you're thinking of just making them into ellipses. I could add that at any time, I just never did because I didn't think anyone would need it.

If you're thinking of more creative 2D models and want to experiment on your own, then I suggest for now you trace through what happens in a PSF model that already exists and then adapt from there. Here is the Gaussian PSF model, which is actually pretty short because it leans on other code that's already out there: https://github.com/Autostronomy/AstroPhot/blob/3d0a5f39ba5eedbdac841422788d875b80a1a455/astrophot/models/gaussian_model.py#L255

To see the full detail of what's going on when you call something like psf_model().data to see an image of the PSF, you can look at the sample function in the PSF model base class: https://github.com/Autostronomy/AstroPhot/blob/main/astrophot/models/psf_model_object.py

but that is really getting in the weeds :)

entaylor commented 4 weeks ago

All good. After today i am pretty sure that i will go ahead with trying to do this, and will come back to you with my best attempt! Thanks again!