Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slight delay in generate network when extra_lems_components present #69

Merged
merged 4 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/LEMS_SimExample3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--

This LEMS file has been automatically generated using PyNeuroML v1.2.3 (libNeuroML v0.5.8)
This LEMS file has been automatically generated using PyNeuroML v1.2.13 (libNeuroML v0.5.9)

-->

Expand Down
2 changes: 1 addition & 1 deletion examples/LEMS_SimExample4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--

This LEMS file has been automatically generated using PyNeuroML v1.2.3 (libNeuroML v0.5.8)
This LEMS file has been automatically generated using PyNeuroML v1.2.13 (libNeuroML v0.5.9)

-->

Expand Down
4 changes: 2 additions & 2 deletions examples/test_files/.test.ex4.jnmleden.omt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ experiments:
spike detection:
method: threshold
threshold: -64
tolerance: 0.0002527679474217274
tolerance: 0.00025278058645101804

v1:
observables:
Expand All @@ -26,4 +26,4 @@ experiments:
spike detection:
method: threshold
threshold: -69
tolerance: 0.0002327287423609406
tolerance: 0.00023269200151868833
56 changes: 49 additions & 7 deletions neuromllite/MatrixHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@
from neuromllite.NetworkGenerator import _get_rng_for_network

import numpy as np
import os


class MatrixHandler(ConnectivityHandler):
colormaps_used = []

weight_arrays_to_show = {}
weight_array_figures = {}

def __init__(self, level=10, nl_network=None):
def __init__(self, level=10, nl_network=None, show_already=True, save_figs_to_dir=None):
self.nl_network = nl_network
self.level = level
self.show_already = show_already
self.save_figs_to_dir=save_figs_to_dir

self.rng, seed = _get_rng_for_network(self.nl_network)

Expand All @@ -34,11 +38,6 @@ def print_settings(self):
print_v("* level: %s" % self.level)
print_v("* is_cell_level: %s" % self.is_cell_level())
print_v("* CUTOFF_INH_SYN_MV: %s" % self.CUTOFF_INH_SYN_MV)
# print_v('* include_inputs: %s'%self.include_inputs)
# print_v('* scale_by_post_pop_size: %s'%self.scale_by_post_pop_size)
# print_v('* scale_by_post_pop_cond: %s'%self.scale_by_post_pop_cond)
# print_v('* min_weight_to_show: %s'%self.min_weight_to_show)
# print_v('* min_weight_to_show: %s'%self.min_weight_to_show)
print_v("*")
print_v("* Used values: ")
print_v("* colormaps_used: %s" % self.colormaps_used)
Expand Down Expand Up @@ -68,6 +67,9 @@ def finalise_document(self):
for v in self.proj_post_pops.values():
all_pops.append(v)

self.weight_matrices_generated = {}
self.weight_matrices_saved = {}

for pop in all_pops:
if self.is_cell_level():
for i in range(self.pop_sizes[pop]):
Expand Down Expand Up @@ -376,10 +378,22 @@ def finalise_document(self):
if proj_type in cbar_labels:
cbar.set_label(cbar_labels[proj_type])

if self.save_figs_to_dir:
safe = proj_type.replace(' ','_').replace('(','-').replace(')','-').replace('*','_').replace('/','_')
save_figure_to = os.path.join(self.save_figs_to_dir, '%s_%s.png'%(self.network_id, safe))
plt.savefig(save_figure_to, bbox_inches="tight")
print_v("Saved image to %s of plot: %s" % (save_figure_to, title))
self.weight_array_figures[title] = save_figure_to



print_v("Generating matrix for: %s" % self.network_id)


self.print_settings()

plt.show()
if self.show_already:
plt.show()

def handle_population(
self,
Expand Down Expand Up @@ -535,3 +549,31 @@ def finalise_projection(

def finalise_input_source(self, inputListId):
pass

if __name__ == "__main__":

from neuromllite.utils import load_network_json

tests = ['/Users/padraig/neuroConstruct/osb/cerebral_cortex/networks/del-Molino2017/NeuroML/delMolinoEtAl_low_baseline.json',
'/Users/padraig/NeuroMLlite/examples/Example12_MultiComp.json']

for test in tests:

network = load_network_json(test)

from neuromllite.NetworkGenerator import generate_network

level = 1
handler = MatrixHandler(level,
nl_network=network,
show_already=True,
save_figs_to_dir='.')

generate_network(
network, handler, always_include_props=True, base_dir=os.path.dirname(test)
)

print_v("Done with MatrixHandler...")

for w in handler.weight_arrays_to_show:
print('%s:\n%s'%(w, handler.weight_arrays_to_show[w]))
2 changes: 2 additions & 0 deletions neuromllite/NetworkGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import numpy as np
import os
import random
import time

import lems.api as lems # from pylems

Expand Down Expand Up @@ -913,6 +914,7 @@ def generate_neuroml2_from_network(

if len(extra_lems_components.components) > 0:
extra_lems_components.export_to_file(extra_lems_file)
time.sleep(0.5)

if validate and format == "xml":
from pyneuroml import pynml
Expand Down