[AstroPy] Accessing a FITS table generates "ValueError: Inconsistent data column lengths: set([0, 27645])"

Jordan Alexander jordan.alexander at aut.ac.nz
Wed Apr 18 02:59:24 EDT 2018


Hello Team,

As suggested, I posted this issue on

https://github.com/astropy/astropy/issues

as

#7386

Accessing a FITS table with a zero-width column generates "ValueError: Inconsistent data column lengths: set([0, 27645])"

Thanks, again, for all your help; I am off and running!
________________________________________
From: AstroPy [astropy-bounces+jordan.alexander=aut.ac.nz at python.org] on behalf of Jordan Alexander [jordan.alexander at aut.ac.nz]
Sent: 18 April 2018 11:46
To: Astronomical Python mailing list
Subject: Re: [AstroPy] Accessing a FITS table generates "ValueError: Inconsistent data column lengths: set([0, 27645])"

Tom's suggested work-around saves the day, thank you folks!

After Derek pointed out my mistake :)

<issuing>

hdulist.info()
dat = hdulist[8].data
dat.dtype.names
names = [name for name in dat.dtype.names if name != 'GATEID']
cols = [dat[name] for name in names]
tbl = Table(cols, names=names)
print names
tbl

<gives>

Filename: WS001H.0.bin0000.source0000.FITS
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 GroupsHDU       51   ()      0 Groups  0 Parameters
  1  ARRAY_GEOMETRY    1 BinTableHDU     53   2R x 7C   ['8A', '3D', '3E', '0D', '1J', '1J', '3E']
  2  SOURCE        1 BinTableHDU     89   3R x 26C   [1J, 16A, 1J, 4A, 1J, 8E, 8E, 8E, 8E, 8E, 8D, 1D, 1D, 8A, 1D, 1D, 8D, 8A, 8A, 8D, 1D, 1D, 1E, 1D, 1D, 1D]
  3  ANTENNA       1 BinTableHDU     52   18R x 13C   [1D, 1E, 8A, 1J, 1J, 1J, 1J, 1A, 8E, 8E, 1A, 8E, 8E]
  4  FREQUENCY     1 BinTableHDU     35   1R x 6C   [1J, 8D, 8E, 8E, 8J, 8J]
  5  INTERFEROMETER_MODEL    1 BinTableHDU     83   946R x 20C   [1D, 1E, 1J, 1J, 1J, 1J, 1E, 8E, 48D, 6D, 48D, 6D, 1E, 1E, 48D, 6D, 48D, 6D, 1E, 1E]
  6  CALC          1 BinTableHDU     75   5R x 11C   [1D, 1D, 1D, 1D, 1A, 2D, 1A, 1D, 1D, 1D, 1D]
  7  MODEL_COMPS    1 BinTableHDU     86   946R x 21C   [1D, 1J, 1J, 1J, 1J, 1D, 1D, 1D, 1D, 1D, 1D, 8E, 8E, 1E, 1E, 1D, 1D, 8E, 8E, 1E, 1E]
  8  UV_DATA       1 BinTableHDU     93   27645R x 13C   ['1E', '1E', '1E', '1D', '1D', '1J', '1J', '1J', '1J', '1E', '32E', '0J', '4096E']
  9  PHASE-CAL     1 BinTableHDU     61   2406R x 17C   [1D, 1E, 1J, 1J, 1J, 1J, 1D, 32E, 16D, 16E, 16E, 16E, 32E, 16D, 16E, 16E, 16E]
 10  GAIN_CURVE    1 BinTableHDU     62   0R x 19C   [1J, 1J, 1J, 8J, 8J, 8J, 8J, 8E, 48E, 48E, 8E, 8J, 8J, 8J, 8J, 8E, 48E, 48E, 8E]

('UU---SIN', 'VV---SIN', 'WW---SIN', 'DATE', 'TIME', 'BASELINE', 'FILTER', 'SOURCE', 'FREQID', 'INTTIM', 'WEIGHT', 'GATEID', 'FLUX')

['UU---SIN', 'VV---SIN', 'WW---SIN', 'DATE', 'TIME', 'BASELINE', 'FILTER', 'SOURCE', 'FREQID', 'INTTIM', 'WEIGHT', 'FLUX']

