{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "![NeuronUnit Logo](https://raw.githubusercontent.com/scidash/assets/master/logos/neuronunit/NeuronUnitBlack2.png)\n", "# Chapter 4\n", "Back to [Chapter 3](chapter3.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the third chapter we tested a reduced neuron model. Here we'll test a multicomparmental Cerebellar Granule Cell model using data from the [NeuroElectro](http://neuroelectro.org) project. \n", "### We'll test the resting potential and action potential width of a couple of cerebellar granule cell models. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\n", "import quantities as pq\n", "import sciunit\n", "from neuronunit import tests,capabilities\n", "from neuronunit import neuroelectro # This module allows interaction with NeuroElecto through a REST API. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example, we'll use models downloaded from [Open Source Brain](http://www.opensourcebrain.org) and run via [neuroConstruct](http://www.neuroconstruct.org) using [execnet](http://codespeak.net/execnet)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "ename": "Exception", "evalue": "Please add an NC_HOME environment variable corresponding to the location of the neuroConstruct directory.", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m/opt/conda/lib/python3.5/site-packages/neuronunit-0.1.8.6-py3.5.egg/neuronunit/neuroconstruct/__init__.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mNC_HOME\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0menviron\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"NC_HOME\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.5/os.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 724\u001b[0m \u001b[0;31m# raise KeyError with the original key value\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 725\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 726\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecodevalue\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mKeyError\u001b[0m: 'NC_HOME'", "\nDuring handling of the above exception, another exception occurred:\n", "\u001b[0;31mException\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mneuronunit\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mneuroconstruct\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodels\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnc_models\u001b[0m \u001b[0;31m# Model classes for use with neuroConstruct\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;31m# (http://www.neuroconstruct.org), a model and\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;31m# simulation manager for detailed neuron models.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mpythonnC\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mputils\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mOSB_MODELS\u001b[0m \u001b[0;31m# Path to models downloaded from Open Source Brain.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/opt/conda/lib/python3.5/site-packages/neuronunit-0.1.8.6-py3.5.egg/neuronunit/neuroconstruct/__init__.py\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m raise Exception(\"Please add an NC_HOME environment variable corresponding\\\n\u001b[0;32m---> 10\u001b[0;31m to the location of the neuroConstruct directory.\")\n\u001b[0m\u001b[1;32m 11\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mNC_HOME\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mException\u001b[0m: Please add an NC_HOME environment variable corresponding to the location of the neuroConstruct directory." ] } ], "source": [ "import neuronunit.neuroconstruct.models as nc_models # Model classes for use with neuroConstruct \n", " # (http://www.neuroconstruct.org), a model and \n", " # simulation manager for detailed neuron models. \n", "from pythonnC.utils.putils import OSB_MODELS # Path to models downloaded from Open Source Brain.\n", "\n", "# We will test cerebellar granule cell models. \n", "brain_area = 'cerebellum'\n", "neuron_type = 'cerebellar_granule_cell'\n", "neuron_type_path = os.path.join(OSB_MODELS,brain_area,neuron_type)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will look up data for cerebellar granule cells by [NeuroLex](http://neurolex.org) ID to make sure we get an unambiguous neuron type.
\n", "You can browse [NeuroLex](http://neurolex.org) to find your favorite neuron type." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "neurolex_id = 'nifext_128' # Cerebellar Granule Cell" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Now we instantiate two tests parameterized by data retrieved on the fly from [NeuroElectro](http://neuroelectro.org).\n", "One for resting membrane potential:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Getting data values from neuroelectro.org\n", "http://www.neuroelectro.org/api/1/nes/?nlex=nifext_128&e__name=Resting+Membrane+Potential\n" ] } ], "source": [ "# Specify reference data for a test of resting potential for a granule cell. \n", "reference_data = neuroelectro.NeuroElectroSummary(\n", " neuron = {'nlex_id':neurolex_id}, # Neuron type lookup using the NeuroLex ID. \n", " ephysprop = {'name':'Resting Membrane Potential'}) # Ephys property name in the NeuroElectro ontology. \n", "reference_data.get_values() # Get and verify summary data for the combination above from neuroelectro.org. \n", "\n", "rmp_test = tests.RestingPotentialTest(\n", " observation = {'mean':reference_data.mean*pq.mV, # In millivolts. \n", " 'std':reference_data.std*pq.mV},\n", " name = 'Resting Potential')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And one for action potential width:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Getting data values from neuroelectro.org\n", "http://www.neuroelectro.org/api/1/nes/?nlex=nifext_128&e__name=Spike+Half-Width\n" ] } ], "source": [ "# Specify reference data for a test of action potential width. \n", "reference_data = neuroelectro.NeuroElectroSummary(\n", " neuron = {'nlex_id':neurolex_id}, # Neuron type lookup using the NeuroLex ID. \n", " ephysprop = {'name':'Spike Half-Width'}) # Ephys property name in the NeuroElectro ontology. \n", "reference_data.get_values() # Get and verify summary data for the combination above from neuroelectro.org. \n", "\n", "spikewidth_test = tests.InjectedCurrentAPWidthTest(\n", " observation = {'mean':reference_data.mean*pq.ms, # In milliseconds. \n", " 'std':reference_data.std*pq.ms},\n", " name = 'Spike Width',\n", " params={'injected_square_current':{'amplitude':6.0*pq.pA,\n", " 'delay':50.0*pq.ms,\n", " 'duration':500.0*pq.ms}}) # 6 pA of injected current in a 500 ms square pulse. " ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [], "source": [ "x = tests.InjectedCurrentAPWidthTest(\n", " observation = {'mean':reference_data.mean*pq.ms, # In milliseconds. \n", " 'std':reference_data.std*pq.ms},\n", " name = 'Spike Width',\n", " injected_square_current = {'amplitude':6.0*pq.pA,\n", " 'delay':50.0*pq.ms,\n", " 'duration':500.0*pq.ms}) # 6 pA of injected current in a 500 ms square pulse. " ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "{'injected_square_current': {'amplitude': array(6.0) * pA,\n", " 'delay': array(50.0) * ms,\n", " 'duration': array(500.0) * ms},\n", " 'params': {'injected_square_current': {'amplitude': array(6.0) * pA,\n", " 'delay': array(50.0) * ms,\n", " 'duration': array(500.0) * ms}}}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x.params" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Let's create a test suite to group these two tests of a granule cell's properties. " ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Create a test suite from these two tests. \n", "suite = sciunit.TestSuite('EPhys Tests',(spikewidth_test,rmp_test))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Tests and tests suites can be executed against single models or lists of model. \n", "Let's instantiate a few different granule cell models and add them to a list to be tested.
\n", "Each of them is already parameterized in corresponding [NeuroML](http://neuroml.org) files associated with the [Open Source Brain](http://opensourcebrain.org) project. " ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [], "source": [ "model_names = ['GranuleCell','cereb_grc_mc'] # The names of two granule cell models \n", " # available at http://opensourcebrain.org.\n", "models = [] # Our list of models to be tested. \n", "for model_name in model_names:\n", " model_info = (brain_area,neuron_type,model_name) # Information about each model. \n", " model = nc_models.OSBModel(*model_info) # Instantiate a model using that information. \n", " models.append(model) # Add to the list of models to be tested. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Run each test against each model. " ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "Executing test Spike Width on model GranuleCell... " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Score is N/A\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Executing test Resting Potential on model GranuleCell... " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Running simulation...\n" ] }, { "ename": "AttributeError", "evalue": "'ellipsis' object has no attribute 'start'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Running these 2 tests against these 2 models means 4 total simulations.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mscore_matrix\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msuite\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjudge\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodels\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mstop_on_error\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m/Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/sciunit/__init__.py\u001b[0m in \u001b[0;36mjudge\u001b[0;34m(self, models, skip_incapable, stop_on_error, deep_error)\u001b[0m\n\u001b[1;32m 422\u001b[0m score = test.judge(model, skip_incapable=skip_incapable, \n\u001b[1;32m 423\u001b[0m \u001b[0mstop_on_error\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstop_on_error\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 424\u001b[0;31m deep_error=deep_error)\n\u001b[0m\u001b[1;32m 425\u001b[0m log('Score is ' % score.color()\n\u001b[1;32m 426\u001b[0m + '%s' % score)\n", "\u001b[0;32m/Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/sciunit/__init__.py\u001b[0m in \u001b[0;36mjudge\u001b[0;34m(self, model, skip_incapable, stop_on_error, deep_error)\u001b[0m\n\u001b[1;32m 294\u001b[0m \u001b[0mscore\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mErrorScore\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 295\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mscore\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mErrorScore\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mstop_on_error\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 296\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mscore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscore\u001b[0m \u001b[0;31m# An exception.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 297\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mscore\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 298\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/sciunit/__init__.py\u001b[0m in \u001b[0;36mjudge\u001b[0;34m(self, model, skip_incapable, stop_on_error, deep_error)\u001b[0m\n\u001b[1;32m 288\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 289\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 290\u001b[0;31m \u001b[0mscore\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_judge\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskip_incapable\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mskip_incapable\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 291\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mCapabilityError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 292\u001b[0m \u001b[0mscore\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mNAScore\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/sciunit/__init__.py\u001b[0m in \u001b[0;36m_judge\u001b[0;34m(self, model, skip_incapable)\u001b[0m\n\u001b[1;32m 231\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcheck_capabilities\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 232\u001b[0m \u001b[0;31m# 2.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 233\u001b[0;31m \u001b[0mprediction\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgenerate_prediction\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 234\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlast_model\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 235\u001b[0m \u001b[0;31m# 3.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/neuronunit/tests/__init__.py\u001b[0m in \u001b[0;36mgenerate_prediction\u001b[0;34m(self, model)\u001b[0m\n\u001b[1;32m 576\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrerun\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 577\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minject_square_current\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'injected_square_current'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 578\u001b[0;31m \u001b[0mmedian\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_median_vm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# Use median for robustness.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 579\u001b[0m \u001b[0mstd\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_std_vm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 580\u001b[0m \u001b[0mprediction\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m'mean'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mmedian\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'std'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mstd\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/neuronunit/neuroconstruct/capabilities.py\u001b[0m in \u001b[0;36mget_median_vm\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[0mvm\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_membrane_potential\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 88\u001b[0m \u001b[0;31m# A neo.core.AnalogSignal object\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 89\u001b[0;31m \u001b[0mmedian_vm\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmedian\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvm\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 90\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mmedian_vm\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 91\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/numpy/lib/function_base.py\u001b[0m in \u001b[0;36mmedian\u001b[0;34m(a, axis, out, overwrite_input, keepdims)\u001b[0m\n\u001b[1;32m 3509\u001b[0m \"\"\"\n\u001b[1;32m 3510\u001b[0m r, k = _ureduce(a, func=_median, axis=axis, out=out,\n\u001b[0;32m-> 3511\u001b[0;31m overwrite_input=overwrite_input)\n\u001b[0m\u001b[1;32m 3512\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mkeepdims\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3513\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/numpy/lib/function_base.py\u001b[0m in \u001b[0;36m_ureduce\u001b[0;34m(a, func, **kwargs)\u001b[0m\n\u001b[1;32m 3423\u001b[0m \u001b[0mkeepdim\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndim\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3424\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3425\u001b[0;31m \u001b[0mr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3426\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeepdim\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3427\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/numpy/lib/function_base.py\u001b[0m in \u001b[0;36m_median\u001b[0;34m(a, axis, out, overwrite_input)\u001b[0m\n\u001b[1;32m 3563\u001b[0m \u001b[0mrout\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpart\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mindexer\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3564\u001b[0m \u001b[0mpart\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrollaxis\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpart\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpart\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndim\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3565\u001b[0;31m \u001b[0mn\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0misnan\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpart\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m...\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3566\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mrout\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3567\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mn\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/Users/rgerkin/Dropbox/miniconda3/lib/python3.5/site-packages/neo-0.4.1-py3.5.egg/neo/core/analogsignal.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, i)\u001b[0m\n\u001b[1;32m 207\u001b[0m \u001b[0mslice_step\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstep\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 208\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtuple\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 209\u001b[0;31m \u001b[0mslice_start\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstart\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 210\u001b[0m \u001b[0mslice_step\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstep\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 211\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mslice_start\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mAttributeError\u001b[0m: 'ellipsis' object has no attribute 'start'" ] } ], "source": [ "# Running these 2 tests against these 2 models means 4 total simulations. \n", "score_matrix = suite.judge(models,stop_on_error=True) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Display the results as a table.\n", "The 'cereb_grc_mc' model doesn't seem to spike, so there is insufficient data to produce a score." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "score_matrix.view()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plot some of the model output that led to those scores:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "fig,ax = plt.subplots(2,2,figsize=(8,6)) # Create plot windows. \n", "for i,test in enumerate(score_matrix.tests): # For each test...\n", " for j,model in enumerate(score_matrix.models): # And each model...\n", " score = score_matrix[test,model] # Get the score. \n", " score.plot_vm(ax[i,j]) # And use a convenience method to plot the membrane potential. \n", "fig.tight_layout() # Space the plots nicely. " ] } ], "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.5.2" } }, "nbformat": 4, "nbformat_minor": 0 }