Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Make cell morphology plots reflect actual cell size #481

Merged
merged 11 commits into from Jul 18, 2022
25 changes: 25 additions & 0 deletions hnn_core/cell.py
Expand Up @@ -208,6 +208,10 @@ def __repr__(self):
def L(self):
return self._L

@L.setter
def L(self, value):
self._L = value
rythorpe marked this conversation as resolved.
Show resolved Hide resolved

@property
def diam(self):
return self._diam
Expand All @@ -216,6 +220,10 @@ def diam(self):
def end_pts(self):
return self._end_pts

@end_pts.setter
def end_pts(self, value):
self._end_pts = value


class Cell:
"""Create a cell object.
Expand Down Expand Up @@ -640,3 +648,20 @@ def plot_morphology(self, ax=None, cell_types=None, show=True):
The matplotlib 3D axis handle.
"""
return plot_cell_morphology(self, ax=ax, show=show)

def update_end_pts(self):
rythorpe marked this conversation as resolved.
Show resolved Hide resolved
""""Create cell and copy coordinates to Section.end_pts"""
self._create_sections(self.sections, self.topology)
section_names = list(self.sections.keys())

for name in section_names:
nrn_pts = self._nrn_sections[name].psection()['morphology'][
'pts3d']

del self._nrn_sections[name]

x0, y0, z0 = nrn_pts[0][0], nrn_pts[0][1], nrn_pts[0][2]
x1, y1, z1 = nrn_pts[1][0], nrn_pts[1][1], nrn_pts[1][2]
self.sections[name]._end_pts = [[x0, y0, z0], [x1, y1, z1]]

self._nrn_sections = dict()
10 changes: 10 additions & 0 deletions hnn_core/tests/test_cell.py
@@ -1,5 +1,6 @@
import pytest
import pickle
import numpy as np

import matplotlib

Expand Down Expand Up @@ -79,6 +80,15 @@ def test_cell():
with pytest.raises(ValueError, match='sec_name_apical must be an'):
cell.build(sec_name_apical='blah')

# Test length modification
sec_name = 'soma'
new_L = 5.0
cell.sections[sec_name].L = new_L
cell.update_end_pts()
new_pts = np.array(cell.sections[sec_name].end_pts)
new_dist = np.linalg.norm(new_pts[0, :] - new_pts[1, :])
np.isclose(new_L, new_dist)


def test_artificial_cell():
"""Test artificial cell object."""
Expand Down