Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're getting the error because you haven't defined a variable named <code>soundings</code>. If you define this variable by</p> <pre><code>soundings = f.dimensions[u'soundings'] </code></pre> <p>then you should be able to find the length of <code>soundings</code> using <code>print len(soundings)</code>.</p> <p>Alternatively, you can access the length of the 'soundings' dimension directly by using</p> <pre><code>print len(f.dimensions[u'soundings']) </code></pre> <p>I have to admit, I've not used netCDF4, so I read the <a href="http://netcdf4-python.googlecode.com/svn/trunk/docs/netCDF4-module.html" rel="nofollow">netCDF4 documentation</a> briefly. In the section 'Dimensions in a netCDF file' it contains the following example of displaying the dimensions of a netCDF4 dataset:</p> <pre class="lang-none prettyprint-override"><code>&gt;&gt;&gt; print rootgrp.dimensions OrderedDict([('level', &lt;netCDF4.Dimension object at 0x1b48030&gt;), ('time', &lt;netCDF4.Dimension object at 0x1b481c0&gt;), ('lat', &lt;netCDF4.Dimension object at 0x1b480f8&gt;), ('lon', &lt;netCDF4.Dimension object at 0x1b48a08&gt;)]) </code></pre> <p>(For brevity, I've omitted the details about where <code>rootgrp</code> comes from.) The next line of code in the following code fragment is this:</p> <pre class="lang-none prettyprint-override"><code>&gt;&gt;&gt; print len(lon) </code></pre> <p>What you might have missed is that the variable <code>lon</code> was declared further up, as</p> <pre class="lang-none prettyprint-override"><code>&gt;&gt;&gt; lon = rootgrp.createDimension('lon', 144) </code></pre> <p>The above section of tutorial deals with <em>creating</em> new dimensions in a netCDF file, whereas you are reading existing dimensions from a netCDF file. You must therefore fetch the dimensions out of the netCDF file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload