def load_neurite_features(filepath): '''Unpack relevant data into megadict''' stuff = defaultdict(lambda: defaultdict(list)) nrns = ezy.load_neurons(filepath) # unpack data into arrays for nrn in nrns: for t in NEURITES_: for feat in FEATURES: stuff[feat][str(t).split('.')[1]].extend( GET_NEURITE_FEATURE[feat](nrn, t) ) return stuff
def test_multiple_distr(filepath): '''Runs the distribution fit for multiple distributions and returns the optimal distribution along with the corresponding parameters. ''' # load a neuron from an SWC file population = ezy.load_neurons(filepath) # Create a list of basic distributions distr_to_check = ('norm', 'expon', 'uniform') # Get the soma radius of a lis of neurons soma_size = [n.get_soma_radius() for n in population] # Find the best fit distribution return st.optimal_distribution(soma_size, distr_to_check)
def extract_data(data_path, feature): '''Loads a list of neurons, extracts feature and transforms the fitted distribution in the correct format. Returns the optimal distribution, corresponding parameters, minimun and maximum values. ''' population = ezy.load_neurons(data_path) feature_data = [getattr(n, 'get_' + feature)() for n in population] try: opt_fit = stats.optimal_distribution(feature_data) except ValueError: from itertools import chain feature_data = list(chain(*feature_data)) opt_fit = stats.optimal_distribution(feature_data) return opt_fit
def extract_data(data_path, feature): """Loads a list of neurons, extracts feature and transforms the fitted distribution in the correct format. Returns the optimal distribution, corresponding parameters, minimun and maximum values. """ population = ezy.load_neurons(data_path) feature_data = [getattr(n, "get_" + feature)() for n in population] try: opt_fit = stats.optimal_distribution(feature_data) except ValueError: from itertools import chain feature_data = list(chain(*feature_data)) opt_fit = stats.optimal_distribution(feature_data) return opt_fit
def extract_data(files, feature, params=None): '''Loads a list of neurons, extracts feature and transforms the fitted distribution in the correct format. Returns the optimal distribution and corresponding parameters. Normal distribution params (mean, std) Exponential distribution params (loc, scale) Uniform distribution params (min, range) ''' neurons = ezy.load_neurons(files) if params is None: params = {} feature_data = [FEATURE_MAP[feature](n, params) for n in neurons] try: opt_fit = stats.optimal_distribution(feature_data) except ValueError: feature_data = list(chain(*feature_data)) opt_fit = stats.optimal_distribution(feature_data) return opt_fit
def extract_data(files, feature, params=None): '''Loads a list of neurons, extracts feature and transforms the fitted distribution in the correct format. Returns the optimal distribution and corresponding parameters. Normal distribution params (mean, std) Exponential distribution params (loc, scale) Uniform distribution params (min, range) ''' population = ezy.load_neurons(files) if params is None: params = {} feature_data = [getattr(n, 'get_' + feature)(**params) for n in population] try: opt_fit = stats.optimal_distribution(feature_data) except ValueError: from itertools import chain feature_data = list(chain(*feature_data)) opt_fit = stats.optimal_distribution(feature_data) return opt_fit
ax = axes[i, j] cell = [cells[j]] if not collapsible else cells feature = features[i] function(cell, feature, ax) _stylize(ax, cell, feature, i, j) if collapsible: ax.legend(loc="best", fontsize="small") return f if __name__ == "__main__": from neurom.ezy import load_neurons args = parse_args() try: nrns = load_neurons(args.datapath) except OSError: print "path not existing: {0}".format(args.datapath) sys.exit() fig = plot_feature_comparison(args.features, nrns, histogram, collapsible=args.collapsible) fig.savefig("output.png") pl.show()
parser.add_argument('datapath', help='Path to morphology data file or directory') parser.add_argument('feature', help='Feature available for the ezy.neuron') return parser.parse_args() if __name__ == '__main__': args = parse_args() data_path = args.datapath feature = args.feature population = ezy.load_neurons(data_path) feature_data = [getattr(n, 'get_' + feature)() for n in population] try: result = st.optimal_distribution(feature_data) except ValueError: from itertools import chain feature_data = list(chain(*feature_data)) result = st.optimal_distribution(feature_data) print "Optimal distribution fit for %s is: %s with parameters %s"\ % (feature, result.type, result.params)
def test_load_neurons_filenames(): nrns = ezy.load_neurons(FILENAMES) nt.assert_equal(len(nrns), 3) for nrn in nrns: nt.assert_true(isinstance(nrn, ezy.Neuron))
def test_load_neurons_directory(): nrns = ezy.load_neurons(DATA_PATH) nt.assert_equal(len(nrns), 5) for nrn in nrns: nt.assert_true(isinstance(nrn, ezy.Neuron))