爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 48118|回复: 37

[参考资料] pyngl绘图命令解析

[复制链接]

新浪微博达人勋

发表于 2019-2-18 15:28:58 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 喵星观天 于 2019-2-22 09:28 编辑

惊闻pyngl取代了ncl的绘图功能,打算把几年前制作的pyng命令手册发布出来。

Ngl全称:Ncl's Graphic Library
中文含义:ncl移植到了python的绘图程序


ngl绘图效果:


                               
登录/注册后可看大图

示例代码:

  1. from __future__ import print_function
  2. import numpy as np
  3. import Nio, Ngl, os, sys
  4. from wrf import getvar, latlon_coords, to_np


  5. # Read data
  6. filename = "wrfout_d03_2012-04-22_23_00_00"
  7. if(not os.path.exists(filename)):
  8.   print("You do not have the necessary '{}' file to run this example.".format(filename))
  9.   print("You need to supply your own WRF output file")
  10.   print("WRF output files usually have names like '{}'".format(filename))
  11.   sys.exit()

  12. # Read some WRF data
  13. a  = Nio.open_file(filename+".nc")  # Must add ".nc" suffix for Nio.open_file
  14. ua = getvar(a,"ua")
  15. va = getvar(a,"va")

  16. # First timestep, lowest (bottommost) level, every 5th lat/lon
  17. nl    = 0
  18. nt    = 0
  19. nstep = 5     # a stride to cull some of the streamlines
  20. u     = ua[nl,::nstep,::nstep]
  21. v     = va[nl,::nstep,::nstep]
  22. spd   = np.sqrt(u**2+v**2)

  23. # Get the latitude and longitude points
  24. lat, lon = latlon_coords(ua)
  25. lat = to_np(lat)
  26. lon = to_np(lon)

  27. # Open file for graphics
  28. wks_type = "png"
  29. wks = Ngl.open_wks(wks_type,"wrf4")

  30. res                   = Ngl.Resources()

  31. res.mpDataBaseVersion = "MediumRes"         # Better map outlines
  32. res.mpLimitMode       = "LatLon"            # Zoom in on map area of interest
  33. res.mpMinLatF         = np.min(lat[:])-0.1
  34. res.mpMaxLatF         = np.max(lat[:])+0.1
  35. res.mpMinLonF         = np.min(lon[:])-0.1
  36. res.mpMaxLonF         = np.max(lon[:])+0.1

  37. res.mpFillOn                = True
  38. res.mpLandFillColor         = "gray85"
  39. res.mpOceanFillColor        = "transparent"
  40. res.mpInlandWaterFillColor  = "transparent"
  41. res.mpGridLatSpacingF       = 1
  42. res.mpGridLonSpacingF       = 1
  43. #res.mpGridAndLimbOn        = False

  44. res.stLineThicknessF  = 3.0          # Thicker streamlines
  45. res.stMonoLineColor   = False        # Use multiple colors for streamlines

  46. res.tiMainString      = "U10/V10 streamlines color by wind speed"

  47. # Necessary to overlay on map correctly.
  48. res.vfYArray          = lat[::nstep,::nstep]
  49. res.vfXArray          = lon[::nstep,::nstep]

  50. plot = Ngl.streamline_scalar_map(wks,u,v,spd,res)

  51. Ngl.end()
复制代码



转帖教材请征求本人同意

ngl操作命令.pdf

643.14 KB, 阅读权限: 10, 下载次数: 504, 下载积分: 金钱 -5

ngl命令解析

评分

参与人数 1金钱 +20 贡献 +10 收起 理由
mofangbao + 20 + 10

查看全部评分

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-2-18 17:19:35 | 显示全部楼层
你这命令听起来比较强大啊!学习一下。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-2-18 20:47:44 | 显示全部楼层
非常实用,感谢分享!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-2-19 09:06:32 | 显示全部楼层
感谢分享!!
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2019-2-19 15:52:18 | 显示全部楼层
已经下载,谢谢楼主分享。以后就要走python的路了
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-2-20 13:49:42 | 显示全部楼层
8说了,就差一个as-yet-to-be-named Python package了。NCAR gkd。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-2-21 19:29:18 | 显示全部楼层
能否介绍一下pyngl是什么?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2019-2-22 09:24:36 | 显示全部楼层
cqcswky 发表于 2019-2-21 19:29
能否介绍一下pyngl是什么?

ncl移植到了python的绘图程序
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-2-24 17:15:28 | 显示全部楼层
十分感谢您对ncl、python在地球科学领域的应用的传播做的贡献
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-2-25 09:45:22 | 显示全部楼层

感谢分享!!
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

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

本版积分规则

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

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

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