使用xarray获取下载的数据集CDS API的属性和详细信息

问题描述

这是问题陈述:

笔记本的第一部分应包含调用CDS API来下载数据集的代码。然后,它应该打开此数据集并打印数据集的基本属性,通常是纬度,经度,数据变量和其他元数据的范围。 提示:处理大型气候数据集时,xarray是您的首选库。

我的代码

 import cdsapi

c = cdsapi.Client()

c.retrieve(
    'reanalysis-era5-land',{
        'format': 'grib','variable': '2m_temperature','year': '2019','month': '12','day': [
            '01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31',],'time': '12:00',},'download.grib') 

我已经成功下载了数据集,输出如下所示

2020-10-31 15:07:50,657 INFO Welcome to the CDS

2020-10-31 15:07:50,664 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-land

2020-10-31 15:07:50,920 INFO Request is completed

2020-10-31 15:07:50,922 INFO Downloading http://136.156.133.25/cache-compute-0008/cache/data7/adaptor.mars.internal-1604136466.9143934-4212-1-0eb95386-8205-41cd-aaa2-9bcec887907b.grib to download.grib (154.8M)

2020-10-31 15:18:19,024 INFO Download rate 252.4K/s    
                                                                
Result(content_length=162325920,content_type=application/x-grib,location=http://136.156.133.25/cache-compute-0008/cache/data7/adaptor.mars.internal-1604136466.9143934-4212-1-0eb95386-8205-41cd-aaa2-9bcec887907b.grib)

有人可以告诉我如何使用带有CDS API的xarray显示数据集的基本属性吗?我已经使用了jupyter笔记本进行工作。

解决方法

您可以使用 xarraycfgrib 打开 GRIB 文件。

import xarray as xr
ds = xr.open_dataset('myfile.grib',engine = 'cfgrib')

然后在 ds 中,您将拥有下载文件的所有变量和属性。