I guess sometimes its best to dig into ipython. I apparently
misunderstood interp, but it seems it doesn't need to be used only
with grids created from a Basemap instance. I created the following
function which accomplishes my goals (I know this shouldn't all be in
one function, I'll look into making it more 'general' as a next step).
If I get around to cleaning it up, I'll repost. --john
def create_land_veg_mask():
""" Process to convert Gaussian grid data to lat lon (0.5 deg)
for gridded data inside the grib2 ncep files available here:
ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/
"""
from mpl_toolkits.basemap import interp, shiftgrid
import pygrib
def interp_shift(data,lslons,lslats,lonsg,latsg,lons):
dataout = interp(data.values,lslons[0,:],lslats[:,0],lonsg,latsg)
data_shft,lon_shft = shiftgrid(-180,dataout.T,lons)
return lon_shft, lats, data_shft
grbs = pygrib.open('gfs.t00z.sfluxgrbf03.grib2')
lsmask = grbs.select(name='Land-sea mask')[0]
vegtypes = grbs.select(name='Vegetation Type')[0]
lslats,lslons = lsmask.latlons() #same for vegtypes
reg_lons = np.arange(-360,0,0.5)
reg_lats = np.arange(-90,90,0.5)
latsg,lonsg = np.meshgrid(reg_lats,reg_lons)
lonsout, lats, vegout =
interp_shift(vegtypes,lslons,lslats,lonsg,latsg,reg_lons)
lonsout, lats, lsmaskout =
interp_shift(lsmask,lslons,lslats,lonsg,latsg,lons)
return lonsout,lats,vegout,lsmaskout