- 数据来源:
NOAA Optimum Interpolation (OI) SST V2
- 下载地址:
https://psl.noaa.gov/data/gridded/data.noaa.oisst.v2.html
- 空间分辨率:
5.0 degree latitude by 5.0 degree longitude global grid (72x36)87.5N,
- 覆盖范围
01/1856 to 2023/01
87.5N, 2.5E - 357.5E.
Monthly
Sea Level
Missing data is flagged with a value of -9.96921e+36.
以下过程,数据选取时间为1983-2022年,为了时间维度的大小可以被12整除
导入库
import numpy as np
import matplotlib.pyplot as plt
import xarray as xr
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap,shiftgrid,addcyclic, cm
from netCDF4 import Dataset as netcdf # netcdf4-python module
from matplotlib.pylab import rcParams
读取 SST 数据
- 原本纬度排序是:90°N ~ -90°S,将其进行反正变为-90°S~90°N
data = xr.open_dataset(r'G:\code_daily\sst.mnmean.nc').sst.sel(time=slice('1983','2022'))
data
sst = data[:,:,1:-1]
lons = sst.lon
lats = sst.lat[::-1]
sst
计算月平均气候态
- 将数据从
timexlatxlon
转化为month x year x lat x lon
- 对转换后的year维度求平均得到月平均的结果
lons,lats = np.meshgrid(lons, lats)
ntime,nrow,ncol = sst.shape
sstym = sst.data.reshape((12,int(ntime/12), nrow,ncol),order='F') # convert (yearmonths|lat|lont) to (years|12months|lat|lon)
sstclm = sstym.mean(axis=1) # along the year axis
sstclm.shape
(12, 180, 360)
绘图
fig, axes = plt.subplots(3,4,figsize=(18,12),dpi=200)
flat_axes = axes.reshape(-1)
m = Basemap(resolution='c', projection='ortho', lat_0=0., lon_0=180.)
# coordinates transformation
x, y = m(lons, lats)
# string month names
month_lst = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December']
imon = -1
for ax in flat_axes:
m.ax = ax
imon = imon + 1
cssst = m.contourf(x,y,sstclm[imon], 20, vmin=0, cmap='jet', vmax=30, extend='both')
m.colorbar(cssst,"right", size="5%", pad='2%')
plt.title( month_lst[imon], fontsize=20)
m.fillcontinents(color='gray', lake_color='aqua')