Skip to content

Commit

Permalink
Minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
lidakanari committed Jan 22, 2019
1 parent 50a1584 commit 23d9dd2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
5 changes: 4 additions & 1 deletion tmd/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def load_neuron(input_file, line_delimiter='\n', soma_type=None,
data = read_h5(input_file=input_file, remove_duplicates=remove_duplicates)
neuron = Neuron.Neuron(name=input_file.replace('.h5', ''))

soma_ids = _np.where(_np.transpose(data)[1] == soma_index)[0]
try:
soma_ids = _np.where(_np.transpose(data)[1] == soma_index)[0]
except IndexError:
raise LoadNeuronError

# Extract soma information from swc
soma = Soma.Soma(x=_np.transpose(data)[SWC_DCT['x']][soma_ids],
Expand Down
12 changes: 7 additions & 5 deletions tmd/view/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ def diagram(ph, new_fig=True, subplot=False, color='b', alpha=1.0,

def persistence_image(ph, new_fig=True, subplot=111, xlims=None, ylims=None,
masked=False, colorbar=False, norm_factor=None, threshold=0.01,
vmin=None, vmax=None, cmap=jet_map, **kwargs):
vmin=None, vmax=None, cmap=jet_map, bw_method=None, **kwargs):
'''Plots the gaussian kernel
of the ph diagram that is given.
'''
if xlims is None or xlims is None:
xlims, ylims = analysis.get_limits(ph, coll=False)

Zn = analysis.get_persistence_image_data(ph, norm_factor=norm_factor, xlims=xlims, ylims=ylims)
Zn = analysis.get_persistence_image_data(ph, norm_factor=norm_factor, bw_method=bw_method,
xlims=xlims, ylims=ylims)
fig, ax = _cm.get_figure(new_fig=new_fig, subplot=subplot)

if masked:
Expand Down Expand Up @@ -150,12 +151,13 @@ def persistence_image_add(Z2, Z1, new_fig=True, subplot=111, xlims=None, ylims=N
return _cm.plot_style(fig=fig, ax=ax, **kwargs)


def persistence_image_average(ph_list, new_fig=True, subplot=111, xlims=None, ylims=None,
norm_factor=1.0, vmin=None, vmax=None, cmap=jet_map, **kwargs):
def persistence_image_average(ph_list, new_fig=True, subplot=111, xlims=None,
ylims=None, norm_factor=1.0, vmin=None, vmax=None,
cmap=jet_map, weighted=False, **kwargs):
"""Merges a list of ph diagrams and plots their respective average image.
"""
av_imgs = analysis.get_average_persistence_image(ph_list, xlims=xlims, ylims=ylims,
norm_factor=norm_factor)
norm_factor=norm_factor, weighted=weighted)
if xlims is None or xlims is None:
xlims, ylims = analysis.get_limits(ph_list)

Expand Down
25 changes: 17 additions & 8 deletions tmd/view/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _seg_2d(seg, x_add=0.0, y_add=0.0):
if _get_default('diameter', **kwargs):

scale = _get_default('diameter_scale', **kwargs)
linewidth = [2 * d * scale for d in tr.d]
linewidth = [d * scale for d in tr.d]

treecolor = _cm.get_color(_get_default('treecolor', **kwargs),
_utils.tree_type[tr.get_type()])
Expand Down Expand Up @@ -122,7 +122,7 @@ def _seg_2d(seg, x_add=0.0, y_add=0.0):
if _get_default('diameter', **kwargs):

scale = _get_default('diameter_scale', **kwargs)
linewidth = [2 * d * scale for d in tr.d]
linewidth = [d * scale for d in tr.d]

if tr.get_type() not in _utils.tree_type:
treecolor = 'black'
Expand Down Expand Up @@ -195,7 +195,7 @@ def soma(sm, plane='xy', new_fig=True, subplot=False, hadd=0.0, vadd=0.0, **kwar


def neuron(nrn, plane='xy', new_fig=True, subplot=False, hadd=0.0, vadd=0.0,
neurite_type='all', rotation=None, nosoma=False, **kwargs):
neurite_type='all', rotation=None, nosoma=False, new_axes=True, **kwargs):
'''Generates a 2d figure of the neuron,
that contains a soma and a list of trees.
Expand Down Expand Up @@ -262,7 +262,7 @@ def neuron(nrn, plane='xy', new_fig=True, subplot=False, hadd=0.0, vadd=0.0,
return None, 'No such plane found! Please select one of: xy, xz, yx, yz, zx, zy.'

# Initialization of matplotlib figure and axes.
fig, ax = _cm.get_figure(new_fig=new_fig, subplot=subplot)
fig, ax = _cm.get_figure(new_fig=new_fig, subplot=subplot, new_axes=new_axes)

kwargs['new_fig'] = False
kwargs['subplot'] = subplot
Expand All @@ -277,7 +277,6 @@ def neuron(nrn, plane='xy', new_fig=True, subplot=False, hadd=0.0, vadd=0.0,

if rotation == 'apical':
angle = _np.arctan2(nrn.apical[0].get_pca()[0], nrn.apical[0].get_pca()[1])
elif isinstance(rotation, list):
angle = _np.arctan2(rotation[1], rotation[0])

if neurite_type == 'all':
Expand Down Expand Up @@ -507,7 +506,7 @@ def _seg_3d(seg):
if _get_default('diameter', **kwargs):

scale = _get_default('diameter_scale', **kwargs)
linewidth = [2 * d * scale for d in tr.d]
linewidth = [d * scale for d in tr.d]

treecolor = _cm.get_color(_get_default('treecolor', **kwargs),
_utils.tree_type[tr.get_type()])
Expand Down Expand Up @@ -578,7 +577,7 @@ def _seg_3d(seg):
if _get_default('diameter', **kwargs):

scale = _get_default('diameter_scale', **kwargs)
linewidth = [2 * d * scale for d in tr.d]
linewidth = [d * scale for d in tr.d]

treecolor = _cm.get_color(_get_default('treecolor', **kwargs),
_utils.tree_type[tr.get_type()])
Expand Down Expand Up @@ -782,7 +781,7 @@ def population3d(pop, new_fig=True, new_axes=True, subplot=False, **kwargs):
# pylint: disable=too-many-locals
def density_cloud(obj, new_fig=True, subplot=111, new_axes=True, neurite_type='all',
bins=100, plane='xy', color_map=blues_map, alpha=0.8,
centered=True, colorbar=True, **kwargs):
centered=True, colorbar=True, plot_neuron=False, **kwargs):
"""
View the neuron morphologies of a population as a density cloud.
"""
Expand Down Expand Up @@ -817,6 +816,16 @@ def density_cloud(obj, new_fig=True, subplot=111, new_axes=True, neurite_type='a
_np.transpose(H2), cmap=color_map,
alhpa=alpha)

kwargs['new_fig'] = False
kwargs['subplot'] = subplot

if plot_neuron:
nrn = obj.neurons[0]
h, v, _ = nrn.soma.get_center()
soma(nrn.soma, plane='xy', hadd=-h, vadd=-v, **kwargs)
for temp_tree in getattr(nrn, ntypes):
tree(temp_tree, plane='xy', hadd=-h, vadd=-v, treecolor='r', **kwargs)

if colorbar:
_cm.plt.colorbar(plots)
# soma(neu.soma, new_fig=False)
Expand Down

0 comments on commit 23d9dd2

Please sign in to comment.