photutils icon indicating copy to clipboard operation
photutils copied to clipboard

User-defined PSF models from psf.prepare_psf_model always have submodel_names attribute

Open ttshimiz opened this issue 9 years ago • 5 comments

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.

ttshimiz avatar Dec 21 '16 22:12 ttshimiz

Thank you for reporting, @ttshimiz I will take a look into that soon =)

mirca avatar Dec 22 '16 12:12 mirca

@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...

mirca avatar Dec 31 '16 23:12 mirca

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?

ttshimiz avatar Jan 02 '17 12:01 ttshimiz

@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 avatar Jan 26 '17 23:01 eteq

@eteq I absolutely agree on having a _is_group attribute.

mirca avatar Feb 02 '17 12:02 mirca