From 93253ce6703398e319c66b7ff0dfd5a34b34b951 Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Mon, 10 Feb 2025 17:46:50 +0000 Subject: [PATCH 1/2] fix(morph-plot): handle files with single point cell types If a file contains the definition of a point cell type, for example, `IafTauRefCell`, we should still be able to plot the file, even if its only a single circle/sphere. Until now, we only handled files if they had multi-compartmental `Cell` or `Morphology` instances, and the plotter would crash for files that had other point cell types. --- pyneuroml/plot/PlotMorphology.py | 2 +- pyneuroml/plot/PlotMorphologyVispy.py | 8 ++++++-- pyneuroml/utils/__init__.py | 9 ++++++--- pyneuroml/utils/plot.py | 3 +-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pyneuroml/plot/PlotMorphology.py b/pyneuroml/plot/PlotMorphology.py index e42a9b4c..543c7e37 100644 --- a/pyneuroml/plot/PlotMorphology.py +++ b/pyneuroml/plot/PlotMorphology.py @@ -483,7 +483,7 @@ def plot_2D( radius = pop_id_vs_radii[pop_id] if pop_id in pop_id_vs_radii else 10 color = pop_id_vs_color[pop_id] if pop_id in pop_id_vs_color else None - if cell is None: + if cell is None or not isinstance(cell, Cell): plot_2D_point_cells( offset=pos, plane2d=plane2d, diff --git a/pyneuroml/plot/PlotMorphologyVispy.py b/pyneuroml/plot/PlotMorphologyVispy.py index 7848e112..9c338230 100644 --- a/pyneuroml/plot/PlotMorphologyVispy.py +++ b/pyneuroml/plot/PlotMorphologyVispy.py @@ -607,6 +607,9 @@ def plot_interactive_3D( # other networks else: plottable_nml_model = nml_model + + logger.debug(plottable_nml_model.info(show_contents=True)) + # what did we get? else: raise ValueError(f"Could not process argument: {nml_model}") @@ -671,7 +674,7 @@ def plot_interactive_3D( else: cell = list(pop_id_vs_cell.values())[0] - if cell is not None: + if cell is not None and isinstance(cell, Cell): view_min, view_max = get_cell_bound_box(cell) else: logger.debug("Got a point cell") @@ -790,7 +793,8 @@ def plot_interactive_3D( except AttributeError: logging.debug(f"Plotting a point cell at {pos}") - if cell is None: + # a point cell component type + if cell is None or not isinstance(cell, Cell): meshdata.append( ( f"{radius:.1f}", diff --git a/pyneuroml/utils/__init__.py b/pyneuroml/utils/__init__.py index 5a7dd075..e2afdb38 100644 --- a/pyneuroml/utils/__init__.py +++ b/pyneuroml/utils/__init__.py @@ -97,8 +97,12 @@ def extract_position_info( cell_elements = [] popElements = [] - cell_elements.extend(nml_model.cells) - cell_elements.extend(nml_model.cell2_ca_poolses) + members = nml_model.info(show_contents=True, return_format="dict") + + for member, mdict in members.items(): + if "cell" in mdict["type"].lower(): + cell_elements.extend(mdict["members"]) + # cell_elements.extend(nml_model.cell2_ca_poolses) # if there are no cells, look at morphologies if len(cell_elements) == 0: @@ -715,7 +719,6 @@ def get_model_file_list( lems_def_dir = get_model_file_list(inc, filelist, rootdir, lems_def_dir) elif rootfile.endswith(".sedml"): - try: import libsedml except ModuleNotFoundError: diff --git a/pyneuroml/utils/plot.py b/pyneuroml/utils/plot.py index 5ba53f90..499993a2 100644 --- a/pyneuroml/utils/plot.py +++ b/pyneuroml/utils/plot.py @@ -351,7 +351,6 @@ def load_minimal_morphplottable__model( model_members = list(vars(nml_model).keys()) required_members = [ "id", - "cells", "morphology", "cell2_ca_poolses", "networks", @@ -359,7 +358,7 @@ def load_minimal_morphplottable__model( "includes", ] for m in model_members: - if m not in required_members: + if m not in required_members and "cells" not in m: setattr(nml_model, m, None) logger.debug(f"Dropped {m}") From 7bc3b1b8d8762fb29be72a84781aab8e1aaa27fb Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Wed, 12 Feb 2025 17:41:06 +0000 Subject: [PATCH 2/2] fix(morph-plotter): ignore exception for an empty list --- pyneuroml/utils/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyneuroml/utils/__init__.py b/pyneuroml/utils/__init__.py index e2afdb38..6580132f 100644 --- a/pyneuroml/utils/__init__.py +++ b/pyneuroml/utils/__init__.py @@ -101,7 +101,10 @@ def extract_position_info( for member, mdict in members.items(): if "cell" in mdict["type"].lower(): - cell_elements.extend(mdict["members"]) + try: + cell_elements.extend(mdict["members"]) + except TypeError: + pass # cell_elements.extend(nml_model.cell2_ca_poolses) # if there are no cells, look at morphologies