全部,
我使用regionmask包0.13.0来掩盖气候NetCDF数据。我发现如果我的数据从-180扩展到180,即使我设置了
wrap_lon=180
并且我没有设置wrap_lon
,掩码函数也会返回所有NAN,我收到以下错误
ValueError: lon has data that is larger than 180 and smaller than 0. Set `wrap_lon=False` to skip this check.
我发现
shp_file['geometry']
产生一个非常大的数字,这可能解释了这个错误,但不确定为什么多多边形数如此之大。
0 MULTIPOLYGON (((-1832380.592 2237164.258, -182 Name: geometry, dtype: geometry
更新:我打印了
shp_file.crs
,我发现CRS是EPSG:3857,
<Projected CRS: EPSG:3857>
Name: WGS 84 / Pseudo-Mercator
Axis Info [cartesian]:
- X[east]: Easting (metre)
- Y[north]: Northing (metre)
Area of Use:
- name: World between 85.06°S and 85.06°N.
- bounds: (-180.0, -85.06, 180.0, 85.06)
Coordinate Operation:
- name: Popular Visualisation Pseudo-Mercator
- method: Popular Visualisation Pseudo Mercator
Datum: World Geodetic System 1984 ensemble
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
但是当我尝试使用 CRS 打开形状文件时
hp_file =gpd.read_file("datafiles/"+filename+'.shp',\
crs='EPSG:3857')
我收到以下错误。
geo_env/lib/python3.12/site-packages/pyogrio/raw.py:198: RuntimeWarning: driver ESRI Shapefile does not support open option CRS
这是最小的例子
import xarray as xr
import geopandas as gpd
import regionmask
#%% opening the dataset
t2m_file = xr.open_dataset("datafiles/"+"temp.nc")
# adjusting longitude.
t2m_file.coords['longitude'] = (t2m_file.coords['longitude'] + 180) % 360 - 180
t2m_file = t2m_file.sortby(t2m_file.longitude)
t2m = t2m_file['t2m']
#%%
filename='North_Africa'
shp_file =gpd.read_file("datafiles/"+filename+'.shp')
shp_region=regionmask.Regions(shp_file.geometry)
shp_file.plot()
#%%
mask_region=shp_region.mask(t2m.longitude,t2m.latitude,wrap_lon=180)
# masked temperture of the raw data
tem_masked_region=t2m.where(mask_region == 0)
shape文件和netcdf都非常小,可以从盒子里下载 https://app.box.com/s/nyauxuuscbk0ws5firpmyjt3y51nrlr2
谢谢
按照@Patrick的建议,将形状坐标从米更改为度解决了这个问题。
shp_file=shp_file.to_crs('EPSG:4326’)
mask
包的regionmask
函数将米坐标视为度坐标;我认为如果该功能首先测试坐标参考系CRS的类型会很好。由于我收到的错误(如下)让我觉得问题出在 netcdf 数据文件上
ValueError: lon has data that is larger than 180 and smaller than 0. Set `wrap_lon=False` to skip this check.