- 积分
- 201
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-8-23
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
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了好久也没找到答案,请论坛上高手帮忙看看错误在哪里。我的源代码如下:
- #Make rasters *.tif file for all time steps (time) in a netcdf file
- ##
- #Import modules
- import arcpy, os, time, datetime, calendar
- import arcpy
- from arcpy import env
- from arcpy.sa import *
-
- #########Path to folder that contains .nc data
- #########This may need to be changed depending on how data are stored
- arcpy.env.workspace = "D:/Example/GSMD" # Change folder++
- #########
-
- arcpy.env.overwriteOutput = True
- arcpy.env.scratchWorkspace = "D:/Example/GSMD"
-
- # Determines the number of netcdf files in the workspace
-
- #Data processing starts
- filename = "pr_2017.nc"
- print("Processing: " + filename)
- # Set local variable (grabs netcdf file(i))
- inNetCDF = arcpy.env.workspace + "/" + filename
-
- ######### This changes depending on variable of interest (tmmx, tmmn, pr, pdsi)
- variable = "precipitation_amount"
- #"surface_downwelling_shortwave_flux_in_air"
- #"specific_humidity"# #"precipitation_amount"# "relative_humidity" ###
- #"palmer_drought_severity_index"##"air_temperature"
-
- #########Change the variable ###
- InMemory_netcdf_raster = "precipitation_amount"
- #"surface_downwelling_shortwave_flux_in_air"#"relative_humidity"
- #"palmer_drought_severity_index"#"air_temperature"
- #########
-
- #########Where the output tiffs will be stored
- outRasterFolder = "D:/Example/GSMD/PR_rasters"
- #########
- #######change the lengths depending on variable (pr is shorter than tmmx) -
- ########This variable assists with naming convention of out file
- fileroot = filename[3:(len(filename)-3)] #change the name lengths too
- #######
-
- Yr = int(fileroot)
- print "Processing --> " + str(Yr)
-
- #Month info
- allmnths = range(1,13)
- for mnths in allmnths:
- Lastday = calendar.monthrange(Yr, mnths)[1]
- MRange = range(1,Lastday+1)
- for dyy in MRange:
- dyys =int(dyy)
- mnthsss = int(mnths)
-
- a = str(mnthsss)+ "/" + str(dyys) +"/" + str(Yr)
-
- #IF Days or Months less than 10, we want to put zero at the front so it is easier to sort.
-
- if (mnthsss < 10) and (dyys < 10):
- b = str(Yr)+ "_" + "0" + str(mnthsss)+ "_" + "0" + str(dyys)
- elif (mnthsss < 10) and (dyys >=10):
- b = str(Yr)+ "_" + "0" + str(mnthsss)+ "_" + str(dyys)
-
- elif (mnthsss >= 10)and (dyys < 10):
- b = str(Yr)+ "_" + str(mnthsss)+ "_" + "0" + str(dyys)
- else:
- b = str(Yr)+ "_" + str(mnthsss)+ "_" + str(dyys)
-
- dimensionValues = "day " + a
-
- ##########CHANGE the word too##
- #################
- outTIFF = outRasterFolder+"/"+"pr_"+b+".tif"
- #################
-
-
- # Execute MakeNetCDFRasterLayer ##############
- arcpy.MakeNetCDFRasterLayer_md(inNetCDF,"precipitation_amount" ,"lon","lat",InMemory_netcdf_raster,"",dimensionValues,"BY_VALUE")
- #print "Created NetCDF Layer for " + a ############
-
- # Process: Copy Raster
- arcpy.CopyRaster_management(InMemory_netcdf_raster,outTIFF,"","","","NONE","NONE")
- print "Created Raster for pr_" + b
- #################
- b=""
- dimensionValues=""
- #InMemory_netcdf_raster=""
- #inNetCDF=""
- 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多兆.
先谢谢大家。
|
|