Skip to content

Commit

Permalink
Merge pull request #10 from borismarin/consistency
Browse files Browse the repository at this point in the history
Added bound checks for activation variables
  • Loading branch information
borismarin committed Apr 30, 2014
2 parents 8e450fc + ed70b6a commit 6b08c11
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 12 deletions.
4 changes: 3 additions & 1 deletion omv/analyzers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from resting import RestingAnalyzer
from morphology import MorphologyAnalyzer
from temperature import TemperatureAnalyzer
from activation import ActivationVariableAnalyzer

OMVAnalyzers = {
'spike times' : SpikeAnalyzer,
'dry': DryRunAnalyzer,
'resting': RestingAnalyzer,
'morphology': MorphologyAnalyzer,
'temperature': TemperatureAnalyzer
'temperature': TemperatureAnalyzer,
'activation variables': ActivationVariableAnalyzer
}


Expand Down
38 changes: 38 additions & 0 deletions omv/analyzers/activation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from analyzer import OMVAnalyzer
from utils import timeseries as ts
from utils import filenode as fn
from ..common.output import inform

class ActivationVariableAnalyzer(OMVAnalyzer):

def parse_observable(self):
if 'file' in self.observable:
f = fn.FileNodeHelper(self.observable['file'])
return f.get_timeseries()

def __call__(self):
obs = self.parse_observable()
allin = ts.all_within_bounds(obs, (0,1))
if not allin:
inform('Activation variable outside of (0,1) interval: ', obs)
return allin




















4 changes: 2 additions & 2 deletions omv/analyzers/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def __call__(self):
exp = self.parse_expected()
try:
tolerance = float(self.observable['tolerance'])
except (TypeError, KeyError) as e: #observable can be None
except (TypeError, KeyError): #observable can be None
tolerance = 1e-1

are_close = ts.compare_arrays((obs, exp), tolerance)
if not are_close:
inform('Comparison of \n %s \n and \n %s \n failed against tolerance %g'%(obs,exp, tolerance))
inform('Comparison of \n%s\nand\n%s\nfailed against tolerance %g'%(obs,exp, tolerance))

return are_close
2 changes: 1 addition & 1 deletion omv/analyzers/utils/filenode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def __init__(self, fn):
self.filename = fn['path']
self.columns = fn.get('columns', (0,1))
self.header = fn.get('header', 0)
self.scaling = fn.get('scaling', (1,1))
self.scaling = fn.get('scaling', [1.]*len(self.columns))

def __str__(self):
return str({'file name' : str(self.filename),
Expand Down
22 changes: 16 additions & 6 deletions omv/analyzers/utils/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def detect_spikes(v, method='threshold', threshold=0.):
#see for example scipy.signal.find_peaks_cwt
return extrema

def load_data_file(fname, columns=(0,1), header_lines=0, scaling=(1,1)):
def load_data_file(fname, columns=(0,1), header_lines=0, scaling=1):
from numpy import loadtxt
ts = loadtxt(fname, usecols=columns, skiprows=header_lines)
return (ts * scaling).T #scratch your heads, matlab users!
return ts * scaling

def compare_arrays(arrays, tolerance):
from numpy import allclose, array
Expand All @@ -32,7 +32,6 @@ def compare_dictionaries(d1, d2, tolerance=0.1):
a2 = array([d2[k] for k in ks if k in d2])
return allclose(a1, a2, tolerance)


def load_spike_times(spiketime):
if isinstance(spiketime, list):
return spiketime
Expand All @@ -42,7 +41,7 @@ def load_spike_times(spiketime):
def spikes_from_timeseries(ts, **kwargs):
method = kwargs.get('method', 'threshold')
threshold = kwargs.get('threshold', 0)
t, v = ts
t, v = ts.T
spk_idx = detect_spikes(v, method, threshold)
return t[spk_idx]

Expand All @@ -51,9 +50,17 @@ def spikes_from_datafile(path, columns=(0,1), header=0, method='threshold', thre
spk_idx = detect_spikes(v, method, threshold)
return t[spk_idx]

def average_resting(tv, window):
def average_resting(tv, window, col=1):
from numpy import mean
return mean(tv[1, -window:])
return mean(tv[-window:,col])

def all_within_bounds(ts, bounds=(0,1)):
from numpy import all
return all((ts[:,1:]>=bounds[0]) & (ts[:,1:]<=bounds[1]))

def all_nonzero(ts):
from numpy import all
return all(ts[:,1:])

def test_detect_spikes():
from numpy import array, all, arange
Expand All @@ -70,3 +77,6 @@ def test_detect_spikes():






2 changes: 1 addition & 1 deletion omv/common/output.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def inform(msg, pars=[], indent=0):
print '\t'*indent + msg, pars if pars else ''
print '\t'*indent + msg, pars if pars is not None else ''



Expand Down
2 changes: 1 addition & 1 deletion omv/parse_omt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def parse_omt(omt_path):

backend = OMVBackends[engine](join(omt_root, target))
for obsname, observable in observables.iteritems():
expected = experiment['expected'][obsname]
expected = experiment['expected'].get(obsname, None)
tests.append(OMVAnalyzers[obsname](observable, expected, backend))

backend.run()
Expand Down

0 comments on commit 6b08c11

Please sign in to comment.