!conda install -y netcdf4

from netCDF4 import Dataset, num2date, date2num
from numpy import *
import matplotlib.pyplot as plt
%matplotlib inline

from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets

x=linspace(0,1,100)
f=2

plt.plot(x, sin(2*pi*x*f))

def pltsin(f):
    plt.plot(x,sin(2*pi*x*f))

pltsin(5)

interact(pltsin, f=(1,10,0.1))

"""
Explanation: Widges and Interactions
End of explanation
"""


def pltsin(f,a):
    plt.plot(x,a * sin(2*pi*x*f))

interact(pltsin, f=(1, 10, 0.1), a=(1, 10, 0.1))

"""
Explanation: Add to the funtion to allow amplitude to be varied and add in an additional slider to vary both f and a
Hint you might want to limit the magnitude of 'y' in the plot - look up matplotlib
End of explanation
"""


f=Dataset('ncep-data/air.sig995.2013.nc')

air=f.variables['air'] #get variable

plt.imshow(air[364,:,:])  #display first timestep

def sh(time):
    plt.imshow(air[time,:,:])

#now make it interactive

interact(sh, time=(0,364,1))

# Browse variable

def sh(var='air', time=0):
    f=Dataset ('ncep-data/'+var+'.sig995.2013.nc')
    vv=f.variables[var]
    plt.imshow(vv[time,:,:])

# Give a list of varibles

variabs= ['air','uwnd','vwnd','rhum']

# Now interact with it

interact(sh, time=(0,355,1), var=variabs)

# Browse variable

def sh(var='air', year="2013", time=0):
    f=Dataset ('ncep-data/'+var+'.sig995.'+year+'.nc')
    vv=f.variables[var]
    plt.imshow(vv[time,:,:])

# Create a list of years

years= [str(x) for x in range (2013,2016)]
years = ['2013', '2014', '2015']

# Give a list of varibles

variabs= ['air','uwnd','vwnd','rhum']

# Now interact with it

interact(sh, time=(0,355,1), var=variabs, year=years)

"""
Explanation: Climate data
End of explanation
"""


