Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Script for plotting PATHFINDER ICE MOTION data from ASCII files
- #2011-09-25
- import Ngl
- import Nio
- import numpy, sys, re
- def rect(r, w, deg=1): # radian if deg=0; degree if deg=1
- from math import cos, sin, pi
- if deg:
- w = pi * w / 180.0
- return r * cos(w), r * sin(w)
- rlist = Ngl.Resources()
- rlist.wkColorMap = ["White","Black","Tan1","SkyBlue","Red"]
- wks_type = "ps"
- #
- # Open the file.
- #
- ff1=sys.argv[1]
- #Search for YEAR and MONTH
- yyyy1 = re.findall(r'\d\d\d\d',ff1)
- yyyy = yyyy1[0]
- mm1 = re.findall(r'\d\d',ff1)
- mm = mm1[2]
- outFileName = './pics/' + yyyy + '/' + yyyy + mm
- wks = Ngl.open_wks(wks_type, outFileName ,rlist)
- ff= './monthly_path/' + ff1
- ffile = Ngl.asciiread(ff,[130321,4], type='float')
- lon = ffile[:,0]
- lat = ffile[:,1]
- U_ang = ffile[:,2]
- V_mag = ffile[:,3]
- xxx = numpy.zeros((len(U_ang)))
- yyy = numpy.zeros((len(V_mag)))
- for uu in range(len(U_ang)):
- x, y = rect(V_mag[uu],U_ang[uu])
- xxx[uu] = x
- yyy[uu] = y
- lon_reshape = numpy.reshape(lon,[361,361])
- lat_reshape = numpy.reshape(lat,[361,361])
- U_ang_reshape = numpy.reshape(U_ang,[361,361])
- V_mag_reshape = numpy.reshape(V_mag,[361,361])
- xxx_reshape = numpy.reshape(xxx,[361,361])
- yyy_reshape = numpy.reshape(yyy,[361,361])
- #xxx_reshape = xxx_reshape[::5,::5]/10
- #yyy_reshape = yyy_reshape[::5,::5]/10
- #lon_reshape = lon_reshape[::5,::5]
- #lat_reshape = lat_reshape[::5,::5]
- xxx_reshape = xxx_reshape[::5,::5]
- yyy_reshape = yyy_reshape[::5,::5]
- lon_reshape = lon_reshape[::5,::5]
- lat_reshape = lat_reshape[::5,::5]
- resources = Ngl.Resources()
- #resources.vfPolarData = True
- resources.vfUDataArray = yyy_reshape[:]
- resources.vfVDataArray = xxx_reshape[:]
- resources.vfXArray = lon_reshape[:]
- resources.vfYArray = lat_reshape[:]
- resources.mpProjection = "LambertEqualArea"
- resources.mpDataBaseVersion = "MediumRes"
- resources.mpLimitMode = 'Corners'
- resources.mpLeftCornerLatF = 54
- resources.mpLeftCornerLonF = -50
- resources.mpRightCornerLatF = 57
- resources.mpRightCornerLonF = 140
- resources.mpCenterLonF = 0.
- resources.mpCenterLatF = 90.
- resources.mpFillOn = True
- igray = Ngl.new_color(wks,0.7,0.7,0.7)
- resources.mpFillColors = [0,-1,igray,-1]
- resources.mpGridAndLimbOn = False
- resources.tmXTOn = False
- resources.tmXBOn = False
- resources.tmYLOn = False
- resources.tmYROn = False
- resources.vcPositionMode = "ArrowTail"
- #resources.vcPositionMode = "ArrowHead"
- resources.vcMinFracLengthF = 0.1
- resources.vcRefMagnitudeF = 5
- resources.mpFillDrawOrder = 'PostDraw'
- resources.vcRefLengthF = 0.05
- #resources.vcGlyphStyle = "CurlyVector"
- #resources.vcFillArrowWidthF = 5
- resources.vcLineArrowHeadMaxSizeF = 0.005
- resources.vcLineArrowHeadMinSizeF = 0.005
- resources.vcPositionMode = 'ArrowTail'
- resources.vcRefAnnoString1 = '5 cm/s'
- resources.vcRefAnnoFontHeightF = 0.020
- resources.vcRefAnnoString2On = False
- resources.vcLineArrowThicknessF = 2
- #resources.vcLineArrowThicknessF = 7
- resources.tiMainString = yyyy + ' / ' + mm
- resources.vcRefAnnoOrthogonalPosF = -0.126 # Move ref anno up into plot.
- resources.vcMapDirection = False
- plot = Ngl.vector_map(wks,xxx_reshape,yyy_reshape,resources)
Advertisement
Add Comment
Please, Sign In to add comment