updating netcdf file in scipy.io.netcdf

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

updating netcdf file in scipy.io.netcdf

Don Batchelor
How does one read in a netcdf file, modify some variables, and write
out the updated file using scipy.io.netcdf?  In the old
Scientific.IO.NetCDF there is the file open mode 'r+' that allows to
both read and write to a file.  I don't see an equivalent
functionality in scipy.io.netcdf.

I have tried just opening the file with mode 'r', modifying some
netcdf variables, and doing a file close to see what would happen.
But when I try to change the netcdf variables I get "RuntimeError:
array is not writeable".  See below.  It never reaches the 'close'
statement.   It must be possible to do this.  Otherwise how could one
make use of a record variable?

Traceback (most recent call last):
   File "netcdf_python_example.py", line 61, in <module>
     Te[:] = radius[:]
   File "/Users/dbh/Python_scripts/netcdf.py", line 677, in __setitem__
     self.data[index] = data
RuntimeError: array is not writeable



--
Donald B. Batchelor
Plasma Theory Group

Phone: (865) 574-1288
Fax:   (865) 576-7926
E-mail: [hidden email]

Oak Ridge National Laboratory
Fusion Energy Division
P. O. Box 2008
Oak Ridge, TN 37831-6169
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: updating netcdf file in scipy.io.netcdf

Benjamin Root-2
On Mon, Jan 10, 2011 at 11:19 AM, Don Batchelor <[hidden email]> wrote:
How does one read in a netcdf file, modify some variables, and write
out the updated file using scipy.io.netcdf?  In the old
Scientific.IO.NetCDF there is the file open mode 'r+' that allows to
both read and write to a file.  I don't see an equivalent
functionality in scipy.io.netcdf.

I have tried just opening the file with mode 'r', modifying some
netcdf variables, and doing a file close to see what would happen.
But when I try to change the netcdf variables I get "RuntimeError:
array is not writeable".  See below.  It never reaches the 'close'
statement.   It must be possible to do this.  Otherwise how could one
make use of a record variable?

Traceback (most recent call last):
  File "netcdf_python_example.py", line 61, in <module>
    Te[:] = radius[:]
  File "/Users/dbh/Python_scripts/netcdf.py", line 677, in __setitem__
    self.data[index] = data
RuntimeError: array is not writeable



This is because the netcdf module uses memmap, so writing to netcdf variables that come from a read-only file won't work.  Does using 'rw' not work for a mode?  I haven't tried such a thing, so I don't know what would happen.  I usually open a file for reading and create a different file for writing.

Ben Root


_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: updating netcdf file in scipy.io.netcdf

Chris Barker - NOAA Federal
On 1/10/2011 10:20 AM, Benjamin Root wrote:

>     How does one read in a netcdf file, modify some variables, and write
>     out the updated file using scipy.io.netcdf?

I use Jeff Whitaker's NetCDF4 package -- it does support this -- that
may be an option for you.

-Chris


--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user