Skip to content

Commit 355da95

Browse files
author
rodriguez-facundo
committed
Merge branch 'issue-79' into 'issue-79-2'
2 parents 07e2ecd + 774ba06 commit 355da95

1 file changed

Lines changed: 90 additions & 7 deletions

File tree

netpyne_ui/netpyne_geppetto.py

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,17 @@ def getAvailablePlots(self):
431431
plots = ["plotRaster", "plotSpikeHist", "plotSpikeStats","plotRatePSD", "plotTraces", "plotLFP", "plotShape", "plot2Dnet", "plotConn", "granger"]
432432
return [plot for plot in plots if plot not in list(self.simConfig.analysis.keys())]
433433

434-
def deleteParam(self, paramToDel):
435-
logging.debug("Checking if netParams."+paramToDel+" is not null")
436-
if eval("self.netParams."+paramToDel) is not None:
437-
exec("del self.netParams.%s" % (paramToDel))
438-
logging.debug('Parameter netParams.'+paramToDel+' has been deleted')
434+
def deleteParam(self, model, label):
435+
if isinstance(model, list): # just for cellParams
436+
if len(model)==1:
437+
self.netParams.cellParams[model[0]]["secs"].pop(label)
438+
elif len(model)==2:
439+
self.netParams.cellParams[model[0]]["secs"][model[1]]["mechs"].pop(label)
440+
else:
441+
pass
439442
else:
440-
logging.debug('Parameter '+paramToDel+' is null, not deleted')
441-
443+
getattr(self.netParams, model).pop(label)
444+
442445
def validateFunction(self, functionString):
443446
return validateFunction(functionString, self.netParams.__dict__)
444447

@@ -492,6 +495,86 @@ def header(title, spacer='-'):
492495
except:
493496
return utils.getJSONError("Error while importing the NetPyNE model", sys.exc_info())
494497

498+
499+
def propagate(self, obj, label, cond, new, old):
500+
for key in obj.keys():
501+
if label in list(obj[key][cond].keys()):
502+
if isinstance(obj[key][cond][label], str):
503+
if old==obj[key][cond][label]:
504+
if new=='' or new==None:
505+
obj[key].pop(label)
506+
else:
507+
obj[key][cond][label] = new
508+
509+
elif isinstance(obj[key][cond][label], list):
510+
if old in obj[key][cond][label]:
511+
if new=='' or new==None:
512+
obj[key][cond][label] = [ value for value in obj[key][cond][label] if value!=old]
513+
else:
514+
obj[key][cond][label] = [ value if value!=old else new for value in obj[key][cond][label] ]
515+
if len(obj[key][cond][label])==0:
516+
obj[key][cond].pop(label)
517+
else:
518+
pass
519+
520+
def propagate_field_rename(self, label, new, old):
521+
def unique(label=label, old=old):
522+
classes = []
523+
for p in self.netParams.popParams:
524+
if label in self.netParams.popParams[p]:
525+
classes.append(self.netParams.popParams[p][label])
526+
if classes.count(old)>1:
527+
return False
528+
else:
529+
return True
530+
531+
if label=='source':
532+
self.propagate_stim_source_rename(new, old)
533+
return True
534+
elif label=='synMech':
535+
self.propagate_syn_mech_rename(new, old)
536+
return True
537+
else:
538+
if unique():
539+
for (model, cond) in [['cellParams','conds'], ['connParams', 'preConds'], ['connParams', 'postConds'], ['stimTargetParams', 'conds']]:
540+
self.propagate(getattr(self.netParams, model), label, cond, new, old)
541+
return True
542+
else:
543+
return False
544+
545+
def propagate_section_rename(self, new, old):
546+
for label in self.netParams.cellParams:
547+
if 'secs' in self.netParams.cellParams[label]:
548+
for sec in self.netParams.cellParams[label]['secs']:
549+
if 'topol' in self.netParams.cellParams[label]['secs'][sec]:
550+
if 'parentSec' in self.netParams.cellParams[label]['secs'][sec]['topol']:
551+
if self.netParams.cellParams[label]['secs'][sec]['topol']['parentSec'] == old:
552+
if new == None:
553+
self.netParams.cellParams[label]['secs'][sec]['topol'].pop('parentSec')
554+
else:
555+
self.netParams.cellParams[label]['secs'][sec]['topol']['parentSec'] = new
556+
557+
def propagate_stim_source_rename(self, new, old):
558+
for label in self.netParams.stimTargetParams:
559+
if old==self.netParams.stimTargetParams[label]['source']:
560+
if new==None:
561+
self.netParams.stimTargetParams[label].pop('source')
562+
else:
563+
self.netParams.stimTargetParams[label]['source'] = new
564+
565+
def propagate_syn_mech_rename(self, new, old):
566+
for label in self.netParams.stimTargetParams:
567+
if 'source' in self.netParams.stimTargetParams[label]:
568+
if self.netParams.stimTargetParams[label]['source'] in self.netParams.stimSourceParams:
569+
if 'type' in self.netParams.stimSourceParams[self.netParams.stimTargetParams[label]['source']]:
570+
if self.netParams.stimSourceParams[self.netParams.stimTargetParams[label]['source']]['type']=='NetStim':
571+
if old==self.netParams.stimTargetParams[label]['synMech']:
572+
if new==None:
573+
self.netParams.stimTargetParams[label].pop('synMech')
574+
else:
575+
self.netParams.stimTargetParams[label]['synMech'] = new
576+
577+
495578
logging.info("Initialising NetPyNE UI")
496579
netpyne_geppetto = NetPyNEGeppetto()
497580
logging.info("NetPyNE UI initialised")

0 commit comments

Comments
 (0)