question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FITS Table columns read as 2D arrays

See original GitHub issue

Description

The following code:

from astropy.io import fits
from astropy.table import Table

with fits.open('whatever.fits') as f:
    d = Table.read(f)
print(d['SUPRA'].shape)

outputs (1294, 1) in v4.2.1 and (1294,) in v3.1.2.

This makes quite a bit of our previous code non-backwards compatible.

Expected behavior

I expected (1294,) as in previous versions.

Actual behavior

Output is (1294, 1) with v4.2.1.

Steps to Reproduce

See code above.

System Details

Linux-5.11.0-25-generic-x86_64-with-glibc2.29
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0]
Numpy 1.20.2
astropy 4.2.1
Scipy 1.6.2
Matplotlib 3.4.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
maxnoecommented, Aug 17, 2021

So the behavior of astropy here is correct and following the standard.

1reaction
maxnoecommented, Aug 17, 2021

The Problem is not TFORM, but TDIM.

An empty TDIM is a 0D element, so the whole column is 1D. A TDIM of (1) means that each element is a 1d array of 1 element, so the whole column becomes 2D.

Please fix the code producing your files if having 2d columns is not the intention. The FITS standard is pretty clear on this:

TDIMn keywords. Thevalue field of this indexedkeywordshall contain a character string describing how to interpret the contents of Field n as a multi-dimensional array with a format of ’(l,m,n…)’, where l, m, n, …are the dimensions of the array. The data are ordered such that the array index of the first dimension given (l) is the most rapidly varying, and that of the last dimension given is the least rapidly varying. The total number of elements in the array equals the product of the dimensions specified in the TDIMn keyword

Read more comments on GitHub >

github_iconTop Results From Across the Web

Table Data — Astropy v5.2
Metadata of a Table. The data in a FITS table HDU is basically a record array with added attributes. The metadata (i.e., information...
Read more >
How to convert a two column fits table into a 2D array in python
Try to access the .data property of the table, should be an array. See also Converting astropy.table.columns to a numpy array.
Read more >
Multi-dimensional arrays in variable-length array columns of a ...
Being able to write any n-dimensional arrays to a VLA column, writing that to a file and then successfully reading the column (round-trip)....
Read more >
6.7.4 Read and Write Column Data Routines - HEASARC
These routines return the values of the table column array elements. Any undefined array elements will have the corresponding flagvals element set equal...
Read more >
Viewing and manipulating data from FITS tables
We can extract data from the table by referencing the column name. For example, I'll make a histogram for the galaxy stellar masses...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found