Skip to content

Commit

Permalink
allow arg fun as str type in Cell.get_rand_idx_area_and_distribution_…
Browse files Browse the repository at this point in the history
…norm
  • Loading branch information
Espen Hagen committed Nov 7, 2018
1 parent 3e62ac0 commit a6d3d3f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions LFPy/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import neuron
import numpy as np
import scipy
import scipy.stats
import sys
import posixpath
from warnings import warn
Expand Down Expand Up @@ -878,9 +878,11 @@ def get_rand_idx_area_and_distribution_norm(self, section='allsec', nidx=1,
depth filter
z_max: float
depth filter
fun : function or iterable
iterable (list, tuple, numpy.array) of function, probability
distribution in scipy.stats module
fun : function or str, or iterable of function or str
if function a scipy.stats method, if str, must be method in
scipy.stats module with the same name (like 'norm'),
if iterable (list, tuple, numpy.array) of function or str some
probability distribution in scipy.stats module
funargs : dict or iterable
iterable (list, tuple, numpy.array) of dict, arguments to fun.pdf
method (e.g., w. keys 'loc' and 'scale')
Expand Down Expand Up @@ -922,10 +924,14 @@ def get_rand_idx_area_and_distribution_norm(self, section='allsec', nidx=1,
assert((len(fun) == len(funargs)) & (len(fun) == len(funweights)))
mod = np.zeros(poss_idx.shape)
for f, args, scl in zip(fun, funargs, funweights):
if type(f) is str and f in dir(scipy.stats):
exec('f = scipy.stats.{}'.format(f))
df = f(**args)
mod += df.pdf(x=self.zmid[poss_idx])*scl
p *= mod
else:
if type(fun) is str and fun in dir(scipy.stats):
exec('fun = scipy.stats.{}'.format(fun))
df = fun(**funargs)
p *= df.pdf(x=self.zmid[poss_idx])
# normalize
Expand Down

0 comments on commit a6d3d3f

Please sign in to comment.