【发布时间】:2017-05-18 01:10:38
【问题描述】:
我最近开始使用 xarray。这是一个非常有用的工具。但是我遇到了一些小问题,我相信这很容易解决。我的问题是,我想从多维(时间、纬度、经度)dask.array 中为给定的纬度和经度值选择时间序列。使用 .sel 切片效果非常好且速度快,但是当我尝试使用 np.array 选项获取实际值时,它需要很长时间。 以下效果非常好:
enter code here
% time y = ENS_MEAN.prec.sel(latitude=20, longitude=20)
% time ENS_MEAN.prec.sel(latitude=20, longitude=20)
Output:
CPU times: user 10.7 ms, sys: 908 µs, total: 11.6 ms
Wall time: 10.6 ms
CPU times: user 2.94 ms, sys: 0 ns, total: 2.94 ms
Wall time: 2.83 ms
Out[42]:
<xarray.DataArray 'prec' (time: 29)>
dask.array<getitem..., shape=(29,), dtype=float64, chunksize=(29,)>
Coordinates:
longitude float32 20.0
latitude float32 20.0
* time (time) datetime64[ns] 1982-05-01 1983-05-01 1984-05-01 ...
但是,当我尝试以 numpy 数组格式(见下文)获取实际值时,转换最多需要 2 分钟。我想知道这个问题是否与块大小有关?
%time np.array(y)
CPU times: user 2min 12s, sys: 47.1 s, total: 2min 59s
Wall time: 2min 20s
/home/......./anaconda3/lib/python3.5/site-
packages/dask/array/numpy_compat.py:45: RuntimeWarning: invalid value
encountered in true_divide
x = np.divide(x1, x2, out)
Out[41]:
array([-0.00881837, -0.02694129, 0.03033962, 0.01635965, -0.01392146,
-0.03904842, -0.00269604, -0.00114008, 0.0051511 , -0.02376757,
-0.01574946, -0.01025411, -0.01544669, -0.02065624, -0.02342096,
-0.01664323, 0.08460527, 0.04862781, -0.0035033 , -0.00721429,
-0.00995117, 0.0263697 , -0.00358022, 0.00376811, -0.01527904,
-0.00548013, 0.03295138, -0.01114444, 0.02648388])
非常感谢您回答我的问题。
【问题讨论】:
标签: python python-xarray