Skip to content

Getting started

Ajayrama Kumaraswamy edited this page Feb 21, 2018 · 26 revisions

Dependencies, in order of installation

  1. numpy==1.11
  2. scipy==0.18.1
  3. matplotlib
  4. sympy
  5. playdoh
  6. pycuda (if you want to use GPU)
  7. brian>=1.4.3
  8. neo==0.4.0
  9. nixpy [Commit from 29 June 2016] (https://github.com/G-Node/nixpy/tree/5d4d194545a0923cef132405b720925373c38860)
  10. seaborn

Installation

  1. First, clone this project.

  2. Create a new virtual environment. For example: conda create -n aynur python=2.7 numpy==1.11 scipy==0.18.1 matplotlib sympy seaborn astropy

  3. Activate the environment. For example: conda activate aynur

  4. Install this project as an editable package using pip install -e <local path to this project>

  5. Open file Storage/ProjectStructure.py and change HOME variable to value you wish (it means, where project folder will be created)

Tests to ensure installation is usable

Activate the environment above. For example: conda activate aynur

Test PyCuda (Skip if not using GPUs)

  1. Download Pycuda source using git clone https://github.com/inducer/pycuda
  2. Navigate into the test directory cd pycuda/test
  3. Check if PyCuda can access GPUs using python -m pytest test_driver.py. As of this writing, this test failed only on 5 tests and skipped 2. Some tests passing indicates that pycuda can access GPUs.

Test Brian Model Fitting

  1. Download Brian source code using git clone https://github.com/brian-team/brian
  2. Navigate into Modelfitting example folder: cd brian/examples/modelfitting
  3. Run a model fitting exmaple: python modelfitting.py. There might be some warnings, this should show some results, importantly "Iteration 1/3", "Iteration 2/3", "Iteration 3/3" and "Results....".

Now you can work!

Create project from original Nix files

  1. Run script Storage/OriginalsToProject.py with folder with original NIX Files and bestPars.json file.

python Storage/OriginalsToProject.py path_to_directory

  1. bestPars.json should have inside "xData" section with times, "bestPars" section with Double Exponent parameters for each neuron.

  2. Only neurons that are present in "bestPars" section, will be included into the project.

  3. Resulting NIX Files in folder HOME/DATA/FITTING/ will have some common inputs (subthreshold and derivative, BeforeStimulus, DuringStimulus, AfterStimulus, DuringAfterSimulus and also scaled versions (e-7)) and outputs (that are given by neoNIXIO.RawDataAnalyser function, but named internally as Trial0-BeforeStimulus, ... Trial0-DuringAfterStimulus e.t.c.)

  4. You can add custom inputs and outputs using ModelfittingIO object (see Inputs and Outputs).

Project configuration files

There are two files: DATA/expIDs.json and DATA/settings.json

  1. expIDs.json has section "ids" with exp names (neurons), used in project.

  2. settings.json has "expname" section with current neuron, used by some tools inside project.

Model fitting

This project gives you several opportunities to work with model fittings, not thinking about how Brian Model Fitting Toolbox works inside.

  1. On basic level, you can use functions from BrianUtils.ModelFitter, they work with neo.AnalogSignal and neo.SpikeTrain, but don't know about NIX format. Use ModelfittingIO additionally, to store all required info.

  2. Second, you can use NixModelFitter interface (NixUtils.NixModelFitter). It directly works with NIX File (takes inputs, outputs, writes fits e.t.c)

  3. Third, there is scripts Fitting/confFitting.py, that runs model fitting, using configuration file. Doesn't require programming.

BrianUtils.ModelFitter

function FitSingleCompartmentalModel(NModel, input, output, popsize=10000, maxiter=100, method="RK", algorithm ="CMAES", algo_params = None, returninfo = True)

returns Brian.modelfitting.modelfittingresults object.

NModel - model instance (see BrianUtils.NeuronalModels)

input - neo.AnalogSignal

output - neo.SpikeTrain

NixModelFitter

Just example of usage:


from NixUtils import NixModelFitter as nmf
from BrianUtils.NeuronalModel import GetModelById
f = nmf.NixModelFitter(expname, dir=None, mode="w") #if dir is None, opens file from HOME/DATA/FITTING
inits = getattr(GetModelById("adex"), "bursting_rebound") #we want to use predefined bursting_rebound initial point
optparams = ["a", "b", "gL", "C"]
fitName = f.FitModel(model="adex", input="subthreshold-DuringAfterStimulus", 
    output = "Trial5-DuringAfterStimulus", #input and output names from NIX file
    inits = inits, maxiter = 1000, # runs model fitting algorithm for 1000 iterations
    optparams = optparams, # parameters we want to fit
    duration=1250) #duration - float, in seconds. If None, then equal to input duration
f.SimulateAndPlorFitting(fitName) # it will simulate model with the fitted parameters and plot (or save as png, you can specify it)
# It always creates json file with simulated traces DATA/TRACES/*.plot.json

Fitting.confFitting

python Fitting/confFitting.py path_to_config_file

example of json config file:


{
  "tasks":[
    {
      "neurons":["130313-4Rh", "130322-1LY"],
      "model":"adex",
      "regimes":["bursting_rebound", "saddle_mixed"],
      "input":"subthreshold-DuringAfterStimulus-e-7",
      "output":"Trial17-DuringAfterStimulus",
      "optparams":["b", "a", "sF", "Vr", "gL", "C", "Vt", "tau", "scaleFactor", "scaleFactor2"],
      "iters":40000,
      "duration":1.250
    },
    {
      "neurons":["130605-2LY"],
      "model":"adex",
      "regimes":["mean_24_08_2016"],
      "input":"subthreshold-DuringAfterStimulus-e-7",
      "output":"Trial3-DuringAfterStimulus",
      "optparams":["b", "a", "sF", "Vr", "gL", "C", "Vt", "tau", "scaleFactor", "scaleFactor2"],
      "iters":60000,
      "duration":1.250
    }
  ]
}

It'll take inputs and outputs from files located in HOME/DATA/FITTING. Also, log files are generated for each single model fitting (DATA/OUTPUT/*.log)

!Important! Please, do not change code in Fitting/singleConfFitting.py during running tasks using confFitting, because it starts separate subprocess for each single model fitting, so it can run it not correctly.

Using GPUs

For model fitting, all three options use all the GPUs available, by default.

If pycuda is not installed properly, will use all the CPUs are available.

Simulation of fittings and plots

You always can simulate and plot fitting separately.

Instead of using NixModelFitter, you can use script Test/SimulateAndPlotFitting.py

python Test/SimulateAndPlotFitting.py -1

This will simulate and plot (or only plot, if DATA/TRACES/fitName.plot.json exists) last fitting, stored in current file (see Specify current exp name)

Fitting results analysis

There is an opportunity to analyse data you have. All of analysis is going with the CSV table, that you can generate using Analysis/csvFromConf.py

Gamma function

To calculate Gamma comarison function for each fitting in NIX files, you can use Analysis/NIXCalculateGamma.py. It will store Gamma value inside NIX File.

Generating CSV file from fitting results.


python Analysis/csvFromConf.py fittings_folder configFile1 configFile2 ... configFileN

Makes csv comparizon table for fittings, driven by configFile1...configFileN files. Script uses log files of fittings, so don't remove them! fitting_folder is foldeer, where NIX files storing fittings are located. You can type ":" instead of fittings_folder, so script will take NIX Files from DATA/FITTING folder.

Analysis of CSV file

See Analysis/csvAnalysis.py script.

Current exp name (neuron)

settings.json


{
    "expname":"130322-1LY"
}

You can change it both in file and using Test/SetCurrentExp.py script. Example of usage:


user@host:dir$ python Storage/SetCurrentExp.py 130313-4Rh
Set current expname  130313-4Rh  for project  /your_project_folder/DATA
user@host:dir$ python Storage/SetCurrentExp.py +
Set current expname  140917-1Al  for project  /your_project_folder/DATA
user@host:dir$ python Storage/SetCurrentExp.py -
Set current expname  130313-4Rh  for project  /your_project_folder/DATA

Useful tools

Test/PlotTrace.py

Simple tool to look at inpus and outputs, stored in NIX file. It can list available inputs and outputs, plot them. Uses current NIX file.