@@ -35,37 +35,6 @@ def load_yaml(filename):
35
35
return data
36
36
37
37
38
- def load_network_json (filename ):
39
- """
40
- Load a NeuroMLlite network JSON file
41
- """
42
-
43
- data = load_json (filename )
44
-
45
- print_v ("Loaded network specification from %s" % filename )
46
-
47
- net = Network ()
48
- net = _parse_element (data , net )
49
-
50
- return net
51
-
52
-
53
- def load_simulation_json (filename ):
54
- """
55
- Load a NeuroMLlite simulation JSON file
56
- """
57
-
58
- with open (filename , "r" ) as f :
59
-
60
- data = json .load (f , object_hook = ascii_encode_dict )
61
-
62
- print_v ("Loaded simulation specification from %s" % filename )
63
-
64
- sim = Simulation ()
65
- sim = _parse_element (data , sim )
66
-
67
- return sim
68
-
69
38
70
39
def save_to_json_file (info_dict , filename , indent = 4 ):
71
40
@@ -326,34 +295,9 @@ def evaluate(expr, parameters={}, rng=None, array_format=FORMAT_NUMPY, verbose=F
326
295
return expr
327
296
328
297
329
- def get_pops_vs_cell_indices_seg_ids (recordSpec , network ):
330
-
331
- pvc = {}
332
- if recordSpec is not None :
333
- for p in recordSpec :
334
- indices = recordSpec [p ]
335
- if p == "all" :
336
- for pop in network .populations :
337
- cell_indices_seg_ids = _generate_cell_indices_seg_ids (
338
- pop .id , indices , network
339
- )
340
- pvc [pop .id ] = cell_indices_seg_ids
341
-
342
- else :
343
- # pop = network.get_child(p, 'populations')
344
- cell_indices_seg_ids = _generate_cell_indices_seg_ids (
345
- p , indices , network
346
- )
347
- pvc [p ] = cell_indices_seg_ids
348
-
349
- return pvc
350
-
351
-
352
298
"""
353
299
Translates a string like '3', '[0,2]' to a list
354
300
"""
355
-
356
-
357
301
def parse_list_like (list_str ):
358
302
359
303
if isinstance (list_str , int ):
@@ -376,176 +320,3 @@ def parse_list_like(list_str):
376
320
if "[" in list_str :
377
321
l = eval (list_str )
378
322
return l
379
-
380
-
381
- def _generate_cell_indices_seg_ids (pop_id , indices_segids , network ):
382
-
383
- a = {}
384
- pop = network .get_child (pop_id , "populations" )
385
-
386
- if not isinstance (indices_segids , str ) or not ":" in indices_segids :
387
- seg_ids = None
388
- indices = indices_segids
389
- else :
390
- indices = indices_segids .split (":" )[0 ]
391
- seg_id_info = indices_segids .split (":" )[1 ]
392
- l = parse_list_like (seg_id_info )
393
- print_v ("Parsed %s as %s" % (seg_id_info , l ))
394
- seg_ids = l
395
-
396
- if indices == "*" :
397
- size = evaluate (pop .size , network .parameters )
398
- for index in range (size ):
399
- a [index ] = seg_ids
400
- else :
401
- l = parse_list_like (indices )
402
- print_v ("Parsed %s (full: %s) as %s" % (indices , indices_segids , l ))
403
- for index in l :
404
- a [index ] = seg_ids
405
- return a
406
-
407
-
408
- def is_spiking_input_population (population , network ):
409
-
410
- cell = network .get_child (population .component , "cells" )
411
-
412
- return is_spiking_input_cell (cell )
413
-
414
-
415
- def is_spiking_input_cell (cell ):
416
- if cell .pynn_cell :
417
- if cell .pynn_cell == "SpikeSourcePoisson" :
418
- return True
419
- else :
420
- return False
421
-
422
-
423
- def is_spiking_input_nml_cell (component_obj ):
424
- if component_obj .__class__ .__name__ == "SpikeSourcePoisson" :
425
- return True
426
- else :
427
- return False
428
-
429
-
430
- def create_new_model (
431
- reference ,
432
- duration ,
433
- dt = 0.025 , # ms
434
- temperature = 6.3 , # degC
435
- default_region = None ,
436
- parameters = None ,
437
- cell_for_default_population = None ,
438
- color_for_default_population = "0.8 0 0" ,
439
- input_for_default_population = None ,
440
- synapses = [],
441
- simulation_seed = 12345 ,
442
- network_filename = None ,
443
- simulation_filename = None ,
444
- ):
445
-
446
- ################################################################################
447
- ### Build a new network
448
-
449
- net = Network (id = reference )
450
- net .notes = "A network model: %s" % reference
451
- net .temperature = temperature # degC
452
- if parameters :
453
- net .parameters = parameters
454
-
455
- ################################################################################
456
- ### Add some regions
457
-
458
- if default_region :
459
- if type (default_region ) == str :
460
- r1 = RectangularRegion (
461
- id = default_region , x = 0 , y = 0 , z = 0 , width = 1000 , height = 100 , depth = 1000
462
- )
463
- net .regions .append (r1 )
464
- default_region = r1
465
- else :
466
- net .regions .append (default_region )
467
-
468
- ################################################################################
469
- ### Add some cells
470
-
471
- if cell_for_default_population :
472
- net .cells .append (cell_for_default_population )
473
-
474
- ################################################################################
475
- ### Add some synapses
476
-
477
- for s in synapses :
478
- net .synapses .append (s )
479
-
480
- ################################################################################
481
- ### Add some populations
482
-
483
- if cell_for_default_population :
484
- pop = Population (
485
- id = "pop_%s" % cell_for_default_population .id ,
486
- size = 1 ,
487
- component = cell_for_default_population .id ,
488
- properties = {"color" : color_for_default_population },
489
- )
490
-
491
- if default_region :
492
- pop .region = default_region
493
-
494
- pop .random_layout = RandomLayout (region = default_region .id )
495
-
496
- net .populations .append (pop )
497
-
498
- ################################################################################
499
- ### Add a projection
500
-
501
- """
502
- net.projections.append(Projection(id='proj0',
503
- presynaptic=p0.id,
504
- postsynaptic=p1.id,
505
- synapse='ampa'))
506
-
507
- net.projections[0].random_connectivity=RandomConnectivity(probability=0.5)"""
508
-
509
- ################################################################################
510
- ### Add some inputs
511
-
512
- if input_for_default_population :
513
-
514
- net .input_sources .append (input_for_default_population )
515
-
516
- net .inputs .append (
517
- Input (
518
- id = "Stim_%s" % input_for_default_population .id ,
519
- input_source = input_for_default_population .id ,
520
- population = pop .id ,
521
- percentage = 100 ,
522
- )
523
- )
524
-
525
- ################################################################################
526
- ### Save to JSON format
527
-
528
- net .id = reference
529
-
530
- print (net .to_json ())
531
- if network_filename == None :
532
- network_filename = "%s.json" % net .id
533
- new_file = net .to_json_file (network_filename )
534
-
535
- ################################################################################
536
- ### Build Simulation object & save as JSON
537
-
538
- sim = Simulation (
539
- id = "Sim_%s" % reference ,
540
- network = new_file ,
541
- duration = duration ,
542
- dt = dt ,
543
- seed = simulation_seed ,
544
- recordTraces = {"all" : "*" },
545
- )
546
-
547
- if simulation_filename == None :
548
- simulation_filename = "%s.json" % sim .id
549
- sim .to_json_file (simulation_filename )
550
-
551
- return sim , net
0 commit comments