<div dir="ltr">Hi Steve,<br><br>Thanks very much for the code snippet. I figured out the following via experimentation.<br><br>- Open specific layer by using:<br>layer = gdal.Open('netCDF:"<a href="http://annual_mean.nc">annual_mean.nc</a>":temp')<br>
<br>- Then get at the layer data data using the following:<br>netcdf_band = layer.GetRasterBand(1)<br><br>- Read in the data one row at a time:<br> for iY in range(y_size):<br> netcdf_data = netcdf_band.ReadAsArray(0, iY, x_size, 1)<br>
<br>It works, but is a complete hack in the sense that I just plugged in stuff from a bunch of different scripts and banged away at it until it gave me what I needed. Glad to see that it is similar to your code. I'm curious about the ".reshape()" method that you pass to "ReadAsArray" above. What does that do?<br>
<br>Thanks again for the help.<br><br>Roger<br>--<br><br><div class="gmail_quote">On Tue, Sep 16, 2008 at 12:05 AM, Steve Gaffigan <span dir="ltr"><<a href="mailto:gaffigan@sfos.uaf.edu">gaffigan@sfos.uaf.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello. Here's an example of reading an entire array for a single subdataset.<br>
<br>
[gaffigan@dp2 AEFF]$ gdalinfo <a href="http://latest.nc" target="_blank">latest.nc</a><br>
Driver: netCDF/Network Common Data Format<br>
...<br>
SUBDATASET_25_NAME=NETCDF:"<a href="http://latest.nc" target="_blank">latest.nc</a>":TMP_GPML<br>
SUBDATASET_25_DESC=[49x11x78x141]<br>
air_temperature_at_constant_altitude_above_m<br>
ean_sea_level (8-bit integer)<br>
...<br>
<br>
[gaffigan@dp2 AEFF]$ python<br>
>>> from osgeo import gdal<br>
>>> ds = gdal.Open('NETCDF:"<a href="http://latest.nc" target="_blank">latest.nc</a>":TMP_GPML')<br>
>>> data = ds.ReadAsArray().reshape(49,11,78,141)<br>
<br>
Using a more generic call of the form below you can get at particular<br>
hyperslabs:<br>
<br>
>>> data=ds.GetRasterBand(i).ReadAsArray(xoff=x0,yoff=y0,win_xsize=nx,win_ysize=ny)<br>
<br>
where, for the above example, i=[1,...,539].<br>
<br>
Steve<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
> Hi List,<br>
><br>
> I'm would like to use the Python bindings to open a specific SUBDATASET in<br>
> a<br>
> NetCDF file and read the contents. I read in<br>
> <a href="http://www.gdal.org/gdal_datamodel.html" target="_blank">http://www.gdal.org/gdal_datamodel.html</a>, under the "SUBDATASETS domain"<br>
> section, that I should be able to pass the "_NAME" parameter into<br>
> GDALOpen()<br>
> in order to do this, but I'm not exactly sure how. Could someone pass me<br>
> a<br>
> couple lines of Python that show how this is done?<br>
><br>
> Thanks in advance.<br>
><br>
> Roger<br>
> --<br>
</div></div>> _______________________________________________<br>
> gdal-dev mailing list<br>
> <a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
<br>
<br>
</blockquote></div><br></div>