I have the following function and code snippet to extract cell values for multiple years, format it, and save to a list. Each raster has 365 bands — one for each day. A separate operation is performed on each flattened list pr_flt
which contains daily cell values of XY for 1991-2015. The cursor contains XY coordinates for each cell. The following code works but it takes hours to finish due to the huge amount of data and possible use of lists instead of multidimensional arrays. I am wondering if there are any suggestions to reduce the runtime of the code, if possible.
import arcpy
def row_to_values(row):
values = []
for col in row:
if isinstance(col, unicode) and col != u'f':
# split and convert all entries to float
values += (float(v) for v in col.split(','))
else:
values.append(col)
return values
with arcpy.da.SearchCursor(fc, fields) as cursor:
for idx, row in enumerate(cursor):
pt_annual_lists = []
pt_loc = str(row[0]) + str(" ") + str(row[1])
for y in xrange(1991,2016,1):
pt_year_list = []
result = arcpy.GetCellValue_management(in_raster = "D:/temp/ras" + str(y) + ".tiff", location_point = pt_loc, band_index="")
cell_value = result.getOutput(0)
pt_year_list.append(cell_value)
cell_value = [s.replace('\\n', ',') for s in pt_year_list]
pt_annual_lists.append(row_to_values(cell_value))
# flatten list of lists
pr_str = [val for sublist in pt_annual_lists for val in sublist]
pr_flt = [float(i) for i in pr_str]
arcpy.da.SearchCursor
has reduced run time by 150%. Other bottleneck isarcpy.GetCellValue_management
which is taking 95% of the processing time in each iteration. Please suggest any open source library to extract pixel values faster. \$\endgroup\$