Skip to content

Commit

Permalink
Merge pull request #705 from the-virtual-brain/EBR-39
Browse files Browse the repository at this point in the history
EBR-39: change contour function from phase plane
  • Loading branch information
liadomide authored Mar 28, 2024
2 parents 8c41a20 + f0aff3f commit 8c6c0f3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
5 changes: 2 additions & 3 deletions tvb_build/docker/requirements_group
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pytest-cov
pytest-xdist
pytest-benchmark
pytest-mock
matplotlib==3.5.3
matplotlib
h5py
typing
BeautifulSoup4
Expand All @@ -28,13 +28,12 @@ jinja2
nibabel>=4.0
sqlalchemy
alembic
allensdk==0.16.3
allensdk
werkzeug
gevent
cherrypy
MarkupSafe
decorator
tables==3.7.0
pandas
requests
simplejson
Expand Down
5 changes: 2 additions & 3 deletions tvb_framework/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pytest-cov
pytest-xdist
pytest-benchmark
pytest-mock
matplotlib==3.5.3
matplotlib
h5py
typing
BeautifulSoup4
Expand All @@ -28,13 +28,12 @@ jinja2
nibabel>=4.0
sqlalchemy
alembic
allensdk==0.16.3
allensdk
werkzeug
gevent
cherrypy
MarkupSafe
decorator
tables==3.7.0
pandas
requests
simplejson
Expand Down
4 changes: 2 additions & 2 deletions tvb_framework/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
TVB_TEAM = "Mihai Andrei, Lia Domide, Stuart Knock, Bogdan Neacsa, Paula Prodan, Paula Sansz Leon, Marmaduke Woodman"

TVB_INSTALL_REQUIREMENTS = ["alembic", "bctpy", "cherrypy", "docutils", "flask==2.3.3", "flask-restx",
"formencode", "gevent", "h5py", "Jinja2", "matplotlib==3.5.3", "nibabel", "numpy", "pandas",
"formencode", "gevent", "h5py", "Jinja2", "matplotlib", "nibabel", "numpy", "pandas",
"Pillow", "psutil", "python-keycloak", "requests", "requests-toolbelt>=0.10",
"scikit-learn", "scipy", "siibra==1.0a5", "simplejson", "six", "sqlalchemy",
"tables==3.7.0", "tvb-data", "tvb-gdist", "tvb-library", "tvb-storage", "werkzeug"]
"tvb-data", "tvb-gdist", "tvb-library", "tvb-storage", "werkzeug"]

# Packaging tvb-framework with REST server inside
with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as fd:
Expand Down
32 changes: 13 additions & 19 deletions tvb_framework/tvb/adapters/visualizers/phase_plane_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,24 @@
# good idea to use a proper library for this.

try:
from matplotlib import _cntr
# older matplotlib

def nullcline(x, y, z):
c = _cntr.Cntr(x, y, z)
# trace a contour
res = c.trace(0.0)
if not res:
return numpy.array([])
# result is a list of arrays of vertices and path codes
# (see docs for matplotlib.path.Path)
nseg = len(res) // 2
segments, codes = res[:nseg], res[nseg:]
return segments

except ImportError:
from matplotlib import _contour
# newer matplotlib >= 2.2
# old matplotlib

def nullcline(x, y, z):
c = _contour.QuadContourGenerator(x, y, z, None, True, 0)
segments = c.create_contour(0.0)
return segments[0]


except ImportError:
import matplotlib.pyplot as plt
# new matplotlib, version 3.8.3

def nullcline(x, y, z):
c = plt.contour(x, y, z, levels=[0.0])
segments = c.collections[0].get_paths()
return segments

# how much courser is the grid used to show the vectors
GRID_SUBSAMPLE = 2
# Set the resolution of the phase-plane and sample trajectories.
Expand Down Expand Up @@ -212,8 +206,8 @@ def compute_phase_plane(self):
u, v = self._calc_phase_plane(self.default_sv, self.svx_ind, self.svy_ind, x, y)
u = u[..., self.mode] # project on active mode
v = v[..., self.mode]
xnull = [{'path': segment.tolist(), 'nullcline_index': 0} for segment in nullcline(x, y, u)]
ynull = [{'path': segment.tolist(), 'nullcline_index': 1} for segment in nullcline(x, y, v)]
xnull = [{'path': segment.vertices.tolist(), 'nullcline_index': 0} for segment in nullcline(x, y, u)]
ynull = [{'path': segment.vertices.tolist(), 'nullcline_index': 1} for segment in nullcline(x, y, v)]

# a courser mesh for the arrows
xsmall = x[::GRID_SUBSAMPLE, ::GRID_SUBSAMPLE]
Expand Down

0 comments on commit 8c6c0f3

Please sign in to comment.