如何简化气候学分析?
你是否厌倦了花费数小时编写复杂的代码来分析气候数据?😒 是否在处理和可视化大型数据集方面感到困扰?🙁 不用再找了,最新加入Python生态系统的Easy Climate正是你需要的。Easy Climate专为气候数据分析而设计,消除了冗长的编码过程,利用了优化的数值库,并支持可扩展的并行处理。
Easy Climate的目标有四个😊:
简化数据和图绘制程序🎈尽可能用一行Python代码完成复杂
有了Easy Climate,你可以轻松进行各种气候数据分析。我们的软件包提供以下功能:
数据分析
气象绘图魔法方法
气候专业领域方法
海气相互作用
:ENSO指数、IOD指数、IOBM指数、AMM指数、大西洋厄尔尼诺指数
遥相关
:PNA指数、NAO指数、EA遥相关型、WA遥相关型、WP遥相关型、EU遥相关型、丝绸之路遥相关型、环球遥相关型
海洋
:混合层变量计算、海洋锋计算、海洋不稳定度计算、海洋温跃层计算
我们的软件包设计得用户友好🤗,灵活🥳,与流行的数据分析库如NumPy、Pandas和Matplotlib兼容。有了Easy Climate,你可以专注于探索气候数据分析的巨大潜力,而不会被复杂的代码所困扰。加入我们👨👩👧👦,一同简化气候数据分析,揭示对地球气候系统的新见解🎉。
http://easyclimate.rtfd.io
如何安装?
使用pip包管理器获取easyclimate的最新版本
$ pip install easyclimate
同样,你可以使用pip从GitHub安装最新的未发布版本(在大多数情况下不推荐)
$ pip install --upgrade git+https://github.com/shenyulu/easyclimate@main
Python 版本要求
Python
3.10
.
Python 版本是Easy climate 包强制性要求。若使用conda环境是旧版Python,请创建一个新的环境以便完成安装。
conda create -n easyclimate_env python=3.10
必需依赖
Easy climate 版本 2024.05.01 所需依赖如下(这些依赖将会在
pip install easyclimate
安装的过程中自动完成)
注意
🚨本包(库)仍在快速研发中🚨
所有API(函数/类/接口)都可能发生变化。当尝试新的设计理念和实现新的功能时,可能会出现不向后兼容的变化。这不是成品,请谨慎使用。
示例
基础统计分析
在继续所有步骤之前,首先导入一些必要的库和软件包
import easyclimate as eclimport matplotlib.pyplot as pltimport cartopy.crs as ccrs
获取巴伦支海—卡拉海(30°-90°E,65°-85°N)的海冰密集度(SIC)数据。
Luo, B., Luo, D., Ge, Y. et al. Origins of Barents-Kara sea-ice interannual variability modulated by the Atlantic pathway of El Niño–Southern Oscillation. Nat Commun 14, 585 (2023). https://doi.org/10.1038/s41467-023-36136-5
sic_data_Barents_Sea = ecl.open_tutorial_dataset('mini_HadISST_ice' ).sic sic_data_Barents_Sea
以及热带 SST 数据集。
sst_data = ecl.open_tutorial_dataset('mini_HadISST_sst' ).sst sst_data
Rayner, N. A.; Parker, D. E.; Horton, E. B.; Folland, C. K.; Alexander, L. V.; Rowell, D. P.; Kent, E. C.; Kaplan, A. (2003) Global analyses of sea surface temperature, sea ice, and night marine air temperature since the late nineteenth century J. Geophys. Res.Vol. 108, No. D14, 4407 https://doi.org/10.1029/2002JD002670 (pdf ~9Mb)
计算指定月份气候态
easyclimate.get_specific_months_data
可轻松获取只含 12 月份SIC数据。
sic_data_Barents_Sea_12 = ecl.get_specific_months_data(sic_data_Barents_Sea, 12 ); sic_data_Barents_Sea_12
现在,我们尝试绘制 12 月份巴伦支海—卡拉海域的 SIC 气候态图。
draw_sic_mean_state = sic_data_Barents_Sea_12.mean(dim = 'time' ) fig, ax = plt.subplots( subplot_kw = {'projection' : ccrs.Orthographic(central_longitude = 70 , central_latitude = 70 )} ) ax.gridlines(draw_labels = ['bottom' , 'left' ], color = "grey" , alpha = 0.5 , linestyle="--" ) ax.coastlines(edgecolor = 'black' , linewidths = 0.5 ) draw_sic_mean_state.plot.contourf( ax = ax, # projection on data transform = ccrs.PlateCarree(), # Colorbar is placed at the bottom cbar_kwargs = {'location' : 'right' }, cmap = 'Blues' , levels = 21 , )
线性倾向
众所周知,由于全球变暖的影响,近年来北极海冰面积日益减少。
easyclimate.calc_linregress_spatial
可提供每个网格点的线性趋势求解计算结果。
sic_data_Barents_Sea_12_linear_trend = ecl.calc_linregress_spatial(sic_data_Barents_Sea_12, dim = 'time' ).compute() sic_data_Barents_Sea_12_linear_trend
slope
即所需线性趋势,让我们尝试绘制每个网格点的线性趋势图。
draw_sic_slope = sic_data_Barents_Sea_12_linear_trend.slope fig, ax = plt.subplots(subplot_kw = {'projection' : ccrs.Orthographic(central_longitude = 70 , central_latitude = 70 )}) ax.gridlines(draw_labels = ['bottom' , 'left' ], color = "grey" , alpha = 0.5 , linestyle="--" ) ax.coastlines(edgecolor = 'black' , linewidths = 0.5 ) draw_sic_slope.plot.contourf( ax = ax, transform = ccrs.PlateCarree(), cbar_kwargs = {'location' : 'right' }, cmap = 'RdBu_r' , levels = 21 , )
pvalue
是相应的 p 值。设定一个显著性水平下(例如,显著性水平设为 0.05),尝试绘制显著性区域。
draw_sic_pvalue = sic_data_Barents_Sea_12_linear_trend.pvalue fig, ax = plt.subplots( subplot_kw={ "projection" : ccrs.Orthographic(central_longitude=70 , central_latitude=70 ) } ) ax.gridlines(draw_labels=["bottom" , "left" ], color="grey" , alpha=0.5 , linestyle="--" ) ax.coastlines(edgecolor="black" , linewidths=0.5 ) ecl.plot.draw_significant_area_contourf( draw_sic_pvalue, ax=ax, thresh=0.05 , transform=ccrs.PlateCarree() )
进一步,我们可以将线性趋势与显著区域叠加,研究显著区域的线性趋势(因为非显著区域的线性趋势往往是虚假的)。
回归
回归分析是一种常见的统计方法,可用于研究因变量和一个或多个自变量之间的联系。
在气候学中,它经常用于分析气候数据的趋势和模式,确定不同气候参数之间的相关性,并创建可以预测未来变化的模型。通过识别大量数据集中的模式和联系,回归分析为天气研究提供了几个好处。例如,回归分析可以用来确定影响全球温度的因素,如太阳辐射、大气温室气体和火山爆发。通过在回归模型中包含这些变量,气候科学家可以创建能够准确预测未来变化的模型。
此外,回归分析可以帮助气候学家探测到气候变率,如厄尔尼诺事件,并确定砍伐森林和化石燃料燃烧等人类活动如何影响环境。回归分析还可以评估各种缓解策略的有效性,例如碳定价政策或可再生能源倡议。
总的来说,回归分析是分析复杂气候数据和对即将发生的变化作出可靠预测的有力工具。
Regression Analysis: Definition, Types, Usage & Advantages. Website: https://www.questionpro.com/blog/regression-analysis/
The Advantages of Regression Analysis & Forecasting. Website: https://smallbusiness.chron.com/advantages-regression-analysis-forecasting-61800.html
本小节我们试图回归Niño 3.4指数至巴伦支海——喀拉海12月份SIC数据。在进行回归分析之前,我们可以可知海温数据的经度范围为-180°~180°,尝试使用
easyclimate.utility.transfer_xarray_lon_from180TO360
将经度范围转换为0°~360°。
sst_data_0_360 = ecl.utility.transfer_xarray_lon_from180TO360(sst_data) sst_data_0_360
此外,使用
easyclimate。Remove_seasonal_cycle_mean
可以很方便地删除各月气候态,以获得各个月的异常。下图展示了1982-83年超级厄尔尼诺期间热带赤道太平洋11月的海温异常状态。
Niño3.4指数常用作检测ENSO指标,函数
easyclimate.field.air_sea_interaction.calc_index_nino34
可以很方便的帮助我们通过海温异常来计算指数。我们简单绘图将其展示出来。
Anthony G. Bamston, Muthuvel Chelliah & Stanley B. Goldenberg (1997) Documentation of a highly ENSO‐related sst region in the equatorial pacific: Research note, Atmosphere-Ocean, 35:3, 367-383, DOI: https://doi.org/10.1080/07055900.1997.9649597
nino34_monthly_index = ecl.field.air_sea_interaction.calc_index_nino34( sst_data_anormaly ) nino34_monthly_index.plot( figsize=(8 , 3 ), )
然后可通过
easyclimate.calc_yearly_climatological_mean
简单实现求解月Niño3.4指数的年平均
nino34_12_index = ecl.get_specific_months_data(nino34_monthly_index, 12 ) nino34_dec_yearly_index = ecl.calc_yearly_climatological_mean(nino34_12_index) nino34_dec_yearly_index
与求解线性趋势无需传入
不同,回归分析必须通过参数
传入待回归指数。必须注意确保时间维度是相同的。