{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Overloaded functions in touchsim\n", "The touchsim modules comes with several overloaded functions that make it easy to create new Afferent, AfferentPopulation, Stimulus, and Response objects from existing ones." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import touchsim as ts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Afferent and AfferentPopulation objects" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Individual Afferent objects can be combined into an AfferentPopulation object using the + operator." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a1 = ts.Afferent('SA1')\n", "a2 = ts.Afferent('PC')\n", "a = a1 + a2\n", "print(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "AfferentPopulation objects can be indexed to access individual Afferent objects or sub-populations." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a[0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(a[0])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a[0:1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(a[0:1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Afferent objects can be added to an AfferentPopulation using the += operator." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a += ts.Afferent('RA')\n", "a.afferents\n", "print(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sub-populations can also be indexed by class." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a5 = ts.affpop_single_models()\n", "a6 = a5['SA1']\n", "a6.affclass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Stimulus objects\n", "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s = ts.stim_ramp(amp=0.1)\n", "s2 = ts.stim_sine(loc=[1,1],freq=15,amp=0.1)\n", "s.location" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s2.location" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s += s2\n", "s.location" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Response objects\n", "Response objects can indexed using Afferent or AfferentPopulation objects to return a subset of responses." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "r = a5.response(s)\n", "len(r)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(r[a5[0]])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "len(r[a6])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }