[Tutor] Request for advice on Python code

Elaina Ann Hyde elainahyde at gmail.com
Tue Feb 14 06:12:36 CET 2012


On Tue, Feb 14, 2012 at 1:38 PM, Andre' Walker-Loud <walksloud at gmail.com>wrote:

> Hi Elaina,
>
> just reading your question (and responses).  There is an issue with what
> you wrote in the email, which may help.
>
> > for row in dat:
> >
>  gcoords=ICRSCoordinates(dat['ra-drad'],dat['dec-drad'],radians=True).convert(GalacticCoordinates)
>
> This line is identical to the one that broke before, and now you are just
> looping over it, so it is not surprising to fail in the same way.  If a
> loop will work, you would need the following instead
>
> """
> for row in dat:
>        gcoords =
> ICRSCoordinates(row['ra-drad'],row['dec-drad'],radians=True).convert(GalacticCoordinates)
> """
>
> notice the "dat" --> "row" inside the loop.  Now if that works, you can
> get it to work along the following lines
>
> Example: suppose the output (gcoords) is a scalar float, and you would
> like to store these data in an array.  Then you can do
>
> """
> import numpy as np #just copying the style from a previous reply
>
> gcoords = np.zeros([len(dat)]) #this creates a numpy array of the length
> of dat, and fills it with all zeros
> for i,row in enumerate(dat):
>        gcoords[i] =
> ICRSCoordinates(row['ra-drad'],row['dec-drad'],radians=True).convert(GalacticCoordinates)
> """
>
> If the loop doesn't work, then you need to investigate the astrophysics
> library you are using, as previously mentioned, and hopefully there is
> someone who is familiar with it you can ask questions to.
>
> Actually, even if the loop does work, you want to be more familiar with
> the astrophysics library.  You certainly would not want to produce results
> with it (and base some conclusions on them/publish them) without being 100%
> sure you know what it is doing.
>
>
> Good luck,
>
> Andre



Thanks to everyone who replied, Andre's idea was very good and led to the
following solution:
l=[]
b=[]
for i in xrange(len(Radeg)):
    gcoords=ICRSCoordinates(Radeg[i],Decdeg[i]).convert(GalacticCoordinates)
    l.append(gcoords.l.degrees)
    b.append(gcoords.b.degrees)

.... you know, just in case anyone ever wants to convert to galactic
coordinates in the future.
Thanks again
~Elaina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120214/81e909cf/attachment.html>


More information about the Tutor mailing list