我正在尝试使用xESMF软件包将一组分辨率为0.25度的GRIB2阵列重新采样为更粗的分辨率为0.5度(xarray的粗化方法在这里不起作用,因为纬度中有奇数个坐标)
我已通过pygrib包将GRIB数据转换为xarray格式,然后将我需要的特定网格子集:
fhr = 96
gridDefs = {
"0.25":
{'url': "https://noaa-gefs-retrospective.s3.amazonaws.com/landsfc.pgrb2.0p25"},
"0.5":
{'url': "https://noaa-gefs-retrospective.s3.amazonaws.com/landsfc.pgrb2.0p50"},
}
fileDefs = {
"0.25":
{'url': "https://noaa-gefs-retrospective.s3.amazonaws.com/GEFSv12/reforecast/2019/2019051900/c00/Days%3A1-10/tmp_pres_2019051900_c00.grib2",
'localfile': "tmp_pres.grib2"},
"0.5":
{'url': "https://noaa-gefs-retrospective.s3.amazonaws.com/GEFSv12/reforecast/2019/2019051900/c00/Days%3A1-10/tmp_pres_abv700mb_2019051900_c00.grib2",
'localfile': "tmp_pres_abv_700.grib2"},
}
def grib_to_xs(grib, vName):
arr = xr.DataArray(grib.values)
arr = arr.rename({'dim_0':'lat', 'dim_1':'lon'})
xs = arr.to_dataset(name=vName)
return xs
gribs = {}
for key, item in gridDefs.items():
if not os.path.exists(item['url'][item['url'].rfind('/')+1:]):
os.system("wget " + item['url'])
lsGrib = pygrib.open(item['url'][item['url'].rfind('/')+1:])
landsea = lsGrib[1].values
gLats = lsGrib[1]["distinctLatitudes"]
gLons = lsGrib[1]["distinctLongitudes"]
gribs["dataset" + key] = xr.Dataset({'lat': gLats, 'lon': gLons})
lsGrib.close()
for key, item in fileDefs.items():
if not os.path.exists(item['localfile']):
os.system("wget " + item['url'])
os.system("mv " + item['url'][item['url'].rfind('/')+1:] + " " + item['localfile'])
for key, item in fileDefs.items():
hold = pygrib.open(item['localfile'])
subsel = hold.select(forecastTime=fhr)
#Grab the first item
gribs[key] = grib_to_xs(subsel[1], "TT" + key)
hold.close()
上面的代码在两个网格域(0.25和0.5)下载两个常量文件(landsfc),然后在每个分辨率下下载两个GRIB文件。我正在尝试将0.25度GRIB文件(tmp_pres.grib2)重新采样为0.5度域,如下所示:
regridder = xe.Regridder(ds, gribs['dataset0.5'], 'bilinear')
print(regridder)
ds2 = regridder(ds)
我的问题是,我在尝试使用regridder时生成了两条警告消息:
/media/robert/HDD/Anaconda3/envs/wrf-work/lib/python3.8/site-packages/xarray/core/dataarray.py:682: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
return key in self.data
/media/robert/HDD/Anaconda3/envs/wrf-work/lib/python3.8/site-packages/xesmf/backend.py:53: UserWarning: Latitude is outside of [-90, 90]
warnings.warn('Latitude is outside of [-90, 90]')
输出xarray确实具有正确的坐标,但是网格内的值相差很远(超出更高分辨率网格的最大值/最小值),并且显示出这些奇怪的带状图案,这些图案没有任何物理意义
我想知道的是,这是使用xEMSF升级阵列的正确过程吗?如果不是,我将如何解决这个问题
任何帮助都将不胜感激,谢谢
多亏了MASACR 99提供的文档链接和建议,我能够对xESMF包进行更多的挖掘,并从包作者(https://github.com/geoschem/GEOSChem-python-tutorial/blob/main/Chapter03_regridding.ipynb)那里找到一个重采样方法的工作示例,我的问题通过两个更改得到了解决:
为了解决第一个变化,我创建了一个新函数来提供边界变量:
对于第二个更改,我修改了Regrider定义和应用程序,以使用静态定义的网格,然后将所需变量传递给重采样:
我建议首先尝试保守而不是双线性(这在他们的文档中是推荐的),并且可能会检查您是否正确使用了参数,因为似乎有什么地方出错了,我的第一个猜测是,您所做的事情会因为某种原因移动纬度,我把文档链接留在这里,希望有人知道更多
重新招标文件: https://xesmf.readthedocs.io/en/latest/user_api.html?highlight=regridder#xesmf.frontend.Regridder.__init_\u
放大建议(搜索放大,还有提高分辨率的指南): https://xesmf.readthedocs.io/en/latest/notebooks/Compare_algorithms.html?highlight=upscaling
相关问题 更多 >
编程相关推荐