[AstroPy] [pywcs] Unit question

Ole Streicher astropy at liska.ath.cx
Tue Apr 5 10:22:59 EDT 2011


Am 05.04.2011 14:02, schrieb Michael Droettboom:
> On 04/05/2011 03:16 AM, Ole Streicher wrote:
>> But the resulting image needs now a new WCS header since the origin may
>> have been changed, and I am wondering how one could easily built one.
>> For CRVALx I have to calculate the world coordinates of the origin of
>> the resulting image within the coordinate system of the primary image,
>> in the units defined by CUNITx.
>>    
> I see.  That makes sense.  So the user input is in some unit, and you 
> need to get to the world units used by the existing WCS.  The 
> UnitConverter class with have = input_unit (whatever that may be) and 
> want = wcs.wcs.cuint[wcs.wcs.spec] should do what you need.

Yes, this is what I do now, and it works fine.

>> This is what I needed, thank you (wcs.wcs.cunit). BTW, I would propose
>> to implement an iterator there (or as wcs.unit)?

> I'm not sure what you mean by having an iterator there.  Right now it 
> returns a list, with one entry for each axis.  As the number of axes is 
> always really small, I'm not sure what advantage an iterator would have.

The code snipped that does the conversion was supposed to be like:

----------------8<---------------------------------------------------

origin_sky = wcs.wcs_pix2sky([ origin ], 1)[0]
fits_units = [ hdu.header['CUNIT%i' % (i+1)]
               for i in range(len(origin_sky)) ]
crval_keys = [ 'CRVAL%i' % (i+1) for i in range(len(origin_sky)) ]

for value, unit, fitsunit, key in zip(origin_sky, wcs.wcs.cunit,
                                      fits_units, crval_keys):
    conv = pywcs.UnitConverter(have = unit, want = fitsunit)
    hdu.header[key] = conv.convert([value])[0]

----------------8<---------------------------------------------------

but this does not work since wcs.wcs.cunit has indexing but is not a
list. Even builing a list like list(wcs.wcs.cunit) does not work here.

This is not a big problem since using

wcs_units = [ wcs.wcs.cunit[i] for i in len(wcs.wcs.cunit) ]

works well; however I would prefer to iterate directly over the list.
I could have a look into str_list_proxy.c and provide you a patch, if I
find some time?

Regards

Ole



More information about the AstroPy mailing list