[AstroPy] Reading Time columns from ascii tables
Aldcroft, Thomas
aldcroft at head.cfa.harvard.edu
Wed Aug 17 23:07:16 EDT 2016
On Wed, Aug 17, 2016 at 1:59 AM, Varun Bhalerao <varunb at iucaa.in> wrote:
> Dear all,
>
> I have a table which has UT dates, and I want the final astropy Table to
> have astropy.time.Time objects. Currently, I have a roundabout way of doing
> it. Can I directly supply the dtype or something else to tell Table.read()
> that this is a astropy.time column?
>
> Sample table:
> rccd160711.0024_s.fits 13.113 0.005 2016-07-18T17:37:07
> rccd160711.0025_s.fits 14.269 0.011 2016-07-18T17:37:12
> rccd160711.0026_s.fits 14.203 0.011 2016-07-18T17:37:12
> rccd160711.0027_s.fits 14.224 0.010 2016-07-18T17:37:12
> rccd160711.0028_s.fits 13.637 0.007 2016-07-18T17:37:10
> rccd160711.0029_s.fits 13.657 0.007 2016-07-18T17:37:10
> rccd160711.0030_s.fits 13.659 0.007 2016-07-18T17:37:11
>
> Current code:
> from astropy.table import Table, column
> tab = Table.read("sample.txt", names=("filename", "mag", "err", "time"),
> format="ascii")
>
> # Now replace the time column
> timecol = Column(name="time", data=Time(tab["time"]))
> tab.remove_column("time")
> tab.add_column(timecol)
>
Hi Varun,
It is *almost* possible to do this directly:
In [25]: from astropy.time import Time
In [26]: from astropy.io import ascii
In [27]: t = Table.read('sample.dat', format='ascii.no_header',
converters={'col4': [(Time, ascii.NoType)]})
In [28]: t
Out[28]:
<Table length=4>
col1 col2 col3 col4
str22 float64 float64 object
---------------------- ------- ------- -----------------------
rccd160711.0024_s.fits 13.113 0.005 2016-07-18T17:37:07.000
rccd160711.0025_s.fits 14.269 0.011 2016-07-18T17:37:12.000
rccd160711.0026_s.fits 14.203 0.011 2016-07-18T17:37:12.000
rccd160711.0027_s.fits 14.224 0.01 2016-07-18T17:37:12.000
In [29]: type(t['col4'])
Out[29]: astropy.time.core.Time
Unfortunately there is currently a limitation that one cannot rename mixin
columns such as the Time column. That should be fixed.
But there is at least a quicker, more direct workaround:
tab = Table.read("sample.txt", names=("filename", "mag", "err", "time"),
format="ascii")
tab.replace_column('time', Time(tab['time']))
- Tom
>
>
> Thanks,
> -- Varun
> ____________________
> - Varun Bhalerao -
> Office: A 214, IUCAA
> Ph: +91 20 2560 4214
> www.iucaa.in/~varunb
>
> This email is encrypted and signed with OpenPGP.
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20160817/04e5ae35/attachment.html>
More information about the AstroPy
mailing list