Xarray-在特定X和Y坐标处选择数据
在x,y位置选择数据时,我会获取任何一对x,y的数据。我想拥有一个1D阵列,而不是选择中的2D数组。有没有有效的方法? (目前我正在使用循环...)
x = [x1,x2,x3,x4] y = [y1,y2,y3,y4]
ds = 2-d阵列
subset = Dataset.sel(longitude=x, latitude=y, method='nearest')
到rephrase,我想在[x1,y1],[x2,y2],[x3,y3],[x4,y4上都有数据集]不在其他位置,即[x1,y2]。
When selecting data with xarray at x,y locations, I get data for any pair of x,y. I would like to have a 1-D array not a 2-D array from the selection. Is there an efficient way to do this? (For now I am doing it with a for-loop...)
x = [x1,x2,x3,x4]
y = [y1,y2,y3,y4]
DS = 2-D array
subset = Dataset.sel(longitude=x, latitude=y, method='nearest')
To rephrase, I would like to have the dataset at [x1,y1],[x2,y2],[x3,y3],[x4,y4] not at other location i.e. [x1,y2].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果索引器为
dataArray
s,则可以沿多个索引选择点列表。这将导致数组沿索引器的共同维度重新索引。直接从更高级的索引:
indexing the Indexing)阵列也可以轻松地从pandas
dataframe
中拔出,并带有da.sel(pertitude = df.df.longendity.to_xarray(),latitude = df.latitude.to_xarray())< /code>,这将导致
dataarray
由 dataframe的索引重新索引。因此,就您而言,而不是选择列表或数组
x,y
,将它们变成带有常见dim的数据阵列 - 让我们称其为location> location
:现在您的选择将工作如您所希望的:
A list of points can be selected along multiple indices if the indexers are
DataArray
s with a common dimension. This will result in the array being reindexed along the indexers' common dimension.Straight from the docs on More Advanced Indexing:
The indexing array can also be easily pulled out of a pandas
DataFrame
, with something likeda.sel(longitude=df.longitude.to_xarray(), latitude=df.latitude.to_xarray())
, which will result in theDataArray
being reindexed by the DataFrame's index.So in your case, rather than selecting with the lists or arrays
x, y
, turn them into DataArrays with a common dim - let's call itlocation
:Now your selection will work as you hope: