Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better astropy.io.fits representation #7648

Open
albireox opened this issue Jul 12, 2018 · 3 comments
Open

Better astropy.io.fits representation #7648

albireox opened this issue Jul 12, 2018 · 3 comments

Comments

@albireox
Copy link

The default representations for HDUList and ImageHDU are not very informative. For HDUList it would be nice if it automatically returned HDUList.info(). For ImageHDU a summary à la fitsio with the shape of the image, dtype, number of header keywords, etc would be useful.

Also, HDUList.info() could use some better formatting: it is sometimes difficult to read when you have things like

Filename: ./manga-7443-12701-MAPS-HYB10-GAU-MILESHC.fits.gz
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU     146   ()
  1  SPX_SKYCOO    1 ImageHDU        43   (72, 72, 2)   float32
  2  SPX_ELLCOO    1 ImageHDU        46   (72, 72, 3)   float32
  3  SPX_MFLUX     1 ImageHDU        36   (72, 72)   float32
  4  SPX_MFLUX_IVAR    1 ImageHDU        37   (72, 72)   float32
  5  SPX_SNR       1 ImageHDU        34   (72, 72)   float32
@saimn
Copy link
Contributor

saimn commented Jul 18, 2018

About the fitsio-like summary, a similar idea was proposed by @astrofrog in #821, putting each kind of information on a line instead of trying to format a table with variable width. This could indeed make a good repr for HDU objects, and probably also HDUList.
Some examples with fitsio's repr:

In [1]: import fitsio

In [2]: fitsio.FITS('astropy/io/fits/tests/data/o4sp040b0_raw.fits')
Out[2]: 

  file: astropy/io/fits/tests/data/o4sp040b0_raw.fits
  mode: READONLY
  extnum hdutype         hduname[v]
  0      IMAGE_HDU       
  1      IMAGE_HDU       SCI[1]
  2      IMAGE_HDU       ERR[1]
  3      IMAGE_HDU       DQ[1]
  4      IMAGE_HDU       SCI[2]
  5      IMAGE_HDU       ERR[2]
  6      IMAGE_HDU       DQ[2]

In [3]: fitsio.FITS('astropy/io/fits/tests/data/o4sp040b0_raw.fits')[1]
Out[3]: 

  file: astropy/io/fits/tests/data/o4sp040b0_raw.fits
  extension: 1
  type: IMAGE_HDU
  extname: SCI
  extver: 1
  image info:
    data type: u2
    dims: [44,62]

In [4]: fitsio.FITS('astropy/io/fits/tests/data/tb.fits')
Out[4]: 

  file: astropy/io/fits/tests/data/tb.fits
  mode: READONLY
  extnum hdutype         hduname[v]
  0      IMAGE_HDU       
  1      BINARY_TBL      

In [5]: fitsio.FITS('astropy/io/fits/tests/data/tb.fits')[1]
Out[5]: 

  file: astropy/io/fits/tests/data/tb.fits
  extension: 1
  type: BINARY_TBL
  rows: 2
  column info:
    c1                  i4  
    c2                  S3  
    c3                  f4  
    c4                  b1  

@albireox
Copy link
Author

That seems like a very nice solution, and sorry for not finding the original issue about this. I'm happy to get this one closed if it's being tracked there.

I have some code that I use to monkeypatch the __repr__ or HDUList and _BaseHDU by converting the summary information to an astropy table. Is not very well tested and it doesn't include binary tables, but I'm happy to share it if it can help.

@saimn
Copy link
Contributor

saimn commented Jul 27, 2018

I would be in favor of this, but it would great to have other opinions, pinging @MSeifert04 @drdavella @astrofrog 😉

For HDUList's repr, we could maybe remove the printing of column formats in HDUList.info, which is causing very long lines when there are too many columns, if we have another way to have these information about columns on the HDU's repr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants