import numpy as np
from mpl_toolkits.basemap import Basemap, interp

def regrid(datain, nyout, nxout, south=-90, north=90, west=-180, east=180):
    """
    varialbe:
        datain: 2d-array
        nyout, nxout: # of grid out dataout
        south, north, west, east: region of datain and dataout
    return:
        dataout: 2d-array (nyout,nxout)
    """
    nyin, nxin = datain.shape[0], datain.shape[1]
    latin = np.arange(south,north,(north-south)/float(nyin))+(north-south)/(2.0*nyin)
    lonin = np.arange(west,east,(east-west)/float(nxin))+(east-west)/(2.0*nxin)
    latout = np.arange(south,north,(north-south)/float(nyout))+(north-south)/(2.0*nyout)
    lonout = np.arange(west,east,(east-west)/float(nxout))+(east-west)/(2.0*nxout)
    lonout, latout = np.meshgrid(lonout,latout)

    dataout = interp(datain,lonin,latin,lonout,latout)

    return dataout


# dataは2d-array, 全球, 左端0˚
# 1˚×1˚ 格子に変換する
# チェックをしない場合は引数の 'check' を消す
data = np.load('data.npy')
nyout, nxout = 180, 360
south, north = -90, 90
west, east = 0, 360
data = regrid(data, nyout, nxout, south=south, north=north, west=west, east=east)