Improving pcolor function

I noticed that the pcolor function uses about twice as much memory as it needs to. When creating the list of vertices, you first create the lists X1, Y1, X2, Y2, X3, Y3, X4, and Y4, and then combine those lists into the “verts” list. I tried to change it to make it not waste memory by changing the lines between the line:

mask = ma.getmaskarray©[0:Nx-1,0:Ny-1]+xymask

and

C = compress(ravel(mask==0),ravel(ma.filled(C[0:Nx-1,0:Ny-1])))

to the following:

numVertices = len(compress(ravel(mask==0),ravel(ma.filled(X[0:-1,0:-1]))))

verts = zeros((numVertices, 4, 2))

verts[:, 0, 0] = compress(ravel(mask==0),ravel(ma.filled(X[0:-1,0:-1])))

verts[:, 0, 1] = compress(ravel(mask==0),ravel(ma.filled(Y[0:-1,0:-1])))

verts[:, 1, 0] = compress(ravel(mask==0),ravel(ma.filled(X[1:,0:-1])))

verts[:, 1, 1] = compress(ravel(mask==0),ravel(ma.filled(Y[1:,0:-1])))

verts[:, 2, 0] = compress(ravel(mask==0),ravel(ma.filled(X[1:,1:])))

verts[:, 2, 1] = compress(ravel(mask==0),ravel(ma.filled(Y[1:,1:])))

verts[:, 3, 0] = compress(ravel(mask==0),ravel(ma.filled(X[0:-1,1:])))

verts[:, 3, 1] = compress(ravel(mask==0),ravel(ma.filled(Y[0:-1,1:])))

However it says that the “array cannot be safely cast to required type” on the third line (verts[:, 0, 0] = …). I have no idea why this is happening because both arrays are the same length (numVertices). Does anyone have any ideas how to fix this problem?

Also, if I do get this working, is there a way to submit it as a patch? Having a pcolor function that doesn’t use up so much memory might be useful for lot of people, not just me.

-Alex Mont

Hi Alexander,

I can’t duplicate your problem using the patch. It works fine for me. However, I’m using numarray and not numeric.
You might want to print out the types of the arrays on the left and
right sides and use an astype() method to convert the right side to the
type of the left side.

– Paul

···

On 11/1/05, Alexander Mont <alexmont1@…614…> wrote:

I noticed that the pcolor function uses about twice as much memory as it needs to. When creating the list of vertices, you first create the lists X1, Y1, X2, Y2, X3, Y3, X4, and Y4, and then combine those lists into the “verts” list. I tried to change it to make it not waste memory by changing the lines between the line:

mask = ma.getmaskarray©[0:Nx-1,0:Ny-1]+xymask

and

C = compress(ravel(mask==0),ravel(ma.filled(C[0:Nx-1,0:Ny-1])))

to the following:

numVertices = len(compress(ravel(mask==0),ravel(ma.filled(X[0:-1,0:-1]))))

verts = zeros((numVertices, 4, 2))

verts[:, 0, 0] = compress(ravel(mask==0),ravel(ma.filled(X[0:-1,0:-1])))

verts[:, 0, 1] = compress(ravel(mask==0),ravel(ma.filled(Y[0:-1,0:-1])))

verts[:, 1, 0] = compress(ravel(mask==0),ravel(ma.filled(X[1:,0:-1])))

verts[:, 1, 1] = compress(ravel(mask==0),ravel(ma.filled(Y[1:,0:-1])))

verts[:, 2, 0] = compress(ravel(mask==0),ravel(ma.filled(X[1:,1:])))

verts[:, 2, 1] = compress(ravel(mask==0),ravel(ma.filled(Y[1:,1:])))

verts[:, 3, 0] = compress(ravel(mask==0),ravel(ma.filled(X[0:-1,1:])))

verts[:, 3, 1] = compress(ravel(mask==0),ravel(ma.filled(Y[0:-1,1:])))

However it says that the “array cannot be safely cast to required type” on the third line (verts[:, 0, 0] = …). I have no idea why this is happening because both arrays are the same length (numVertices). Does anyone have any ideas how to fix this problem?

Also, if I do get this working, is there a way to submit it as a patch? Having a pcolor function that doesn’t use up so much memory might be useful for lot of people, not just me.

-Alex Mont