我有一个带有土地覆盖类型的 dataArray。我想掩盖列表中的某些值。是否可以在多个条件下使用 xr.where() 函数?
import numpy as np
import xarray as xr
a = xr.DataArray(np.arange(25).reshape(5, 5), dims=('x', 'y'))
print a
LC = [10,12,19]
a.where((a == LC[0]) | (a == LC[1]))
这使:
<xarray.DataArray (x: 5, y: 5)>
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])
Coordinates:
* x (x) int64 0 1 2 3 4
* y (y) int64 0 1 2 3 4
<xarray.DataArray (x: 5, y: 5)>
array([[ nan, nan, nan, nan, nan],
[ nan, nan, nan, nan, nan],
[ 10., nan, 12., nan, nan],
[ nan, nan, nan, nan, nan],
[ nan, nan, nan, nan, nan]])
Coordinates:
* x (x) int64 0 1 2 3 4
* y (y) int64 0 1 2 3 4
以上适用于两种土地覆盖值,但对 30 种类型执行此操作很乏味。有没有更好的办法?