1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
<a name="Module:Scientific.IO.NetCDF"><h1>Module Scientific.IO.NetCDF</h1></a>
<hr width=70%>
<a name="Class:Scientific.IO.NetCDF.NetCDFFile"><h2>Class NetCDFFile: netCDF file</h2></a>
<p>Constructor: NetCDFFile(<i>filename</i>, <i>mode</i>=<tt>"r"</tt>)</p>
<p><dl>
<dt><i>filename</i></dt>
<dd><p>
name of the netCDF file. By convention, netCDF files
have the extension ".nc", but this is not enforced.
The filename may contain a home directory indication
starting with "~".</p></dd>
<dt><i>mode</i></dt>
<dd><p>
access mode. "r" means read-only; no data can be modified.
"w" means write; a new file is created, an existing
file with the same name is deleted. "a" means append
(in analogy with serial files); an existing file is
opened for reading and writing, and if the file does
not exist it is created. "r+" is similar to "a",
but the file must already exist. An "s" can be appended
to any of the modes listed above; it indicates that the
file will be opened or created in "share" mode, which
reduces buffering in order to permit simultaneous read
access by other processes to a file that is being written.</p></dd>
</dl>
</p>
<p>A NetCDFFile object has two standard attributes: <tt>dimensions</tt> and
<tt>variables</tt>. The values of both are dictionaries, mapping dimension
names to their associated lengths and variable names to variables,
respectively. Application programs should never modify these
dictionaries.</p>
<p>All other attributes correspond to global attributes defined in the
netCDF file. Global file attributes are created by assigning to
an attribute of the NetCDFFile object.
</p>
<b>Methods:</b><br>
<ul>
<li> <b><i>close</i></b>()
<p>Closes the file. Any read or write access to the file
or one of its variables after closing raises an exception.</p>
<li> <b><i>createDimension</i></b>(<i>name</i>, <i>length</i>)
<p>Creates a new dimension with the given <i>name</i> and
<i>length</i>. <i>length</i> must be a positive integer or <tt>None</tt>,
which stands for the unlimited dimension. Note that there can
be only one unlimited dimension in a file.</p>
<li> <b><i>createVariable</i></b>(<i>name</i>, <i>type</i>, <i>dimensions</i>)
<p>Creates a new variable with the given <i>name</i>, <i>type</i>, and
<i>dimensions</i>. The <i>type</i> is a one-letter string with the same
meaning as the typecodes for arrays in module Numeric; in
practice the predefined type constants from Numeric should
be used. <i>dimensions</i> must be a tuple containing dimension
names (strings) that have been defined previously.</p>
<p>The return value is the NetCDFVariable object describing the
new variable.</p>
<li> <b><i>sync</i></b>()
<p>Writes all buffered data to the disk file.</p>
</ul>
<hr width=70%>
<a name="Class:Scientific.IO.NetCDF.NetCDFVariable"><h2>Class NetCDFVariable: Variable in a netCDF file</h2></a>
<p>NetCDFVariable objects are constructed by calling the method
<tt>createVariable</tt> on the NetCDFFile object.</p>
<p>NetCDFVariable objects behave much like array objects defined
in module Numeric, except that their data resides in a file.
Data is read by indexing and written by assigning to an
indexed subset; the entire array can be accessed by the index
<tt>[:]</tt> or using the methods <tt>getValue</tt> and
<tt>assignValue</tt>. NetCDFVariable objects also have attribute
"shape" with the same meaning as for arrays, but the shape
cannot be modified. There is another read-only attribute
"dimensions", whose value is the tuple of dimension names.</p>
<p>All other attributes correspond to variable attributes defined in the
netCDF file. Variable attributes are created by assigning to
an attribute of the NetCDFVariable object. </p>
<p>Note:
If a file open for reading is simultaneously written by another program,
the size of the unlimited dimension may change. Every time the shape
of a variable is requested, the current size will be obtained from
the file. For reading and writing, the size obtained during the last
shape request is used. This ensures consistency: foo[-1] means the
same thing no matter how often it is evaluated, as long as the shape
is not re-evaluated in between.
</p>
<b>Methods:</b><br>
<ul>
<li> <b><i>assignValue</i></b>(<i>value</i>)
<p>Assigns <i>value</i> to the variable. This method allows
assignment to scalar variables, which cannot be indexed.</p>
<li> <b><i>getValue</i></b>()
<p>Returns the value of the variable. This method allows
access to scalar variables, which cannot be indexed.</p>
<li> <b><i>typecode</i></b>()
<p>Return the variable's type code (a string).</p>
</ul>
|