[AstroPy] DATAMD5 calculation

Erik Bray embray at stsci.edu
Wed May 25 10:10:23 EDT 2011

On 05/24/2011 06:08 PM, Erik Bray wrote:
> At any rate, in the meantime you can use hashlib to generate a checksum
> on hdu.data--no need to use any internal attributes:
> import hashlib
> md5sum = hashlib.md5()
> md5sum.update(hdu.data.tostring())

I should add, the tostring() here was a typo--I don't know why I thought 
to insert that.  just md5sum.update(hdu.data) is sufficient.  Calling 
tostring() is a bad idea, since it actually causes the array to be copied.

> hdu.header['DATAMD5'] = md5sum.hexdigest()
> My version of hashlib seems to know how to efficiently handle objects
> that implement the buffer interface (i.e. numpy arrays), so this should
> be pretty fast.
> Erik
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy

More information about the AstroPy mailing list