如何使用gdal.wrap()用NAN单元重新样本栅格

发布于 2025-01-23 07:34:12 字数 824 浏览 3 评论 0原文

我使用 gdal.wrap()将高分辨率重新采样到较低。但是,我的栅格没有价值( nan )。因此,当我设置Resamplealg时,NAN(S)的较大网格将成为Nan。

这是我的 python中的python

from osgeo import gdal

### resample and reproject
### data are from MOD11A2 and MYD11A2, and have been converted into annual mean values
raster_rprj = gdal.Warp("./2015_daytime_mean_re.tif",
                        "./2015_daytime_mean_clip2.tif", dstSRS = "EPSG:4326",
                        xRes = 0.008, yRes = 0.008, resampleAlg = "average")

raster_rprj = None

我希望它以函数 np.nanmean()

栅格数据在这里。

I used gdal.Wrap() to resample from a high resolution to a lower. However, my raster has no value (nan). So, when I set resampleAlg, the larger grids with nan(s) will become nan.

Here is my reprex in Python:

from osgeo import gdal

### resample and reproject
### data are from MOD11A2 and MYD11A2, and have been converted into annual mean values
raster_rprj = gdal.Warp("./2015_daytime_mean_re.tif",
                        "./2015_daytime_mean_clip2.tif", dstSRS = "EPSG:4326",
                        xRes = 0.008, yRes = 0.008, resampleAlg = "average")

raster_rprj = None

I hope it runs as the function np.nanmean()

Raster data is here.

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

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

发布评论

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

评论(1

戏蝶舞 2025-01-30 07:34:12

在重新采样之前,您可以将NAN值替换为平均值。

实现这一目标的numpy表达式如下:

numpy.nan_to_num(A,nan=numpy.nanmean(A))

其中a是您的像素的numpy阵列。

您会这​​样运行:

gdal_calc.py -A 2015_daytime_mean_clip2.tif \
--calc="numpy.nan_to_num(A,nan=numpy.nanmean(A))" \
--outfile=2015_daytime_mean_nan_to_num.tif

更多有关GDAL CALC: https://gdal.org/gdal.org/progms/gdal_calc.calc.html

然后您可以运行重新采样。

Before the resample, you could replace NaN values with averages.

The numpy expression to achieve that is the following:

numpy.nan_to_num(A,nan=numpy.nanmean(A))

Where A is the numpy array of your pixels.

You run it like this:

gdal_calc.py -A 2015_daytime_mean_clip2.tif \
--calc="numpy.nan_to_num(A,nan=numpy.nanmean(A))" \
--outfile=2015_daytime_mean_nan_to_num.tif

More about GDAL Calc: https://gdal.org/programs/gdal_calc.html

Then you can run the resample.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文