cfgrib - 如何按压力级别提取信息?
问题描述
我是cfgrib的新手,所以请原谅可能是一个直截了当的问题..
我有一个异构 grib 文件,它表示网格上各点和大气压力水平的天气信息。
对于我的一生,我无法弄清楚如何以可用的方式提取我需要的信息。
例如,我想获取每个可用压力水平下网格中每个点的温度信息(数据变量 = t)。或者,如果不可能,请获取特定压力水平下每个纬度、经度的温度。
我的 grib 文件如下所示:
Dimensions: (isobaricInhPa: 17, latitude: 145, longitude: 288)
Coordinates:
time datetime64[ns] 2020-10-16T12:00:00
step timedelta64[ns] 06:00:00
* isobaricInhPa (isobaricInhPa) int64 850 750 700 600 500 ... 175 150 125 100
* latitude (latitude) float64 -90.0 -88.75 -87.5 ... 87.5 88.75 90.0
* longitude (longitude) float64 0.0 1.25 2.5 3.75 ... 356.2 357.5 358.8
valid_time datetime64[ns] 2020-10-16T18:00:00
Data variables:
t (isobaricInhPa, latitude, longitude) float32 ...
u (isobaricInhPa, latitude, longitude) float32 ...
v (isobaricInhPa, latitude, longitude) float32 ...
gh (isobaricInhPa, latitude, longitude) float32 ...
Attributes:
GRIB_edition: 2
GRIB_centre: egrr
GRIB_centreDescription: U.K. Met Office - Exeter
GRIB_subCentre: 5
Conventions: CF-1.7
institution: U.K. Met Office - Exeter, <xarray.Dataset>
Dimensions: (isobaricInhPa: 5, latitude: 145, longitude: 288)
Coordinates:
time datetime64[ns] 2020-10-16T12:00:00
step timedelta64[ns] 06:00:00
* isobaricInhPa (isobaricInhPa) int64 850 750 700 600 500
* latitude (latitude) float64 -90.0 -88.75 -87.5 ... 87.5 88.75 90.0
* longitude (longitude) float64 0.0 1.25 2.5 3.75 ... 356.2 357.5 358.8
valid_time datetime64[ns] ...
Data variables:
r (isobaricInhPa, latitude, longitude) float32 ...
Attributes:
GRIB_edition: 2
GRIB_centre: egrr
GRIB_centreDescription: U.K. Met Office - Exeter
GRIB_subCentre: 5
Conventions: CF-1.7
institution: U.K. Met Office - Exeter, <xarray.Dataset>
Dimensions: (latitude: 145, longitude: 288)
Coordinates:
time datetime64[ns] 2020-10-16T12:00:00
step timedelta64[ns] 06:00:00
maxWind int64 0
* latitude (latitude) float64 -90.0 -88.75 -87.5 -86.25 ... 87.5 88.75 90.0
* longitude (longitude) float64 0.0 1.25 2.5 3.75 ... 356.2 357.5 358.8
valid_time datetime64[ns] 2020-10-16T18:00:00
Data variables:
u (latitude, longitude) float32 ...
v (latitude, longitude) float32 ...
icaht (latitude, longitude) float32 ...
Attributes:
GRIB_edition: 2
GRIB_centre: egrr
GRIB_centreDescription: U.K. Met Office - Exeter
GRIB_subCentre: 5
Conventions: CF-1.7
institution: U.K. Met Office - Exeter, <xarray.Dataset>
Dimensions: (latitude: 145, longitude: 288)
Coordinates:
time datetime64[ns] 2020-10-16T12:00:00
step timedelta64[ns] 06:00:00
tropopause int64 0
* latitude (latitude) float64 -90.0 -88.75 -87.5 -86.25 ... 87.5 88.75 90.0
* longitude (longitude) float64 0.0 1.25 2.5 3.75 ... 356.2 357.5 358.8
valid_time datetime64[ns] 2020-10-16T18:00:00
Data variables:
t (latitude, longitude) float32 ...
icaht (latitude, longitude) float32 ...
Attributes:
GRIB_edition: 2
GRIB_centre: egrr
GRIB_centreDescription: U.K. Met Office - Exeter
GRIB_subCentre: 5
Conventions: CF-1.7
institution: U.K. Met Office - Exeter]
非常感谢任何帮助!
解决方案
这适用于我使用 NWS NCEP grib2 文件,并且应该适用于英国气象局 grib 文件。它也只在特定的压力水平上抓住't'。
使用 cfgrib.open_datasets() 打开 grib 文件。(我在这里使用“data.grib”作为示例文件名,并使用 grib 文件的输出来获取变量):
import cfgrib
ds = cfgrib.open_datasets('data.grib')
由于您想要位于 grib 输出的第 0 个索引中的温度变量“t”,请使用:
tmp = ds[0].t
但是,您仍然需要指定压力级别。为了知道要使用什么索引,请查看 grib 输出中的“isobaricInhPa”值:
* isobaricInhPa (isobaricInhPa) int64 850 750 700 600 500 ... 175 150 125 100
将这些值视为一个列表:
[850 750 700 600 500 ... 175 150 125 100]
所以如果你想要 700mb 的 't',你会使用 t[2] 因为 700 位于第二个索引:
tmp700 = ds[0].t[2]
(如果您需要 grib 文件输出中未显示的 'isobaricInhPa' 值,请使用:)
ds[0].isobaricInhPa
然后对于纬度和经度,使用:
lat = ds[0].latitude
lon = ds[0].longitude
推荐阅读
- java - 如何在 Windows 上设置 JUNIT 以使用 Sublime 和命令行?
- reactjs - Reactjs:使用类与功能组件的最佳实践是什么?
- node.js - 在 puppeteer 中使用 browser.close() 与简单地终止整个程序有何不同?
- r - R data.frame 将字符转换为数字时的奇怪行为
- database - Cassandra 数据建模:选择分区键和复合键
- python - 我不明白为什么这不会打印,它说标题没有在第 5 行定义,即使我在括号中定义了它
- python-3.x - 使用 tkinter 将 Python 2.7 转换为 Python 3
- laravel-5.8 - 我在 laravel 5.8 上迁移时遇到问题
- php - 获取带有静态 html 内容的 wordpress 页面模板以在搜索中显示
- c - *((int*)&f) 在 C 中做了什么?