Python:从 shapefile(多边形/多重多边形)中屏蔽 ERA5 数据(NetCDF)

发布于 2025-01-17 15:30:13 字数 673 浏览 3 评论 0原文

我想从瑞士北部和南部地理掩码(加上雷达缓冲区)内的 ERA5 网格数据(仅表面水平)中选择网格单元,以计算区域平均值。 4 个遮罩 (遮罩) 以多边形/多多边形 (多边形) 在 shapefile 中,到目前为止,对于 2 个蒙版,我能够使用 salem roi得到我想要的:

radar_north = salem.read_shapefile('radar_north140.shp')
file_radar_north = file.salem.roi(shape=radar_north)
file_radar_north.cape.mean(dim='time').salem.quick_map() 

但是,对于radar_south和alpensuedseite形状文件,代码一开始不起作用(错误选择或不显示数据),现在什么也不起作用了(?)。我不知道为什么,因为从第一次到第二次我没有改变任何东西。

如果有人看到这个问题或知道屏蔽 ERA 数据的不同方法(可能更快),我将不胜感激! (我在这里没有成功地回答类似问题)。

最好的 莉娜

I want to select grid cells from ERA5 gridded data (surface level only) that are inside geographical masks for North- and South-Switzerland (plus the radar buffer), to calculate regional means.
The 4 masks (masks) are given as polygons/multipolygons (polygons) in a shapefile and so far for 2 of the masks I was able to use salem roi to get what I want:

radar_north = salem.read_shapefile('radar_north140.shp')
file_radar_north = file.salem.roi(shape=radar_north)
file_radar_north.cape.mean(dim='time').salem.quick_map() 

However, for the radar_south and alpensuedseite shapefiles the code didn´t work at the beginning (wrong selection or shows no data), and now the nothing works anymore (?). I don´t know why, as I have not changed anything from the first time to the second.

If someone sees the issue or knows a different way to mask the ERA data (which is maybe quicker) I would be grateful! (I was unsuccessfull with the answers from similar questions here).

Best
Lena

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

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

发布评论

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

评论(1

那请放手 2025-01-24 15:30:13

如果您正在处理NETCDF文件,这可能会起作用

import geopandas as gpd
import xarray as xr
import rioxarray
from shapely.geometry import mapping

# load shapefile with geopandas
radar_north = gpd.read_file('radar_north140.shp')

# load ERA5 netcdf with xarray
era = xr.open_dataset('ERA5.nc')

# add projection system to nc
era = era.rio.write_crs("EPSG:4326", inplace=True)

# mask ERA5 data with shapefile
era_radar_north = era.rio.clip(radar_north.geometry.apply(mapping), radar_north.crs)

This could work if you are working on netcdf files

import geopandas as gpd
import xarray as xr
import rioxarray
from shapely.geometry import mapping

# load shapefile with geopandas
radar_north = gpd.read_file('radar_north140.shp')

# load ERA5 netcdf with xarray
era = xr.open_dataset('ERA5.nc')

# add projection system to nc
era = era.rio.write_crs("EPSG:4326", inplace=True)

# mask ERA5 data with shapefile
era_radar_north = era.rio.clip(radar_north.geometry.apply(mapping), radar_north.crs)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文