Skip to content

Commit

Permalink
Merge pull request #437 from NeuroML/feat-improve-summary
Browse files Browse the repository at this point in the history
wip: improve `pynml-summary`
  • Loading branch information
sanjayankur31 authored Nov 8, 2024
2 parents 1a909ba + 76958b4 commit dd57bf6
Showing 1 changed file with 75 additions and 23 deletions.
98 changes: 75 additions & 23 deletions pyneuroml/utils/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import sys
import textwrap
import typing
from io import StringIO

from neuroml import Cell, NeuroMLDocument

from pyneuroml.io import read_neuroml2_file
from pyneuroml.utils.units import convert_to_units, get_value_in_si

Expand Down Expand Up @@ -91,31 +93,81 @@ def summary(

if nml2_doc is None:
nml2_file_name = sys.argv[1]
nml2_doc = read_neuroml2_file(nml2_file_name, include_includes=verbose, fix_external_morphs_biophys=True)

info = nml2_doc.summary(show_includes=False)

if verbose:
cell_info_str = ""
for cell in nml2_doc.cells:
cell_info_str += cell_info(cell) + "*\n"
lines = info.split("\n")
info = ""
still_to_add = False
for line in lines:
if "Cell: " in line:
still_to_add = True
pass
elif "Network: " in line:
still_to_add = False
if len(cell_info_str) > 0:
info += "%s" % cell_info_str
info += "%s\n" % line
else:
if still_to_add and "******" in line:
nml2_doc = read_neuroml2_file(
nml2_file_name, include_includes=verbose, fix_external_morphs_biophys=True
)

info = ""
# network, show full
if len(nml2_doc.networks) > 0:
info = nml2_doc.summary(show_includes=False)
if verbose:
cell_info_str = ""
for cell in nml2_doc.cells:
cell_info_str += cell_info(cell) + "*\n"
lines = info.split("\n")
info = ""
still_to_add = False
for line in lines:
if "Cell: " in line:
still_to_add = True
pass
elif "Network: " in line:
still_to_add = False
if len(cell_info_str) > 0:
info += "%s" % cell_info_str
info += "%s\n" % line
info += "%s\n" % line
else:
if still_to_add and "******" in line:
if len(cell_info_str) > 0:
info += "%s" % cell_info_str
info += "%s\n" % line
else:
# not a full network
# cell file
if len(nml2_doc.cells) > 0:
for cell in nml2_doc.cells:
if verbose:
info += cell_info(cell) + "*\n"
else:
cell_info_buffer = StringIO()
cell.summary(string_buffer=cell_info_buffer)
info += cell_info_buffer.getvalue()
# other things, just use info
else:
nml2_doc_info = nml2_doc.info(show_contents=True, return_format="dict")

doc_id = nml2_doc_info.pop("id", None)
try:
info += f"** Summary: id: {doc_id['members']} **\n\n"
except (KeyError, AttributeError):
info += f"** Summary: id: {nml2_file_name} **\n\n"

notes = nml2_doc_info.pop("notes", None)
if notes:
try:
info += f"{notes['members']}\n\n"
except KeyError:
pass

for attr, membs in nml2_doc_info.items():
if "members" in membs.keys():
amemb_info = ""
num_members = len(membs["members"])
ctr = 0
for amemb in membs["members"]:
ctr += 1
if isinstance(amemb, str):
amemb_info += amemb
else:
amemb_info += amemb.info(
show_contents="set", return_format="string"
)
if len(amemb_info) > 0:
info += f"*** {attr} ({ctr}/{num_members}) ***\n\n{amemb_info}\n*** {attr} ({ctr}/{num_members}) ***\n\n"
else:
info += f"*** {attr} ***\n\n{membs}\n*** {attr} ***\n\n"

print(info)


Expand Down

0 comments on commit dd57bf6

Please sign in to comment.