Skip to content

Commit d8f1702

Browse files
committed
improved the way of handling PointCell params if they specified in cellParams. some code enhancements
1 parent a1068e5 commit d8f1702

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

netpyne/cell/pointCell.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ class PointCell(Cell):
4141
def __init__(self, gid, tags, create=True, associateGid=True):
4242
from .. import sim
4343

44-
# enable defining pointCell properties directly in cellParams
45-
exclude = ['cellType']
46-
47-
# import IPython; IPython.embed()
48-
49-
if 'cellType' in tags and tags['cellType'] in sim.net.params.cellParams:
50-
tags.update({k: v for k, v in sim.net.params.cellParams[tags['cellType']].items() if k not in exclude})
51-
5244
# call parent calls (Cell) constructor to set gid and tags
5345
super(PointCell, self).__init__(gid, tags)
5446
self.hPointp = None

netpyne/network/pop.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ def __init__(self, label, tags):
3131
self.tags['pop'] = label
3232
self.cellGids = [] # list of cell gids beloging to this pop
3333

34-
self._setCellClass() # set type of cell
34+
self.cellModelClass, cellRuleForPointCell = self._resolveCellClass()
35+
3536
if self.cellModelClass == sim.PointCell:
36-
self.__handlePointCellParams()
37+
self.__handlePointCellParams(cellRuleForPointCell)
3738

3839
self.rand = h.Random() # random number generator
3940

@@ -481,18 +482,22 @@ def _createCellTags(self, ind=None, diversityFractions=None):
481482

482483
return cellTags
483484

484-
def _setCellClass(self):
485+
def _resolveCellClass(self):
485486
"""
486-
Set cell class (CompartCell, PointCell, etc)
487+
Determines cell class (CompartCell, PointCell, etc). Returns it, and a cellRule for PointCell if it refers to cellParams entry.
487488
"""
489+
cellRule = None
488490

489491
# Check whether it's a NeuroML2 based cell
490492
# ! needs updating to read cellModel info from cellParams
491-
if 'originalFormat' in self.tags:
492-
if self.tags['originalFormat'] == 'NeuroML2':
493-
self.cellModelClass = sim.NML2Cell
494-
if self.tags['originalFormat'] == 'NeuroML2_SpikeSource':
495-
self.cellModelClass = sim.NML2SpikeSource
493+
if origFormat := self.tags.get('originalFormat'):
494+
if origFormat == 'NeuroML2':
495+
cellClass = sim.NML2Cell
496+
elif origFormat == 'NeuroML2_SpikeSource':
497+
cellClass = sim.NML2SpikeSource
498+
else:
499+
print(f"Warning: unknown original format {origFormat} for population {self.tags['pop']}")
500+
cellClass = None
496501
else:
497502
# obtain cellModel either from popParams..
498503
cellModel = self.tags.get('cellModel')
@@ -504,25 +509,25 @@ def _setCellClass(self):
504509
cellRule = sim.net.params.cellParams.get(cellType, {})
505510
cellModel = cellRule.get('cellModel')
506511
else:
507-
# TODO: or throw error?
508-
pass
512+
print(f"Warning: no 'cellType' or 'cellModel' found for population {self.tags['pop']}. Cells will be created as CompartCell, but with no sections.")
509513

510514
# set cell class: CompartCell for compartmental cells of PointCell for point neurons (NetStims, IntFire1,...)
511515
if cellModel and hasattr(h, cellModel):
512516
# check if cellModel corresponds to an existing point process mechanism; if so, use PointCell
513-
self.cellModelClass = sim.PointCell
517+
cellClass = sim.PointCell
514518
else:
515519
# otherwise assume has sections and some cellParam rules apply to it; use CompartCell
516-
self.cellModelClass = sim.CompartCell
520+
cellClass = sim.CompartCell
517521
# if model is known but wasn't recognized, issue warning
518522
knownPointps = ['NetStim', 'DynamicNetStim', 'VecStim', 'IntFire1', 'IntFire2', 'IntFire4']
519523
if getattr(self.tags, 'cellModel', None) in knownPointps:
520524
print(
521525
'Warning: could not find %s point process mechanism required for population %s'
522526
% (cellModel, self.tags['pop'])
523527
)
528+
return cellClass, cellRule
524529

525-
def __handlePointCellParams(self):
530+
def __handlePointCellParams(self, cellRule=None):
526531

527532
if 'params' in self.tags and isinstance(self.tags['params'], dict):
528533
# in some cases, params for point cell may already be grouped in the nested 'params' dict.
@@ -559,6 +564,15 @@ def __handlePointCellParams(self):
559564

560565
CellParams.updateStringFuncsWithPopParams(self.tags['pop'], params)
561566

567+
# if popParams for PointCell contain 'cellType' and it exists in cellParams, take from there cellModel and params (if any)
568+
if cellRule:
569+
self.tags['cellModel'] = cellRule['cellModel']
570+
571+
for k,v in cellRule.get('params', {}).items():
572+
# But don't override! If param is already there, it comes from popParams, which takes precedence
573+
if k not in self.tags['params']:
574+
self.tags['params'][k] = v
575+
562576

563577
def calcRelativeSegCoords(self):
564578
"""Calculate segment coordinates from 3d point coordinates

0 commit comments

Comments
 (0)