touchsim
¶The touchsim
package uses holoviews
for plotting.
import touchsim as ts
from touchsim.plotting import plot, figsave
import numpy as np
import holoviews as hv
hv.notebook_extension()
%output holomap='scrubber' # animate holomaps
import warnings
warnings.simplefilter("ignore")
plot() # short for plot(ts.hand_surface)
Regions labels and the coordinate system can be overlaid on the plot.
%%output size=250
plot(tags=True,coord=10) # coord sets the lengths of the coordinate axes in mm
AfferentPopulation
objects¶a = ts.affpop_hand(region='D2d')
plot(a,size=10)
Plots can be overlaid using the *
operator.
Plots are holoviews
objects and can be indexed to only show, say, a specific afferent population. The *
operator overlays different plots (e.g. the hand outline and the afferent locations, as shown below).
plot(region='D2d') * plot(a,size=10)['PC']
New subpanels can be added using the +
operator.
(plot(region='D2d') * plot(a,size=10)['SA1']) + (plot(region='D2d') * plot(a,size=10)['RA']) + (plot(region='D2d') * plot(a,size=10)['PC'])
The first index of an AfferentPopulation
plot object is the afferent type, while the next two indices are pixel coordinates.
# zoom into fingertip
plot(a,size=10)[:,120:140,450:475]
Stimulus
objects¶Plotting a Stimulus
object shows the trace of all pins by default.
s = ts.stim_ramp(len=0.25,amp=.1,ramp_len=0.05)
plot(s)
s += ts.stim_sine(freq=25.,len=.25,loc=[1.,1.])
plot(s)
Pin traces can also be shown in a grid view.
plot(s,grid=True)
Pin positions can also be shown spatially.
s = ts.stim_indent_shape(ts.shape_circle(hdiff=0.5,pins_per_mm=2,radius=3),ts.stim_ramp(len=0.1))
plot(s,spatial=True)
The spatial view can be animated with pin depths indicated by color.
plot(region='D2d') * plot(s,spatial=True,bin=10)
Response
objects¶Plotting a Response
object shows the spike trains of all included neurons
a = ts.affpop_hand(region='D2')
s = ts.stim_sine(freq=50.,amp=0.1,len=0.5)
r = a.response(s)
plot(r)
The second index is the time index.
plot(r)[:,0:0.2]
Responses can also be plotted spatially, in which case the size of each dot scaled with the neuron's firing rate.
%%output size=150 # increase size of plot by 150%
plot(region='D2') * plot(r,spatial=True,scaling_factor=.1)
Alternatively, firing rate can be indicated by color instead:
plot(region='D2') * plot(r,spatial=True,scale=False)[:,'RA'] + plot(region='D2') * plot(r,spatial=True,scale=False)[:,'PC']
Responses in spatial view can also be shown animated if a bin size (in ms) is given.
plot(region='D2') * plot(r,spatial=True,bin=10)
contact_locs = np.zeros((2,2))
contact_locs[0] = np.array([0.,0.])
contact_locs[1] = np.array([150.,0])
a = ts.affpop_hand(noisy=False)
s = ts.stim_indent_shape(contact_locs,ts.stim_ramp(amp=0.75,len=.2,ramp_len=0.05,ramp_type='lin',pin_radius=5.,pad_len=0.025))
r = a.response(s)
plot(r)
plot() * plot(r,spatial=True,bin=10)
Figures can be saved using the figsave
function; figure size and resolution can be controlled using the size
and dpi
parameters, respectively.
figsave(plot(),'test_fig',size=150,dpi=50)
When the gif
format is selected, animations will be saved as animated gifs; their framerate can be controlled with the fps
parameter
bin = 50
fig = plot(s,bin=bin) + plot()*plot(r,spatial=True,bin=bin)
figsave(fig,'test_gif',size=150,fps=5,fmt='gif')