如何按压力级别提取信息?

How do I extract information by pressure level?

我是 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 文件有效,并且应该适用于 U.K。英国气象局 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]

所以如果你想要 't' 700mb,你会使用 t[2] 因为 700 位于第二个索引:

tmp700 = ds[0].t[2]

(如果您需要 grib 文件输出中未显示的 'isobaricInhPa' 值,请使用:)

ds[0].isobaricInhPa

然后对于纬度和经度,使用:

lat = ds[0].latitude
lon = ds[0].longitude