如何插值多维Xarray?

发布于 2025-01-19 07:32:36 字数 623 浏览 2 评论 0原文

我使用 xarray 读取了 netCDF 文件。该数据集包含 1975 年、1990 年、2000 年和 2015 年人口latlon信息。

该数据集如下所示我也提供了它此处

import xarray as xr
ds = xr.open_dataset('borneo_pop_t.nc')
ds

在此处输入图像描述

对于每个像素,我希望获得 1975 年至 2000 年之间每年的信息(考虑到趋势)我拥有的数据点。我特别想为缺失的年份生成更多信息和不同层次的人口。

我怎样才能做到这一点?

I read a netCDF file using xarray. The dataset contains lat, lon information of the population for the years: 1975, 1990, 2000 and 2015.

The dataset looks like the following and I made it also available here:

import xarray as xr
ds = xr.open_dataset('borneo_pop_t.nc')
ds

enter image description here

For each pixel I would like to have the information of each year between 1975 and 2000 given the trend of the data points I have. In particular I would like to generate more information and different layers of the population for the missing years.

How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溇涏 2025-01-26 07:32:36

您可以使用xarray的插值函数< /a>.

使用变量名称,

import pandas as pd

# Create time series of 1x a year data
# (you can use any date range; you can generate pretty much 
# any sequence you need with pd.date_range()) 
dates = pd.date_range('1975-01-01','2015-01-01',freq='1Y') 

# Linear interpolation
ds_interp = ds.interp(time=dates)

请注意以下几点:

  1. 此代码仅生成一个简单的线性插值,尽管 ds.interp() 支持 scipy.interpolate.interp1d() 所做的一切- 例如,三次插值、多项式插值等。检查上面链接的扩展坞以获取示例。
  2. 这当然不会创建新信息;而是创建新信息。你仍然只“知道”原始点的人口。请注意插值数据会对您了解特定年份的实际人口数量产生什么影响。

You can use xarray's interpolation function.

Using your variable names,

import pandas as pd

# Create time series of 1x a year data
# (you can use any date range; you can generate pretty much 
# any sequence you need with pd.date_range()) 
dates = pd.date_range('1975-01-01','2015-01-01',freq='1Y') 

# Linear interpolation
ds_interp = ds.interp(time=dates)

Note a few things:

  1. This code just generates a simple linear interpolation, though ds.interp() supports everything that scipy.interpolate.interp1d() does - e.g., cubic, polynomial, etc. interpolation. Check the docks linked above for examples.
  2. This of course doesn't create new information; you still only "know" the population at the original points. Be wary what consequences interpolating the data will have on your understanding of what the population actually was in a given year.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文