"""
example1 for snnet

Demonstrates: do_sweep, parallelization, global dynamics

Requires matplotlib to make the figures.

Robert A McDougal, 2011
"""

from snnet import *

# define the simulation
def simulation():
    # The state variables in the file will be accessible to all neurons,
    # other global dynamics. (Here, I'm using a neuron file, but it could
    # just as easily be an equation for dopamine, etc...)
    dynamics = global_dynamics('hh.snnet')
    run_to(500)

# sweep over multiple values of iapp
run(simulation, 'example1', integrator=xpp_integrator,
    save_type=full, num_parallel=2, sweep={'iapp': [1, 5, 10]})



#
# make figure
#

iapps = [1, 5, 10]
colors = ['black', 'red', 'blue']

for iapp, color in zip(iapps, colors):
    data = load_simulation('example1/iapp/%d/0.sdat' % iapp)
    plot(data.v, data.h, color=color)

xlabel('V (mV)')
ylabel('h')
xlim(-100, 50)
ylim(0, .8)
legend(('iapp =  1', 'iapp =  5', 'iapp = 10'))
title('Comparison of phase planes for different iapp')

savefig('example1.pdf')
