1

When executing the following code I keep getting an error and I was unable to fix it. Any ideas what could be wrong? I tried to change the file name to a simpler one but it didn't help. NetCDF data comes from TRMM.

import arcpy
import os
dir_name = 'D:\Data'


# Set local variables
inNetCDFFile = "D:\Data\3B43.20090201.7A.HDF.nc"
variable = "precipitation"
XDimension = "nlon"
YDimension = "nlat"
outRasterLayer = "D:\Data\test"
bandDimmension = ""
dimensionValues = ""
valueSelectionMethod = ""

# Execute MakeNetCDFRasterLayer
arcpy.MakeNetCDFRasterLayer_md(inNetCDFFile, variable, XDimension, YDimension,
                               outRasterLayer, bandDimmension, dimensionValues, 
                               valueSelectionMethod)

Error:

Traceback (most recent call last):
  File "D:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
    exec codeObject in __main__.__dict__
  File "D:\Google Drive\Gates Project\Data\Climate\TRMM\Python\TRMMNetCDFtoRaster.py", line 19, in <module>
    valueSelectionMethod)
  File "D:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\md.py", line 171, in MakeNetCDFRasterLayer
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input netCDF File: Dataset D:\DataB43.20090201.7A.HDF.nc does not exist or is not supported
Failed to execute (MakeNetCDFRasterLayer).
MIH
  • 1,083
  • 3
  • 14
  • 26

3 Answers3

3

Clearly you are trynig to load a wrong file path:

ERROR 000732: Input netCDF File: Dataset D:\DataB43.20090201.7A.HDF.nc does not exist or is not supported

If you are on Windows use:

inNetCDFFile = "D:\\Data\\3B43.20090201.7A.HDF.nc"

or

inNetCDFFile = r"D:\Data\3B43.20090201.7A.HDF.nc"

Charlie

Charlie
  • 1,750
  • 15
  • 20
  • Thank you! Now it clearly reads the path, but the output file is not there. How do I fix it, so I actually have a raster file in my folder as a result? – MIH Oct 27 '16 at 13:47
2

Thanks for your help, I have managed to make a nice script which takes all the NetCDF files from directory and converts them to rasters, so I am going to post it here - others might find it useful! (it is specifically for TRMM rainfall data).

import arcpy
import os

dir_name = 'D:\\Data'

# Set local variables
variable = "precipitation"
XDimension = "nlon"
YDimension = "nlat"
bandDimmension = ""
dimensionValues = ""
valueSelectionMethod = "BY_VALUE"


# Loop that converts NetCDF files from directory and converts to .img rasters:
dir_name = 'D:\\Data'
for filename in os.listdir(dir_name):
    if not filename.endswith(".nc"): continue
    full_path = os.path.join(dir_name, filename)
    outRaster = '%s.img' % (full_path,)
    fileroot = filename[0:(len(filename)-10)]   
    outRasterLayer = dir_name + "\\" + fileroot
    arcpy.MakeNetCDFRasterLayer_md(full_path, variable, XDimension, YDimension,
                               outRasterLayer, bandDimmension, dimensionValues, 
                               valueSelectionMethod)
    arcpy.CopyRaster_management(outRasterLayer,outRaster)

Voila!

MIH
  • 1,083
  • 3
  • 14
  • 26
1

I'm not familiar with arcpy but the example uses foward slashes, not backslashes. I'd try

inNetCDFFile = "D:/Data/3B43.20090201.7A.HDF.nc"
Eric Bridger
  • 3,751
  • 1
  • 19
  • 34
  • Thank you! Now it clearly reads the path, but the output file is not there. How do I fix it, so I actually have a raster file in my folder as a result? – MIH Oct 27 '16 at 13:47
  • The outRasterLayer is just a layer, not a file. You really should read the manual. See: http://pro.arcgis.com/en/pro-app/tool-reference/data-management/save-to-layer-file.htm – Eric Bridger Oct 27 '16 at 15:13