[AstroPy] [pywcs] Unit question

Michael Droettboom mdroe at stsci.edu
Tue Apr 5 11:36:36 EDT 2011


On 04/05/2011 09:26 AM, Michael Droettboom wrote:
> On 04/05/2011 10:22 AM, Ole Streicher wrote:
>    
>> 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?
>>
>>      
> Ah -- I understand your question now.  I will look into this and keep
> you posted on progress.
>
>
>    

Hmm.  Once looking into this, it seems this works for me -- Python 
creates an implicit iterator when __getitem__ and __len__ are defined.  
What version of pywcs and Python are you using?

In [1]: import pywcs

In [2]: wcs = pywcs.WCS()

In [3]: wcs.wcs.cunit
Out[3]: ['', '']

In [4]: type(wcs.wcs.cunit)
Out[4]: pywcs.StrListProxy

In [5]: for x in wcs.wcs.cunit:
    ...:     print repr(x)
    ...:
''
''

In [6]: list(wcs.wcs.cunit)
Out[6]: ['', '']

Mike

-- 
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA




More information about the AstroPy mailing list