- 积分
- 1428
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2021-7-21
- 最后登录
- 1970-1-1

|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 xiaoxiao啊 于 2022-7-7 17:08 编辑
气象统计方法所有数据获取方式如下
链接:https://pan.baidu.com/s/1KbxLS8nmvpqkxbVt5Q-iHA
提取码:wumq
import numpy as np
import xarray as xr
import pandas as pd
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import cmaps
import warnings
warnings.filterwarnings('ignore')
plt.rcParams['font.sans-serif'] = ['Times New Roman']
plt.rcParams['axes.unicode_minus'] = False
lon = np.arange(121.88, 121.88 + 32 * 5.65, 5.65)
lat = np.array([-18.0950, -12.3808, -6.6666, -0.9524, 4.7618, 10.4761, 16.1902])
time = np.arange(1978, 1978 + 30)
tpsst = np.fromfile('NCEP_TPSST_30y_Wt.dat', dtype='<f4').reshape(30, 7, 32)
tpsst = xr.DataArray(tpsst, coords=[time, lat, lon], dims=['time', 'lat', 'lon'])
tpsst = tpsst.where(tpsst!=1e+33, np.nan)
tpsst_clim = tpsst.mean('time') # 气候态
tpsst_std = tpsst.std('time') # 均方差
tpsst_82 = tpsst.loc[1982]
tpsst_98 = tpsst.loc[1998]
def tpsst_plot():
fig = plt.figure(figsize=(10, 9), facecolor='w')
for j in range(3):
for i in range(2):
ax = fig.add_axes([0 + 0.5 * i, 1 - 0.33 * j, 0.4, 0.3], projection=ccrs.PlateCarree(210))
ax.add_feature(cfeature.LAND.with_scale('110m'), facecolor='w', edgecolor='dimgrey', linewidth=0.3, zorder=2)
ax.set_extent([120, 300, -20, 20], ccrs.PlateCarree())
ax.set_xticks(np.arange(120, 300 + 40, 40), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-20, 20 + 10, 10), crs=ccrs.PlateCarree())
ax.xaxis.set_major_formatter(LongitudeFormatter())
ax.yaxis.set_major_formatter(LatitudeFormatter())
ax.tick_params(which='major', width=0.5, length=5)
ax.spines['geo'].set_linewidth(0.5)
ax.set_aspect(2)
if i == 0 and j == 0:
clevels = np.arange(20, 31, 1)
ax.set_title('Winter TPSST Clim', loc='left')
cf = ax.contourf(lon, lat, tpsst_clim, cmap='jet', levels=clevels, transform=ccrs.PlateCarree(), zorder=1)
if i == 1 and j == 0:
clevels = np.arange(0, 1.8, 0.2)
ax.set_title('Winter TPSST Std', loc='left')
cf = ax.contourf(lon, lat, tpsst_std, cmap='Reds', levels=clevels, transform=ccrs.PlateCarree(), zorder=1)
if i == 0 and j == 1:
clevels = np.arange(20, 31, 1)
ax.set_title('1982 Winter TPSST', loc='left')
cf = ax.contourf(lon, lat, tpsst_82, cmap='jet', levels=clevels, transform=ccrs.PlateCarree(), zorder=1)
if i ==1 and j ==1:
clevels = np.arange(-5, 6, 1)
ax.set_title('1982 Winter TPSST Ano', loc='left')
cf = ax.contourf(lon, lat, tpsst_82 - tpsst_clim, cmap=cmaps.NCV_blue_red, levels=clevels, transform=ccrs.PlateCarree(), zorder=1)
if i == 0 and j == 2:
clevels = np.arange(20, 31, 1)
ax.set_title('1998 Winter TPSST', loc='left')
cf = ax.contourf(lon, lat, tpsst_98, cmap='jet', levels=clevels, transform=ccrs.PlateCarree(), zorder=1)
if i ==1 and j ==2:
clevels = np.arange(-2.5, 3, 0.5)
ax.set_title('1998 Winter TPSST Ano', loc='left')
cf = ax.contourf(lon, lat, tpsst_98 - tpsst_clim, cmap=cmaps.NCV_blue_red, levels=clevels, transform=ccrs.PlateCarree(), zorder=1)
cb = fig.colorbar(cf, orientation='horizontal', shrink=0.9, pad=0.17, ticks=clevels)
cb.outline.set_linewidth(0.1)
cb.ax.tick_params(length=0)
plt.savefig('tpsst.png', dpi=300, bbox_inches='tight')
tpsst_plot()
nino34 = tpsst.loc[:, -5:5, 190:240].mean(['lat', 'lon']) # nino3.4区海温指数
nino34_ano = nino34 - nino34.mean('time') # 距平值
nino34_norm = nino34_ano / nino34.std('time') # 标准化
year = np.arange(1978, 1978 + 30)
print('El Nino years: ', year[nino34_norm.values >= 1])
print('La Nina years: ', year[nino34_norm.values <= -1])
def nino34_plot():
fig = plt.figure(figsize=(5, 10), facecolor='w')
ax1 = fig.add_axes([0.1, 0.75, 0.8, 0.2])
ax1.plot(year, nino34, linewidth=1)
ax1.set_title('Nino3.4 SST Index', loc='left')
ax1.tick_params(which='major', width=0.5, length=5)
for i in ['bottom', 'top', 'left', 'right']:
ax1.spines【i】.set_linewidth(0.5) # 记得改成英文的中括号,气象家园无法显示英文中括号加i
ax1.set_xlabel('year')
ax1.set_xlim(1977, 2008)
ax1.set_ylim(24.5, 29.5)
ax2 = fig.add_axes([0.1, 0.45, 0.8, 0.2])
bars = ax2.bar(year, nino34_ano, facecolor='#ff9999', edgecolor='r', width=1)
for bar, height in zip(bars, nino34_ano):
if height < 0:
bar.set(facecolor='#9999ff', edgecolor='blue')
ax2.set_title('Nino3.4 SST Index Ano', loc='left')
ax2.tick_params(which='major', width=0.5, length=5)
for i in ['bottom', 'top', 'left', 'right']:
ax2.spines【i】.set_linewidth(0.5) # 记得改成英文的中括号,气象家园无法显示中括号加i
ax2.set_xlabel('year')
ax2.set_xlim(1977, 2008)
ax2.set_ylim(-2.5, 2.5)
ax3 = fig.add_axes([0.1, 0.15, 0.8, 0.2])
bars = ax3.bar(year, nino34_norm, facecolor='#ff9999', edgecolor='r', width=1)
for bar, height in zip(bars, nino34_norm):
if height < 0:
bar.set(facecolor='#9999ff', edgecolor='blue')
ax3.set_title('Nino3.4 SST Index Norm', loc='left')
ax3.tick_params(which='major', width=0.5, length=5)
for i in ['bottom', 'top', 'left', 'right']:
ax3.spines【i】.set_linewidth(0.5) # 记得改成英文的中括号,气象家园无法显示中括号加i
ax3.set_xlabel('year')
ax3.set_xlim(1977, 2008)
ax3.set_ylim(-2.5, 2.5)
plt.axhline(1, lw=1, c='red', ls=':')
plt.axhline(-1, lw=1, c='blue', ls=':')
plt.savefig('nino34.png', dpi=300, bbox_inches='tight')
nino34_plot()
|
-
-
|