AnalyseNetwork.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import neuromllite
  2. from pyneuroml import pynml
  3. import os
  4. from neuromllite.MatrixHandler import MatrixHandler
  5. from neuromllite.GraphVizHandler import GraphVizHandler
  6. f = 'HL23Net_1.0.net.nml'
  7. #f = 'HL23Net_0.1.net.nml'
  8. level = 1
  9. print("Converting %s to matrix form, level %i" % (f, level))
  10. from neuroml.hdf5.NeuroMLXMLParser import NeuroMLXMLParser
  11. handler = MatrixHandler(level=level,
  12. nl_network=None,
  13. show_already=False,
  14. save_figs_to_dir='.')
  15. currParser = NeuroMLXMLParser(handler)
  16. currParser.parse(f)
  17. handler.finalise_document()
  18. level_gv = 6
  19. engine = 'dot'
  20. def generate_graph(level_gv, engine):
  21. handler_gv = GraphVizHandler(level_gv,
  22. engine=engine,
  23. nl_network=None,
  24. include_ext_inputs=False,
  25. include_input_pops=False,
  26. view_on_render=False)
  27. currParser_gv = NeuroMLXMLParser(handler_gv)
  28. currParser_gv.parse(f)
  29. handler_gv.finalise_document()
  30. os.rename('HL23Network.gv.png','%s.%s.%s.png'%(f,engine,level_gv))
  31. generate_graph(level_gv, engine)
  32. level_gv = 2
  33. engine = 'circo'
  34. generate_graph(level_gv, engine)
  35. info = '## Analysis of NeuroML network: %s\n\n'%(f)
  36. nml2_doc = pynml.read_neuroml2_file(f)
  37. net_info = nml2_doc.summary(show_includes=False)
  38. info +='```\n%s\n```\n'%(net_info)
  39. info +='![fig](%s.circo.2.png)\n'%(f)
  40. info +='![fig](%s.dot.6.png)\n'%(f)
  41. for w in handler.weight_arrays_to_show:
  42. info +='### %s\n'%w
  43. info +='![fig](%s)\n'%(handler.weight_array_figures[w])
  44. info +='```\n%s\n```\n'%(handler.weight_arrays_to_show[w])
  45. #weight_array_figures
  46. with open('Analysis_%s.md'%f,'w') as rm_file:
  47. rm_file.write(info)