-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4d6cb3
commit 942fce0
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import tmd | ||
from view import polar_plots | ||
|
||
filename = './' | ||
|
||
pop = tmd.io.load_population(filename) | ||
|
||
# Get the data for a single cell | ||
res = polar_plots.get_histogram_polar_coordinates(pop.neurons[0], neurite_type='basal', N=30) | ||
|
||
# Plot the data for a single cell | ||
polar_plots.plot_polar_coordinates(res) | ||
|
||
# Extract the polar plots of all neurons in the population and save images | ||
# in a selected directory | ||
for n in pop.neurons: | ||
res = polar_plots.get_histogram_polar_coordinates(n, neurite_type='basal', N=30) | ||
polar_plots.plot_polar_coordinates(res, output_path='./PolarPlots/', output_name=n.name.split('/')[-1]) | ||
plt.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import numpy as np | ||
from matplotlib import pylab as plt | ||
|
||
def get_histogram_polar_coordinates(neuron, neurite_type='basal', N=25): | ||
''' | ||
''' | ||
def seg_angle(seg): | ||
mean_x = np.mean([seg[0][0], seg[1][0]]) | ||
mean_y = np.mean([seg[0][1], seg[1][1]]) | ||
|
||
return np.arctan2(mean_y, mean_x) | ||
|
||
segs = [] | ||
for tr in getattr(neuron, neurite_type): | ||
segs = segs + tr.get_segments() | ||
|
||
angles = np.array([seg_angle(s) for s in segs]) | ||
lens = [] | ||
|
||
for tr in getattr(neuron, neurite_type): | ||
lens = lens + tr.get_segment_lengths().tolist() | ||
|
||
angles = np.array(angles) | ||
lens = np.array(lens) | ||
|
||
step = 2*np.pi/N | ||
ranges = [[i*step -np.pi, (i+1)*step-np.pi] for i in xrange(N)] | ||
|
||
results = [] | ||
|
||
for r in ranges: | ||
results.append(r + [np.sum(lens[np.where((angles > r[0]) & (angles < r[1]))[0]])]) | ||
|
||
return results | ||
|
||
|
||
def plot_polar_coordinates(input_data, output_name=None, output_path=None, output_format='png'): | ||
''' | ||
''' | ||
fig = plt.figure() | ||
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) | ||
|
||
theta = np.array(input_data)[:,0] | ||
radii = np.array(input_data)[:,2] / np.max(input_data) | ||
width = 2*np.pi/len(input_data) | ||
bars = ax.bar(theta, radii, width=width, bottom=0.0, alpha=0.8) | ||
|
||
if output_path is not None: | ||
plt.savefig(output_path + '/Polar_' + output_name, format=output_format) |