npross
npross

Reputation: 1888

Simple formatting of astropy Tables ascii output

I have three variables, wavelength, flux and err_flux which are all type astropy.table.table.Table. I've combined them into one variable, output as such:

output = Table([wavelength,flux,err_flux], names=['wavelength', 'flux', 'err_flux']))

However, when I now look at `output', I get the single entries having ( and ,) formatting and being type numpy.voids

In [1]: output                                                                                                                                                                
Out[1]: 
<Table length=5384>
  wavelength         flux         err_flux   
     void64          void64         void64    
----------------- -------------- --------------
(3199.30539694,)  (9.04838805,)  (0.90483881,)
(3200.35733828,)  (7.50614256,)  (0.75061426,)
(3201.40933772,)  (6.93674224,)  (0.69367422,)
....

What's going on, and how can I just have three floats per line here?

Upvotes: 0

Views: 193

Answers (1)

Tom Aldcroft
Tom Aldcroft

Reputation: 2542

I have three variables, wavelength, flux and err_flux which are all type astropy.table.table.Table.

Having each of those three variables starting as a single-column table is a little strange, so backing up one step and understanding why these data columns are Table objects is one place to start.

But if you really have these three data tables, you can use the astropy.table.hstack function to stack them horizontally into a single table:

from astropy.table import hstack
output = hstack([wavelength, flux, err_flux])

You could also pull out the first column from each table:

output = Table([wavelength.columns[0], flux.columns[0], err_flux.columns[0]],
               names=['wavelength', 'flux', 'err_flux'])

FYI, what's going on? An astropy Table column can be a Table!

In [45]: t = simple_table()

In [46]: t2 = Table([t, t])

In [47]: t2
Out[47]: 
<Table length=3>
     col0          col1    
   void160       void160   
------------- -------------
(1,  1., 'c') (1,  1., 'c')
(2,  2., 'd') (2,  2., 'd')
(3,  3., 'e') (3,  3., 'e')

Upvotes: 1

Related Questions