xdenisx

Plot pathfinder month

Mar 27th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.37 KB | None | 0 0
  1. #Script for plotting PATHFINDER ICE MOTION data from ASCII files
  2. #2011-09-25
  3.  
  4. import Ngl
  5. import Nio
  6. import numpy, sys, re
  7.  
  8. def rect(r, w, deg=1): # radian if deg=0; degree if deg=1
  9.      from math import cos, sin, pi
  10.      if deg:
  11.          w = pi * w / 180.0
  12.      return r * cos(w), r * sin(w)
  13.  
  14. rlist            = Ngl.Resources()
  15. rlist.wkColorMap = ["White","Black","Tan1","SkyBlue","Red"]
  16. wks_type = "ps"
  17.  
  18.  
  19. #
  20. #  Open the file.
  21. #
  22. ff1=sys.argv[1]
  23.  
  24. #Search for YEAR and MONTH
  25. yyyy1 = re.findall(r'\d\d\d\d',ff1)
  26. yyyy = yyyy1[0]
  27.  
  28. mm1 = re.findall(r'\d\d',ff1)
  29. mm = mm1[2]
  30.  
  31. outFileName = './pics/' + yyyy + '/' + yyyy + mm
  32.  
  33. wks = Ngl.open_wks(wks_type, outFileName ,rlist)
  34.  
  35. ff= './monthly_path/' + ff1
  36. ffile = Ngl.asciiread(ff,[130321,4], type='float')
  37.  
  38. lon  = ffile[:,0]
  39. lat = ffile[:,1]
  40. U_ang  = ffile[:,2]
  41. V_mag  = ffile[:,3]
  42.  
  43. xxx = numpy.zeros((len(U_ang)))
  44. yyy = numpy.zeros((len(V_mag)))
  45.  
  46. for uu in range(len(U_ang)):
  47.     x, y = rect(V_mag[uu],U_ang[uu])
  48.     xxx[uu] = x
  49.     yyy[uu] = y
  50.    
  51.  
  52. lon_reshape = numpy.reshape(lon,[361,361])
  53. lat_reshape = numpy.reshape(lat,[361,361])
  54. U_ang_reshape = numpy.reshape(U_ang,[361,361])
  55. V_mag_reshape = numpy.reshape(V_mag,[361,361])
  56. xxx_reshape   = numpy.reshape(xxx,[361,361])
  57. yyy_reshape   = numpy.reshape(yyy,[361,361])
  58.  
  59. #xxx_reshape   = xxx_reshape[::5,::5]/10
  60. #yyy_reshape   = yyy_reshape[::5,::5]/10
  61.  
  62. #lon_reshape = lon_reshape[::5,::5]
  63. #lat_reshape = lat_reshape[::5,::5]
  64.  
  65. xxx_reshape   = xxx_reshape[::5,::5]
  66. yyy_reshape   = yyy_reshape[::5,::5]
  67.  
  68. lon_reshape = lon_reshape[::5,::5]
  69. lat_reshape = lat_reshape[::5,::5]
  70.  
  71. resources = Ngl.Resources()
  72.  
  73. #resources.vfPolarData = True
  74. resources.vfUDataArray = yyy_reshape[:]
  75. resources.vfVDataArray = xxx_reshape[:]
  76.  
  77. resources.vfXArray     = lon_reshape[:]
  78. resources.vfYArray     = lat_reshape[:]
  79.  
  80. resources.mpProjection          = "LambertEqualArea"
  81.  
  82. resources.mpDataBaseVersion     = "MediumRes"
  83. resources.mpLimitMode           = 'Corners'
  84. resources.mpLeftCornerLatF      = 54
  85. resources.mpLeftCornerLonF      = -50
  86. resources.mpRightCornerLatF     = 57
  87. resources.mpRightCornerLonF     = 140
  88.  
  89. resources.mpCenterLonF           = 0.
  90. resources.mpCenterLatF           = 90.
  91. resources.mpFillOn     = True
  92. igray = Ngl.new_color(wks,0.7,0.7,0.7)
  93. resources.mpFillColors = [0,-1,igray,-1]
  94. resources.mpGridAndLimbOn      = False
  95. resources.tmXTOn                = False
  96. resources.tmXBOn                = False
  97. resources.tmYLOn                = False
  98. resources.tmYROn                = False
  99.  
  100. resources.vcPositionMode = "ArrowTail"
  101. #resources.vcPositionMode = "ArrowHead"
  102.  
  103. resources.vcMinFracLengthF   = 0.1
  104. resources.vcRefMagnitudeF    = 5
  105. resources.mpFillDrawOrder    = 'PostDraw'
  106. resources.vcRefLengthF       = 0.05
  107. #resources.vcGlyphStyle       = "CurlyVector"
  108. #resources.vcFillArrowWidthF   = 5
  109. resources.vcLineArrowHeadMaxSizeF = 0.005
  110. resources.vcLineArrowHeadMinSizeF = 0.005
  111. resources.vcPositionMode          = 'ArrowTail'
  112. resources.vcRefAnnoString1        = '5 cm/s'
  113. resources.vcRefAnnoFontHeightF    = 0.020
  114. resources.vcRefAnnoString2On      = False
  115. resources.vcLineArrowThicknessF   = 2
  116. #resources.vcLineArrowThicknessF   = 7
  117.  
  118. resources.tiMainString            = yyyy + ' / ' + mm
  119.  
  120. resources.vcRefAnnoOrthogonalPosF = -0.126     # Move ref anno up into plot.
  121.  
  122. resources.vcMapDirection          = False
  123.  
  124. plot = Ngl.vector_map(wks,xxx_reshape,yyy_reshape,resources)
Advertisement
Add Comment
Please, Sign In to add comment