爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 123843|回复: 218

[经验总结] 基于地球影像的台风路径绘制脚本,超级酷炫

  [复制链接]

新浪微博达人勋

发表于 2017-12-20 00:04:09 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 夏朗的芒果 于 2018-11-27 08:19 编辑

2017.12.21 更新
替代了更加精细美观的底图(下载地址 https://visibleearth.nasa.gov/view_cat.php?categoryID=1484),同时加强了路径绘制效果,形成了终极魔改版
track05.png


-----------------------------------------------------------------------


以下为原帖:
废话不多说,先上效果图,这是我小试牛刀绘制的今年1705号奥鹿路径。当然作用肯定不止于此,这里权作抛砖引玉。
track_1705.png

引子:一次偶然的机遇,我在ncl官网上看到ncl可以将在jpg图片上再次绘图,具体见官网http://www.ncl.ucar.edu/Applications/topo.shtml 第9个案例。由此想到,如果在地球影像上叠加台风路径,岂不十分美妙?说干就干。

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

EarthMap_2500x1250.nc 的下载地址为
游客,如果您要查看本帖隐藏内容请回复


子函数部分为
  1. undef("recreate_jpeg_image")
  2. function recreate_jpeg_image(wks,minlat,maxlat,minlon,maxlon)
  3. begin
  4.   jpg_filename = "EarthMap_2500x1250.jpg"
  5.   nc_filename       = "EarthMap_2500x1250.nc"

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

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

  15.   band_dims = dimsizes(Band3)
  16.   nlat      = band_dims(0)
  17.   nlon      = band_dims(1)
  18.   print("dimensions of image = " + nlat + " x " + nlon)

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

  28.   Band1!0   = "lat"
  29.   Band1!1   = "lon"
  30.   Band2!0   = "lat"
  31.   Band2!1   = "lon"
  32.   Band3!0   = "lat"
  33.   Band3!1   = "lon"
  34.   Band1&lat = lat
  35.   Band1&lon = lon
  36.   Band2&lat = lat
  37.   Band2&lon = lon
  38.   Band3&lat = lat
  39.   Band3&lon = lon

  40.   res                 = True
  41.   ; res@vpWidthF        = 0.85          ; Force image to fill screen.
  42.   ; res@vpHeightF       = 0.42
  43.   res@gsnMaximize     = True

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

  46.   res@cnFillOn        = True
  47.   res@cnFillMode      = "RasterFill" ; Raster fill can be faster
  48.   res@cnFillDrawOrder = "PreDraw"
  49.   ; res@cnRasterCellSizeF = 0.0003

  50.   res@cnLevelSelectionMode  = "EqualSpacedLevels"
  51.   res@cnMaxLevelCount       = 254
  52.   res@cnFillBackgroundColor = (/ 1., 1., 1., 1./)

  53.   res@cnLinesOn       = False              ; Turn off contour lines      .
  54.   res@cnLineLabelsOn  = False              ; Turn off contour labels
  55.   res@cnInfoLabelOn   = False              ; Turn off info label
  56.   res@lbLabelBarOn    = False              ; Turn off labelbar
  57.   res@gsnRightString  = ""                 ; Turn off subtitles
  58.   res@gsnLeftString   = ""
  59.   ; res@gsnTickMarksOn  = False              ; Turn off tickmarks
  60.   res@pmTickMarkDisplayMode    = "Always"

  61. ;---Construct RGBA colormaps...
  62.   ramp   = fspan(0., 1., 255)
  63.   reds   = new((/255, 4/), float)
  64.   greens = new((/255, 4/), float)
  65.   blues  = new((/255, 4/), float)

  66.   reds   = 0
  67.   greens = 0
  68.   blues  = 0

  69.   reds(:,0)   = ramp
  70.   greens(:,1) = ramp
  71.   blues(:,2)  = ramp

  72.   ; The red contour map is plotted fully opaque; the green and blue
  73.   ; are plotted completely transparent. When overlain, the colors
  74.   ; combine (rather magically).
  75.   reds(:,3)   = 1.
  76.   greens(:,3) = 0
  77.   blues(:,3)  = 0

  78.   res@cnFillColors = greens
  79.   greenMap = gsn_csm_contour(wks, Band2, res)

  80.   res@cnFillColors = blues
  81.   blueMap = gsn_csm_contour(wks, Band3, res)

  82. ;---This will be our base, so make it a map plot.
  83.   res@gsnAddCyclic             = False
  84.   ; res@mpShapeMode = "FreeAspect"
  85.   res@mpDataBaseVersion        = "MediumRes"
  86.   res@mpDataSetName              = "Earth..4"
  87.   res@mpOutlineSpecifiers        = (/"China:Provinces","Taiwan"/)
  88.   res@mpNationalLineColor = "yellow"
  89.   res@mpProvincialLineColor = "yellow"
  90.   res@mpNationalLineThicknessF = 9.0
  91.   res@mpProvincialLineThicknessF = 5.0
  92.   res@mpGeophysicalLineColor = "white"
  93.   res@mpGeophysicalLineThicknessF = 1.5
  94.   res@mpOutlineDrawOrder = "Draw"
  95.   res@mpFillOn                 = False

  96.   res@mpGridAndLimbOn   = True
  97.   res@mpGridLineThicknessF = 0.8
  98.   res@mpGridLineColor   = "gray"
  99.   res@mpGridLatSpacingF     =  5.
  100.   res@mpGridLonSpacingF     =  5.
  101.   res@gsnMajorLatSpacing    =  5.
  102.   res@gsnMajorLonSpacing    =  5.

  103. ;---Zoom in on area of interest
  104.   res@mpMinLatF                = minlat
  105.   res@mpMaxLatF                = maxlat
  106.   res@mpMinLonF                = minlon
  107.   res@mpMaxLonF                = maxlon

  108.   res@cnFillColors             = reds
  109.   redMap = gsn_csm_contour_map(wks, Band1, res)

  110. ;---Overlay everything to create the topo map
  111.   overlay(redMap, greenMap)
  112.   overlay(redMap, blueMap)

  113.   return(redMap)
  114. end
复制代码


主脚本为
游客,如果您要查看本帖隐藏内容请回复


台风路径见附件
201705.txt (3.49 KB, 下载次数: 136)

评分

参与人数 3金钱 +60 贡献 +23 体力 +80 收起 理由
mofangbao + 20 + 10
尽头的尽头 + 20 + 5
言深深 + 20 + 8 + 80

查看全部评分

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

新浪微博达人勋

发表于 2017-12-20 08:25:16 | 显示全部楼层
这个看看学习下
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-12-20 08:45:12 | 显示全部楼层
楼主的想法很有创意,厉害了!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-12-20 08:49:04 | 显示全部楼层
楼主辛苦了。看看。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-12-20 09:01:51 | 显示全部楼层
楼主厉害!学习了!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-12-20 09:13:20 | 显示全部楼层
这么厉害啊
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-12-20 09:59:34 | 显示全部楼层
厉害了~!!!来学习!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-12-20 10:45:13 | 显示全部楼层
楼主厉害了!这么一画确实好看多了
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-12-20 10:57:03 | 显示全部楼层
楼主厉害了。来学习
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-12-20 10:59:37 | 显示全部楼层
紧跟楼主学python,不对,学ncl
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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