Skip to content

Commit

Permalink
Fix: handle edge case in synapse location calculation with syn_descri…
Browse files Browse the repository at this point in the history
…ption (#184)

* Handle edge case in synapse location when using syn_description

* fix: replace deprecated get_cmap with colormaps

* fix unit tests
  • Loading branch information
ilkilic authored May 24, 2024
1 parent 2de98ed commit ebd0c1d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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

0 comments on commit ebd0c1d

Please sign in to comment.