Created
December 8, 2015 22:17
-
-
Save augustfly/b4c6e30c2a39587267ee to your computer and use it in GitHub Desktop.
Convert an AAS Journal MRT file to a CSV, fixing sexidecimal column madness as you go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # brought to you by [email protected] | |
| # version 0.1; 2015-12-08T17:17:00-0500 | |
| from astropy.table import Table | |
| from astropy.coordinates import Angle, SkyCoord | |
| import astropy.units as u | |
| # parse some ApJ/AJ MRT file. it's really that easy. | |
| data = Table.read("datafile4.txt", format="ascii.cds") | |
| ra = [] | |
| # we always use the same column names. always. | |
| for row in data['RAh', 'RAm', 'RAs']: | |
| ra.append(Angle((row[0], row[1], row[2]), unit=u.hour)) | |
| dec = [] | |
| # thank you taldcroft | |
| for row in data['DE-', 'DEd', 'DEm', 'DEs']: | |
| dec.append(Angle((np.where(row[0] == '-', -1.0, 1.0) * row[1], row[2], row[3]),unit=u.deg)) | |
| pos = SkyCoord(ra=ra, dec=dec) | |
| # you could try `data['pos'] = pos` as a Mixin column, | |
| # but I couldn't get table.write to write it to a file *easily* | |
| data[‘RAdeg'] = pos.ra.deg | |
| data[‘DEdeg'] = pos.dec.deg | |
| data.write("datafile4.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment