views:

43

answers:

2

I'm running python2.5 and trying to use the astLib library to analyse WCS information in astronomical images. I try and get the object instanciated with the following skeleton code:

from astLib import astWCS

w = astWCS.WCS('file.fits') # error here

where file.fits is a string pointing to a valid fits file.

I have tried using the alternate method of passing a pyfits header object and this fails also:

import pyfits
from astLib import astWCS

f = pyfits.open('file.fits')
header = f[0].header
f.close()

w = astWCS.WCS(header, mode='pyfits') # error here also

The error is this:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/astro/phrfbf/build/lib/python2.6/site-packages/astLib/astWCS.py", line 79, in __init__
    self.updateFromHeader()
  File "/home/astro/phrfbf/build/lib/python2.6/site-packages/astLib/astWCS.py", line 119, in updateFromHeader
    self.WCSStructure=wcs.wcsinit(cardstring)
  File "/home/astro/phrfbf/build/lib/python2.6/site-packages/PyWCSTools/wcs.py", line 70, in wcsinit
    return _wcs.wcsinit(*args)
TypeError: in method 'wcsinit', argument 1 of type 'char *'

When I run in ipython, I get the full error here on the pastebin

I know the astWCS module is a wrapped version of WCStools but i'd prefer to use the Python module as the rest of my code is in Python

Can anyone help with this problem?

A: 

Oh sorry, I should have seen. Looking at the pastebin in more detail, the only error I can think of is that, for some reason the header has unicode in it. It can't be converted to char *, and you get the error. I tried searching for something in the header, but everything looks okay. Can you do this and post the output in another pastebin?

import pyfits

f = pyfits.open('file.fits')
header = f[0].header
f.close()

for x, i in enumerate(header.iteritems()):
    if len(str(i[1])) >= 70:
        print x, str(i[1])

cardlist = header.ascardlist() 
cardstring = "" 
for card in cardlist: 
    cardstring = cardstring + str(card)

print repr(cardstring)

Or, if you can check the header of your fits file for "funny" characters, getting rid of them should solve the issue.

Alok
A: 

Just found out the updated version of this library has fixed the problem, thanks for everyone's help

Simon Walker