爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 105201|回复: 116

[作图] NCL批量绘制CMA台风路径(基于地球影像)

  [复制链接]

新浪微博达人勋

发表于 2020-10-6 20:08:58 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 小其其格 于 2020-10-7 15:31 编辑

---------------------------------- 我是分割线 ------------------------------------------------------------------------------
最新效果图:
1909.jpg
1918.jpg


---------------------------------- 我是分割线 ------------------------------------------------------------------------------




看到@夏朗的芒果 大神的帖子:http://bbs.06climate.com/forum.php?mod=viewthread&tid=57969
画出来的台风路径效果太棒啦,所以也参照他的帖子,基于地球影像和中国气象局热带气旋资料中心提供的数据(http://tcdata.typhoon.org.cn/zjljsjj_zlhq.html),借助NCL批量绘制台风路径。


---------------------------------- 我是分割线 ---------------------------------------------------------------------------------
step1. 根据官网方法,将 EarthMap_2500x1250.jpg 转换成 EarthMap_2500x1250.nc
step2. 根据官网方法http://www.ncl.ucar.edu/Applications/Scripts/topo_9.ncl ,复制其 recreate_jpeg_image 函数,并进行相应修改
step3. 台风路径绘制脚本
---------------------------------- 我是分割线 ---------------------------------------------------------------------------------


子函数部分为:
  1. ;----------------------------------------------------------------------
  2. ; function recreate_jpeg_image
  3. ;----------------------------------------------------------------------
  4. undef("recreate_jpeg_image")
  5. function recreate_jpeg_image(wks,minlat,maxlat,minlon,maxlon,tcname_cma,tcname_cma2)
  6. begin
  7.   jpg_filename = "EarthMap_2500x1250.jpg"
  8.   nc_filename       = "EarthMap_2500x1250.nc"

  9. ;--You could use a system call to do the NetCDF conversion
  10. ; cmd = "gdal_translate -ot Int16 -of netCDF " + jpg_filename + \
  11. ;        " " + nc_filename
  12. ; system(cmd)

  13. ;---Read the three bands of data
  14.   f     = addfile(nc_filename,"r")
  15.   Band1 = where(f->Band1.gt.255, 255, f->Band1)  ; red channel
  16.   Band2 = where(f->Band2.gt.255, 255, f->Band2)  ; green channel
  17.   Band3 = where(f->Band3.gt.255, 255, f->Band3)  ; blue channel

  18.   band_dims = dimsizes(Band3)
  19.   nlat      = band_dims(0)
  20.   nlon      = band_dims(1)
  21.   print("dimensions of image = " + nlat + " x " + nlon)

  22. ;
  23. ; Add lat/lon data so we can overlay on a map, and/or
  24. ; overlay contours. We know the image is global,
  25. ; cylindrical equidistant, and centered about lon=0.
  26. ;
  27.   lat       = fspan( -90, 90,nlat)
  28.   lon       = fspan(-180,180,nlon)
  29.   lat@units = "degrees_north"
  30.   lon@units = "degrees_east"

  31.   Band1!0   = "lat"
  32.   Band1!1   = "lon"
  33.   Band2!0   = "lat"
  34.   Band2!1   = "lon"
  35.   Band3!0   = "lat"
  36.   Band3!1   = "lon"
  37.   Band1&lat = lat
  38.   Band1&lon = lon
  39.   Band2&lat = lat
  40.   Band2&lon = lon
  41.   Band3&lat = lat
  42.   Band3&lon = lon

  43.   res                 = True
  44.   ; res@vpWidthF        = 0.85          ; Force image to fill screen.
  45.   ; res@vpHeightF       = 0.42
  46.   res@gsnMaximize     = True

  47.   res@gsnFrame        = False        ; Don't draw or advance
  48.   res@gsnDraw         = False        ; frame yet.

  49.   res@cnFillOn        = True
  50.   res@cnFillMode      = "RasterFill" ; Raster fill can be faster
  51.   res@cnFillDrawOrder = "PreDraw"
  52.   ; res@cnRasterCellSizeF = 0.0003

  53.   res@cnLevelSelectionMode  = "EqualSpacedLevels"
  54.   res@cnMaxLevelCount       = 254
  55.   res@cnFillBackgroundColor = (/ 1., 1., 1., 1./)

  56.   res@cnLinesOn       = False              ; Turn off contour lines      .
  57.   res@cnLineLabelsOn  = False              ; Turn off contour labels
  58.   res@cnInfoLabelOn   = False              ; Turn off info label
  59.   res@lbLabelBarOn    = False              ; Turn off labelbar
  60.   res@gsnRightString  = ""                 ; Turn off subtitles
  61.   ;res@gsnLeftString   = ""
  62.   ;res@gsnLeftString   = "track_"+tcname_cma+"_"+tcname_cma2        ; add the gsn/ti titles
  63.   ; res@gsnTickMarksOn  = False              ; Turn off tickmarks
  64.   res@pmTickMarkDisplayMode    = "Always"


  65.   ;;----    add the title
  66.   res@tiMainString    = "TRACK_"+tcname_cma+"_"+tcname_cma2   ; add titles
  67.   ;res@tiMainString         = "Main title left-justified"
  68.   ;res@tiMainJust           = "CenterLeft"
  69.   ;res@tiMainPosition       = "Left"
  70.   

  71. ;---Construct RGBA colormaps...
  72.   ramp   = fspan(0., 1., 255)
  73.   reds   = new((/255, 4/), float)
  74.   greens = new((/255, 4/), float)
  75.   blues  = new((/255, 4/), float)

  76.   reds   = 0
  77.   greens = 0
  78.   blues  = 0

  79.   reds(:,0)   = ramp
  80.   greens(:,1) = ramp
  81.   blues(:,2)  = ramp

  82.   ; The red contour map is plotted fully opaque; the green and blue
  83.   ; are plotted completely transparent. When overlain, the colors
  84.   ; combine (rather magically).
  85.   reds(:,3)   = 1.
  86.   greens(:,3) = 0
  87.   blues(:,3)  = 0

  88.   res@cnFillColors = greens
  89.   greenMap = gsn_csm_contour(wks, Band2, res)

  90.   res@cnFillColors = blues
  91.   blueMap = gsn_csm_contour(wks, Band3, res)

  92. ;---This will be our base, so make it a map plot.
  93.   res@gsnAddCyclic             = False
  94.   ; res@mpShapeMode = "FreeAspect"
  95.   res@mpDataBaseVersion        = "MediumRes"
  96.   res@mpDataSetName              = "Earth..4"
  97.   res@mpOutlineSpecifiers        = (/"China:Provinces","Taiwan"/)
  98.   res@mpNationalLineColor = "yellow"
  99.   res@mpProvincialLineColor = "yellow"
  100.   res@mpNationalLineThicknessF = 9.0
  101.   res@mpProvincialLineThicknessF = 5.0
  102.   res@mpGeophysicalLineColor = "white"
  103.   res@mpGeophysicalLineThicknessF = 1.5
  104.   res@mpOutlineDrawOrder = "Draw"
  105.   res@mpFillOn                 = False

  106.   res@mpGridAndLimbOn   = True
  107.   res@mpGridLineThicknessF = 0.8
  108.   res@mpGridLineColor   = "gray"
  109.   res@mpGridLatSpacingF     =  5.
  110.   res@mpGridLonSpacingF     =  5.
  111.   res@gsnMajorLatSpacing    =  5.
  112.   res@gsnMajorLonSpacing    =  5.

  113. ;---Zoom in on area of interest
  114.   res@mpMinLatF                = minlat
  115.   res@mpMaxLatF                = maxlat
  116.   res@mpMinLonF                = minlon
  117.   res@mpMaxLonF                = maxlon

  118.   res@cnFillColors             = reds
  119.   redMap = gsn_csm_contour_map(wks, Band1, res)

  120. ;---Overlay everything to create the topo map
  121.   overlay(redMap, greenMap)
  122.   overlay(redMap, blueMap)

  123.   return(redMap)
  124. end
复制代码


主函数部分,读取CMA提供的台风数据并批量绘制台风路径(增加了标题、台风标签以及图例,标注00时对应日期和放大对应圆圈):
main1.png
main2.png
main3.png
main4.png
main5.png
--------------------------------- 我是分割线 ----------------------------------------------------------------------------------



效果图:
track_1905_DANAS.png
track_1909_LEKIMA.png
track_1913_LINGLING.png
track_1918_MITAG.png
---------------------------------- 我是分割线 ------------------------------------------------------------------------------

底图图像和测试数据附件下载:
游客,如果您要查看本帖隐藏内容请回复



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

新浪微博达人勋

发表于 2020-10-6 21:52:37 | 显示全部楼层
赞。谢谢分享                 
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-10-7 09:51:11 | 显示全部楼层
赞,谢谢分享
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-10-8 06:18:24 | 显示全部楼层
谢谢大佬分享
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2020-10-8 07:19:19 | 显示全部楼层

共同进步
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-10-8 16:15:43 | 显示全部楼层
不错不错不错不错不错不错不错
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-10-10 08:31:52 | 显示全部楼层
1111111111111111111
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-10-10 09:13:58 | 显示全部楼层
太厉害了,多向大佬学习。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-10-10 11:42:20 | 显示全部楼层
谢谢大佬分享
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-10-11 09:24:13 | 显示全部楼层
谢谢大佬分享
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

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