#----------------------------------------------------------------------
# Read and plots GRIB1 data using PyNIO/PyNGL.
#
# Curvilinear grid, 113 x 151
#----------------------------------------------------------------------
import numpy as np
import Nio, Ngl

# Read data
dir      = "../Data/"
filename = "ruc.grb"
a   = Nio.open_file("%s/%s" %(dir,filename))
u   = a.variables["U_GRD_236_MWSL"][:]    # [::2,::2]
v   = a.variables["V_GRD_236_MWSL"][:]    # [::2,::2]
lat = a.variables["gridlat_236"][:]       # [::2,::2]
lon = a.variables["gridlon_236"][:]       # [::2,::2]

wks = Ngl.open_wks("png","grib1_plot_uv_ngl")

# Set some plot options
res = Ngl.Resources()

# Vector options
res.vcGlyphStyle          = "CurlyVector"
res.vcLineArrowThicknessF = 2.0           # default is 1
res.vcRefLengthF          = 0.03
res.vcMinDistanceF        = 0.01
res.vcRefMagnitudeF       = 40

# Control look of the vector reference annotation
res.vcRefAnnoArrowUseVecColor = False
res.vcRefAnnoOrthogonalPosF = -0.27

# Fill the vectors with the given color map
res.vcLevelPalette        = "ncl_default"
res.vcMonoLineArrowColor  = False

# Map options
res.mpLimitMode       = "LatLon"
res.mpMinLatF         = lat.min()-1
res.mpMaxLatF         = lat.max()+1
res.mpMinLonF         = lon.min()-1
res.mpMaxLonF         = lon.max()+1
res.mpDataBaseVersion = "MediumRes"

# Main Title
res.tiMainString      = filename

# Labelbar
res.lbOrientation      = "Horizontal"
res.lbLabelFontHeightF = 0.01

# Additional resources needed for putting contours on map
res.vfXArray          = lon  # [::2,::2]
res.vfYArray          = lat  # [::2,::2]

plot = Ngl.vector_map(wks,u,v,res)

Ngl.end()

