Возьмем этот массив данных в качестве примера (настоящий массив намного больше). )
Код: Выделить всё
import xarray as xr
import numpy as np
da = xr.DataArray(
np.random.randint(5, size=(10, 100, 100)),
coords=[range(10), range(100), range(100)],
dims=["time", "x", "y"],
).chunk(chunks={"x":10, "y":10}) # comment this to opt out of chunking
def sum_storage(arr):
my_max = 10
arr_new = xr.zeros_like(arr)
for idx in range(1,len(arr)):
arr_new[dict(time=idx)] = arr_new[dict(time=idx-1)] + da[dict(time=idx)]
arr_storage[dict(time=idx)] = arr_storage[dict(time=idx)].where(arr_storage[dict(time=idx)]
Подробнее здесь: [url]https://stackoverflow.com/questions/79273644/finding-a-way-to-iterate-using-the-input-of-two-xarray-dataarrays-when-chunked[/url]
Мобильная версия