爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 6650|回复: 2

WRF_out文件绘制降水空间填色图时出现白线

[复制链接]

新浪微博达人勋

发表于 2022-4-12 09:58:42 | 显示全部楼层 |阅读模式

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

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

x
使用ERA5作为初始场,运行WRF模式,对输出的文件进行处理绘制,使用python降水填色空间场。出现以下问题:
- 当指定levels时,在赤道以北3°左右会出现一条白线,已经检测了该范围内的数据结果,并没有异常值
- 只有使用python提取数据绘制填色图时出现此问题;
- ncl、ncview、xarray.plot()都没有该问题
微信图片_20220412095409.png 微信图片_20220412095454.png


绘图code如下:
  1. from wrf import getvar,get_cartopy
  2. import xarray as xr
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. import cartopy.crs as ccrs
  6. import cartopy.feature as cfeature
  7. from cartopy.mpl.ticker import LongitudeFormatter,LatitudeFormatter
  8. from netCDF4 import Dataset as nc
  9. import cmaps

  10. ncfile=nc(r'D:/wrf/wrfout_d01_2004-06-25_04_00_00.nc')
复制代码
希望大家提提建议
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2022-4-12 10:01:18 | 显示全部楼层
  1. from wrf import getvar,get_cartopy
  2. import xarray as xr
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. import cartopy.crs as ccrs
  6. import cartopy.feature as cfeature
  7. from cartopy.mpl.ticker import LongitudeFormatter,LatitudeFormatter
  8. from netCDF4 import Dataset as nc
  9. import cmaps

  10. ncfile=nc(r'D:/wrf/wrfout_d01_2004-06-25_04_00_00.nc')


  11. slp=getvar(ncfile, "slp")

  12. rain_exp=np.array(getvar(ncfile, "RAINNC"))
  13. rain_con=np.array(getvar(ncfile, "RAINC"))
  14. rain_tot=np.array(rain_exp+rain_con)
  15. rain1=getvar(ncfile, "RAINNC")
  16. rain2=getvar(ncfile, "RAINC")
  17. lon=getvar(ncfile, "XLONG")
  18. lat=getvar(ncfile, "XLAT")
  19. rain=(rain1+rain2)

  20. fig = plt.figure(figsize=(10, 14),dpi=100)


  21. box=[0,180,-30,30.5]
  22. scale='50m'
  23. xstep, ystep = 40, 15

  24. #######plot####################
  25. def make_map(ax, title):
  26.     # set_extent  set crs
  27.     ax.set_extent(box, crs=ccrs.PlateCarree())
  28.     land = cfeature.NaturalEarthFeature('physical',
  29.                                         'land',
  30.                                         scale,
  31.                                         edgecolor='grey',
  32.                                         facecolor='none',zorder=1
  33.                                         )
  34.     ax.add_feature(land)  # set land color
  35.     ax.coastlines(scale)  # set coastline resolution
  36.     # set coordinate axis
  37.     ax.set_xticks(np.arange(box[0],box[1], xstep),crs=ccrs.PlateCarree())
  38.     ax.set_yticks(np.arange(box[2], box[3]+ystep, ystep),crs=ccrs.PlateCarree(central_longitude=0))
  39.     ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label =False))#经度0不加标识
  40.     ax.yaxis.set_major_formatter(LatitudeFormatter())

  41.     ax.set_title(title, fontsize=15, loc='left',pad=10)
  42.     ax.tick_params(which='major',
  43.                     direction='out',
  44.                     length=8,
  45.                     width=0.99,
  46.                     pad=3,
  47.                     labelsize=15,
  48.                     bottom=True, left=True, right=False, top=False)
  49.     return ax
  50. ax0=fig.add_subplot(311,projection=ccrs.PlateCarree())
  51. ax0=make_map(ax0,'2004-06-25_04--RAINC(set levels(0,5.1,0.1))')

  52. cb0=ax0.contourf(lon,lat,rain2,transform=ccrs.PlateCarree(),levels=np.arange(0,5.1,0.1))
  53. c0=fig.colorbar(cb0,ax=ax0,shrink=0.8,pad=0.05,aspect=13)

  54. ax1=fig.add_subplot(312,projection=ccrs.PlateCarree())
  55. ax1=make_map(ax1,'2004-06-25_04--RAINNC(set levels(0,5.1,0.1))')

  56. cb1=ax1.contourf(lon,lat,rain1,transform=ccrs.PlateCarree(),levels=np.arange(0,5.1,0.1))
  57. c1=fig.colorbar(cb1,ax=ax1,shrink=0.8,pad=0.05,aspect=13)

  58. ax2=fig.add_subplot(313,projection=ccrs.PlateCarree())
  59. ax2=make_map(ax2,'2004-06-25_04--RAINNC+RAINC(set levels(0,5.1,0.5))')

  60. cb2=ax2.contourf(lon,lat,rain,transform=ccrs.PlateCarree(),levels=np.arange(0,5.1,0.5))
  61. c2=fig.colorbar(cb2,ax=ax2,shrink=0.8,pad=0.05,aspect=13)


  62. plt.show()
复制代码
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2022-11-11 10:12:15 | 显示全部楼层
问题解决了,原因是,模式中的lon的排列是(0-180,-180-0)导致的,将负的那一部分加上360.使得lon的排列范围是0-360,就解决该问题啦~
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

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