Beispiel #1
0
def stat_spatial(ifile0,
                 ifile1,
                 funcs=__all__,
                 variables=['O3'],
                 counties=False):
    """
    ifile0 - left hand side of equation
    ifile1 - right hand side of equation
    variables - list of variables to plot
    """
    from mpl_toolkits.basemap import Basemap
    from matplotlib.pyplot import figure, show
    lonlatcoords = getattr(ifile0, 'lonlatcoords',
                           getattr(ifile1, 'lonlatcoords', ''))
    lon, lat = np.array(
        map(lambda x: map(float, x.split(',')), lonlatcoords.split('/'))).T
    latmin, latmax = lat.min(), lat.max()
    lonmin, lonmax = lon.min(), lon.max()
    bmap = Basemap(llcrnrlat=latmin,
                   llcrnrlon=lonmin,
                   urcrnrlat=latmax,
                   urcrnrlon=lonmax,
                   resolution='i')
    for vark in variables:
        for statname in funcs:
            statfunc = eval(statname)
            fig = figure()
            ax = fig.add_subplot(111)
            ax.set_title(vark + ' ' + statname)
            var_0 = ifile0.variables[vark]
            var_1 = ifile1.variables[vark]
            try:
                pidx = list(var_0.dimensions).index('points')
            except Exception:
                pidx = list(var_1.dimensions).index('points')
            statvs = []
            for sitei in range(var_0.shape[pidx]):
                val_0 = var_0[:].take([sitei], axis=pidx).ravel()
                val_1 = var_1[:].take([sitei], axis=pidx).ravel()
                statvs.append(statfunc(val_0, val_1))
            dots = bmap.scatter(x=lon, y=lat, c=statvs, ax=ax, cmap='jet')

            bmap.drawcoastlines(ax=ax)
            bmap.drawcountries(ax=ax)
            bmap.drawstates(ax=ax)
            fig.colorbar(dots)
            if counties:
                bmap.counties(ax=ax)
            show()
Beispiel #2
0
def stat_spatial(ifile0, ifile1, funcs = __all__, variables = ['O3'], counties = False):
    """
    ifile0 - left hand side of equation
    ifile1 - right hand side of equation
    variables - list of variables to plot
    """
    from mpl_toolkits.basemap import Basemap
    from matplotlib.pyplot import figure, show
    lonlatcoords = getattr(ifile0, 'lonlatcoords', getattr(ifile1, 'lonlatcoords', ''))
    lon, lat = np.array(map(lambda x: map(float, x.split(',')), lonlatcoords.split('/'))).T
    latmin, latmax = lat.min(), lat.max()
    lonmin, lonmax = lon.min(), lon.max()
    bmap = Basemap(llcrnrlat = latmin, llcrnrlon = lonmin, urcrnrlat = latmax, urcrnrlon = lonmax, resolution = 'i')
    for vark in variables:
        for statname in funcs:
            statfunc = eval(statname)
            fig = figure()
            ax = fig.add_subplot(111)
            ax.set_title(vark + ' ' + statname)
            var_0 = ifile0.variables[vark]
            var_1 = ifile1.variables[vark]
            try:
                pidx = list(var_0.dimensions).index('points')
            except:
                pidx = list(var_1.dimensions).index('points')
            statvs = []
            for sitei in range(var_0.shape[pidx]):
                val_0 = var_0[:].take([sitei], axis = pidx).ravel()
                val_1 = var_1[:].take([sitei], axis = pidx).ravel()
                statvs.append(statfunc(val_0, val_1))
            dots = bmap.scatter(x = lon, y = lat, c = statvs, ax = ax, cmap = 'jet')
            
            bmap.drawcoastlines(ax = ax)
            bmap.drawcountries(ax = ax)
            bmap.drawstates(ax = ax)
            fig.colorbar(dots)
            if counties: bmap.counties(ax = ax)
            show()