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] MAINT: remove move_to_pos #314

Merged
merged 6 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Changelog
Bug
~~~

- Remove rounding error caused by repositioning of NEURON cell sections, by `Mainak Jas`_ and `Ryan Thorpe`_ in `#314 <https://github.com/jonescompneurolab/hnn-core/pull/314>`_

API
~~~
- New API for defining cell-cell connections. Custom connections can be added with :func:`~hnn_core.Network.add_connection`, by `Nick Tolley`_ in `#276 <https://github.com/jonescompneurolab/hnn-core/pull/276>`_
Expand Down
25 changes: 10 additions & 15 deletions hnn_core/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,22 @@ def _create_sections(self, p_secs, topology):
for height and xz plane for depth. This is opposite for model as a
whole, but convention is followed in this function ease use of gui.
"""
# distance from initial to final root postion
# Resolve: y-coordinate here corresponds to the z-coordinate in
# self.pos[2]
dx = self.pos[0] - self.p_secs['soma']['sec_pts'][0][0]
dy = self.pos[2] - self.p_secs['soma']['sec_pts'][0][1]
dz = self.pos[1] - self.p_secs['soma']['sec_pts'][0][2]

for sec_name in p_secs:
sec = h.Section(name=f'{self.name}_{sec_name}')
self.sections[sec_name] = sec

h.pt3dclear(sec=sec)
for pt in p_secs[sec_name]['sec_pts']:
h.pt3dadd(pt[0], pt[1], pt[2], 1, sec=sec)
h.pt3dadd(pt[0] + dx,
pt[1] + dy,
pt[2] + dz, 1, sec=sec)
Comment on lines +256 to +268
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consequences of these lines are very confusing to me (still: I realise nothing has changed in that respect in this PR). Are we reorienting the apical sections to align with the Z-axis here?

In any case, we now have a situation where net.pos_dict, Cell.pos and the Section end points are inconsistent, right?

@rythorpe are you planning to address this in the follow-up you mention? I'm working on some qualified opinions about the spacing-issue too, based on "reduced" model literature.

Copy link
Collaborator Author

@jasmainak jasmainak Jun 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we should be reorienting the apical sections to align with the Z-axis ... but maybe it's not the case?

The Section end points are specified relative to the Cell.pos or net.pos_dict ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that I think of it, to reorient along the Z-axis, you'd need to do:

dy = self.pos[1] - self.p_secs['soma']['sec_pts'][0][2]

what might be more clear though is to apply a trans matrix first:

trans = [[1, 0, 0], [0, 0, 1], [0, 1, 0]]
self.p_secs['soma']['sec_pts'] = np.dot(trans, self.p_secs['soma']['sec_pts'])

there is a wealth of functions we can copy from MNE :) There is even a function to align along a target axis:

https://github.com/mne-tools/mne-python/blob/b3f4b05b3933a3b73458205c7e786166f90ad1f7/mne/transforms.py#L298

that we can use to our advantage

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand your question @cjayb. Are you asking about the implementation in this PR or what we plan to do in later PRs?

If we change the section endpoints in params_default.py, I think we should do that in a separate PR.

sec.L = p_secs[sec_name]['L']
sec.diam = p_secs[sec_name]['diam']
sec.Ra = p_secs[sec_name]['Ra']
Expand Down Expand Up @@ -301,20 +310,6 @@ def build(self, sec_name_apical=None):
f'section of the current cell or None. '
f'Got {sec_name_apical}.')

def move_to_pos(self):
"""Move cell to position."""
x0 = self.sections['soma'].x3d(0)
y0 = self.sections['soma'].y3d(0)
z0 = self.sections['soma'].z3d(0)
dx = self.pos[0] * 100 - x0
dy = self.pos[2] - y0
dz = self.pos[1] * 100 - z0

for s in list(self.sections.values()):
for i in range(s.n3d()):
h.pt3dchange(i, s.x3d(i) + dx, s.y3d(i) + dy,
s.z3d(i) + dz, s.diam3d(i), sec=s)

# two things need to happen here for h:
# 1. dipole needs to be inserted into each section
# 2. a list needs to be created with a Dipole (Point Process) in each
Expand Down
8 changes: 0 additions & 8 deletions hnn_core/network_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ def _build(self):
self._all_spike_gids = h.Vector()

self._record_spikes()

self.move_cells_to_pos() # position cells in 2D grid
self._connect_celltypes()

if _get_rank() == 0:
Expand Down Expand Up @@ -482,7 +480,6 @@ def _record_spikes(self):
if _PC.gid_exists(gid):
_PC.spike_record(gid, self._spike_times, self._spike_gids)

# aggregate recording all the somatic voltages for pyr
def aggregate_data(self):
"""Aggregate somatic currents, voltages, and dipoles."""
for cell in self._cells:
Expand Down Expand Up @@ -516,11 +513,6 @@ def state_init(self):
elif cell.name == 'L5Basket':
seg.v = -64.9737

def move_cells_to_pos(self):
"""Move cells 3d positions to positions used for wiring."""
for cell in self._cells:
cell.move_to_pos()

def _clear_neuron_objects(self):
"""Clear up NEURON internal gid information.

Expand Down