gpt4 book ai didi

python - 尺寸坐标具有填充值,因此值是重复的

转载 作者:太空宇宙 更新时间:2023-11-03 21:16:48 24 4
gpt4 key购买 nike

我从同事那里收到了一些数据文件 (NetCDF),我正在尝试将这些文件连接到一个文件中,以便我能够使用我以前的一些脚本来运行它。问题是我收到的 NetCDF 文件的尺寸为“高度”,填充值为 1e20。当我对文件尝试几乎任何 xarray 操作时,这会导致错误,因为维度坐标中存在重复值。

以下是其中一个文件的信息(您可以在“高度”坐标的最终值中看到重复值):

<xarray.Dataset> Dimensions:  (height: 1061) 
Coordinates: * height (height) float64 0.0 10.0 20.0 30.0 ... 1e+20 1e+20 1e+20 1e+20
Data variables:
pres (height) float32 ...
tdry (height) float32 ...
rh (height) float32 ...
u_wind (height) float32 ...
v_wind (height) float32 ...
mr (height) float32 ...
theta (height) float32 ...
theta_e (height) float32 ...
theta_v (height) float32 ...
lat (height) float32 ...
lon (height) float32 ...
alt (height) float32 ...
wdir (height) float32 ...

我认为重新索引到没有填充值的新索引可能会有所帮助,但我也无法这样做,因为错误再次弹出:

ValueError: cannot reindex or align along dimension 'height' because the index has duplicate values

如果有人可以帮助我,那将是一个很大的帮助!我已经为此苦苦挣扎了一段时间,但也许解决方案非常简单,而且我的初学者状态在这里并没有真正的帮助。 :/

最佳答案

如何按照 this post 中的建议删除重复条目?

即使坐标有重复的条目,

.isel 方法也应该起作用。下面的脚本可能有效

_, index = np.unique(ds['time'], return_index=True)
ds.isel(time=index)

关于python - 尺寸坐标具有填充值,因此值是重复的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54633398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com