Re: problem with PyNIO dimension sizes

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri, 12 Dec 2008 15:25:39 -0700

Hi Zach,

This looks like a bug, but I'm not certain.

I took your code snippet, and made it into code I could
actually run, and I got the same results as you:

import numpy, os, Nio

ncols = 1024
nrows = 1024
nt = 41

prcp = numpy.zeros([nt,nrows,ncols], dtype='float32')

filename = ""

for t in range(nt):
   if os.path.exists(filename): os.remove(filename)
   ncfile = Nio.open_file(filename, 'c')
   d4 = ('record','levels','y','x')
   prcp_NC = ncfile.create_variable('prcp','f',d4)
   print prcp_NC.shape
   print prcp.shape
   print prcp_NC[0,0,:,:].shape
   print prcp[t,:,:].shape
   prcp_NC[0,0,:,:] = prcp[t,:,:]

Hopefully Dave can take a look at this and see a
work-around. I tried a few things with no luck.


On Fri, 12 Dec 2008 10:48:16 -0600
  Zach DuFran <> wrote:
> I am trying to write a 4D variable to a NetCDF file and
>I am receiving a fatal error. The line where the error
>occurs is prcp_NC[0,0,:,:] = prcp[t,:,:]. I have printed
>out the shapes of each variable and they match. When I
>switch the order in prcp_NC to be prcp_NC[:,:,0,0] the
>script will run succesfully, but the data in the NetCDF
>file is all blank.
> If I assign prcp_NC as a 2D variable (only x and y) and
>do prcp_NC[:,:] = prcp[t,:,:] the data is written
> The error message for the attached script is:
> fatal:Dimension sizes of left hand side do
>not match right hand side
> The only way I can get the assignment to a 4D variable
>to work is to add 2 loops so the code reads:
> for i in xrange(nrows):
> for j in xrange(ncols):
> prcp_NC[0,0,i,j] = prcp[t,i,j]
> Of course, this method is considerably slower.
> I would appreciate any help you can provide-
> Zach DuFran

pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
Received on Fri Dec 12 2008 - 15:25:39 MST

This archive was generated by hypermail 2.2.0 : Thu Jan 01 2009 - 08:39:20 MST