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等软件进行绘图处理和使用了。
(更多数据获取和处理方法,请参考官网文件)