From cc7d74761cf1e01b903894b6a3947bb57636575d Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Tue, 7 Nov 2023 16:59:14 +0000 Subject: [PATCH] feat(connectivity-plots): move matrix plot to new sub-module --- pyneuroml/plot/Connectivity.py | 35 ++++++++++++++++++++++++++++++++++ pyneuroml/pynml.py | 17 ++--------------- 2 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 pyneuroml/plot/Connectivity.py diff --git a/pyneuroml/plot/Connectivity.py b/pyneuroml/plot/Connectivity.py new file mode 100644 index 000000000..e2878c889 --- /dev/null +++ b/pyneuroml/plot/Connectivity.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +""" +Connectivity plotting methods + +File: pyneuroml/plot/Connectivity.py + +Copyright 2023 NeuroML contributors +""" + +import logging + +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...") diff --git a/pyneuroml/pynml.py b/pyneuroml/pynml.py index 703e54022..82603364f 100644 --- a/pyneuroml/pynml.py +++ b/pyneuroml/pynml.py @@ -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: