masked_array/matplotlib issue with memmaps
If I initialize an AxesImage using a np.zeros array and then set the
axes data later to a np.memmap array, I get a RuntimeError when
matplotlib tries to autoscale the image. The errors continue to fill
my console and I'm forced to close the shell. This bug was introduced
when I switched from numpy v1.0.3.1 to the trunk v1.0.5.dev4815
The two hacks to get around this are:
1) Setting any array element to something other than zero fixes the error:
zdata[0,0] = 1
2) Specify the extent and max/min values when creating the image:
imgaxes = pylab.imshow(zdata, extent=(0, data_shape[1],
data_shape[0], 0), vmin=0, vmax=1)
Unfortunately, due to the way this errors I'm having a difficult time
debugging it. I'm hoping someone with in-depth knowledge of
masked_arrays will have some insight.
Code and output are below.
Thanks!
Chris
---- script to reproduce the bug ----
import pylab
import numpy as np
def printinfo(imgaxes):
a = imgaxes.get_array()
print '\nimgaxes array info:'
print 'type', type(a)
print 'shape', a.shape
print 'dtype', a.dtype
print 'has _mmap', hasattr(a, '_mmap')
data_type = 'float32'
data_shape = (30, 40)
zdata = np.zeros(data_shape, dtype=data_type)
#zdata[0,0] = 1 # No exception raised if this line is executed
imgaxes = pylab.imshow(zdata)
printinfo(imgaxes)
mmdata = np.memmap('foo.dat', dtype=zdata.dtype, shape=zdata.shape, mode='w+')
imgaxes.set_data(mmdata)
printinfo(imgaxes) # imgaxes array now has a _mmap
pylab.show()
---- version info ----
In [2]: pylab.matplotlib.__version__
Out[2]: '0.91.2'
In [4]: numpy.version.version
Out[4]: '1.0.5.dev4817'
---- error ----
In [26]: run memmap_reassign.py
imgaxes array info:
type
On Tue, Feb 26, 2008 at 5:26 PM, Christopher Burns
If I initialize an AxesImage using a np.zeros array and then set the axes data later to a np.memmap array, I get a RuntimeError when matplotlib tries to autoscale the image. The errors continue to fill my console and I'm forced to close the shell. This bug was introduced when I switched from numpy v1.0.3.1 to the trunk v1.0.5.dev4815
The two hacks to get around this are: 1) Setting any array element to something other than zero fixes the error: zdata[0,0] = 1 2) Specify the extent and max/min values when creating the image: imgaxes = pylab.imshow(zdata, extent=(0, data_shape[1], data_shape[0], 0), vmin=0, vmax=1)
Unfortunately, due to the way this errors I'm having a difficult time debugging it. I'm hoping someone with in-depth knowledge of masked_arrays will have some insight.
Exception exceptions.AttributeError: "'memmap' object has no attribute '_mmap'" in
ignored
Some operations on numpy.memmap objects create new arrays, but unfortunately, the new array objects, which should be ndarrays, are created as numpy.memmap instances even though they aren't. When they go to clean up after themselves, they fail. A workaround would be to make numpy.memmap.__del__ more robust and do nothing if ._mmap isn't present. A real fix would be to figure out how to make sure that "memmap+memmap", etc., make ndarray instances rather than memmap instances. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (2)
-
Christopher Burns
-
Robert Kern