<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Great, that makes perfect sense. I figured it was a type problem,
but I didn't know how to check the type that the file variable was
expecting.<br>
<br>
Thanks!<br>
<br>
Walter<br>
<br>
<div class="moz-cite-prefix">On 9/3/14, 3:09 PM, David Brown wrote:<br>
</div>
<blockquote
cite="mid:CAC92F7dhcLgdRQxdxzD05hzZcWTby+eFn9+ZcSmrvh=sZp+VCQ@mail.gmail.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div dir="ltr">The error message says "type or dimensional
mismatch" and in this case it's a type mismatch. This is an easy
thing to forget and a cause of much wasted effort. The typecode
'f' specifies a 32 bit float, but in Python (not just numpy) a
float is 64 bits, equivalent to the typecode 'd'.
<div>
Maybe in the future we can have separate messages for type and
dimensional mismatches. <br>
<div>Here is a script that does what you want:</div>
<div><br>
</div>
<div>
<div>import Nio</div>
<div>import numpy as np</div>
<div>import os</div>
<div>os.system('rm -f <a moz-do-not-send="true"
href="http://test.nc">test.nc</a>')</div>
<div>ofile = '<a moz-do-not-send="true"
href="http://test.nc">test.nc</a>'</div>
<div>outfile = Nio.open_file(ofile, 'w')</div>
<div>outfile.create_dimension('time',None)</div>
<div>outfile.create_dimension('lat', 50)</div>
<div>outfile.create_dimension('lon',50)</div>
<div>v =
outfile.create_variable('tvar','f',('time','lat','lon'))</div>
<div>
v[0,:,:] = np.ones( (50,50), dtype = 'float32')</div>
<div># but you only really need to specify the leftmost
dimension</div>
<div>v[1] = np.ones( (50,50), dtype = 'float32') </div>
<div>outfile.close()</div>
</div>
<div><br>
</div>
<div> -dave</div>
<div><br>
</div>
</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Wed, Sep 3, 2014 at 12:06 PM,
whannah <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:whannah@rsmas.miami.edu" target="_blank">whannah@rsmas.miami.edu</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"> Hi,<br>
<br>
I'm trying to develop some code that will write new data
to a file once a day. The "time" dimension is unlimited.<br>
<br>
Here are some snippets of code that I thought should work<br>
<blockquote><tt>outfile = nio.open_file(ofile, "w")</tt><tt><br>
</tt><tt>fvar = outfile.create_variable('test', 'f',
('time','lat','lon'))</tt><tt><br>
</tt><tt><br>
</tt><tt>fvar[0,:,:] = np.ones( (nlat,nlon) ,
dtype=float )</tt></blockquote>
The last line throws this error:<br>
<blockquote><tt>NIOError: type or dimensional mismatch
writing to variable (test)</tt><br>
</blockquote>
if I use a constant value<br>
<blockquote><tt>fvar[0,:,:] = 1.</tt></blockquote>
or I don't specify the indices of "fvar":<br>
<blockquote><tt>fvar = np.ones( (nlat,nlon) , dtype=float
)</tt></blockquote>
I don't have any problems. But I really need to specify
the time index. How do I write different numpy arrays to <tt>fvar[0,:,:]</tt>
and <tt>fvar[1,:,:]</tt>?<br>
<br>
<br>
thanks,<br>
Walter<br>
</div>
<br>
_______________________________________________<br>
pyngl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a moz-do-not-send="true"
href="http://mailman.ucar.edu/mailman/listinfo/pyngl-talk"
target="_blank">http://mailman.ucar.edu/mailman/listinfo/pyngl-talk</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</body>
</html>