<Table length=27645>
UU---SIN        VV---SIN        WW---SIN        DATE    TIME    BASELINE        FILTER  SOURCE  FREQID  INTTIM  WEIGHT [32]     FLUX [4096]
float32 float32 float32 float64 float64 int32   int32   int32   int32   float32 float32 float32
-3.5595775e-07  4.8471287e-07   -1.3040803e-07  2458150.5       0.46869212962962964     258     0       1       1       4.0     0.498897 .. 0.498897    -0.00053550233 .. 0.0001868349
0.0     0.0     0.0     2458150.5       0.46869212962962964     257     0       1       1       4.0     0.498897 .. 0.498897    0.12680201 .. -0.00014993937
0.0     0.0     0.0     2458150.5       0.46869212962962964     514     0       1       1       4.0     0.498898 .. 0.498898    0.13645686 .. -4.7759924e-05
-3.559708e-07   4.8473083e-07   -1.3030568e-07  2458150.5       0.4687384259259259      258     0       1       1       4.0     1.0 .. 1.0      0.00012936759 .. 0.00020031894
0.0     0.0     0.0     2458150.5       0.4687384259259259      257     0       1       1       4.0     1.0 .. 1.0      0.25439927 .. -0.00019075086
0.0     0.0     0.0     2458150.5       0.4687384259259259      514     0       1       1       4.0     1.0 .. 1.0      0.27794644 .. -0.000108667715
-3.5598381e-07  4.8474874e-07   -1.302033e-07   2458150.5       0.4687847222222222      258     0       1       1       4.0     1.0 .. 1.0      -7.832311e-05 .. 0.00019760148
0.0     0.0     0.0     2458150.5       0.4687847222222222      257     0       1       1       4.0     1.0 .. 1.0      0.25515017 .. 3.8746617e-05
0.0     0.0     0.0     2458150.5       0.4687847222222222      514     0       1       1       4.0     1.0 .. 1.0      0.27692768 .. -8.5447784e-05
-3.559968e-07   4.847667e-07    -1.3010094e-07  2458150.5       0.4688310185185185      258     0       1       1       4.0     1.0 .. 1.0      0.00023608183 .. 0.00012750328
...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...
0.0     0.0     0.0     2458150.5       0.9504282407407407      257     0       3       1       4.0     1.0 .. 1.0      0.25559133 .. 9.5562056e-05
0.0     0.0     0.0     2458150.5       0.9504282407407407      514     0       3       1       4.0     1.0 .. 1.0      0.27768683 .. 9.952805e-05
-1.2753328e-07  5.2233025e-07   -2.9934213e-07  2458150.5       0.950474537037037       258     0       3       1       4.0     1.0 .. 1.0      0.0016913593 .. 5.9099006e-05
0.0     0.0     0.0     2458150.5       0.950474537037037       257     0       3       1       4.0     1.0 .. 1.0      0.25483266 .. -1.5832578e-05
0.0     0.0     0.0     2458150.5       0.950474537037037       514     0       3       1       4.0     1.0 .. 1.0      0.27675447 .. 6.571587e-05
-1.2743546e-07  5.223637e-07    -2.9932542e-07  2458150.5       0.9505208333333334      258     0       3       1       4.0     1.0 .. 1.0      0.00025846672 .. -0.0002902149
0.0     0.0     0.0     2458150.5       0.9505208333333334      257     0       3       1       4.0     1.0 .. 1.0      0.255608 .. -0.0001676612
0.0     0.0     0.0     2458150.5       0.9505208333333334      514     0       3       1       4.0     1.0 .. 1.0      0.27796867 .. 0.00022455976
-1.2733761e-07  5.223971e-07    -2.993087e-07   2458150.5       0.9505671296296296      258     0       3       1       4.0     1.0 .. 1.0      -0.00098487 .. 8.03614e-05
0.0     0.0     0.0     2458150.5       0.9505671296296296      257     0       3       1       4.0     1.0 .. 1.0      0.25570583 .. -5.7318623e-05


________________________________________
From: AstroPy [astropy-bounces+jordan.alexander=aut.ac.nz at python.org] on behalf of Derek Homeier [derek at astro.physik.uni-goettingen.de]
Sent: 18 April 2018 11:18
To: Astronomical Python mailing list
Subject: Re: [AstroPy] Accessing a FITS table generates "ValueError: Inconsistent data column lengths: set([0, 27645])"

On 18 Apr 2018, at 12:59 am, Jordan Alexander <jordan.alexander at aut.ac.nz> wrote:
>
> Your "tested" work-around, Tom:
>
> hdulist.info()
> dat = hdulist[8].data
> names = [name for name in dat.dtype.names if name != 'col_with_0J']
> cols = [dat[name] for name in names]
> tbl = Table(cols, names=names)

‘col_with_0J’ was meant to be the actual column name of the 0-width column (#12).

names = [name for name in dat.dtype.names if dat[name].shape[-1] > 0]

should automatically filter the 0-shaped columns out.

Cheers,
                                        Derek

_______________________________________________
AstroPy mailing list
AstroPy at python.org
https://mail.python.org/mailman/listinfo/astropy
_______________________________________________
AstroPy mailing list
AstroPy at python.org
https://mail.python.org/mailman/listinfo/astropy


More information about the AstroPy mailing list