爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 906|回复: 0

[求助] python绘制wrf数据降水分布图出现错误

[复制链接]

新浪微博达人勋

发表于 2024-1-4 11:23:55 | 显示全部楼层 |阅读模式

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

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

x
我是利用WRF模式数据绘制1989-2009年的4-6月降水逐日平均分布(包括RAINC和RAINNC两部分降水之和),我是利用模式数据是累计降水所以将每一年的6月最后一天的降水与4月的第一天的降水之差作为整个年份的降水做91天的平均,再将这21年的降水做平均得到平均场,但是图上出现了一条一条的线,感觉这不太像正常的分布,但我尝试剔除缺测也不行(也可能是我方法不对),请各位大佬帮忙看看是什么原因。


这个是画的降水分布图,上面有一条一条的线。

代码附上,谢谢大家!


我是利用WRF模式数据绘制1989-2009年的4-6月降水逐日平均分布(包括RAINC和RAINNC两部分降水之和),我是利用模式数据是累计降水所以将每一年的6月最后一天的降水与4月的第一天的降水之差作为整个年份的降水做91天的平均,再将这21年的降水做平均得到平均场,但是图上出现了一条一条的线,感觉这不太像正常的分布,但我尝试剔除缺测也不行(也可能是我方法不对),请各位大佬帮忙看看是什么原因。

这个是画的降水分布图,上面有一条一条的线。
代码附上,谢谢大家!
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
from matplotlib import font_manager
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.io.shapereader as shpreader
import cmaps
import matplotlib.colors as col
from cartopy.mpl.ticker import LongitudeFormatter,LatitudeFormatter
import scipy
from scipy.stats.distributions import chi2
from scipy import signal,stats
from matplotlib.pyplot import MultipleLocator
from matplotlib.ticker import AutoMinorLocator,FuncFormatter
from scipy.stats import pearsonr
import os
from netCDF4 import Dataset
from wrf import getvar, ALL_TIMES
from wrf import xy_to_ll,ll_to_xy

#提取数据
path='E:/lch/python/South_China_Pre/RAINNC_wrf.nc'
f=xr.open_dataset(path)
print(f)
rain1_wrf=f['RAINNC']
print(np.array(f.XLAT.sel(y=slice(200,250))))
lon=f.variables['XLONG'][:]
lat=f.variables['XLAT'][:]
tim=f.variables['XTIME']

path1='E:/lch/python/South_China_Pre/RAINC_wrf.nc'
f1=xr.open_dataset(path1)

rain2_wrf=f1['RAINC']
#平均场
pre_wrf3=np.zeros((252,384))
for i in range(21):
    pre1_wrf=rain1_wrf.loc[str(1989+i)+'-03-01T00:00:00.000000000':str(1989+i)+'-08-01T00:00:00.000000000',:,:]
    pre2_wrf=rain2_wrf.loc[str(1989+i)+'-03-01T00:00:00.000000000':str(1989+i)+'-08-01T00:00:00.000000000',:,:]
    print(pre2_wrf)
    pre_wrf3[:,:]=pre_wrf3[:,:]+(rain1_wrf.loc[str(1989+i)+'-06-30T18:00:00.000000000',:,:]-rain1_wrf.loc[str(1989+i)+'-04-01T00:00:00.000000000',:,:]+rain2_wrf.loc[str(1989+i)+'-06-30T18:00:00.000000000',:,:]-rain2_wrf.loc[str(1989+i)+'-04-01T00:00:00.000000000',:,:])/91

pre_wrf3=pre_wrf3/21.0

#绘图
fig=plt.figure(figsize=(12,8))
##wrf
ax1=fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(central_longitude=180))
font_manager.fontManager.addfont('c:/windows/fonts/times.ttf')
font_manager.fontManager.addfont('c:/windows/Fonts/simhei.ttf')
levels=np.arange(0,19,1.5)
h=ax1.contourf(lon[:,:],lat[:,:],pre_wrf3[:,:],cmap=cmaps.precip4_11lev,transform=ccrs.PlateCarree(),levels=levels)
cb=fig.colorbar(h,location='bottom')
ax1.set_extent([70,150,5,55],ccrs.PlateCarree())
#海岸线
ax1.add_feature(cfeature.COASTLINE.with_scale('50m'))
#x,y坐标轴标签
gl=ax1.gridlines(draw_labels=False)
gl.top_labels=False
gl.right_labels=False
ax1.set_xticks(np.arange(75,160,15),crs=ccrs.PlateCarree())
ax1.set_yticks(np.arange(10,60,10),crs=ccrs.PlateCarree())
ax1.xaxis.set_major_formatter(LongitudeFormatter())
ax1.yaxis.set_major_formatter(LatitudeFormatter())
plt.show()





下载.png
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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