diff --git a/pyneuroml/plot/PlotMorphology.py b/pyneuroml/plot/PlotMorphology.py index bb214946d..b3066de51 100644 --- a/pyneuroml/plot/PlotMorphology.py +++ b/pyneuroml/plot/PlotMorphology.py @@ -261,13 +261,24 @@ def plot_2D( verbose=False, optimized=True, ) - + if title is None: + try: + title = f"{nml_model.networks[0].id} from {nml_file}" + except IndexError: + title = f"{nml_model.cells[0].id} from {nml_file}" elif isinstance(nml_file, Cell): nml_model = NeuroMLDocument(id="newdoc") nml_model.add(nml_file) + if title is None: + title = f"{nml_model.cells[0].id}" elif isinstance(nml_file, NeuroMLDocument): nml_model = nml_file + if title is None: + try: + title = f"{nml_model.networks[0].id} from {nml_file.id}" + except IndexError: + title = f"{nml_model.cells[0].id} from {nml_file.id}" else: raise TypeError( "Passed model is not a NeuroML file path, nor a neuroml.Cell, nor a neuroml.NeuroMLDocument" @@ -283,12 +294,6 @@ def plot_2D( nml_model, verbose, nml_file if type(nml_file) is str else "" ) - if title is None: - if len(nml_model.networks) > 0: - title = "2D plot of %s from %s" % (nml_model.networks[0].id, nml_file) - else: - title = "2D plot of %s" % (nml_model.cells[0].id) - if verbose: logger.debug(f"positions: {positions}") logger.debug(f"pop_id_vs_cell: {pop_id_vs_cell}") @@ -296,6 +301,9 @@ def plot_2D( logger.debug(f"pop_id_vs_color: {pop_id_vs_color}") logger.debug(f"pop_id_vs_radii: {pop_id_vs_radii}") + # not used, clear up + del cell_id_vs_cell + fig, ax = get_new_matplotlib_morph_plot(title, plane2d) axis_min_max = [float("inf"), -1 * float("inf")] @@ -322,7 +330,8 @@ def plot_2D( except KeyError: pass - for pop_id, cell in pop_id_vs_cell.items(): + while pop_id_vs_cell: + pop_id, cell = pop_id_vs_cell.popitem() pos_pop = positions[pop_id] # type: typing.Dict[typing.Any, typing.List[float]] # reinit point_cells for each loop @@ -337,7 +346,8 @@ def plot_2D( except KeyError: pass - for cell_index, pos in pos_pop.items(): + while pos_pop: + cell_index, pos = pos_pop.popitem() 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 diff --git a/pyneuroml/plot/PlotMorphologyVispy.py b/pyneuroml/plot/PlotMorphologyVispy.py index af5eca998..f6a0d73b9 100644 --- a/pyneuroml/plot/PlotMorphologyVispy.py +++ b/pyneuroml/plot/PlotMorphologyVispy.py @@ -357,11 +357,25 @@ def plot_interactive_3D( verbose=False, optimized=True, ) + if title is None: + try: + title = f"{nml_model.networks[0].id} from {nml_file}" + except IndexError: + title = f"{nml_model.cells[0].id} from {nml_file}" + elif isinstance(nml_file, Cell): nml_model = NeuroMLDocument(id="newdoc") nml_model.add(nml_file) + if title is None: + title = f"{nml_model.cells[0].id}" + elif isinstance(nml_file, NeuroMLDocument): nml_model = nml_file + if title is None: + try: + title = f"{nml_model.networks[0].id} from {nml_file.id}" + except IndexError: + title = f"{nml_model.cells[0].id} from {nml_file.id}" else: raise TypeError( "Passed model is not a NeuroML file path, nor a neuroml.Cell, nor a neuroml.NeuroMLDocument" @@ -386,19 +400,17 @@ def plot_interactive_3D( marker_points = [] marker_colors = [] - if title is None: - try: - title = f"{nml_model.networks[0].id} from {nml_file}" - except IndexError: - title = f"{nml_model.cells[0].id} from {nml_file}" - logger.debug(f"positions: {positions}") logger.debug(f"pop_id_vs_cell: {pop_id_vs_cell}") logger.debug(f"cell_id_vs_cell: {cell_id_vs_cell}") logger.debug(f"pop_id_vs_color: {pop_id_vs_color}") logger.debug(f"pop_id_vs_radii: {pop_id_vs_radii}") - if len(positions.keys()) > 1: + # not used, clear up + print(f"Plotting {len(cell_id_vs_cell)} cells") + del cell_id_vs_cell + + if len(positions) > 1: only_pos = [] for posdict in positions.values(): for poss in posdict.values(): @@ -467,8 +479,9 @@ def plot_interactive_3D( except KeyError: pass - for pop_id, cell in pop_id_vs_cell.items(): - pos_pop = positions[pop_id] # type: typing.Dict[typing.Any, typing.List[float]] + while pop_id_vs_cell: + pop_id, cell = pop_id_vs_cell.popitem() + pos_pop = positions[pop_id] # reinit point_cells for each loop point_cells_pop = [] @@ -482,7 +495,8 @@ def plot_interactive_3D( except KeyError: pass - for cell_index, pos in pos_pop.items(): + while pos_pop: + cell_index, pos = pos_pop.popitem() 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 @@ -530,6 +544,7 @@ def plot_interactive_3D( or plot_type == "constant" or cell.id in constant_cells ): + logger.debug(f"Cell for 3d is: {cell.id}") pts, sizes, colors = plot_3D_cell_morphology( offset=pos, cell=cell, diff --git a/pyneuroml/utils/__init__.py b/pyneuroml/utils/__init__.py index f266da0c6..717b0c278 100644 --- a/pyneuroml/utils/__init__.py +++ b/pyneuroml/utils/__init__.py @@ -97,11 +97,12 @@ def extract_position_info( # document for inc in nml_model_copy.includes: incl_loc = os.path.abspath(os.path.join(base_path, inc.href)) - inc = read_neuroml2_file(incl_loc) - for acell in inc.cells: - if acell.id in required_cell_types: - acell.biophysical_properties = None - nml_model_copy.add(acell) + if os.path.isfile(incl_loc): + inc = read_neuroml2_file(incl_loc) + for acell in inc.cells: + if acell.id in required_cell_types: + acell.biophysical_properties = None + nml_model_copy.add(acell) cell_elements.extend(nml_model_copy.cells) cell_elements.extend(nml_model_copy.cell2_ca_poolses) @@ -111,10 +112,11 @@ def extract_position_info( # add any included cells to the main document for inc in nml_model_copy.includes: incl_loc = os.path.abspath(os.path.join(base_path, inc.href)) - inc = read_neuroml2_file(incl_loc) - for acell in inc.cells: - acell.biophysical_properties = None - nml_model_copy.add(acell) + if os.path.isfile(incl_loc): + inc = read_neuroml2_file(incl_loc) + for acell in inc.cells: + acell.biophysical_properties = None + nml_model_copy.add(acell) cell_elements.extend(nml_model_copy.cells) cell_elements.extend(nml_model_copy.cell2_ca_poolses)