Hi GeoNet community,
I have a little bit of problem in my code. I have a raster list from 0-365 representing day of year (doy1-doy366). I would like to calculate the mean of my rasters using the last three rasters (these are raster364, raster365, raster366, which are indexed as 363,364,365) and the first three rasters of my list (raster1, raster2, and raster3, which are indexed as 0, 1, 2).
this is my initial code:
rasters = arcpy.ListRasters("*", "tif")
last3 = range(363,366)
first3 = range(0,3)
lastdek = (last5, first1)
lastDekad = []
# process only the 6 rasters - last and first three rasters
for l in range(0,7):
print l
lastDekad.append(rasters
) dek37 = CellStatistics(lastDekad, "MEAN", "NODATA")
output = 'E:/Test/Temp/tmax_dek_037.tif'
dek37.save(output)
Any help is much appreciated.
Hope my query is clear.
Thanks,
-Leo
Solved! Go to Solution.
as a possible demo, examine this idea...
>>> aList = [i for i in range(366)]
>>> aList
[0, 1, 2, 3, .... 360, 361, 362, 363, 364, 365] #a big snip here
>>> bList = [aList for i in range(-3,3)]
>>> bList
[363, 364, 365, 0, 1, 2]
>>>
will at least give you some ideas on accessing the head and tail of a list
sorry...it is not clear. This line lastdek = (last5, first1) should have started throwing error messages since last5 and first1 aren't defined. Can your provide the full code or list the error messages
Hi Dan thanks for your reply. Sorry the line lastdek, it should be:
lastdek = (last3, first3).
This is the script that I am trying but with no success. I think the range that I specified below (line 14) still refers to my list of rasters data in my rasters variable (line 7).
>>> import arcpy >>> from arcpy import env >>> from arcpy.sa import * >>> arcpy.CheckOutExtension("Spatial") u'CheckedOut' >>> arcpy.env.workspace = 'raster/path' >>> rasters = arcpy.ListRasters("*", "tif") >>> last4 = range(362,366) >>> first3 = range(0,3) >>> lastdek = (last4,first3) >>> lastdek ([362, 363, 364, 365], [0, 1, 2]) >>> dek = [] >>> for l in range(0,7): ... print l ... dek.append(rasters) ... 0 1 2 3 4 5 6 >>> outCellStatistics = CellStatistics(dek, "MEAN", "NODATA") >>> output = 'folder/path/dek_037.tif' >>> outCellStatistics.save(output)
Is there a workaround to set the range starting from the last four rasters to the first three rasters in my list?
for l in range(363,3): print l
Thanks.
-Leo
as a possible demo, examine this idea...
>>> aList = [i for i in range(366)]
>>> aList
[0, 1, 2, 3, .... 360, 361, 362, 363, 364, 365] #a big snip here
>>> bList = [aList for i in range(-3,3)]
>>> bList
[363, 364, 365, 0, 1, 2]
>>>
will at least give you some ideas on accessing the head and tail of a list
Hi Dan, thanks. It worked okay.
Thanks for the help.
-Leo