Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python进程的for循环出现问题_Python_For Loop_Numpy_Gis_Arcpy - Fatal编程技术网

python进程的for循环出现问题

python进程的for循环出现问题,python,for-loop,numpy,gis,arcpy,Python,For Loop,Numpy,Gis,Arcpy,我最近发现了如何在光栅文件上进行一些NumPy计算,但现在尝试在208个光栅上迭代运行我提出的过程是徒劳的,所有这些光栅都在一个文件夹中 我认为这是一项非常简单的任务,但在查阅了大量stackexchange线程和教程之后,我仍然没有弄清楚。(我对python非常陌生。) 我已经包括了下面的代码。我得到的错误是: invalid syntax on "def cumulativecalculation()" 提前感谢您的帮助 import os import sys import arcp

我最近发现了如何在光栅文件上进行一些NumPy计算,但现在尝试在208个光栅上迭代运行我提出的过程是徒劳的,所有这些光栅都在一个文件夹中

我认为这是一项非常简单的任务,但在查阅了大量stackexchange线程和教程之后,我仍然没有弄清楚。(我对python非常陌生。)

我已经包括了下面的代码。我得到的错误是:

invalid syntax on "def cumulativecalculation()"
提前感谢您的帮助

import os 
import sys 
import arcpy 
import numpy as np 
import glob


arcpy.env.overwriteOutput=True

def cumulativecalculation()

    #Set geoprocessing variables
    inRaster = filename
    des = arcpy.Describe(inRaster)
    sr = des.SpatialReference
    ext = des.Extent
    ll = arcpy.Point(ext.XMin,ext.YMin)

    #Convert GeoTIFF to numpy array
    a = arcpy.RasterToNumPyArray(inRaster)

    #Flatten for calculations
    a.flatten()

    #Find unique values, and record their indices to a separate object
    a_unq, a_inv = np.unique(a, return_inverse=True)

    #Count occurences of array indices
    a_cnt = np.bincount(a_inv)

    #Cumulatively sum the unique values multiplied by the number of
    #occurences, arrange sums as initial array
    b = np.cumsum(a_unq * a_cnt)[a_inv]

    #Divide all values by 10 (reverses earlier multiplication done to
    #facilitate accurate translation of ASCII scientific notation
    #values < 1 to array)
    b /= 10

    #Rescale values between 1 and 100
    maxval = np.amax(b)
    b /= maxval
    b *= 100

    #Restore flattened array to shape of initial array
    c = b.reshape(a.shape)

    #Convert the array back to raster format
    outRaster = arcpy.NumPyArrayToRaster(c,ll,des.meanCellWidth,des.meanCellHeight)

    #Set output projection to match input
    arcpy.DefineProjection_management(outRaster, sr)

    #Setting the OutName
    OutName = "filename" + "_cumulative" + ".tif"

    #Save the raster as a TIFF
    outRaster.save("E:\\NSF Project\\Salamander_Data\\New_Cumulative_Rasters\\OutName")

src = "E:\\NSF Project\\Salamander_Data\\NoDataToZero\\HadleyGCM\\*.tif"

for filename in glob.glob(src):
    cumulativecalculation(filename)

sys.exit()
导入操作系统
导入系统
导入arcpy
将numpy作为np导入
导入glob
arcpy.env.overwriteOutput=True
def累积计算()
#设置地理处理变量
inmaster=filename
des=arcpy.描述(主)
sr=des.空间参考
ext=des.区段
ll=arcpy.点(ext.XMin,ext.YMin)
#将GeoTIFF转换为numpy数组
a=arcpy.RasterToNumPyArray(主)
#为计算而展平
a、 展平()
#找到唯一的值,并将其索引记录到单独的对象
a_unq,a_inv=np.unique(a,return_inverse=True)
#计数数组索引的出现次数
a\u cnt=np.bincount(a\u inv)
#将唯一值乘以
#发生时,将总和排列为初始数组
b=np.cumsum(a_unq*a_cnt)[a_inv]
#将所有值除以10(与之前对
#促进ASCII科学符号的准确翻译
#值<1到数组)
b/=10
#重新缩放介于1和100之间的值
maxval=np.amax(b)
b/=maxval
b*=100
#将展平阵列恢复为初始阵列的形状
c=b.重塑(a.形状)
#将阵列转换回光栅格式
outRaster=arcpy.NumpyarRayTorMaster(c、ll、des.meanCellWidth、des.meanCellHeight)
#设置输出投影以匹配输入
arcpy.DefineProjection_管理(outRaster,sr)
#设置出站名称
OutName=“filename”+“\u累计”+“.tif”
#将光栅另存为TIFF
outgraster.save(“E:\\NSF项目\\蝾螈\u数据\\新建\u累积\u光栅\\OutName”)
src=“E:\\NSF项目\\蝾螈\u数据\\NoDataToZero\\HadleyGCM\\\*.tif”
对于glob.glob(src)中的文件名:
累积计算(文件名)
sys.exit()

您需要在()后面添加冒号


如果OP的问题是通过添加颜色或某处解决的,最好标记为offtopic->simple排版错误谢谢。对不起,我想这个问题太简单了。
def cumulativecalculation():