[gdal-dev] Reading a NetCDF file with python (not recognised as a supported dataset name

Rutger kassies at gmail.com
Fri Jun 8 05:00:48 PDT 2012


Dear list,

I am trying to open a NetCDF file with the Python bindings. My GDAL 1.9
build (Win32 from Tamas) shows the NetCDF driver when i run "gdalinfo
--formats", so it should be possible.

When using the pre-build command-line utilities all works well. But when i
move to Python i get the message:
/" ... does not exist in the file system, and is not recognised as a
supported dataset name."/
I dont have the slightest clue about what i'm doing wrong.

I have simplified the problem to 3 steps:
1. Use gdal_translate to select a subdataset and output to VRT
2. Read the VRT in Python with gdal.Open()
3. Use gdal_translate to convert the VRT to a Geotiff

Step 1 & 3 work well, but 2 fails. Is there some limitation of the Python
bindings regarding NetCDF? The script runs fine if i replace the NetCDF with
a Geotiff file.

Any help would be appreciated.

An example NetCDF i used can be found at:
ftp://hydro1.sci.gsfc.nasa.gov/data/s4pa/WAOB/LPRM_TMI_DY_SOILM3.001/2012/05/
ftp://hydro1.sci.gsfc.nasa.gov/data/s4pa/WAOB/LPRM_TMI_DY_SOILM3.001/2012/05/ 

Below is the Python script i have used for exploring the issue:

import os
try:
    from osgeo import gdal
except ImportError:
    import gdal

netcdffile =
"NETCDF:LPRM-TMI_L3_DY_SOILM3_V001-20120411T144114Z_20120102.nc:soil_moisture_x"
vrtfile = "LPRM-TMI_L3_DY_SOILM3_V001-20120411T144114Z_20120102.vrt"
tiffile = "LPRM-TMI_L3_DY_SOILM3_V001-20120411T144114Z_20120102.tif"

# 1: convert the netcdf to vrt externally (works well)
os.system('gdal_translate -of "VRT" ' + netcdffile + ' ' + vrtfile)

# 2: try to open the vrt in Python (fails at .ReadAsArray)
dsin = gdal.Open(vrtfile)
   
if not dsin is None:
  indata = dsin.ReadAsArray(0, 0, dsin.RasterXSize, dsin.RasterYSize)

# 3: convert the same vrt to a tif externally (works well)
os.system('gdal_translate ' + vrtfile + ' ' + tiffile)


Regards,
Rutger


--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Reading-a-NetCDF-file-with-python-not-recognised-as-a-supported-dataset-name-tp4979943.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list