[AstroPy] fits type of bintable extension

Alexander Rudy arrudy at ucsc.edu
Wed Mar 13 14:07:56 EDT 2013


Hi Paul,

What about using the 'isinstance()' built-in method in python?
http://docs.python.org/2/library/functions.html#isinstance
http://docs.python.org/2/library/functions.html#issubclass
That checks the type at runtime, and easily differentiates between them. Try:

>>> import astropy.io.fits.hdu.table
>>> import pyfits.hdu.table
>>> pyFITStable = pyfits.hdu.table.BinTableHDU()
>>> apFITStable = astropy.io.fits.hdu.table.BinTableHDU()
>>> isinstance(pyFITStable,astropy.io.fits.hdu.table.BinTableHDU)
False
>>> isinstance(apFITStable,pyfits.hdu.table.BinTableHDU)
False
>>> isinstance(pyFITStable,pyfits.hdu.table.BinTableHDU)
True

Or, if you want compatibility for both, just use
>>> isinstance(pyFITStable,(pyfits.hdu.table.BinTableHDU,astropy.io.fits.hdu.table.BinTableHDU))
True

I'm not sure what you are looking for here. How are you testing the class differences now? You could register pyfits.hdu.table.BinTableHDU as a subclass of astropy.io.fits.hdu.table.BinTableHDU, but that would only work if HDUs use python's abstract base class construct (which they don't right now). See http://docs.python.org/2/library/abc.html for fun registering subclasses to their superclass.

I hope that helps.

~ Alex

On Mar 13, 2013, at 10:25 , Paul Kuin <npkuin at gmail.com> wrote:

> Hi,
> 
> Just looking at the type of one of my bintable extensions and see that it is
> astropy.io.fits.hdu.table.BinTableHDU
> 
> I was thinking that this makes is a little more difficult to test the
> type between the
> pyfits and astropy.io.fits packages.
> 
> Was this done on purpose or is this a 'feature' ?
> 
> Cheers,
> 
>   Paul
> 
> -- 
> 
> * * * * * * * * http://www.mssl.ucl.ac.uk/~npmk/ * * * *
> Dr. N.P.M. Kuin      (n.kuin at ucl.ac.uk)
> phone +44-(0)1483 (prefix) -204927 (work) -276110 (home)
> mobile +44(0)7806985366  skype ID: npkuin
> Mullard Space Science Laboratory  – University College London  –
> Holmbury St Mary – Dorking – Surrey RH5 6NT–  U.K.
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy




More information about the AstroPy mailing list