[AstroPy] pywcs problem

Jae-Joon Lee lee.j.joon at gmail.com
Thu Jul 3 13:39:58 EDT 2008


Hi Stefan,

I guess you're providing a wrong input for pywcs.WCS, i.e., "h"
contains invalid FITS header. As far as I remember (but you'd better
double check), a line in FITS header should be 80-char-long without
"\n". You may use the following code to convert your string to valid
FITS header.

h = "".join([s + " " * (80-len(s)) for s in h.split("\n")])

With this change, I get

[[ 279.322    -7.3123]]

as expected.

I hope this solves your problem.
Regards,

-JJ




On Thu, Jul 3, 2008 at 10:51 AM, Stefan Schwarzburg
<stefan.schwarzburg at googlemail.com> wrote:
> Hi,
> I have a problem with pywcs. I tried to get a feeling for the library by
> playing around with it.
> At the end of the email, there is my modified "test", which is taken from
> here "http://stsdas.stsci.edu/astrolib/pywcs-1.0a1-4.3_api/"
>
> Now when I let this test run, I get the following output:
>>-------------------USING TEST HEADER-------------------
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>[[ 99.322   36.3123]]
>
> To me this seems rather strange, since in the testheader, there is this part
> here:
> CRPIX1  =                151.0 / Reference pixel on axis 1
> CRPIX2  =                151.0 / Reference pixel on axis 2
> CRVAL1  =              279.322 / Value at ref. pixel on axis 1
> CRVAL2  =              -7.3123 / Value at ref. pixel on axis 2
>
> and my test uses [150,150] as test pixel position.
> Should I not get something like:~ [[279, -7]] ?
>
> I hope someone can help me here.
>
> Thanks,
> Stefan
>
>
>
> #!/usr/bin/env python
> import numpy
> import pywcs
> import pyfits
> import sys
>
> print "-------------------USING TEST HEADER-------------------"
> h = """
> SIMPLE  =                    T / file does conform to FITS standard
> BITPIX  =                  -32 / number of bits per data pixel
> NAXIS   =                    2 / number of data axes
> NAXIS1  =                  301 / length of data axis 1
> NAXIS2  =                  301 / length of data axis 2
> EXTEND  =                    T / FITS dataset may contain extensions
> COMMENT   FITS (Flexible Image Transport System) format is defined in
> 'Astronomy
> COMMENT   and Astrophysics', volume 376, page 359; bibcode:
> 2001A&A...376..359H
> CTYPE1  = 'RA---CAR'           / Type of co-ordinate on axis 1
> CTYPE2  = 'DEC--CAR'           / Type of co-ordinate on axis 2
> CRPIX1  =                151.0 / Reference pixel on axis 1
> CRPIX2  =                151.0 / Reference pixel on axis 2
> CRVAL1  =              279.322 / Value at ref. pixel on axis 1
> CRVAL2  =              -7.3123 / Value at ref. pixel on axis 2
> CDELT1  =                -0.02 / Pixel size on axis 1
> CDELT2  =                 0.02 / Pixel size on axis 2
> MJD-OBS =     51544.4992571308 / Modified Julian Date of observation
> DATE-OBS= '2000-01-01T11:58:55.816'/ Date of observation
> RADESYS = 'FK5     '           / Reference frame for RA/DEC values
> EQUINOX =               2000.0 / [yr] Epoch of reference equinox
> OBJECT  = 'SOMETHING'
> BUNIT   = 'Count   '
> BSCALE  =                  1.0
> BZERO   =                  0.0
> """
>
> wcs = pywcs.WCS(h)
>
> # Print out the "name" of the WCS, as defined in the FITS header
> print wcs.name
>
> # Some interesting pixel coordinates
> pixcrd = numpy.array([[150,150]], numpy.double)
>
> # Convert pixel coordinates to world coordinates
> world = wcs.pixel2world(pixcrd)
> print world
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://lists.astropy.scipy.org/mailman/listinfo/astropy
>
>



More information about the AstroPy mailing list