User-defined PSF models from psf.prepare_psf_model always have submodel_names attribute
I've ran into some issues using my own PSF model generated from the psf.prepare_psf_model function. I want to use a Moffat2D model as my PSF model so I imported that from astropy.modeling.models and set the gamma and alpha values to what's needed for my data. I then ran it through prepare_psf_model to convert it and be useable with DAOPhotPSFPhotometry. After setting up DAOPhotPSFPhotometry, I tried running it on my image and came up with the following error:
AttributeError: x_0_0
The problem seems to be occurring in the _model_params2table function. On line 371 the function tests whether the input PSF model has the attribute submodel_names which I'm guessing is to see whether it's fitting a group of stars or just a single star. The issue is that when I defined my own Moffat2D psf model, the model that was returned has the submodel_names attribute even though it is just a single model. So whether or not DAOPhotPSFPhotometry is fitting a group or single star, it will always have the submodel_names attribute. I'm not sure but I'm guessing this is because its technically a CompoundModel?
The output of submodel_names for my PSF model is:
(u'None_0', u'None_1', u'None_2', 'renormalize_scaling')
The fix I'm guessing is either the submodel_names attribute needs to be removed in the model output from prepare_psf_model or there needs to be another way of testing whether the fitting is for a group or single star.
Here's some example code that should reproduce the error I'm getting:
from astropy.modeling.models import Moffat2D
import photutils
psf = Moffat2D(x_0=0., y_0=0., gamma=2.0, alpha=0.8)
new_psf = photutils.psf.prepare_psf_model(psf, xname='x_0', yname='y_0', fluxname='amplitude')
my_phot = photutils.psf.DAOPhotPSFPhotometry(crit_separation=8., threshold=5, fwhm=4.0, psf_model=prf_mod, fitshape=21)
psf_phot = my_phot(image=data)
This is assuming an arbitrary image which shouldn't matter.
Thank you for reporting, @ttshimiz I will take a look into that soon =)
@ttshimiz I don't have a quick solution for you right now, maybe PRFAdapter, but it looks like it is a bit slow... Anyways, maybe adapting prepare_psf_model to play with the PSF Photometry should be the way to go...
Thanks for looking into this @mirca! Its not urgent for it to be fixed so no problem if it takes a little time to find a solution. But yeah I think the best solution is to modify prepare_psf_model to play better the PSF Photometry classes. I'm wondering if within prepare_psf_model you can just reset the submodel_names attribute?
@mira - is @ttshimiz right that the reason for checking that is to see if it's a group? If that's the case, then maybe the grouper class should add a special attribute specifically for that? E.g. model._is_group = True, and then to check for it, do something like getattr(model, '_is_group', True)?
@eteq I absolutely agree on having a _is_group attribute.