xarray 多维插值到没有大矩阵的点
有没有办法在不创建巨大数组/循环的情况下多维地插值到特定点?
import xarray as xr
import pandas as pd
xds = xr.tutorial.open_dataset('air_temperature')
xds['airx2'] = xds['air'] * 2
pdf = pd.DataFrame(dict(lat=[45, 60, 75], lon=[225, 320, 315],
time=pd.to_datetime(['2013-01-10', '2013-01-12', '2013-01-15'])))
# this seems to be very fast, but creates a large 3x3x3 array
# not ideal if I have 800 rows which will make a final array of 800x800x800
xds.interp(**pdf)
# this doesn't create a 800x800x800 array
# if there's 800 rows in the dataframe, but not vectorized
pd.concat([xds.interp(**row).to_array().to_dataframe('kelvin')
for i, row in pdf.iterrows()])
大数组
所需结果(如果未循环):
Is there a way to interpolate to specific points multi-dimensionally without creating an enormous array / looping?
import xarray as xr
import pandas as pd
xds = xr.tutorial.open_dataset('air_temperature')
xds['airx2'] = xds['air'] * 2
pdf = pd.DataFrame(dict(lat=[45, 60, 75], lon=[225, 320, 315],
time=pd.to_datetime(['2013-01-10', '2013-01-12', '2013-01-15'])))
# this seems to be very fast, but creates a large 3x3x3 array
# not ideal if I have 800 rows which will make a final array of 800x800x800
xds.interp(**pdf)
# this doesn't create a 800x800x800 array
# if there's 800 rows in the dataframe, but not vectorized
pd.concat([xds.interp(**row).to_array().to_dataframe('kelvin')
for i, row in pdf.iterrows()])
Large array
Desired result (if isn't looped):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您想要使用多维点列表从多个维度中进行选择(而不是使用正交索引对数据进行子设置)时,您需要使用具有公共索引的 DataArray 从数据中进行选择:
请参阅 有关更高级索引的文档了解更多信息。
When you want to select from multiple dimensions using a list of multidimensional points (rather than sub-setting the data using orthogonal indices), you want to select from the data using DataArrays with a common index:
See the docs on More Advanced Indexing for more info.