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

Anton Korosov anton.korosov at nersc.no
Fri Jun 8 07:50:17 PDT 2012


Hi Rutger,

I remember I had similar problems when reading NetCDF in Windows. The 
solution in my case was pretty simple - I had to include the full path 
to the file in double quotes:

Try this way (but replace this path with yours):

ds = 
gdal.Open('NETCDF:"c:/data/LPRM-TMI_L3_DY_SOILM3_V001-20120411T144114Z_20120102.nc":soil_moisture_x')

I cannot test on Win, but it works on Linux perfectly.

If that doesn't work, can you please provide the VRT file?

Regards,
Anton


On 06/08/2012 02:00 PM, Rutger wrote:
> 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.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev



More information about the gdal-dev mailing list