Skip to content

Commit 527d9bf

Browse files
authored
Merge pull request #12 from BhallaLab/enable_test
Enabled tests for tsv scripts.
2 parents 326297e + 5644042 commit 527d9bf

File tree

3 files changed

+57
-34
lines changed

3 files changed

+57
-34
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ before_script:
99
- sleep 3 # give xvfb some time to start
1010
- # this require latest moose.
1111
- sudo apt-get update
12-
- sudo apt-get install python-scipy python-networkx python-tk python-matplotlib -qq
12+
- sudo apt-get install graphviz python-networkx python-tk -qq
1313

1414
script:
1515
- cp ./.travis/matplotlibrc .

findSim.py

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#
1+
# -*- coding: utf-8 -*-
2+
23
# This program is free software; you can redistribute it and/or
34
# modify it under the terms of the GNU General Public License as
45
# published by the Free Software Foundation; either version 3, or
@@ -33,9 +34,9 @@
3334
**********************************************************************/
3435
3536
'''
36-
from __future__ import print_function
37+
from __future__ import print_function, division
3738
import heapq
38-
import pylab
39+
import matplotlib.pyplot as plt
3940
import numpy as np
4041
import sys
4142
import argparse
@@ -280,7 +281,11 @@ def displayPlots( self, fname, modelLookup, stim, hideSubplots, exptType ):
280281
elms = modelLookup[i]
281282
for j in elms:
282283
pp = PlotPanel( self, exptType, xlabel = j.name +'('+stim.quantityUnits+')' )
283-
pp.plotme( fname, pp.ylabel, joinSimPoints = True )
284+
try:
285+
pp.plotme( fname, pp.ylabel, joinSimPoints = True )
286+
except Exception as e:
287+
print('Warning: displayPlot: Failed to plot '
288+
'%s due to "%s"' % (fname,e))
284289
elif "barchart" in exptType:
285290
for i in self.entities:
286291
elms = modelLookup[i]
@@ -320,17 +325,17 @@ def displayPlots( self, fname, modelLookup, stim, hideSubplots, exptType ):
320325
sumvec += ypts
321326
if (not hideSubplots) and (len( elms ) > 1):
322327
# Plot summed components
323-
pylab.plot( xpts, ypts, 'r:', label = j.name )
328+
plt.plot( xpts, ypts, 'r:', label = j.name )
324329

325-
pylab.plot( xpts, sumvec, 'r--' )
330+
plt.plot( xpts, sumvec, 'r--' )
326331
ylabel = pp.ylabel
327332
if self.field in ( epspFields + epscFields ):
328333
if self.field in ( epspFields ):
329-
pylab.ylabel( '{} Vm ({})'.format( self.entities[0], tsUnits ) )
334+
plt.ylabel( '{} Vm ({})'.format( self.entities[0], tsUnits ) )
330335
else:
331-
pylab.ylabel( '{} holding current ({})'.format( self.entities[0], tsUnits ) )
336+
plt.ylabel( '{} holding current ({})'.format( self.entities[0], tsUnits ) )
332337

333-
pylab.figure(2)
338+
plt.figure(2)
334339
if self.useNormalization:
335340
ylabel = '{} Fold change'.format( self.field )
336341
pp.plotme( fname, ylabel )
@@ -1249,39 +1254,39 @@ def convertBarChartLabels( self, readout, stim ):
12491254
def plotbar( self, readout, stim, scriptName ):
12501255
barpos = np.arange( len( self.sim ) )
12511256
width = 0.35 # A reasonable looking bar width
1252-
exptBar = pylab.bar(barpos - width/2, self.expt, width, yerr=self.yerror, color='SkyBlue', label='Experiment')
1253-
simBar = pylab.bar(barpos + width/2, self.sim, width, color='IndianRed', label='Simulation')
1254-
pylab.xlabel( "Stimulus combinations" )
1255-
pylab.ylabel( self.ylabel )
1256-
pylab.title(scriptName)
1257-
pylab.legend(fontsize="small",loc="upper left")
1257+
exptBar = plt.bar(barpos - width/2, self.expt, width, yerr=self.yerror, color='SkyBlue', label='Experiment')
1258+
simBar = plt.bar(barpos + width/2, self.sim, width, color='IndianRed', label='Simulation')
1259+
plt.xlabel( "Stimulus combinations" )
1260+
plt.ylabel( self.ylabel )
1261+
plt.title(scriptName)
1262+
plt.legend(fontsize="small",loc="upper left")
12581263
ticklabels = [ i[0] + '\n' for i in readout.data ]
12591264
assert len( ticklabels ) == len( barpos )
12601265
ticklabels = self.convertBarChartLabels( readout, stim )
1261-
pylab.xticks(barpos, ticklabels )
1266+
plt.xticks(barpos, ticklabels )
12621267

12631268
def plotme( self, scriptName, ylabel, joinSimPoints = False ):
12641269
sp = 'ro-' if joinSimPoints else 'ro'
12651270
if self.useXlog:
12661271
if self.useYlog:
1267-
pylab.loglog( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' )
1268-
pylab.loglog( self.xpts, self.sim, sp, label = 'sim', linewidth='2' )
1272+
plt.loglog( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' )
1273+
plt.loglog( self.xpts, self.sim, sp, label = 'sim', linewidth='2' )
12691274
else:
1270-
pylab.semilogx( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' )
1271-
pylab.semilogx( self.xpts, self.sim, sp, label = 'sim', linewidth='2' )
1275+
plt.semilogx( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' )
1276+
plt.semilogx( self.xpts, self.sim, sp, label = 'sim', linewidth='2' )
12721277
else:
12731278
if self.useYlog:
1274-
pylab.semilogy( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' )
1275-
pylab.semilogy( self.xpts, self.sim, sp, label = 'sim', linewidth='2' )
1279+
plt.semilogy( self.xpts, self.expt, 'bo-', label = 'expt', linewidth='2' )
1280+
plt.semilogy( self.xpts, self.sim, sp, label = 'sim', linewidth='2' )
12761281
else:
1277-
pylab.plot( self.xpts, self.expt,'bo-', label = 'experiment', linewidth='2' )
1278-
pylab.errorbar( self.xpts, self.expt, yerr=self.yerror )
1279-
pylab.plot( self.xpts, self.sim, sp, label = 'sim', linewidth='2' )
1282+
plt.plot( self.xpts, self.expt,'bo-', label = 'experiment', linewidth='2' )
1283+
plt.errorbar( self.xpts, self.expt, yerr=self.yerror )
1284+
plt.plot( self.xpts, self.sim, sp, label = 'sim', linewidth='2' )
12801285

1281-
pylab.xlabel( self.xlabel )
1282-
pylab.ylabel( ylabel )
1283-
pylab.title(scriptName)
1284-
pylab.legend(fontsize="small",loc="lower right")
1286+
plt.xlabel( self.xlabel )
1287+
plt.ylabel( ylabel )
1288+
plt.title(scriptName)
1289+
plt.legend(fontsize="small",loc="lower right")
12851290

12861291
########################################################################
12871292
def loadTsv( fname ):
@@ -1590,10 +1595,10 @@ def innerMain( script, modelFile = "model/synSynth7.g", dumpFname = "", paramFna
15901595
if not hidePlot:
15911596
print( "Score = {:.3f} for\t{}\tElapsed Time = {:.1f} s".format( score, os.path.basename(script), elapsedTime ) )
15921597
for i in readouts:
1593-
pylab.figure(1)
1598+
plt.figure(1)
15941599
i.displayPlots( script, model.modelLookup, stims[0], hideSubplots, expt.exptType )
15951600

1596-
pylab.show()
1601+
plt.show()
15971602
moose.delete( modelId )
15981603
if moose.exists( '/library' ):
15991604
moose.delete( '/library' )

test.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
#!/usr/bin/env bash
22

33
set -e
4-
set -x
54

65
# virtualenv does not require --user
76
PYTHON=$(which python)
87

8+
# From here https://stackoverflow.com/a/40950971/1805129
9+
PYTHON_VERSION=$(python -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]\).*/\1\2/')
10+
if [ "$PYTHON_VERSION" -eq "27" ]; then
11+
# $PYTHON -m pip uninstall matplotlib -y || echo "Failed to remove matplotlib"
12+
$PYTHON -m pip install matplotlib==2.2.3 --upgrade
13+
$PYTHON -m pip install scipy==1.1.0 --upgrade
14+
else
15+
# $PYTHON -m pip uninstall matplotlib -y || echo "Failed to remove matplotlib"
16+
$PYTHON -m pip install matplotlib --upgrade
17+
$PYTHON -m pip install --upgrade
18+
fi
19+
920
$PYTHON -m pip install pymoose --pre --upgrade
1021
$PYTHON -m pip install pylint numpy --upgrade
1122

@@ -14,8 +25,15 @@ find . -type f -name "*.py" | xargs -I file $PYTHON -m pylint \
1425
--exit-zero \
1526
-E file
1627

28+
# Run it in ./TestTSV directory.
29+
for _tsv in $(find ./TestTSV -name *.tsv -type f); do
30+
echo "[INFO] Running experiment ${_tsv}"
31+
$PYTHON findSim.py ${_tsv} --model models/synSynth7.g
32+
done
33+
1734
$PYTHON findSim.py ./Curated/FindSim-Jain2009_Fig4F.tsv --model models/synSynth7.g
1835
$PYTHON findSim.py ./Curated/FindSim-Bhalla1999_fig2B.tsv --model models/synSynth7.g
19-
$PYTHON findSim.py ./Curated/FindSim-Gu2004_fig3B.tsv --model models/synSynth7.g
36+
# Following takes a lot of time to run.
37+
#$PYTHON findSim.py ./Curated/FindSim-Gu2004_fig3B.tsv --model models/synSynth7.g
2038
$PYTHON findSim.py ./Curated/FindSim-Ji2010_fig1C_ERK_acute.tsv --model models/synSynth7.g
2139
$PYTHON findSim.py ./Curated/FindSim-Bhalla1999_fig4C.tsv --model models/synSynth7.g

0 commit comments

Comments
 (0)