fraserw / trippy

Python based Trailed Source Photometry
GNU General Public License v3.0
20 stars 13 forks source link

Restore function not complete restore #9

Closed Mikea1985 closed 8 years ago

Mikea1985 commented 8 years ago

I have noticed that if I first run through the tutorial (with Polonskaya.fits or my own images), then use the restore function mentioned in the tutorial:

goodPSF=psf.modelPSF(restore='psf.fits')
goodPSF.fitted=False
goodPSF.line(rate,angle,EXPTIME/3600.,pixScale=0.185,useLookupTable=True)

and then do everything from the tutorial after the restore again, three things happen:

1) goodPSF.FWHM() returns the pure moffat FWHM, not the FWHM including the lookup table (even though goodPSF.genLookupTable(data,goodFits[:,4]-0.5,goodFits[:,5]-0.5,verbose=False) was run before storing the PSF).

2) After running

phot(xt,yt,radius=fwhm*1.4,l=(EXPTIME/3600.)*rate/pxscale,a=angle,
     skyRadius=4*fwhm,width=6*fwhm,
     zpt=26.0,exptime=EXPTIME,enableBGSelection=True,display=True,
     mode="smart",trimBGHighPix=3.)

the value of phot.magnitude is significantly different from what it was the first time (with the newly-made, non-restored PSF). In some cases phot.magnitude differs by more than the uncertainty between the two cases. I assume this is because phot is using a different (incorrect?) fwhm the second time.

3) fitter.fitWithModelPSF() fails with the error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "run_new.py", line 166, in <module>
    fitter.fitWithModelPSF(200+xt-int(xt)-1,200+yt-int(yt)-1, m_in=1000.,fitWidth=10, nWalkers=12, nBurn=12, nStep=12, bg=phot.bg, useLinePSF=True, verbose=True,useErrorMap=False)
  File "/usr/local/lib/python2.7/dist-packages/trippy/MCMCfit/MCMCfit.py", line 87, in fitWithModelPSF
    if fitWidth>self.psf.boxSize:
AttributeError: modelPSF instance has no attribute 'boxSize'

(I'm aware that nBurn=nStep=nWalkers=12 is probably not enough, but I'm just trying to speed things up while I'm just playing around - that's irrelevant to the error.)

It is unclear to me whether a) the psfStore function needs to save more information (which the psf.modelPSF(restore=filename) then needs to restore correctly), or b) the tutorial needs to have a few extra steps explaining how to fully restore the restored PSF into something useable.

fraserw commented 8 years ago

Crap. This is the result of changing how I generated lookup tables. I thought I had got it right, but looks not so. Once I get this fixed, I'll bump to v0.3. :)

NOTE - you are still subtracting -0.5 off the pixel coordinates, which is something you shouldn't do anymore.

fraserw commented 8 years ago

Quick fix for 1 and 2: after a PSF restore, do a .genPSF(). That will create the object longPSF from which the correct FWHM will be computed. This will be folded into the restore command soon.

NOTE: in 2, the magnitude should be different because you are using a different aperture radius. So it is not reasonable to compare photometry of two separate apertures unless you first correct for relative aperture radii. I am assuming you didn't which is why you got the strange result.

NOTE: even after a restore, the aperture corrections you calculated before as still kept and accessible via the appropriate functions.

3) This is probably a bug like what I refered to in the last message. Will fix and let you know when to update.

fraserw commented 8 years ago

OK. Big changes to the psf/psfchooser/pill to handle these bugs. Save/Restore should now work. Also, psf.FWHM() now uses fromMoffatProfile boolean to determine if you want the moffat-only or moffat+lookupTable FWHM, because both are different.