Johannes Bauer wrote:
Hi group,

I'm confused, kind of. The application I'm writing currently reads data
from a FITS file and should display it on a gtk window. So far I have:

[...]
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)
pb_pixels = pb.get_pixels_array()

print(type(fits_pixels))
print(type(pb_pixels))

which gives

<type 'numpy.ndarray'>
<type 'array'>

So now I want to copy the fits_pixels -> pb_pixels. Doing

pb_pixels = fits_pixels

This simply makes pb_pixels refer to the same object as fits_pixels. It
doesn't copy the values into the existing pb_pixels object.

works and is insanely fast, however the picture looks all screwed-up
(looks like a RGB picture of unititialized memory, huge chunks of 0s
interleaved with lots of white noise).

Doing the loop:

for x in range(width):
        for y in range(height):
                pb_pixels[y, x] = fits_pixels[y, x]

works as expected, but is horribly slow (around 3 seconds for a 640x480
picture).

This does copy the values into the existing pb_pixels object.

So now I've been trying to somehow convert the array in a fast manner,
but just couldn't do it. What exactly is "array" anyways? I know
"array.array", but that's something completely different, right? Does
anyone have hints on how to go do this?

You should be able to copy the values using array slicing, something
like:

    pb_pixels[:] = fits_pixels

or:

    pb_pixels[:, :] = fits_pixels

perhaps.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to