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

apply small refactorings #132

Merged
merged 7 commits into from
Feb 16, 2024
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
60 changes: 25 additions & 35 deletions bluecellulab/cell/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ def __init__(self,
# time recording needs this push
self.soma.push()
self.hocname = neuron.h.secname(sec=self.soma).split(".")[0]
self.somatic = [x for x in public_hoc_cell(self.cell).somatic]
self.basal = [x for x in public_hoc_cell(self.cell).basal] # dend is same as basal
self.apical = [x for x in public_hoc_cell(self.cell).apical]
self.axonal = [x for x in public_hoc_cell(self.cell).axonal]
self.all = [x for x in public_hoc_cell(self.cell).all]
self.somatic = list(public_hoc_cell(self.cell).somatic)
self.basal = list(public_hoc_cell(self.cell).basal) # dend is same as basal
self.apical = list(public_hoc_cell(self.cell).apical)
self.axonal = list(public_hoc_cell(self.cell).axonal)
self.all = list(public_hoc_cell(self.cell).all)
self.record_dt = record_dt
self.add_recordings(['self.soma(0.5)._ref_v', 'neuron.h._ref_t'],
dt=self.record_dt)
Expand Down Expand Up @@ -557,11 +557,7 @@ def add_replay_minis(self,
syn_description, self
)

if 'Weight' in connection_modifiers:
weight_scalar = connection_modifiers['Weight']
else:
weight_scalar = 1.0

weight_scalar = connection_modifiers.get('Weight', 1.0)
exc_mini_frequency, inh_mini_frequency = mini_frequencies \
if mini_frequencies is not None else (None, None)

Expand All @@ -570,11 +566,10 @@ def add_replay_minis(self,
# SpontMinis in sim config takes precedence of values in nodes file
if 'SpontMinis' in connection_modifiers:
spont_minis_rate = connection_modifiers['SpontMinis']
elif synapse.mech_name in ["GluSynapse", "ProbAMPANMDA_EMS"]:
spont_minis_rate = exc_mini_frequency
else:
if synapse.mech_name in ["GluSynapse", "ProbAMPANMDA_EMS"]:
spont_minis_rate = exc_mini_frequency
else:
spont_minis_rate = inh_mini_frequency
spont_minis_rate = inh_mini_frequency

if spont_minis_rate is not None and spont_minis_rate > 0:
sec = self.get_hsection(post_sec_id)
Expand All @@ -587,8 +582,7 @@ def add_replay_minis(self,
self.syn_mini_netcons[synapse_id].delay = 0.1
self.syn_mini_netcons[synapse_id].weight[0] = weight * weight_scalar
# set netcon type
nc_param_name = 'nc_type_param_{}'.format(
synapse.hsynapse).split('[')[0]
nc_param_name = f'nc_type_param_{synapse.hsynapse}'.split('[')[0]
if hasattr(neuron.h, nc_param_name):
nc_type_param = int(getattr(neuron.h, nc_param_name))
# NC_SPONTMINI
Expand Down Expand Up @@ -652,7 +646,7 @@ def get_childrensections(self, parentsection: HocObjectType) -> list[HocObjectTy
"""Get the children section of a neuron section."""
number_children = neuron.h.SectionRef(sec=parentsection).nchild()
children = []
for index in range(0, int(number_children)):
for index in range(int(number_children)):
children.append(neuron.h.SectionRef(sec=self.soma).child[index])
return children

Expand All @@ -676,10 +670,10 @@ def getAxialCurrentRecording(self, section):
self.get_recording(secname)
self.get_recording(child)

def somatic_branches(self):
def somatic_branches(self) -> None:
"""Show the index numbers."""
nchild = neuron.h.SectionRef(sec=self.soma).nchild()
for index in range(0, int(nchild)):
for index in range(int(nchild)):
secname = neuron.h.secname(sec=neuron.h.SectionRef(
sec=self.soma).child[index])
if "axon" not in secname:
Expand All @@ -696,9 +690,9 @@ def somatic_branches(self):
public_hoc_cell(self.cell).nSecBasal + apicnumber)
logger.info((apicnumber, secnumber))
else:
raise Exception(
"somaticbranches: No apic or \
dend found in section %s" % secname)
raise BluecellulabError(
f"somaticbranches: No apic or dend found in section {secname}"
)

@staticmethod
@deprecated("Use bluecellulab.cell.section_distance.EuclideanSectionDistance instead.")
Expand Down Expand Up @@ -740,7 +734,7 @@ def apical_trunk(self):

children = [
neuron.h.SectionRef(sec=max_diam_section).child[index]
for index in range(0, int(neuron.h.SectionRef(
for index in range(int(neuron.h.SectionRef(
sec=max_diam_section).nchild()))]
if len(children) == 0:
break
Expand Down Expand Up @@ -805,18 +799,14 @@ def add_synapse_replay(
@property
def info_dict(self):
"""Return a dictionary with all the information of this cell."""

cell_info = {}

cell_info['synapses'] = {}
for sid, synapse in self.synapses.items():
cell_info['synapses'][sid] = synapse.info_dict

cell_info['connections'] = {}
for sid, connection in self.connections.items():
cell_info['connections'][sid] = connection.info_dict

return cell_info
return {
'synapses': {
sid: synapse.info_dict for sid, synapse in self.synapses.items()
},
'connections': {
sid: connection.info_dict for sid, connection in self.connections.items()
}
}

def delete(self):
"""Delete the cell."""
Expand Down
2 changes: 1 addition & 1 deletion bluecellulab/circuit/circuit_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def extract_synapses(
edges = self._circuit.edges
# select edges that are in the projections, if there are projections
if projections is None or len(projections) == 0:
edge_population_names = [x for x in edges]
edge_population_names = list(edges)
elif isinstance(projections, str):
edge_population_names = [x for x in edges if edges[x].source.name == projections]
else:
Expand Down
2 changes: 1 addition & 1 deletion bluecellulab/plotwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, var_list, cell, xlim, ylim, title):
# Sorry, don't see a way but disable this warning to access this
colors = pylab.rcParams['axes.prop_cycle'].by_key()['color']

linecolors = [x for x in itertools.islice(itertools.cycle(colors), 0, 50)]
linecolors = list(itertools.islice(itertools.cycle(colors), 0, 50))

self.line[var_name] = pylab.Line2D(
time, recording, label=var_name,
Expand Down
7 changes: 2 additions & 5 deletions bluecellulab/psection.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def getTreeVarBounds(self, variable):

def getAllPDescendants(self):
"""Return all the psection that are descendants of this psection."""
pdescendants = [x for x in self.pchildren]
pdescendants = list(self.pchildren)
for child in self.pchildren:
pdescendants += child.getAllPDescendants()
return pdescendants
Expand Down Expand Up @@ -158,10 +158,7 @@ def treeWidth(self):
if self.isLeaf:
treeWidth = self.maxsegdiam + self.xSpacing
else:
treeWidth = 0
for child in self.pchildren:
treeWidth += child.treeWidth()

treeWidth = sum(child.treeWidth() for child in self.pchildren)
return max(self.diam + self.xSpacing, treeWidth)

def treeHeight(self):
Expand Down