#----------------------------------------------------------------------
# Read and plots GRIB2 data in a non-native projection using
# PyNIO/PyNGL.
#
# Curvilinear grid, 461 x 421
#----------------------------------------------------------------------
import numpy as np
import Nio, Ngl

#---Read data
dir      = "./"
filename = "MET9_IR108_cosmode_0909210000.grb2"
a    = Nio.open_file(dir+filename)
sbt  = a.variables["SBTMP_P31_GRLL0"][:]
lat  = a.variables["gridlat_0"][:]
lon  = a.variables["gridlon_0"][:]

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

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

# Contour options
res.cnFillOn           = True          # turn on contour fill
res.cnLinesOn          = False         # turn off contour lines
res.cnLineLabelsOn     = False         # turn off line labels
res.cnFillPalette      = "MPL_jet"
res.cnFillMode         = "RasterFill"  # Can be much faster than "AreaFill"
res.cnLevelSpacingF    = 10

res.lbOrientation      = "horizontal"   # default is vertical   
res.lbLabelFontHeightF = 0.01          # default is a bit large

res.sfXArray           = lon
res.sfYArray           = lat

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

res.mpDataBaseVersion     = "MediumRes"
res.mpDataSetName         = "Earth..2"
res.mpOutlineBoundarySets = "AllBoundaries"
res.mpGridAndLimbOn       = False

# Main Title
res.tiMainString          = filename
res.tiMainFontHeightF     = 0.015

plot = Ngl.contour_map(wks,sbt,res)

Ngl.end()

