-
Notifications
You must be signed in to change notification settings - Fork 0
Getting started
- numpy==1.11
- scipy==0.18.1
- matplotlib
- sympy
- playdoh
- pycuda (if you want to use GPU)
- brian>=1.4.3
- neo==0.4.0
- nixpy [Commit from 29 June 2016] (https://github.com/G-Node/nixpy/tree/5d4d194545a0923cef132405b720925373c38860)
- seaborn
-
First, clone this project.
-
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
-
Activate the environment. For example:
conda activate aynur
-
Install this project as an editable package using
pip install -e <local path to this project>
-
Open file Storage/ProjectStructure.py and change HOME variable to value you wish (it means, where project folder will be created)
Activate the environment above. For example: conda activate aynur
- Download Pycuda source using
git clone https://github.com/inducer/pycuda
- Navigate into the test directory
cd pycuda/test
- 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.
- Download Brian source code using
git clone https://github.com/brian-team/brian
- Navigate into Modelfitting example folder:
cd brian/examples/modelfitting
- 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!
- Run script Storage/OriginalsToProject.py with folder with original NIX Files and bestPars.json file.
python Storage/OriginalsToProject.py path_to_directory
-
bestPars.json should have inside "xData" section with times, "bestPars" section with Double Exponent parameters for each neuron.
-
Only neurons that are present in "bestPars" section, will be included into the project.
-
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.)
-
You can add custom inputs and outputs using ModelfittingIO object (see Inputs and Outputs).
There are two files: DATA/expIDs.json and DATA/settings.json
-
expIDs.json has section "ids" with exp names (neurons), used in project.
-
settings.json has "expname" section with current neuron, used by some tools inside project.
This project gives you several opportunities to work with model fittings, not thinking about how Brian Model Fitting Toolbox works inside.
-
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.
-
Second, you can use NixModelFitter interface (NixUtils.NixModelFitter). It directly works with NIX File (takes inputs, outputs, writes fits e.t.c)
-
Third, there is scripts Fitting/confFitting.py, that runs model fitting, using configuration file. Doesn't require programming.
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
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
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.
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.
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)
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
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.
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.
See Analysis/csvAnalysis.py script.
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
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.