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

Fix: handle edge case in synapse location calculation with syn_description #184

Merged
merged 3 commits into from
May 24, 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
4 changes: 2 additions & 2 deletions bluecellulab/psegment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PSegment:

def __init__(self, hsegment, parentsection):
# import matplotlib as plt
from matplotlib import cm
from matplotlib import colormaps

self.hsegment = hsegment
self.parentsection = parentsection
Expand All @@ -35,7 +35,7 @@ def __init__(self, hsegment, parentsection):
self.figure = None
self.figX = None
self.figY = None
self.color_map = cm.get_cmap("hot")
self.color_map = colormaps["hot"]
self.ax = None
self.patch = None
self.plotvariable = None
Expand Down
4 changes: 4 additions & 0 deletions bluecellulab/synapse/synapse_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def determine_synapse_location(cls, syn_description: pd.Series, cell: bluecellul
not np.isnan(syn_description[SynapseProperty.AFFERENT_SECTION_POS])):
# position is pre computed in SONATA
location = syn_description[SynapseProperty.AFFERENT_SECTION_POS]
if location == 0.0:
location = 0.0000001
elif location >= 1.0:
location = 0.9999999
else:
ipt = syn_description[SynapseProperty.POST_SEGMENT_ID]
syn_offset = syn_description[SynapseProperty.POST_SEGMENT_OFFSET]
Expand Down
5 changes: 4 additions & 1 deletion tests/test_synapse/test_synapse_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ def test_determine_synapse_location(self):
# set afferent_section_pos
self.syn_description[SynapseProperty.AFFERENT_SECTION_POS] = 1.2
res = SynapseFactory.determine_synapse_location(self.syn_description, self.cell)
assert res.location == 1.2
assert res.location == 0.9999999
assert res.section.L == pytest.approx(9.530376893488256)
self.syn_description[SynapseProperty.AFFERENT_SECTION_POS] = 0
res = SynapseFactory.determine_synapse_location(self.syn_description, self.cell)
assert res.location == 0.0000001

def test_synlocation_to_segx(self):
ipt = 13
Expand Down