[AstroPy] ATpy questions

Tom Aldcroft aldcroft at head.cfa.harvard.edu
Tue Aug 23 12:41:40 EDT 2011


On Tue, Aug 23, 2011 at 12:27 PM, Jean-Baptiste Marquette
<marquett at iap.fr> wrote:
> Hi all,
> I have 3 questions about the use of ATpy:
>
> How to add a leading "#" to the header of the Table? It is possible to read
> tables with a header like "#  erosid      Ra         Dec      MagR", but
> writing such a table removes the "#".

Hopefully this example helps with two of your questions:

In [1]: import asciitable
In [2]: dat = asciitable.read('a b\n 1 2')   # Read a simple table
In [3]: asciitable.write(dat, sys.stdout,
Writer=asciitable.CommentedHeader, formats={'a': '%.4f', 'b': '%.2f'})
# a b
1.0000 2.00


> How to replace in a table an entire column by the content of a single-column
> asciitable ?
>
> Coding like:
> Data = atpy.Table(Catalog, type='ascii', numpy=False)
> DataDistort = Data
> RA, DEC = asciitable.read(RAdec, delimiter='\n', Reader=asciitable.NoHeader,
> numpy=False), asciitable.read(DECdec, delimiter='\n',
> Reader=asciitable.NoHeader, numpy=False)
> DataDistort.Ra = RA[0]
> DataDistort.Dec = DEC[0]

This should work:

DataDistort.Ra[:] = RA[0]
DataDistort.Dec[:] = DEC[0]

> put the first value of RA/DEC on all the rows of DataDistort.Ra/Dec.
> Finally:
>
> How to change the format of a column? I didn't find anything to force the
> writing of trailing zeros.

As above, use the "formats" keyword when writing using asciitable.
And don't be afraid to read the docs, it's right there for you.  :-)

http://cxc.harvard.edu/contrib/asciitable/#commonly-used-parameters-for-write

- Tom

> Thanks for your help,
> Cheers
> Jean-Baptiste
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>
>



More information about the AstroPy mailing list