【在线处理和下载ERA5地表温度数据并导出为csv】

ECMWF提供了多种数据下载方式,其中手动选择下载nc文件的方法对于如想获取单一经纬度温度值的用户来说较为麻烦,为此使用官网提供的cdstoolbox进行在线处理和下载,极大的方便了有效数据的获取。

1、数据下载网址

官网链接
在这里插入图官网片描述

官网提供了Toolbox、API等下载通道,本文使用第一种Toolbox对所需数据进行预处理和下载,避免了对原始数据的处理过程,直接获取到所需区域的相关数据。

2、Toolbox

在这里插入图片描述

Toolbox页面给出了两种下载方式,即Toolbox Editor 和API方式,这里主要使用Toolbox Editor进行下载。该页面给出了相关方法的使用和绘图实例,可以根据自己的需求,进行修改使用,相当方便!!

3、近10年地表2m温度数据批量下载

本文对相关代码进行修改获取到近十年的2m气温数据,保存为csv格式

在这里插入图片描述

这里获取的数据包含时间、数据类型,经纬度、开尔文温度(摄氏温度请做X-273.15处理)。数据获取页面会给出所获得数据随时间变化的折线图,方便查看其趋势变化。(详情请参考example:03 Extract time series and plot graph)
在这里插入图片描述
在这里插入图片描述

4、本文所用代码

import cdstoolbox as ct

layout = {
    'input_ncols': 3,
}
#数据类型选择
variables = {
    'Near-Surface Air Temperature': '2m_temperature',
    'Eastward Near-Surface Wind': '10m_u_component_of_wind',
    'Northward Near-Surface Wind': '10m_v_component_of_wind',
    'Sea Level Pressure': 'mean_sea_level_pressure',
    'Sea Surface Temperature': 'sea_surface_temperature',
    'Soil temperature level 1 0-7cm':'Soil temperature level 1',
    'Soil temperature level 2 7-28cm':'Soil temperature level 2',
    'Soil temperature level 3 28-100cm':'Soil temperature level 3',
    'Soil temperature level 4 100-289cm':'Soil temperature level 4',
}

#这里仅需要修改lon和lat的值,即想获取数据的经纬度,我这里是101和38
@ct.application(title='Extract a time series and plot graph', layout=layout)
@ct.input.dropdown('var', label='Variable', values=variables.keys(), description='Sample variables')
@ct.input.text('lon', label='Longitude', type=float, default=101., description='Decimal degrees')
@ct.input.text('lat', label='Latitude', type=float, default=38., description='Decimal degrees')
@ct.output.livefigure()
@ct.output.download()

#绘制趋势图
def plot_time_series(var, lon, lat):
    """
    Application main steps:

    - set the application layout with 3 columns for the input and output at the bottom
    - retrieve a variable over a defined time range
    - select a location, defined by longitude and latitude coordinates
    - compute the daily average
    - show the result as a timeseries on an interactive chart

    """
    #数据的获取部分,修改年、月、日、时,以取得自己的数据
    # Time range
    data = ct.catalogue.retrieve(
        'reanalysis-era5-single-levels',
        {
            'variable': variables[var],
            'grid': ['3', '3'],
            'product_type': 'reanalysis',
            'year': [
                '2014', '2015', '2016',
                '2017', '2018', '2019',
                '2020', '2021', '2022',
                '2023'
            ],
            'month': [
                '01', '02', '03', '04', '05', '06',
                '07', '08', '09', '10', '11', '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': ['00:00', '06:00', '12:00', '18:00'],
        }
    )

    # Location selection

    # Extract the closest point to selected lon/lat (no interpolation).
    # If wrong number is set for latitude, the closest available one is chosen:
    # e.g. if lat = 4000 -> lat = 90.
    # If wrong number is set for longitude, first a wrap in [-180, 180] is made,
    # then the closest one present is chosen:
    # e.g. if lon = 200 -> lon = -160.
    #获取所需的每个时刻数据
    data_sel = ct.geo.extract_point(data, lon=lon, lat=lat)
	#对小时数据取平均获得日均温度
    # Daily mean on selection
    data_daily = ct.climate.daily_mean(data_sel)
    #绘图
    fig = ct.chart.line(data_daily)
    #导出为CSV格式
    csv_data=ct.cdm.to_csv(data_daily)
    
    return fig , csv_data

运行(Run)之后,等待之后,会出现趋势图和csv文件下载链接,点击下载
在这里插入图片描述
在这里插入图片描述
打开CSV文件就获取到了想要的时间段内的日平均温度,然后就可以对其利用Origin等软件进行绘图处理和使用了。
(更多数据获取和处理方法,请参考官网文件

  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值