[AstroPy] Constructing Angle from a tuple specified as sign string plus numbers for degrees, arcmin, arcsec

Erik Bray embray at stsci.edu
Tue Aug 11 10:32:02 EDT 2015


On 08/10/2015 11:18 PM, Aldcroft, Thomas wrote:
> I'll dispense with my standard rant on how moronic sexigesimal is, and suggest this:
>
> dec = Angle((np.where(t['DE-'] == '-', -1.0, 1.0) * t['DEd'], t['DEm'], t['DEs']),
>              unit='deg')
>
> This relies on a tricky behavior that -0.0 has a sign of -1.  I'm not 100% sure
> if that works on all platforms, but it works on 64-bit mac and linux.

+1 to Tom's version.  That seems the simplest of all.


> On Mon, Aug 10, 2015 at 8:19 PM, John Gizis <gizis at udel.edu
> <mailto:gizis at udel.edu>> wrote:
>
>     "It seems a bit strange that the table format in this case indicates the sign of
>     the declination as a completely separate field, rather than as just part of the
>     numeric string.  But I'm not intimately familiar with the quirks of the CDS
>     table format. "
>
>     I don't think is unusual for CDS tables. I always thought it was because
>     Fortran77 didn't know -00 is different than +00.
>
>     On Mon, Aug 10, 2015 at 11:49 AM, Erik Bray <embray at stsci.edu
>     <mailto:embray at stsci.edu>> wrote:
>
>         On 08/10/2015 05:26 PM, Eric L. N. Jensen wrote:
>         > Hi all,
>         >
>         > I’m working with a table from CDS (i.e. from an ApJ paper) that specifies the declination coordinate in four separate columns:  a string for the sign of the declination, and three numerical columns for degrees, arcminutes, and arcseconds.  Is there a straightforward way to combine these into a single astropy.coordinates Angle object?  The standard Angle function (constructor?) only accepts a tuple with three entries.
>         >
>         > I guess what I’m looking for is the inverse method of ‘signed_dms’.
>         >
>         > If it’s of use, the table I’m working with is here:http://iopscience.iop.org/0067-0049/184/1/18/fulltext/apjs300673t4_mrt.txt
>         >
>         > Thanks in advance for your help with this,
>
>         It seems a bit strange that the table format in this case indicates the
>         sign of
>         the declination as a completely separate field, rather than as just part
>         of the
>         numeric string.  But I'm not intimately familiar with the quirks of the CDS
>         table format.  Is that normal?  I wonder if there's a way to get the CDS
>         reader
>         to format those fields as a single column.  Tom Aldcroft would know better.
>
>         You can instantiate an Angle array using a generator, so you could
>         probably just
>         slurp in the data using a generator expression, allowing you to
>         transform the
>         values one a time while creating the Angle rather than transforming the
>         table
>         all at once first (please bear with the LISPiness of this example):
>
>         dec = Angle(((int(row[0] + str(row[1])), row[2], row[3])
>                        for row in table['DE-', 'DEd', 'DEm', 'DEs'))
>
>
>         # (Note: originally I used row[2:] above, but there seems to be an
>         unrelated bug
>         involved in taking slices of rows...I'll report on that.)
>
>         Erik




More information about the AstroPy mailing list