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

Chord diagram and other connectivity plot related refactoring #272

Draft
wants to merge 4 commits into
base: development
Choose a base branch
from
Draft
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
57 changes: 57 additions & 0 deletions pyneuroml/plot/Connectivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
"""
Connectivity plotting methods

File: pyneuroml/plot/Connectivity.py

Copyright 2023 NeuroML contributors
"""

import logging
import numpy as np

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


def plot_connectivity_matrix(filename, level):
"""Plot a connectivity matrix

:param filename: name of NeuroML file
:type filename: str
:param level: level at which to plot
:type level: int
"""
from neuromllite.MatrixHandler import MatrixHandler
from neuroml.hdf5.NeuroMLXMLParser import NeuroMLXMLParser

logger.info("Converting %s to matrix form, level %i" % (filename, level))

handler = MatrixHandler(level=level, nl_network=None)

currParser = NeuroMLXMLParser(handler)
currParser.parse(filename)
handler.finalise_document()

logger.info("Done with MatrixHandler...")


def plot_chord_diagram(filename):
"""Plot a chord connectivity diagram

:param filename: name of NeuroML file
:type filename: str
"""
from pyneuroml.pynml import read_neuroml2_file
from mne_connectivity.viz import plot_connectivity_circle

doc = read_neuroml2_file(filename)

nodes = [p.id for p in doc.networks[0].populations]
print(f"Nodes for chord diagram are: {nodes}")

con = []
# TODO: logic to get connectivity information
print(f"Connecitivity is {con}")

fix, axes = plot_connectivity_circle(con, nodes)
17 changes: 2 additions & 15 deletions pyneuroml/pynml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2312,23 +2312,10 @@ def evaluate_arguments(args):
exit_on_fail = True
elif args.matrix:
confirm_neuroml_file(f)
from neuromllite.MatrixHandler import MatrixHandler

level = int(args.matrix[0])
from pyneuroml.plot.Connectivity import plot_connectivity_matrix

logger.info("Converting %s to matrix form, level %i" % (f, level))

from neuroml.hdf5.NeuroMLXMLParser import NeuroMLXMLParser

handler = MatrixHandler(level=level, nl_network=None)

currParser = NeuroMLXMLParser(handler)

currParser.parse(f)

handler.finalise_document()

logger.info("Done with MatrixHandler...")
plot_connectivity_matrix(f, level)

exit(0)
elif args.validate:
Expand Down
12 changes: 12 additions & 0 deletions tests/plot/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pathlib as pl

from pyneuroml.plot import generate_plot, generate_interactive_plot
from pyneuroml.plot.Connectivity import plot_chord_diagram
from .. import BaseTestCase

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -86,6 +87,17 @@ def test_generate_interactive_plot(self):
self.assertIsFile(filename)
pl.Path(filename).unlink()

def test_chord_diagram(self):
"""Test the chord diagram plotter"""
filename = "tests/plot/test_chord_diagram.png"

# remove the file first
try:
pl.Path(filename).unlink()
except FileNotFoundError:
pass
plot_chord_diagram("./Izh2007Cells.net.nml")


if __name__ == "__main__":
unittest.main()
Loading