Hello Guys, I need to perform Mann Kendall test on 5 series raster data yearly basis, from 2007 to 2011.
if need to iterate pixel by pixel on raster cell values for calculating the sign. How can i do it... Below is code but i have problem with numpy...
import arcpy import numpy from arcpy import env env.workspace = r"D:\PythonProject\Data" rasterlist = arcpy.ListRasters() for raster in rasterlist: print raster n = len(rasterlist) pairs = (n * ( n - 1)) / 2 print "Pairs to be formed: ", pairs def pairsRasters(raster1, raster2): print raster1, " - ", raster2 inRas1 = arcpy.Raster(raster1) lowerLeft1 = arcpy.Point(inRas1.extent.XMin,inRas1.extent.YMin) #cellSize = inRas.meanCellWidth my_array1 = arcpy.RasterToNumPyArray(inRas1,nodata_to_value=0) inRas2 = arcpy.Raster(raster2) lowerLeft2 = arcpy.Point(inRas2.extent.XMin,inRas2.extent.YMin) #cellSize = inRas.meanCellWidth my_array2 = arcpy.RasterToNumPyArray(inRas2,nodata_to_value=0) for current in reversed(rasterlist): for previous in rasterlist: if current == previous: pass elif current > previous: pairsRasters(current, previous) else: pass
Suppose the two raster of similar extent, i need to calculate difference, if it's greater than 1 the value store in output raster would be 1, if less than 1 the value would be -1 and else zero. How can i iterate on pixel by pixel of two rasters. so i can save it into new raster. That's it..
Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
---|---|---|---|---|
50 | 25 | 98 | 102 | 98 |
122 | 98 | 10 | 210 | 100 |
57 | 66 | 92 | 21 | 10 |
98 | 45 | 255 | 9 | 59 |
58 | 98 | 17 | 31 | 54 |
Message was edited by: Ahsan Abbas
Solved! Go to Solution.
I made some minor changes to the code:
To assign an output projection, you will probably have to set the output coordinate system in the environments. The numpy to raster conversion seems to honor this setting (arcpy.env.outputCoordinateSystem):
I tried this method but i get error, one problem more, the spatial extent of output raster is different, mean height is different but mean cell width is same, i don't understand ?
Do all the input rasters have the same dimension (width, height, resolution and location)? If not, you will have to account for these differences.