-
I am trying to use # The goal is to feed in a 2d array, reduce along one dimension and add two new dimensions to the output.
chunks={}
dummy = xr.DataArray(data=np.random.random([8,100]),dims=['dim1','dim2']).chunk(chunks)
def some_func(func):
dims=func.dims
n1 = len(func[func.dims[1]]) # This is 'dim2', we will average along 'dim1' below in the for loop
newdim1 = 2; newdim2 = 5;
output = xr.DataArray(np.nan*np.ones([n1,newdim1,newdim2]),dims=[dims[1],'new1','new2'])
for n in range(n1):
fmean = func.isel(dim2=n).mean(dims[0]).compute()
for i in range(newdim1):
for j in range(newdim2):
output[n,i,j] = fmean
return output
#out = some_func(dummy) # This works
template=xr.DataArray(np.nan*np.ones([len(dummy.dim2),2,5]),
dims=['dim2','new1','new2'])
out = xr.map_blocks(some_func,dummy,template=template).compute() # gives me the error message in the title [Edit: Fixed a typo in the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
A PR raising a nice error message here when We can also delete the xarray/xarray/core/parallel.py Lines 383 to 388 in ce40b93 and use the new |
Beta Was this translation helpful? Give feedback.
-
Thanks! that worked. A couple of follow-up questions:
I will check the docs on how to submit a PR. |
Beta Was this translation helpful? Give feedback.
template.chunks
is None. It needs to have the expected output chunking.A PR raising a nice error message here when
if not template.chunksizes:
would be very welcomeWe can also delete the
if
clause here:xarray/xarray/core/parallel.py
Lines 383 to 388 in ce40b93
and use the new
chunksizes
property:output_chunks = template.chunksizes