本人利用python对20年NDVI栅格数据进行sen-mk检验,总文件45G,在读取栅格数据时出现内存溢出错误。在此想请较大家如何修改读取栅格语句,循环释放内存?
for file in os.listdir(path1):
filepath1=os.path.join(path1,file)
filepaths.append(filepath1)
#获取影像数量
num_images=len(filepaths)
#读取影像数据
img1=ras.open(filepaths[0])
#获取影像的投影,高度和宽度
transform1=img1.transform
height1=img1.height
width1=img1.width
array1=img1.read()
img1.close()
#读取所有影像
for path1 in filepaths[1:]:
if path1[-3:]=='tif':
print(path1)
img2=ras.open(path1)
array2=img2.read()
array1=np.vstack((array1,array2))
img2.close()
array1=np.vstack((array1,array2))
File "<__array_function__ internals>", line 180, in vstack
File "E:\pychram\lib\site-packages\numpy\core\shape_base.py", line 282, in vstack
return _nx.concatenate(arrs, 0)
File "<__array_function__ internals>", line 180, in concatenate
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 17.1 GiB for an array with shape (8, 20354, 28112) a