首页 > 解决方案 > 为什么将 eofs.xarray.Eof 应用于分块数组时会引发错误?

问题描述

我有一个v带有空间和时间坐标的分块数组,它沿时间维度分块,我希望计算它的经验正交函数。代码如下所示:

import xarray
from eofs.xarray import Eof

v = xarray.DataArray( data=np.zeros((481,77359)), coords={'time':u.time}, dims=['time', 'node'], name='ssh' )
v = v.chunk({'time':24, 'node':77359})

solver = Eof(v)

这会导致以下错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/.conda/envs/py363/lib/python3.6/site-packages/eofs/standard.py in __init__(self, dataset, weights, center, ddof)
    164                 # Use the parallel Dask algorithm
--> 165                 dsvd = dask.array.linalg.svd(dataNoMissing)
    166                 A, Lh, E = (x.compute() for x in dsvd)

~/.conda/envs/py363/lib/python3.6/site-packages/dask/array/linalg.py in svd(a, coerce_signs)
    961     if coerce_signs:
--> 962         u, v = svd_flip(u, v)
    963     return u, s, v

~/.conda/envs/py363/lib/python3.6/site-packages/dask/array/utils.py in svd_flip(u, v, u_based_decision)
    541     # Force all singular vectors into same half-space
--> 542     u, v = u * signs, v * signs.T
    543     return u, v

~/.conda/envs/py363/lib/python3.6/site-packages/dask/array/core.py in wrapper(self, other)
    210         else:
--> 211             return f(self, other)
    212 

~/.conda/envs/py363/lib/python3.6/site-packages/dask/array/core.py in __mul__(self, other)
   2046     def __mul__(self, other):
-> 2047         return elemwise(operator.mul, self, other)
   2048 

~/.conda/envs/py363/lib/python3.6/site-packages/dask/array/core.py in elemwise(op, *args, **kwargs)
   4254     out_ndim = len(
-> 4255         broadcast_shapes(*shapes)
   4256     )  # Raises ValueError if dimensions mismatch

~/.conda/envs/py363/lib/python3.6/site-packages/dask/array/core.py in broadcast_shapes(*shapes)
   4215                 "operands could not be broadcast together with "
-> 4216                 "shapes {0}".format(" ".join(map(str, shapes)))
   4217             )

ValueError: operands could not be broadcast together with shapes (481, 481) (1, nan)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-96-6bb6625c8486> in <module>
----> 1 solver = Eof(v)

~/.conda/envs/py363/lib/python3.6/site-packages/eofs/xarray.py in __init__(self, array, weights, center, ddof)
    131                                     weights=wtarray,
    132                                     center=center,
--> 133                                     ddof=ddof)
    134         # Name of the input DataArray.
    135         self._name = array.name

~/.conda/envs/py363/lib/python3.6/site-packages/eofs/standard.py in __init__(self, dataset, weights, center, ddof)
    175 
    176         except (np.linalg.LinAlgError, ValueError):
--> 177             raise ValueError('error encountered in SVD, check that missing '
    178                              'values are in the same places at each time and '
    179                              'that all the values are not missing')

ValueError: error encountered in SVD, check that missing values are in the same places at each time and that all the values are not missing

如果我使用未分块的v.

我知道已经询问了一个类似的问题(如果某些块仅包含 NaN 值,则 Dask 分布式不会运行 SVD),但建议仅沿时间维度对数组进行分块。我已经这样做了,并且我的数组不包含 NaN,那么为什么仍然存在错误?

标签: daskeofpython-xarraysvd

解决方案


推荐阅读