[AstroPy] ATpy questions

Jean-Baptiste Marquette marquett@iap...
Wed Aug 24 02:46:44 CDT 2011


Hi Tom,

Thanks for your answer, very helpful.

> On Tue, Aug 23, 2011 at 12:27 PM, Jean-Baptiste Marquette
> <marquett@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]

The right code is:

RA, DEC = asciitable.read(RAdec, delimiter=' ', Reader=asciitable.NoHeader, numpy=True), asciitable.read(DECdec, delimiter=' ', Reader=asciitable.NoHeader, numpy=True)
DataDistort.Ra[:] = np.asarray(RA)
DataDistort.Dec[:] = np.asarray(DEC)

> 
>> 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

I did browse the doc quite a while before to ask help. I was lost in the ATpy doc where the link to asciitable one is maybe not as evident as it should be.

Anyway, I probably will be at CfA before December. In such a case, you will deserve a beer...{:-)

Cheers
JB



More information about the AstroPy mailing list