import os
import sys
import math
import pickle
from pylab import *
sys.path.extend(["..","../networks","../generators","../simulations"])
from simset_inhibition import *
from stimuliConstants import *
from data_utils import *
SETTLETIME = 500e-3
RUNTIME = REALRUNTIME + SETTLETIME
if __name__ == "__main__":
mit_responses = pickle.load( open( sys.argv[1], "rb" ) )
timevec = arange(0.0,RUNTIME+1e-10,SIMDT)*1e3
tmin,tmax = 400,1200
Vrest = -65
Vmin,Vmax = -80,40
fig = figure(figsize=(columnwidth*1.5,linfig_height*1.5),dpi=300,facecolor='w')
ax1 = fig.add_subplot(2,2,1)
ax1.plot((tmin,tmax),(Vrest,Vrest),linestyle='dashed',linewidth=plot_linewidth,color=(0.5,0.5,0.5))
ax1.plot(timevec,mit_responses[1][0]*1e3,color='r',linewidth=plot_linewidth,label='Lateral')
beautify_plot(ax1,x0min=False,y0min=False,xticksposn='none',yticksposn='left')
ax1.set_xlim(tmin,tmax)
ax1.set_ylim(Vmin,Vmax)
ax1.set_yticks([Vmin,Vmax])
axes_labels(ax1,'','Vm (mV)',ypad=-2)
ax2 = fig.add_subplot(2,2,3)
ax2.plot((tmin,tmax),(Vrest,Vrest),linestyle='dashed',linewidth=plot_linewidth,color=(0.5,0.5,0.5))
ax2.plot(timevec,mit_responses[0][0]*1e3,color='r',linewidth=plot_linewidth,label='Recurrent')
beautify_plot(ax2,x0min=False,y0min=False,xticksposn='bottom',yticksposn='left')
ax2.set_xlim(tmin,tmax)
ax2.set_xticks([tmin,800,tmax])
ax2.set_ylim(Vmin,Vmax)
ax2.set_yticks([Vmin,Vmax])
axes_labels(ax2,'time (ms)','Vm (mV)',xpad=2,ypad=-2)
from mpl_toolkits.axes_grid.inset_locator import mark_inset
Bbox = matplotlib.transforms.Bbox.from_bounds(.75, .6, .5, .5)
trans = ax1.transAxes + fig.transFigure.inverted()
l, b, w, h = matplotlib.transforms.TransformedBbox(Bbox,trans).bounds
axinset = fig.add_axes([l, b, w, h])
axinset.plot(timevec,mit_responses[1][0]*1e3,color='r',linewidth=plot_linewidth,label='Lateral')
for loc, spine in axinset.spines.items():
spine.set_linewidth(axes_linewidth)
axinset.set_xlim(910,975)
axinset.set_ylim(-71.5,-70)
axinset.set_xticks([])
axinset.set_yticks([])
mark_inset(ax1, axinset, loc1=2, loc2=4, fc="none", ec="0.5", linewidth=axes_linewidth)
ax1 = fig.add_subplot(2,2,2)
ax1.plot((tmin,tmax),(Vrest,Vrest),linestyle='dashed',linewidth=plot_linewidth,color=(0.5,0.5,0.5))
ax1.plot(timevec,mit_responses[1][1]*1e3,color='g',linewidth=plot_linewidth,label='Lateral')
beautify_plot(ax1,x0min=False,y0min=False,xticksposn='none',yticksposn='none')
ax1.set_xlim(tmin,tmax)
ax1.set_ylim(Vmin,Vmax)
ax1.set_yticks([])
axes_labels(ax1,'','')
ax2 = fig.add_subplot(2,2,4)
ax2.plot((tmin,tmax),(Vrest,Vrest),linestyle='dashed',linewidth=plot_linewidth,color=(0.5,0.5,0.5))
ax2.plot(timevec,mit_responses[0][1]*1e3,color='g',linewidth=plot_linewidth,label='Recurrent')
beautify_plot(ax2,x0min=False,y0min=False,xticksposn='bottom',yticksposn='none')
ax2.set_xlim(tmin,tmax)
ax2.set_xticks([tmin,800,tmax])
ax2.set_ylim(Vmin,Vmax)
ax2.set_yticks([])
axes_labels(ax2,'time (ms)','',xpad=2)
fig.subplots_adjust(top=0.95,left=0.1,right=0.97, wspace=0.25,hspace=0.25)
fig.savefig('../figures/recvslat.svg',dpi=fig.dpi)
fig.savefig('../figures/recvslat.png',dpi=fig.dpi)
show()