def make_movie(datadir, deltaname, variable, framenum):

    datafile = utils.datafiles[variable]
    delta = utils.get_data(datadir, datafile, deltaname)
    mp = utils.gridEdges(datadir)

    cmap = utils.cmap[variable]
    vmin = np.nanmin(delta["data"])
    vmax = np.nanmax(delta["data"])
    norm = colors.Normalize(vmin=vmin, vmax=vmax)

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    bm = utils.basemap(ax)

    X, Y = bm(mp["lons"], mp["lats"])
    print ax.get_xlim()
    print ax.get_ylim()

    ax.axis(utils.mapbounds[deltaname])

    def updatefig(i):
        mp["map"][delta["inds"][0], delta["inds"][1]] = delta["data"].iloc[i, :]
        date = delta["data"].index[i].strftime("%Y-%m-%d")
        im = bm.pcolormesh(X, Y, np.ma.masked_invalid(mp["map"]), cmap=cmap, norm=norm)
        cbar = bm.colorbar(im, "bottom", cmap=cmap, norm=norm)
        ax.set_title("{}: {}".format(utils.fullname[variable], date))

        framenum = 5

    ani = animation.FuncAnimation(fig, updatefig, frames=framenum)
    ani.save("{}_{}_{}.mp4".format(utils.fullname[variable], deltaname, framenum))
import sys
import utils

"""
python means.py [delta]

"""
deltaname = str(sys.argv[1])

datadir = 'data'

datafile = 'inun_minremoved_v1v2.pkl'

#Array of nans the size of dataset based on size of map
#Array of bounding map edges
globalMap = utils.gridEdges(datadir)

#Actual inundation data for specified river
delta = utils.get_data(datadir, datafile, deltaname)
dates = delta['data'].index


timeMean = delta['data'].mean(axis=1)
locMean = delta['data'].mean(axis=0)

cmap = cm.GMT_drywet
vmin = np.amin(locMean)
vmax = np.amax(locMean)
norm = colors.Normalize(vmin=vmin, vmax=vmax)

fig = plt.figure()
import matplotlib.pyplot as plt
import pickle
from mpl_toolkits.basemap import Basemap, cm
import matplotlib.animation as animation
from matplotlib import colors

import utils
import PCAmekong

datadir = 'data'
deltaname = 'Amazon'
datafile = 'inun_minremoved_v1v2.pkl'

#Array of nans the size of dataset based on size of map
#Array of bounding map edges
map = utils.gridEdges(datadir)

#Actual inundation data for specified river
delta = utils.get_data(datadir, datafile,deltaname)

cmap = cm.GMT_drywet
vmin = np.nanmin(delta['data'])
vmax = np.nanmax(delta['data'])
norm = colors.Normalize(vmin=vmin, vmax=vmax)

fig = plt.figure()
ax = fig.add_subplot(2,2,1)
#sets up basemap object to plot
bm = utils.basemap(ax)

X, Y = bm(map['lons'], map['lats'])
pmtm = pmdata.std(axis=1)
itm,pmtm = cleanNans(itm,pmtm)
slope, intercept, _, _, _ = st.linregress(itm, pmtm)
ax = addScatter(fig,plt,itm,pmtm,1,1,1)
ax.set_xlabel("Inundation")
ax.set_ylabel("Precipitation")
ax.plot(itm, slope*itm + intercept, color='k')
ax.set_title("Correlation is: {}".format(st.pearsonr(itm,pmtm)[0]),y=1.02)
# plt.savefig("./graphs/tendaystats.png")
corrs = []
for i, p in zip(idata.values.T, pmdata.values.T):
    mask = (np.isfinite(i) & np.isfinite(p))
    corrs.append(st.pearsonr(i[mask],p[mask])[0])

print len(corrs)
globe = utils.gridEdges('data')
delta = utils.get_data('data', 'delta_3B42_precip.pkl', 'Amazon')

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)

cmap = cm.GMT_drywet

vmax = np.nanmax(corrs)
# vmin = -vmax
vmin = 0
norm = colors.Normalize(vmin=vmin, vmax=vmax)
bm = utils.basemap(ax1)
X, Y = bm(globe['lons'], globe['lats'])

datadir = 'data_old'
datafile = 'delta_3B42_precip.pkl'

delta = utils.get_data(datadir, datafile, deltaName)
results = get(analysisType,delta['data'],row);
f = open('output.txt','w')
for i in results:
	f.write(str(i)+"\n")
f.close()
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
# ax1.plot(np.arange(len(results)),results)

# i dont know what I am doing starting over here
globe = utils.gridEdges(datadir)

cmap = cm.GMT_drywet
# cmap = "copper"
vmin = np.nanmin(results.values)
vmax = np.nanmax(results.values)
norm = colors.Normalize(vmin=vmin, vmax=vmax)
bm = utils.basemap(ax1)
X, Y = bm(globe['lons'], globe['lats'])

#results = np.array(results)
ax1.axis(utils.mapbounds[deltaName])
ax1.set_title("Precipitation {} {}s by location".format(deltaName,analysisType))
globe['map'][delta['inds'][0], delta['inds'][1]] = results