[Tutor] Request for advice on Python code

Alan Gauld alan.gauld at btinternet.com
Tue Feb 14 01:52:04 CET 2012

On 13/02/12 23:50, Elaina Ann Hyde wrote:
> Hi, I'm working on a routine for reading in the Schlegel dustmaps.  I
> have an ascii table with values, Ra-Dec and I'm trying to convert 2
> columns to l,b and get the dust values out, this is a 2 part problem as
> I need to first convert to l,b, keep those values for other uses
> (calculating VLSR), and get extinctions for each l,b value,

That sounds very interesting but almost totally meaningless to most of 
us on this list I suspect! :-)

> import astropysics
> from astropysics.coords import ICRSCoordinates,GalacticCoordinates
> import asciitable

 From those lines alone I suspect you might have more luck on either a 
specialised forum or on the general Python mailing list/newsgroup.
It looks like a much more specialised query than is usual on this list 
which is for beginning Python programmers.


> dustmap='SFD_dust_4096_ngp.fits'
> EB_V=astropysics.obstools.get_SFD_dust(l,b,dustmap,interpolate=True)
> -------
> this gives the error 'Only length-1 arrays can be converted to Python
> scalars' ... however, I cannot do:

Always post the full error text not just the last line or a summary.
It usually contains a lot of useful information, especially what code 
Python actually saw when it tried to execute your code.

> gcoords=ICRSCoordinates(dat['ra-drad'],dat['dec-drad'],radians=True).convert(GalacticCoordinates)
> without the same error.  Any ideas would be appreciated, thanks!

On the surface I have no idea because that looks like an issue
related to the use of the astrophysics module. But the error
message may reveal a more fundamental issue underneath.

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list