- 积分
- 1626
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2016-1-5
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2018-4-29 14:40:24
|
显示全部楼层
增加了简单的注释,请批评指正,参考脚本;table = readtable('f:/nino34.csv', delimiter=',', format='%s%f')
yy = table['yyJJA']
nino34 = table['nino34']
#print nino34
f = addfile('f:/precip.mon.mean.2.5x2.5.nc')
#prep = f['precip'][0::12,'0:60','60:150']
var = f['precip'][0,'0:60','60:150']
syears = arange(1981,2016)
nx = var.dimlen(1)
ny = var.dimlen(0)
prepJJA = [] #1981-2015年夏季降水序列
syears = arange(1981,2016)
for i in range(1981,2016):
tidx = (i-1948)*12 #每年1月
t = f.gettime(tidx)
data = f['precip'][tidx+5,'0:60','60:150']+\
f['precip'][tidx+6,'0:60','60:150']+\
f['precip'][tidx+7,'0:60','60:150']
prepJJA.append(data)
nt = len(prepJJA)
#trend固定某一格点,得到年份和降水两个时间序列,计算两者线性回归拟合值
for i in arange(0,nx):
for j in arange(0,ny):
xx = []
yy = []
for t in syears:
tidx = t -1981
if(prepJJA[tidx][j,i]>-9.96921E36):
xx.append(t)
yy.append(prepJJA[tidx][j,i])
y = zeros([nt])
if(len(xx)>1):
slope, intercept, r, p, std,number = linregress(xx, yy)
#print slope, intercept, r
y = polyval([slope, intercept], syears)
else:
y = nan
#print i,j,y
#1981-2015去掉了降水的线性拟合
for t in syears:
tidx = t -1981
if(prepJJA[tidx][j,i]>-9.96921E36):
prepJJA[tidx][j,i] = prepJJA[tidx][j,i]-y[tidx]
else:
prepJJA[tidx][j,i] = nan
#构建相关系数二维场(年份序列和去掉了它们的线性趋势的降水序列)
cor = zeros([ny,nx])
cor = dim_array(cor,var.dims)
for i in arange(0,nx):
for j in arange(0,ny):
x = []
y = []
for t in syears:
tidx = t -1981
if(prepJJA[tidx][j,i]>-9.96921E36):
x.append(nino34[t-1981])
y.append(prepJJA[tidx][j,i])
#scatter(xx, yy, s=2, color='k', label='PM')
if(len(x)>1):
slope, intercept, r, p, std,number = linregress(x, y)
cor[j,i] = r
else:
cor[j,i] = nan
#print cor
axesm()
mlayer = shaperead('F:\MeteoInfo\MeteoInfo\Map\country1.shp')
geoshow(mlayer,edgecolor=(115,115,115))
clevs =[-0.53,-0.43,-0.33,-0.28,0,0.28,0.33,0.43,0.53]
cols=[(86,49,5),(138,80,0),(186,145,42),(216,179,107),(245,236,212),\
(217,238,235),(117,197,186),(46,145,137),(0,99,91),(0,59,47)]
#layer = contourfm(cor,20)
layer = contourfm(cor,clevs,colors=cols)
colorbar(layer,orientation='horizontal')
xlim(60,150)
ylim(0,60)
title('Correlation:nino34(JJA)-prep(JJA) 1981-2015')
|
-
|