#!/usr/bin/env python # coding: utf-8 # # Overloaded functions in touchsim # The touchsim modules comes with several overloaded functions that make it easy to create new Afferent, AfferentPopulation, Stimulus, and Response objects from existing ones. # In[ ]: import touchsim as ts # ## Afferent and AfferentPopulation objects # Individual Afferent objects can be combined into an AfferentPopulation object using the + operator. # In[ ]: a1 = ts.Afferent('SA1') a2 = ts.Afferent('PC') a = a1 + a2 print(a) # The len function can be used to determine the number of afferents in a given AfferentPopulation objects (this works on Afferent objects, too, and will always return 1 for those). # In[ ]: len(a) # AfferentPopulation objects can be indexed to access individual Afferent objects or sub-populations. # In[ ]: a[0] # In[ ]: len(a[0]) # In[ ]: a[0:1] # In[ ]: len(a[0:1]) # Afferent objects can be added to an AfferentPopulation using the += operator. # In[ ]: a += ts.Afferent('RA') a.afferents print(a) # Sub-populations can also be indexed by class. # In[ ]: a5 = ts.affpop_single_models() a6 = a5['SA1'] a6.affclass # ## Stimulus objects # The pin locations and traces of a Stimulus object can be added to those of another object using the += operator. Note that the pin size of the initial Stimulus will take precedent and that the Stimulus durations and sampling frequencies for both Stimulus objects must be the same. # In[ ]: s = ts.stim_ramp(amp=0.1) s2 = ts.stim_sine(loc=[1,1],freq=15,amp=0.1) s.location # In[ ]: s2.location # In[ ]: s += s2 s.location # ## Response objects # Response objects can indexed using Afferent or AfferentPopulation objects to return a subset of responses. # In[ ]: r = a5.response(s) len(r) # In[ ]: len(r[a5[0]]) # In[ ]: len(r[a6])