Skip to content

Commit 2dd8233

Browse files
author
facu.r
committed
use one function for all plots
1 parent 0cd8f2a commit 2dd8233

1 file changed

Lines changed: 64 additions & 140 deletions

File tree

netpyne_ui/netpyne_geppetto.py

Lines changed: 64 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -211,151 +211,25 @@ def getDirList(self, dir=None, onlyDirs = False):
211211
elif not onlyDirs:
212212
dir_list.append({'title': f, 'path': ff})
213213
return dir_list
214-
215-
def getNetPyNE2DNetPlot(self):
216-
args = self.getPlotSettings('plot2Dnet')
217-
fig = analysis.plot2Dnet(showFig=False, **args)
218-
if fig==-1:
219-
return fig
220-
svgs=[]
221-
svgs.append(ui.getSVG(fig))
222-
return svgs.__str__()
223-
224-
def getNetPyNEShapePlot(self):
225-
args = self.getPlotSettings('plotShape')
226-
fig = analysis.plotShape(showFig=False, **args)
227-
if fig==-1:
228-
return fig
229-
svgs = []
230-
svgs.append(ui.getSVG(fig))
231-
return svgs.__str__()
232-
233-
def getNetPyNEConnectionsPlot(self):
234-
args = self.getPlotSettings('plotConn')
235-
fig = analysis.plotConn(showFig=False, **args)
236-
if fig==-1:
237-
return fig
238-
svgs=[]
239-
svgs.append(ui.getSVG(fig))
240-
return svgs.__str__()
241-
242-
def getNetPyNERasterPlot(self):
243-
args = self.getPlotSettings('plotRaster')
244-
fig = analysis.plotRaster(showFig=False, **args)
245-
if fig==-1:
246-
return fig
247-
svgs=[]
248-
svgs.append(ui.getSVG(fig))
249-
return svgs.__str__()
250-
251-
def getNetPyNETracesPlot(self):
252-
args = self.getPlotSettings('plotTraces')
253-
figs = analysis.plotTraces(showFig=False, **args)
254-
if figs==-1:
255-
return figs
256-
svgs = []
257-
for key, value in figs.iteritems():
258-
logging.debug("Found plot for "+ key)
259-
svgs.append(ui.getSVG(value))
260-
return svgs.__str__()
261214

262-
def getNetPyNESpikeHistPlot(self):
263-
args = self.getPlotSettings('plotSpikeHist')
264-
fig = analysis.plotSpikeHist(showFig=False, **args)
265-
if fig==-1:
266-
return fig
267-
else:
268-
svgs=[]
269-
svgs.append(ui.getSVG(fig[0]))
270-
return svgs.__str__()
271-
272-
def getNetPyNESpikeStatsPlot(self):
273-
args = self.getPlotSettings('plotSpikeStats')
274-
fig = analysis.plotSpikeStats(showFig=False, **args)
275-
if fig==-1:
276-
return fig
277-
else:
278-
svgs=[]
279-
svgs.append(ui.getSVG(fig[0]))
280-
return svgs.__str__()
281-
282-
def getNetPyNEGrangerPlot(self):
283-
args = self.getPlotSettings('granger')
284-
fig = analysis.granger(plotFig=True, showFig=False, **args)
285-
if fig==-1:
286-
return fig
287-
else:
288-
fig=fig[-1]
289-
svgs=[]
290-
svgs.append(ui.getSVG(fig))
291-
return svgs.__str__()
292-
293-
def getNetPyNERatePSDPlot(self):
294-
args = self.getPlotSettings('plotRatePSD')
295-
fig = analysis.plotRatePSD(showFig=False, **args)
215+
def getPlot(self, plotName, LFPflavour):
216+
args = self.getPlotSettings(plotName)
217+
if LFPflavour:
218+
args['plots'] = [LFPflavour]
219+
fig = getattr(analysis, plotName)(showFig=False, **args)[0]
220+
print(fig)
296221
if fig==-1:
297222
return fig
298-
else:
299-
fig=fig[0]
300-
svgs = []
301-
svgs.append(ui.getSVG(fig))
302-
return svgs.__str__()
303-
304-
def getNetPyNELFPTimeSeriesPlot(self):
305-
args = self.getPlotSettings('plotLFP')
306-
args['plots'] = ['timeSeries']
307-
fig = analysis.plotLFP(showFig=False, **args)
308-
if fig==-1:
309-
return fig
310-
else:
311-
svgs = []
312-
svgs.append(ui.getSVG(fig[0][0]))
313-
return svgs.__str__()
314-
315-
def getNetPyNELFPPSDPlot(self):
316-
args = self.getPlotSettings('plotLFP')
317-
args['plots'] = ['PSD']
318-
fig = analysis.plotLFP(showFig=False, **args)
319-
if fig==-1:
320-
return fig
321-
else:
223+
elif isinstance(fig, list):
224+
return [ui.getSVG(fig[0])].__str__()
225+
elif isinstance(fig, dict):
322226
svgs = []
323-
svgs.append(ui.getSVG(fig[0][0]))
324-
325-
return svgs.__str__()
326-
327-
def getNetPyNELFPSpectrogramPlot(self):
328-
args = self.getPlotSettings('plotLFP')
329-
args['plots'] = ['spectrogram']
330-
fig = analysis.plotLFP(showFig=False, **args)
331-
if fig==-1:
332-
return fig
227+
for key, value in fig.iteritems():
228+
logging.debug("Found plot for "+ key)
229+
svgs.append(ui.getSVG(value))
230+
return svgs.__str__()
333231
else:
334-
svgs = []
335-
svgs.append(ui.getSVG(fig[0][0]))
336-
337-
return svgs.__str__()
338-
339-
def getNetPyNELFPLocationsPlot(self):
340-
args = self.getPlotSettings('plotLFP')
341-
args['plots'] = ['locations']
342-
fig = analysis.plotLFP(showFig=False, **args)
343-
if fig==-1:
344-
return fig
345-
else:
346-
svgs = []
347-
svgs.append(ui.getSVG(fig[0][0]))
348-
349-
return svgs.__str__()
350-
351-
def getNetPyNERxDConcentrationPlot(self):
352-
args = self.getPlotSettings('plotRxDConcentration')
353-
fig = analysis.plotRxDConcentration(showFig=False, **args)
354-
if fig==-1:
355-
return fig
356-
svgs=[]
357-
svgs.append(ui.getSVG(fig))
358-
return svgs.__str__()
232+
return [ui.getSVG(fig)].__str__()
359233

