如何使用Python处理ERA5每小时的陆上数据? [英] How manipulate ERA5 land hourly data with Python?
问题描述
我最近开始按小时每小时使用 ERA5 数据和python代码.
I recently started to use ERA5 land-hourly data and python code.
我将使用整个一年(2017年)的两个变量(总降水量和 2米温度)的数据.
I will use data of 2 variables (total precipitation and 2 metre temperature) from an entire year (2017).
下载的数据为GRIB或netCDF格式.
Data downloaded are in GRIB or netCDF format.
我想做的事情是:
1)转换单位.对于以下情况:
- 总降水量-将"m"转换为"mm"
- 2m温度-将开尔文"转换为摄氏温度"
2)每小时将其转换为每日值:
我从ECMWF的官方站点找到了以下代码: https://confluence.ecmwf. int/display/CKB/ERA5%3A +如何+计算+每日+总+降水 不幸的是,该代码仅用于编译一天的每日值 (2017年1月1日).
I've found the following code from ECMWF's offficial site: https://confluence.ecmwf.int/display/CKB/ERA5%3A+How+to+calculate+daily+total+precipitation Unfortunately, the code is designed only to compile daily values for one day (January 1st, 2017).
我要转换整个一年的所有值.我知道(如果我是对的):
I want to convert all values for an entirely year. I know that (if I'm right):
-
总降水量代表累计值.因此,每天的价值就是24小时的总和.
温度表示平均值.因此,每日价值是24小时的平均值.
- total precipitation presents acumulated values. So daily value is the sum of 24 hours.
- temperature presents mean values. So daily value is the mean of 24 hours.
3)从数据文件中选择特定信息:
为了进行分析,我只想保留以下信息:
In order to do an analysis, I want to keep only information about:
- 值
- 纬度
- 经度
- 时间
两个变量(总降水量和2米温度)
for both variables (total precipitation and 2 metre temperature)
4)将GRIB或netCDF文件转换为Stata软件可以读取的某种格式
我真的很感谢任何帮助手势
I really will appreciate any gesture of help
推荐答案
如果您使用 xarray
1)单位换算:
import xarray as xr
ds = xr.open_dataset(path/to/netcdf/file)
# converting total precipitation from m to mm
ds.tp = ds.tp * 1000
# converting t2m from K to C
ds.t2m = ds.t2m - 273.15
2)每小时到每天的数据:
2) Hourly to Daily data:
xarray .resample 方法可以为您提供帮助.
xarray .resample method can help you here.
# daily temperature mean from hourly values
ds.t2m.resample(time='1D').mean()
# daily precipitation sum from hourly values
ds.tp.resample(time='1D').sum()
应该更好地解释您的3)和4)点,以增加获得适当帮助的机会
Your points 3) and 4) should be better explained to increase your chances of getting proper help
这篇关于如何使用Python处理ERA5每小时的陆上数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!