Skip to content

Commit

Permalink
ENH: cell shouldn't take soma_props as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmainak committed Apr 30, 2021
1 parent d07bec8 commit 9b1921b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
27 changes: 11 additions & 16 deletions hnn_core/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ class Cell:
Parameters
----------
soma_props : dict
The properties of the soma. Must contain
keys 'L', 'diam'.
pos : tuple
The (x, y, z) coordinates.
gid : int or None (optional)
Expand Down Expand Up @@ -109,9 +106,8 @@ class Cell:
GID of the cell in a network (or None if not yet assigned)
"""

def __init__(self, soma_props, pos, gid=None):
def __init__(self, pos, gid=None):
self.pos = pos
self.soma_props = soma_props
# preallocate dict to store dends
self.dends = dict()
self.synapses = dict()
Expand All @@ -127,11 +123,7 @@ def __init__(self, soma_props, pos, gid=None):

def __repr__(self):
class_name = self.__class__.__name__
soma_props = self.soma_props
s = ('soma: L %f, diam %f, Ra %f, cm %f' %
(soma_props['L'], soma_props['diam'],
soma_props['Ra'], soma_props['cm']))
return '<%s | %s>' % (class_name, s)
return f'<{class_name} | gid={self._gid}>'

@property
def gid(self):
Expand Down Expand Up @@ -176,13 +168,16 @@ def create_dends(self, p_dend):
self.dends[key].Ra = p_dend[key]['Ra']
self.dends[key].cm = p_dend[key]['cm']

def create_soma(self):
"""Create soma and set geometry."""
# make L_soma and diam_soma elements of self
# Used in shape_change() b/c func clobbers self.soma.L, self.soma.diam
soma_props = self.soma_props
def create_soma(self, soma_props):
"""Create soma and set geometry.
self.soma = h.Section(cell=self, name=soma_props['name'] + '_soma')
Parameters
----------
soma_props : dict
The properties of the soma. Must contain
keys 'L', 'diam', 'Ra', and 'cm'.
"""
self.soma = h.Section(cell=self, name=self.name + '_soma')
self.soma.L = soma_props['L']
self.soma.diam = soma_props['diam']
self.soma.Ra = soma_props['Ra']
Expand Down
18 changes: 8 additions & 10 deletions hnn_core/cell_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def _get_soma_props(p_all, cell_type):
'L': p_all[f'{cell_type}_soma_L'],
'diam': p_all[f'{cell_type}_soma_diam'],
'cm': p_all[f'{cell_type}_soma_cm'],
'Ra': p_all[f'{cell_type}_soma_Ra'],
'name': cell_type,
'Ra': p_all[f'{cell_type}_soma_Ra']
}


Expand All @@ -52,8 +51,7 @@ def _get_basket_soma_props(cell_name):
'L': 39.,
'diam': 20.,
'cm': 0.85,
'Ra': 200.,
'name': cell_name,
'Ra': 200.
}


Expand Down Expand Up @@ -99,12 +97,12 @@ def basket(pos, cell_name='L2Basket', gid=None):
cell : instance of BasketSingle
The basket cell.
"""
props = _get_basket_soma_props(cell_name)
cell = Cell(props, pos=pos, gid=gid)
cell = Cell(pos=pos, gid=gid)
cell.name = cell_name

cell.create_soma()
soma_props = _get_basket_soma_props(cell_name)
cell.create_soma(soma_props)
cell.sections = [cell.soma] # XXX: needed?
cell.name = cell_name
cell.secs = _secs_Basket()

cell.set_geometry()
Expand Down Expand Up @@ -186,7 +184,7 @@ def __init__(self, pos, celltype, override_params=None, gid=None):
# Get somatic, dendritic, and synapse properties
soma_props = _get_soma_props(p_all, self.name)

Cell.__init__(self, soma_props, pos=pos, gid=gid)
Cell.__init__(self, pos=pos, gid=gid)

level2_keys = ['L', 'diam', 'Ra', 'cm']
p_dend = _flat_to_nested(p_all, cell_type=self.name,
Expand All @@ -196,7 +194,7 @@ def __init__(self, pos, celltype, override_params=None, gid=None):

# Geometry
# dend Cm and dend Ra set using soma Cm and soma Ra
self.create_soma()
self.create_soma(soma_props)
self.create_dends(p_dend) # just creates the sections
self.sections = [self.soma] + list(self.dends.values())

Expand Down
10 changes: 4 additions & 6 deletions hnn_core/tests/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@

def test_cell():
"""Test cells object."""
# test that ExpSyn always takes nrn.Segment, not float
soma_props = {"L": 22.1, "diam": 23.4, "cm": 0.6195, "Ra": 200.0,
'name': 'test_cell'}
pos = (0., 0., 0.)

# GID is assigned exactly once for each cell, either at initialisation...
cell = Cell(soma_props=soma_props, pos=pos, gid=42)
cell = Cell(pos=pos, gid=42)
assert cell.gid == 42
with pytest.raises(RuntimeError,
match='Global ID for this cell already assigned!'):
cell.gid += 1
# ... or later
# cells can exist fine without gid
cell = Cell(soma_props=soma_props, pos=pos)
cell = Cell(pos=pos)
assert cell.gid is None # check that it's initialised to None
with pytest.raises(ValueError,
match='gid must be an integer'):
Expand All @@ -33,8 +30,9 @@ def test_cell():
with pytest.raises(ValueError,
match='gid must be an integer'):
# test init checks gid
cell = Cell(soma_props=soma_props, pos=pos, gid='one')
cell = Cell(pos=pos, gid='one')

# test that ExpSyn always takes nrn.Segment, not float
with pytest.raises(TypeError, match='secloc must be instance of'):
cell.syn_create(0.5, e=0., tau1=0.5, tau2=5.)

Expand Down

0 comments on commit 9b1921b

Please sign in to comment.