360234
def getAvailablePops(self):
361235
return netParams.popParams.keys()
@@ -415,6 +289,56 @@ def deleteParam(self, paramToDel):
415289

416290
def validateFunction(self, functionString):
417291
return utils.ValidateFunction(functionString, netParams.__dict__)
292+
293+
def generateScript(self, metadata):
294+
def convert2bool(string):
295+
return string.replace('true', 'True').replace('false', 'False')
296+
297+
def header(title, spacer='-'):
298+
return '\n# ' + title.upper() + ' ' + spacer*(77-len(title)) + '\n'
299+
300+
try :
301+
params = ['popParams' , 'cellParams', 'synMechParams']
302+
params += ['connParams', 'stimSourceParams', 'stimTargetParams']
303+
304+
fname = metadata['scriptName'] if metadata['scriptName'][-3:]=='.py' else metadata['scriptName']+'.py'
305+
306+
with open(fname, 'w') as script:
307+
script.write('from netpyne import specs, sim\n')
308+
script.write(header('documentation'))
309+
script.write("''' Script generated with NetPyNE-UI. Please visit:\n")
310+
script.write(" - https://www.netpyne.org\n - https://github.com/MetaCell/NetPyNE-UI\n'''\n")
311+
script.write(header('script', spacer='='))
312+
script.write('netParams = specs.NetParams()\n')
313+
script.write('simConfig = specs.SimConfig()\n')
314+
script.write(header('single value attributes'))
315+
for attr, value in netParams.__dict__.items():
316+
if attr not in params:
317+
if value!=getattr(specs.NetParams(), attr):
318+
script.write('netParams.' + attr + ' = ')
319+
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
320+
321+
script.write(header('network attributes'))
322+
for param in params:
323+
for key, value in getattr(netParams, param).items():
324+
script.write("netParams." + param + "['" + key + "'] = ")
325+
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
326+
327+
script.write(header('network configuration'))
328+
for attr, value in simConfig.__dict__.items():
329+
if value!=getattr(specs.SimConfig(), attr):
330+
script.write('netParams.' + attr + ' = ')
331+
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
332+
333+
script.write(header('create simulate analyze network'))
334+
script.write('sim.createSimulateAnalyze(netParams=netParams, simConfig=simConfig)\n')
335+
336+
script.write(header('end script', spacer='='))
337+
338+
return self.getJSONReply()
339+
340+
except:
341+
return self.getJSONError("Error while importing the NetPyNE model", traceback.format_exc())
418342

419343
class LoopTimer(threading.Thread):
420344
"""

0 commit comments

Comments
 (0)