[lsst-dm-stack-users] image.getArray() question

Mario Juric mjuric at lsst.org
Mon Feb 10 13:02:25 PST 2014


On 2/10/14, 10:41 , Chris Walter wrote:
> Hi All,
> 
> I was curious: why does image.getArray return an array in the order (Y,X)? The builtin AFW functions all seem to use X,Y (width, height).
> 
> from image::ImageBase<PixelT>::Array lsst.afw.image::ImageBase<PixelT>::getArray()
> 	
>  return ndarray::external(
>         reinterpret_cast<PixelT*>(row_begin(0)),
>         ndarray::makeVector(getHeight(), getWidth()),
>         ndarray::makeVector(rowStride, 1),
>         this->_manager
>     );
> 
> Is it something about memory or disk layout?  I got caught up trying to find a particular pixel and it wasn't working since I assumed getArray would use the same convention.  I assume there is a good reason but I was curious as to what it was.
> 

As Dustin replied, it's to be consistent with numpy. But it's not very
satisfactory and it's likely it will lead to bugs...

An optimal thing would be to allow the other convention by overloading
__call__, e.g.:

   img(x, y) = blah

but Python syntax doesn't allow calls on the left hand side of an
assignment, nor slices outside of [] (i.e., you wouldn't be able to
write "blah = img(1:10, 5:10)" ).

And if we reversed the convention, than all functions or utilities that
expect a numpy array (many of them!), would require a transpose.
-- 
Mario Juric,
Data Mgmt. Project Scientist, Large Synoptic Survey Telescope
Web : http://research.majuric.org     Phone : +1 617 744 9003



More information about the dm-users mailing list