[AstroPy] Constructing Angle from a tuple specified as sign string plus numbers for degrees, arcmin, arcsec
Thomas Robitaille
thomas.robitaille at gmail.com
Mon Aug 10 17:53:06 EDT 2015
Erik Bray 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.)
In case you want to do this without loops, np.char.add can be used to
concatenate string arrays element-wise. So for instance you could
concatenate the sign column and the degree column of the declination with
np.add(t['DE-'], t['DEd'])
then you would end up with three arrays instead of four.
Cheers,
Tom
>
> Erik
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
More information about the AstroPy
mailing list