[AstroPy] Pywcs: Creation, access to properties

Ole Streicher astropy at liska.ath.cx
Fri Apr 29 11:04:26 EDT 2011


Hello,

I have two questions about pywcs:

First is, how do I create a pywcs.WCS object not from a file, but with 
certain parameters? The way I do it now is first to create a header with 
the required keywords, and then use the pywcs.WCS constructor, but this 
seems to me a bit indirect.

The second question is on how do I access some parameters in a robust 
way? For example, I want to get the instrument resolution in arcsec out 
of the image. Currently, I implemented it like

import numpy
import pywcs

def get_resolution(wcs, units = None)
     c = numpy.sqrt(numpy.sum((wcs.wcs.cd if wcs.wcs.has_cd()
                               else wcs.wcs.pc) ** 2, axis = 0))
     if units is None:
       return c
     else
       return [
          pywcs.UnitConverter(from_unit, to_unit).convert(cc)
          if to_unit is not None else cc
          for from_unit, to_unit, cc in zip(wcs.wcs.cunit, units, c)
          ]

but this looks a bit weird, and I feel that I still did not took all 
possible cases to construct the WCS. Is there a simpler way?

This question arises since I often have to implement something like 
"give me the pixel position just 1 arcsec upwards (in CCD orientation) 
from the image center".

Best regards

Ole



More information about the AstroPy mailing list