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).

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

1 Comment

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?
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!

Comments

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"

2 Comments

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?
The outRasterLayer is just a layer, not a file. You really should read the manual. See: pro.arcgis.com/en/pro-app/tool-reference/data-management/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.