2D PSF models?
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.
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 :)
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!
I'm finally coming back to this after a tumultuous time, compounded by teaching. My intention was just to try to code a Moffat2D. I have started looking into this, and i have to admit to being (more than) a bit intimidated!!
The path that i can (kind of?) see is to try to use the galaxy_model_object.Galaxy_Model class as a template for how to add q and pa parameters to a psf_model_object.PSF_Model class to create a new psf_model_object.PSF_2D_model. I think i can see that this should be easy in principle, but not understanding the code architecture and really not operating at this level of python, i'm also quite afraid of doing something silly, and getting lost in trying to figure out debug strategies.
Is making/adding a Moffat2D model really something easy for you to do, and if so, would you mind? Or maybe i just need some reassurance? : )
Hi @entaylor ! Yes I can just make a Moffat2D psf model and add it into the main code base. I'll let you know when it's ready (since I'm traveling, probably next week). In the meantime, I suggest you take a stab at it just to learn a bit about how the code works. Your intuition to base it off the galaxy model class is a good one!
Looking over things it seems I may have achieved "easy but not simple" with the code design... It's easy in that only a few lines of code should be needed to get what you want, but it is not simple in that knowing which few lines to write is very hard... I have some restructuting ideas for AstroPhot depending on my next postdoc which would make things much simpler :)
Hi @entaylor I have just merged in a new moffat2d psf model in PR #233 . You can see an example use of the model in the ModelZoo tutorial. I hope that helps! Let me know if you need anything else :)
Hi again! I'm sorry not to have replied before now, but the year has continued to be full and eventful ... and not always in good ways!!
But just to say that this works like a charm!! I'm so very grateful. I will be at least nominally on leave through Jan, but i'm sure that i will pick and this project here and there, and it's my first priority when i'm actually back at my desk. But until then, i will rest easy knowing that there is a clear path through!
So: thank you! You're amazing!
ned
Hi @entaylor best of luck with your project! Let me know if you need anything else!