爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 8735|回复: 2

[求助] Netcdf转raster出现的错误

[复制链接]

新浪微博达人勋

发表于 2017-7-2 22:26:45 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
我想把netcdf文件转为raster,结果出现了如下错误:

Traceback (most recent call last):
  File "1.netcdf_to_raster.py", line 86, in <module>

  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 14213, in CopyRaster
    raise e
arcgisscripting.ExecuteError: ERROR 999999: Error executing function.
Failed to create raster dataset
Failed to execute (CopyRaster).


Google了好久也没找到答案,请论坛上高手帮忙看看错误在哪里。我的源代码如下:

  1. #Make rasters *.tif file for all time steps (time) in a netcdf file  

  2. ##

  3. #Import modules

  4. import arcpy, os, time, datetime, calendar

  5. import arcpy

  6. from arcpy import env  

  7. from arcpy.sa import *  

  8.   
  9. #########Path to folder that contains .nc data

  10. #########This may need to be changed depending on how data are stored

  11. arcpy.env.workspace = "D:/Example/GSMD" # Change folder++  

  12. #########  

  13.   
  14. arcpy.env.overwriteOutput = True  

  15. arcpy.env.scratchWorkspace = "D:/Example/GSMD"  

  16.   

  17. # Determines the number of netcdf files in the workspace


  18. #Data processing starts

  19. filename = "pr_2017.nc"



  20. print("Processing: " + filename)  

  21.     # Set local variable (grabs netcdf file(i))

  22. inNetCDF = arcpy.env.workspace + "/" + filename  

  23.   

  24. ######### This changes depending on variable of interest (tmmx, tmmn, pr, pdsi)  

  25. variable =  "precipitation_amount"

  26.     #"surface_downwelling_shortwave_flux_in_air"

  27.     #"specific_humidity"# #"precipitation_amount"# "relative_humidity" ###

  28.     #"palmer_drought_severity_index"##"air_temperature"   

  29.   

  30. #########Change the variable ###  

  31. InMemory_netcdf_raster = "precipitation_amount"

  32.     #"surface_downwelling_shortwave_flux_in_air"#"relative_humidity"

  33.     #"palmer_drought_severity_index"#"air_temperature"   

  34. #########  

  35.       

  36. #########Where the output tiffs will be stored   

  37. outRasterFolder = "D:/Example/GSMD/PR_rasters"  

  38. #########

  39. #######change the lengths depending on variable (pr is shorter than tmmx) -

  40. ########This variable assists with naming convention of out file  

  41. fileroot = filename[3:(len(filename)-3)] #change the name lengths too  

  42. #######

  43.       

  44. Yr = int(fileroot)   

  45. print "Processing --> " + str(Yr)  

  46.       

  47. #Month info  

  48. allmnths = range(1,13)  

  49. for mnths in allmnths:  

  50.     Lastday = calendar.monthrange(Yr, mnths)[1]  

  51.     MRange = range(1,Lastday+1)  

  52.     for dyy in MRange:  

  53.         dyys =int(dyy)  

  54.         mnthsss = int(mnths)  

  55.               

  56.         a = str(mnthsss)+ "/" + str(dyys) +"/" + str(Yr)  

  57.   

  58.         #IF Days or Months less than 10, we want to put zero at the front so it is easier to sort.  

  59.   

  60.         if (mnthsss < 10) and (dyys < 10):   

  61.             b = str(Yr)+ "_" + "0" + str(mnthsss)+ "_" + "0" + str(dyys)  

  62.         elif (mnthsss < 10) and (dyys >=10):  

  63.             b = str(Yr)+ "_" + "0" + str(mnthsss)+ "_" + str(dyys)  

  64.   

  65.         elif (mnthsss >= 10)and (dyys < 10):  

  66.             b = str(Yr)+ "_" + str(mnthsss)+ "_" + "0" + str(dyys)                     

  67.         else:  

  68.             b = str(Yr)+ "_" + str(mnthsss)+ "_" + str(dyys)  

  69.                   

  70.         dimensionValues = "day " + a

  71.               

  72. ##########CHANGE the word too##              

  73.                                         #################  

  74.         outTIFF = outRasterFolder+"/"+"pr_"+b+".tif"  

  75.                                         #################  

  76.   

  77.               

  78.             # Execute MakeNetCDFRasterLayer         ##############

  79.         arcpy.MakeNetCDFRasterLayer_md(inNetCDF,"precipitation_amount" ,"lon","lat",InMemory_netcdf_raster,"",dimensionValues,"BY_VALUE")  

  80.             #print "Created NetCDF Layer for " + a   ############

  81.               

  82.             # Process: Copy Raster  

  83.         arcpy.CopyRaster_management(InMemory_netcdf_raster,outTIFF,"","","","NONE","NONE")  

  84.         print "Created Raster for pr_" + b  

  85.                                 #################  

  86.         b=""

  87.         dimensionValues=""

  88.             #InMemory_netcdf_raster=""

  89.             #inNetCDF=""

  90. print "\nEnd of processing!!!"  

复制代码

在D盘建了一个文件夹,名为"Example"。里面包含一个子文件夹GSMD和上述Python程序文件。GSMD中包含输入文件pr_2017.nc和子文件夹PR_rasters.
如果需要测试程序的话,pr_2017.nc可以在这里下载:http://northwestknowledge.net/metdata/data/pr_2017.nc. 大概有500多兆.

先谢谢大家。


密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-7-2 22:27:57 | 显示全部楼层
有朋友说在他的电脑上测试没问题,现在我也不知道问题在哪里。我重新安装过ArcGIS,还是不管用。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-7-8 11:09:38 | 显示全部楼层
还没有解决,继续请教
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表