python中NetCDF文件的空间重采样

发布于 2025-01-19 07:49:01 字数 1276 浏览 2 评论 0原文

我正在使用 NetCDF 文件格式的 Sentinel 3 SLSTR 数据。该文件包含 11 个频段: S1-S6(500 m 分辨率)和 S7-S9 以及 F1 & F2(1000 米分辨率)。 S1-S6 包含辐射值,S7-S9 包含亮度温度值。现在,我想将 S7-S9 频段重新采样至 500 m 分辨率,以匹配 S1-S6 频段的分辨率。

我正在使用 xarray 读取 netCDF 文件。有一个函数 xarray.Dataset.resample() 但文档说它会重新采样到新的时间分辨率。

我还尝试使用 gdal 重新采样但无法得到任何结果。

import gdal
import xarray as xr
import matplotlib.pyplot as plt

data = xr.open_dataset('S7_BT_in.nc')          # one of the files in 1000 m resolution
geo = xr.open_dataset(path+'geodetic_an.nc')   # file containing the geodetic values


ds = data['S7_BT_in']                # fetching variable I need to work on
lat = geo['latitude_an']             # fetching latitude values
lon = geo['longitude_an']            # fetching longitude values



#assigning latitude and longitude values to the coordinates of ds 
ds = ds.assign_coords(coords = {'Latitude': lat, 'Longitude': lon})    

x = gdal.Open('ds')             # Opening the netCDF file using gdal


# resampling the data to 500 m resolution
xreproj = gdal.Warp('resampled.nc', x, xRes = 500, yRes = 500)

这是我收到的错误:

SystemError: <built-in function wrapper_GDALWarpDestName> returned NULL without setting an error.

我也尝试使用 gdal 直接打开文件,但仍然收到相同的错误。

I am working with Sentinel 3 SLSTR data which comes in netCDF file format. The file contains 11 bands:
S1-S6 (500 m resolution) and S7-S9 and F1 & F2 (1000 m resolution). S1-S6 contains radiance values and S7-S9 contains brightness temperature values. Right now, I want to resample my S7-S9 band to 500 m resolution to match the resolution of S1-S6 bands.

I am using xarray to read the netCDF files. There is a function xarray.Dataset.resample() but the documentation says that it resample to a new temporal resolution.

I also tried to resample using gdal but couldn't get any result.

import gdal
import xarray as xr
import matplotlib.pyplot as plt

data = xr.open_dataset('S7_BT_in.nc')          # one of the files in 1000 m resolution
geo = xr.open_dataset(path+'geodetic_an.nc')   # file containing the geodetic values


ds = data['S7_BT_in']                # fetching variable I need to work on
lat = geo['latitude_an']             # fetching latitude values
lon = geo['longitude_an']            # fetching longitude values



#assigning latitude and longitude values to the coordinates of ds 
ds = ds.assign_coords(coords = {'Latitude': lat, 'Longitude': lon})    

x = gdal.Open('ds')             # Opening the netCDF file using gdal


# resampling the data to 500 m resolution
xreproj = gdal.Warp('resampled.nc', x, xRes = 500, yRes = 500)

This is the error I am getting:

SystemError: <built-in function wrapper_GDALWarpDestName> returned NULL without setting an error.

I also tried opening the file directly using gdal but still getting the same error.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文