爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 22118|回复: 5

[求助] 用AO指数回归得到1979-2017年5月地面降水场时,为什么填色图上是点状的呢?

[复制链接]

新浪微博达人勋

发表于 2021-5-29 13:49:26 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 岫鹿森涌 于 2021-5-29 15:06 编辑

用AO指数回归得到1979-2017年5月地面降水场时,为什么填色图上是点状的呢?
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.mpl.ticker as cticker
from scipy import stats
import os
import glob as glob
import xarray as xr
data=pd.read_csv('E:\\norm.daily.ao.index.b500101.current.ascii',header=None,sep='\s+',names=['year','month','day','ao'])
a = data.loc[10592:24837,['month','ao']]  # 1979-2017年的月份和ao指数
b=a.ao[a.month==5] #5月的ao指数
#print(b)
c=np.zeros(39)
for i in range(0,1209,31):
    c=c+sum(b[i:i+31]/31)

os.chdir('D:\\A\\data\\pdaily')
files2=glob.glob('*.nc')
xy=np.zeros((1,360,720))
for file in files2:
    precip=xr.open_dataset(file)['precip'][120:151,:,:]
    lon=xr.open_dataset(file)['lon']
    lat=xr.open_dataset(file)['lat']
    xy=np.append(xy,precip,axis=0)
xy1=xy[1:,:,:]
a=np.zeros((39,360,720),)
for i in range(0,39):
    a[i,:,:]=np.mean(xy1[i*31:(i+1)*31,:,:],axis=0)
#print(a.shape)
#print(type(b))
#print(type(b[0]))      
a[np.isnan(a)] = 0
#print(a)
slope, intercept, r_value, p_value, std_err = np.zeros((360,720)),np.zeros((360,720)),np.zeros((360,720)),np.zeros((360,720)),np.zeros((360,720))
for i in range(360):
    for j in range(720):
        slope[i,j], intercept[i,j], r_value[i,j], p_value[i,j], std_err[i,j] = stats.linregress(c,a[:,i,j])


#选择投影
proj = ccrs.PlateCarree(central_longitude=90)
#创建图形
fig = plt.figure(figsize=(12,8))
fig_ax1 = fig.add_axes([0.1, 0.1, 0.8, 0.8],projection = proj)
#设置边界
leftlon, rightlon, lowerlat, upperlat = (0,120,-20,70)
img_extent = [leftlon, rightlon, lowerlat, upperlat]
fig_ax1.set_extent(img_extent, crs=ccrs.PlateCarree())
#绘制海岸线和湖泊等地理特征
fig_ax1.add_feature(cfeature.COASTLINE.with_scale('50m'))
fig_ax1.add_feature(cfeature.LAKES, alpha=0.5)
#设置刻度及刻度标签格式
fig_ax1.set_xticks(np.arange(leftlon,rightlon+30,20), crs=ccrs.PlateCarree())
fig_ax1.set_yticks(np.arange(lowerlat,upperlat+30,20), crs=ccrs.PlateCarree())
lon_formatter = cticker.LongitudeFormatter()
lat_formatter = cticker.LatitudeFormatter()
fig_ax1.xaxis.set_major_formatter(lon_formatter)
fig_ax1.yaxis.set_major_formatter(lat_formatter)
#绘制相关系数填色
cf1 = fig_ax1.contourf(lon,lat,slope, zorder=0, levels=np.arange(-8,8.1,0.1),extend = 'both',transform=ccrs.PlateCarree(), cmap=plt.cm.RdBu_r)
#绘制显著性打点。思路为将0-0.01范围内的区域用点的标记来填充,来表示显著性99%水平。
#cf2 = fig_ax1.contourf(lon,lat, p_value, [0,0.01,1] ,
#                     zorder=1,hatches=['...', None],colors="none", transform=ccrs.PlateCarree())
#色标
position=fig.add_axes([0.35, 0.03, 0.35, 0.025])
fig.colorbar(cf1,cax=position,orientation='horizontal',format='%.2f')
#显示
plt.savefig('D:\\A\\SFW\\figure\\5phuigui.png')
plt.show()

Figure 2021-05-29 132524.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2021-5-31 14:37:57 | 显示全部楼层
感觉单纯是因为拟合效果不好。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-6-3 15:24:05 | 显示全部楼层
分辨率太高了
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2022-2-24 00:13:24 | 显示全部楼层
楼主你好,想请教下你代码中计算斜率slope的部分,如果数据中有nan值,返回的也是nan吗?我看你把nan值都赋值为0,这样计算趋势是不是不对啊?另外,我看你另一篇帖子中有提到cdo,想问下你用过cdo求空间趋势吗?谢谢!
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2022-3-9 15:11:30 | 显示全部楼层
看云淡风清 发表于 2022-2-24 00:13
楼主你好,想请教下你代码中计算斜率slope的部分,如果数据中有nan值,返回的也是nan吗?我看你把nan值都赋 ...

现在我就直接用np.nanmean这类命令了,可以忽略nan值,这个图我后来没再研究久了,我没有用cdo求过空间趋势
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2022-11-23 11:06:11 来自手机 | 显示全部楼层
ao指数怎么算,楼主清楚吗,望赐教
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表