# Import libraries
import numpy as np

%config InlineBackend.figure_format = 'retina'
%matplotlib inline
import matplotlib.pyplot as plt

"""
Explanation: Scott Cole
6 May 2017
This notebook is to formalize the hypothesis that the neural response to a very fast movement in the preferred direction can be more similar to that of a movement in the opposite direction (perceptually: the wagon wheel effect).
The predicted neural response to a motion is computed by convolving the neural responses to static gratings
End of explanation
"""


kernel_fast = np.array([0, .5, 1, .8, .4, .2, .1, 0])
kernel_slow = np.hstack([np.arange(0,1,.2),np.arange(1,0,-.04)])

plt.figure(figsize=(5,6))
plt.subplot(2,1,1)
plt.plot(kernel_fast,'k')
plt.xlim((0,30))
plt.ylabel('Neural response\n(fast)',size=15)
plt.subplot(2,1,2)
plt.plot(kernel_slow,'k')
plt.xlim((0,30))
plt.xlabel('Time (a.u.)',size=20)
plt.ylabel('Neural response\n(slow)',size=15)

"""
Explanation: 1. Define kernels of neuronal response to static gratings
The kernels plotted here represent the transient and sustained neural responses. (I believe these are firing rates in thalamic projection neurons in response to static gratings?)
End of explanation
"""


# Define times of sustained-response-inducing (slow)
# and transient-response-inducing (fast) stimuli
slow_event_times = np.arange(0,100,20)
fast_event_times = np.arange(10,110,20)

# Compute rasters of events
N = 200
slow_event_raster = np.zeros(N)
slow_event_raster[slow_event_times] = 1
fast_event_raster = np.zeros(N)
fast_event_raster[fast_event_times] = 1

# Compute trace of neural activity
slow_neural = np.convolve(slow_event_times, kernel_slow, mode='same')
fast_neural = np.convolve(fast_event_times, kernel_fast, mode='same')
neural = slow_neural + fast_neural

"""
Explanation: 2. Estimate neural response to preferred and opposite directions
Preferred direction
End of explanation
"""


