错误000732在Python中调用NetCDF文件

时间:2016-10-26 16:36:17

标签: python raster netcdf

执行以下代码时,我一直收到错误,但我无法修复它。什么想法可能是错的?我试图将文件名更改为更简单的文件名,但它没有帮助。 NetCDF数据来自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)

错误:

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 个答案:

答案 0 :(得分:3)

显然,您尝试加载错误的文件路径:

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

如果您使用的是Windows:

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

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

查理

答案 1 :(得分:2)

感谢您的帮助,我设法创建了一个很好的脚本,它从目录中获取所有NetCDF文件并将它们转换为栅格,所以我将在这里发布 - 其他人可能会觉得它很有用! (它专门用于TRMM降雨数据)。

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)

瞧!

答案 2 :(得分:1)

我不熟悉WHERE TRADE_DATE=TRUNC(SYSDATE) ,但example使用了斜线,而不是反斜杠。我试试

arcpy