generate report for usaf base

def report(usaf):
    """generate report for usaf base"""
    fig = plt.figure()
    ax = fig.add_subplot(111)
    station_info = geo.station_info(usaf)
    y = {}
    for i in range(1991, 2011):
        monthData = monthly(usaf, i)
        t = sum(monthData)
        y[i] = t
        print t
    tmy3tot = tmy3.total(usaf)
    average = sum([v for k, v in y.items()])/20.
    s = sorted(y.items(), key=lambda t: t[1])
    o = sorted(y.items(), key=lambda t: t[0])
    twohigh = s[-1][1] + s[-2][1]
    twolow = s[0][1] + s[1][1]
    mintol = 1-twolow/2./average
    plustol = twohigh/2./average-1
    txt = ""
    txt += "%s\n" % station_info['Site Name']
    txt += 'TMY3/hist: %s/' % int(round(tmy3tot))
    txt += '%s\n' % int(round(average))
    txt += "high/low av: %s/" % int(round(twohigh/2.))
    txt += "%s\n" % int(round(twolow/2.))
    txt += "+%s/-%s%% " % (round(plustol*100, 0), round(mintol*100, 0))
    txt += "(-%s%% of TMY3)" % round((1-twolow/2./tmy3tot)*100, 0)
    print txt
    x = np.array([k for k, v in o])
    y = np.array([v for k, v in o])

    rx = x[1:]
    ry = [(v + y[i+1])/2 for i, v in enumerate(y[:-1])]
    fit = pylab.polyfit(x, y, 3)
    fit_fn = pylab.poly1d(fit)
    f = interp1d(x, y, kind='cubic')
    f2 = interp1d(rx, ry, kind='cubic')
    xnew = np.linspace(min(x), max(x), 200)
    x2 = np.linspace(min(rx), max(rx), 200)
    # ax.plot(x,y)
    ax.plot(xnew, f(xnew), label="Annual GHI")
    ax.plot(xnew, fit_fn(xnew), label='trendline')
    ax.plot(x2, f2(x2), label='2 Year Ave')
    ax.plot([min(x), max(x)], [tmy3tot, tmy3tot], linestyle='--')
    leg = plt.legend(title=txt, loc=4, fancybox=True)
    leg.get_frame().set_alpha(0.5)
    # fig.text(min(x),min(y)-min(y)*.1,txt)
    # fig.text(.1,.1,txt)
    plt.tight_layout()
    fig.savefig('%s_annual_GHI.pdf' % (usaf), format='pdf')