我用这么长时间处理下面的代码。我必须在光栅图像中显示计算太阳能发电厂电力成本的结果。问题是我必须使用公式与“DNI”(直接正常照射)层进行交互,并且公式的值在生命工厂的30年期间每年(costReductionFactorPlant)的因子变化。因素如下所示。
运行代码时,收到以下错误:
Runtime error
Traceback (most recent call last):
File "<string>", line 56, in <module>
File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py", line 4049, in Times
in_raster_or_constant2)
File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Utils.py", line 47, in swapper
result = wrapper(*args, **kwargs)
File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py", line 4046, in wrapper
return _wrapLocalFunctionRaster(u"Times_sa", ["Times", in_raster_or_constant1, in_raster_or_constant2])
RuntimeError: ERROR 000732: Input Raster: Dataset D:_ArcGIS\Python\LCOE_test does not exist or is not supported
>>>
我担心调用图层“DNI”时出错了。但没有任何线索。也许循环也有错误...我也试着看一下,因为我看起来不错,但我不是专家。
我正在运行ArcGis 10.1。所有建议都非常受欢迎。
CODE:
import arcpy, os, sys
from arcpy import env
from arcpy.sa import *
# Set Workspace
env.workspace = "D:\02_ArcGIS\Python\LCOE_test"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Variables definition
capacity = 100000
actualOutput = .94 * capacity
storageHours = 16
loadFactor = (.57 * storageHours + 7.1)/24
costReductionFactorPlant = [0.4790, 0.4533, 0.4297, 0.4080, 0.3880, 0.3696, 0.3526, 0.3368, 0.3222, 0.3087, 0.2961, 0.2844, 0.2735, 0.2633, 0.2538, 0.2449, 0.2366, 0.2288, 0.2215, 0.2146, 0.2081, 0.2021, 0.1964, 0.1910, 0.1859, 0.1811, 0.1765, 0.1723, 0.1682, 0.1643, 0.1607]
efficiency = [0.1822, 0.1827, 0.1831, 0.1834, 0.1837, 0.1840, 0.1841, 0.1843, 0.1844, 0.1845, 0.1846, 0.1847, 0.1847, 0.1848, 0.1848, 0.1849, 0.1849, 0.1849, 0.1849, 0.1849, 0.1849, 0.1850, 0.1850, 0.1850, 0.1850, 0.1850, 0.1850, 0.1850, 0.1850, 0.1850, 0.1850]
years = 30
i = .1
ir = .01
lcoePlantTotal = 0
productionPlant = loadFactor * actualOutput * 8760
DNI = "D:\02_ArcGIS\Python\LCOE_test" #layer#
Count=len(costReductionFactorPlant)+ 1
counter=1
while counter < Count:
for i in range(counter,(counter+1)):
# Set the cell size environment using a keyword.
arcpy.env.cellSize = "MAXOF"
# Set the extent environment using a keyword
arcpy.env.extent = "MAXOF"
#intermediate formula plant
# size = (capacity * 8760 * loadFactor)/(DNI * efficiency[counter-1])
size1 = (capacity * 8760 * loadFactor)
timesConstant = efficiency[counter-1]
size2 = Times(3, timesConstant)
print size2
size = Divide(size1, size2)
# Calculate power block & storage
powerBlock = capacity * 1484.9918 * costReductionFactorPlant[counter-1]
storage = storageHours * capacity * 39.45759 * costReductionFactorPlant[counter-1]
# Calculate mirrowField
# mirrorField = size * 155.6975 * costReductionFactorPlant[cont-1]
timesConstant2 = costReductionFactorPlant[counter-1]
inconstant = Times(155.6975, timesConstant2)
mirrorField = Times(size, inconstant)
# calculate PowerTower
powerTower = ((capacity * 121.03883) + (capacity * 128.50378)) * costReductionFactorPlant[counter-1]
# Calculate investmentPlant
investmentPlant = powerBlock + storage + mirrorField + powerTower
# Calculate omPlant
omPlant = Times(investmentPlant, 0.048)
#formula: lcoePlant = ((investmentPlant * (((i * (1 + i)^counter)/((1 + i)^counter-1))+ ir))+omPlant)/productionPlant*100
# Formula Part 1 = (investmentPlant * (((i * (1 + i)^counter) Power symbol = **
InConstant3= i * ((1 + i)**counter)
FormulaPart1 = Times(investmentPlant, InConstant3)
# Formula Part 2 = ((1 + i)^counter-1))+ ir))+omPlant)/productionPlant*100
FormulaPart2 =(((1 + i)**(counter-1)+ ir)+omPlant)/productionPlant*100
# Formula
lcoePlant = Divide(FormulaPart1, FormulaPart2)
lcoePlantTotal = lcoePlantTotal + lcoePlant
lcoePlantTotal.save = "D:\\02_ArcGIS\\Python" + str(lcoePlantTotal) + ".img"
print "lcoePlanttotal calculated"
答案 0 :(得分:0)
你需要逃避你的反斜杠,你可以看到它认为你是怎么说hex-2。如果您查看错误消息中的最后一行,它会告诉您该文件不存在,并且它显示它与您给出的文件名不同。
>>> DNI = "D:\02_ArcGIS\Python\LCOE_test"
>>> DNI
'D:\x02_ArcGIS\\Python\\LCOE_test'
>>> DNI = "D:\\02_ArcGIS\\Python\\LCOE_test"
>>> DNI
'D:\\02_ArcGIS\\Python\\LCOE_test'
>>> print DNI
D:\02_ArcGIS\Python\LCOE_test