Skip to content

Commit 572be48

Browse files
authored
Merge pull request #262 from MetaCell/feature/215_plots
Feature/215 plots
2 parents 82805af + 72b9dcc commit 572be48

5 files changed

Lines changed: 178 additions & 124 deletions

File tree

netpyne_ui/netpyne_geppetto.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def compileModMechFiles(self, compileMod, modFolder):
158158

159159
def loadModel(self, args): # handles all data coming from a .json file (default file system for Netpyne)
160160
def remove(dictionary):
161-
# remove reserved keys such as __dict__, __Method__, etc
161+
# remove reserved keys such as __dict__, __Method__, etc
162162
# they appear when we do sim.loadAll(json_file)
163163
if isinstance(dictionary, dict):
164164
for key, value in list(dictionary.items()):
@@ -244,7 +244,7 @@ def importModel(self, modelParameters):
244244
netParamsPath = str(modelParameters["netParamsPath"])
245245
sys.path.append(netParamsPath)
246246
os.chdir(netParamsPath)
247-
# Import Module
247+
# Import Module
248248
netParamsModuleName = importlib.import_module(str(modelParameters["netParamsModuleName"]))
249249
# Import Model attributes
250250
self.netParams = getattr(netParamsModuleName, str(modelParameters["netParamsVariable"]))
@@ -257,7 +257,7 @@ def importModel(self, modelParameters):
257257
simConfigPath = str(modelParameters["simConfigPath"])
258258
sys.path.append(simConfigPath)
259259
os.chdir(simConfigPath)
260-
# Import Module
260+
# Import Module
261261
simConfigModuleName = importlib.import_module(str(modelParameters["simConfigModuleName"]))
262262
# Import Model attributes
263263
self.simConfig = getattr(simConfigModuleName, str(modelParameters["simConfigVariable"]))
@@ -428,6 +428,9 @@ def getDirList(self, dir=None, onlyDirs=False, filterFiles=False):
428428
file_list.append({'title': f, 'path': ff})
429429
return dir_list + file_list
430430

431+
def checkAvailablePlots(self):
432+
return analysis.checkAvailablePlots()
433+
431434
def getPlot(self, plotName, LFPflavour, theme='gui'):
432435
try:
433436
with redirect_stdout(sys.__stdout__):
@@ -443,21 +446,18 @@ def getPlot(self, plotName, LFPflavour, theme='gui'):
443446

444447
if plotName in ("iplotConn", "iplot2Dnet") and sim.net.allCells:
445448
# To prevent unresponsive kernel, we don't show conns if they become too many
446-
numConn = sum([len(cell.conns) for cell in sim.net.allCells if cell.conns])
447-
if numConn > NUM_CONN_LIMIT:
449+
num_conn = sum([len(cell.conns) for cell in sim.net.allCells if cell.conns])
450+
if num_conn > NUM_CONN_LIMIT:
448451
args["showConns"] = False
449452

450453
html = getattr(analysis, plotName)(**args)
451454
if not html or html == -1:
452455
return ""
453456

454457
# some plots return "fig", some return "(fig, data)"
455-
if plotName == 'iplotRaster':
456-
html = html[0]
457-
elif plotName == 'iplotRxDConcentration':
458-
html = html[0]
459-
elif plotName == 'iplot2Dnet':
458+
if plotName in ('iplotRaster', 'iplotRxDConcentration', 'iplot2Dnet'):
460459
html = html[0]
460+
461461
return html
462462

463463
else:
@@ -479,9 +479,6 @@ def getPlot(self, plotName, LFPflavour, theme='gui'):
479479
return [ui.getSVG(fig)]
480480
else:
481481
return figData
482-
483-
484-
485482
except Exception as e:
486483
# TODO: Extract these two lines as a function and call it in every catch clause
487484
err = "There was an exception in %s():" % (e.plotName)
@@ -529,8 +526,18 @@ def getMechParams(self, mechanism):
529526
return [value[:-(len(mechanism) + 1)] for value in params]
530527

531528
def getAvailablePlots(self):
532-
plots = ["iplotRaster", "iplotSpikeHist", "plotSpikeStats", "iplotRatePSD", "iplotTraces", "iplotLFP",
533-
"plotShape", "plot2Dnet", "iplotConn", "granger"]
529+
plots = [
530+
"iplotRaster",
531+
"iplotSpikeHist",
532+
"plotSpikeStats",
533+
"iplotRatePSD",
534+
"iplotTraces",
535+
"iplotLFP",
536+
"plotShape",
537+
"plot2Dnet",
538+
"iplotConn",
539+
"granger"
540+
]
534541

535542
return [plot for plot in plots if plot not in list(self.simConfig.analysis.keys())]
536543

webapp/components/layout/WidgetFactory.tsx

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as React from 'react'
2-
3-
import { NetPyNEInstantiated, HTMLViewer } from '..';
1+
import * as React from 'react';
42

53
import {
4+
HTMLViewer,
5+
NetPyNEInstantiated,
66
NetPyNESynapses,
77
NetPyNEConnectivityRules,
88
NetPyNECellRules,
@@ -11,19 +11,18 @@ import {
1111
NetPyNESimConfig,
1212
NetPyNEPopulations,
1313
NetPyNEPlots,
14-
NetPyNEPythonConsole
15-
} from "../";
14+
NetPyNEPythonConsole,
15+
} from '..';
1616

1717
import { WidgetComponent } from './model';
1818

1919
export default class WidgetFactory {
20-
2120
widgets = {};
2221

2322
// FIXME didn't found a way to make standard refs work here, so using a custom callback
2423
refs: { [id: string]: WidgetComponent } = {};
2524

26-
constructor() {
25+
constructor () {
2726
this.widgets = {};
2827
}
2928

@@ -34,15 +33,15 @@ export default class WidgetFactory {
3433
*
3534
* @param { id, name, component, panelName, [instancePath], * } widgetConfig
3635
*/
37-
factory(widgetConfig) {
36+
factory (widgetConfig) {
3837
if (!this.widgets[widgetConfig.id]) {
3938
this.widgets[widgetConfig.id] = this.newWidget(widgetConfig);
4039
}
4140

4241
return this.widgets[widgetConfig.id];
4342
}
4443

45-
getComponents(): { [id: string]: WidgetComponent } {
44+
getComponents (): { [id: string]: WidgetComponent } {
4645
const confs: { [id: string]: WidgetComponent } = {};
4746
for (const wid in this.refs) {
4847
const component = this.refs[wid];
@@ -53,65 +52,77 @@ export default class WidgetFactory {
5352
return confs;
5453
}
5554

56-
getComponent(widgetId: string) {
55+
getComponent (widgetId: string) {
5756
return this.refs[widgetId];
5857
}
5958

60-
updateWidget(widgetConfig) {
59+
updateWidget (widgetConfig) {
6160
this.widgets[widgetConfig.id] = this.newWidget(widgetConfig);
6261
return this.widgets[widgetConfig.id];
6362
}
6463

65-
newWidget(widgetConfig) {
66-
const component = widgetConfig.component;
64+
newWidget (widgetConfig) {
65+
const { component } = widgetConfig;
6766
switch (component) {
68-
case "PythonConsole": {
67+
case 'PythonConsole': {
6968
return <NetPyNEPythonConsole/>;
7069
}
71-
case "D3Canvas":
72-
return <NetPyNEInstantiated/>
73-
case "Plot": {
74-
const data = window['plotCache'][widgetConfig.id]
75-
if (widgetConfig.method.plotMethod.startsWith("iplot")) {
70+
case 'D3Canvas':
71+
return <NetPyNEInstantiated/>;
72+
case 'Plot': {
73+
const data = window['plotCache'][widgetConfig.id];
74+
if (widgetConfig.method.plotMethod.startsWith('iplot')) {
7675
return (
77-
<div style={{ width: '100%', height: '100%', textAlign: "center" }}>
78-
<iframe name='dipole' srcDoc={data}
76+
<div style={{
77+
width: '100%',
78+
height: '100%',
79+
textAlign: 'center',
80+
}}
81+
>
82+
<iframe
83+
name="dipole"
84+
srcDoc={data}
7985
// onLoad={() => this.centerIframe('dipole')}
80-
style={{ border: 0, width: '100%', height: '100%' }}/>
86+
style={{
87+
border: 0,
88+
width: '100%',
89+
height: '100%',
90+
}}
91+
/>
8192
</div>
82-
)
93+
);
8394
}
8495
return (
8596
<HTMLViewer
8697
content={data}
8798
id={widgetConfig.id}
8899
/>
89-
)
100+
);
90101
}
91102

92-
case "popParams": {
93-
return <NetPyNEPopulations model={"netParams.popParams"}/>
103+
case 'popParams': {
104+
return <NetPyNEPopulations model="netParams.popParams"/>;
94105
}
95-
case "cellParams": {
96-
return <NetPyNECellRules model={"netParams.cellParams"}/>
106+
case 'cellParams': {
107+
return <NetPyNECellRules model="netParams.cellParams"/>;
97108
}
98-
case "synMechParams": {
99-
return <NetPyNESynapses model={"netParams.synMechParams"}/>
109+
case 'synMechParams': {
110+
return <NetPyNESynapses model="netParams.synMechParams"/>;
100111
}
101-
case "connParams": {
102-
return <NetPyNEConnectivityRules model={"netParams.connParams"}/>
112+
case 'connParams': {
113+
return <NetPyNEConnectivityRules model="netParams.connParams"/>;
103114
}
104-
case "stimSourceParams": {
105-
return <NetPyNEStimulationSources model={"netParams.stimSourceParams"}/>
115+
case 'stimSourceParams': {
116+
return <NetPyNEStimulationSources model="netParams.stimSourceParams"/>;
106117
}
107-
case "stimTargetParams": {
108-
return <NetPyNEStimulationTargets model={"netParams.stimTargetParams"}/>
118+
case 'stimTargetParams': {
119+
return <NetPyNEStimulationTargets model="netParams.stimTargetParams"/>;
109120
}
110-
case "simConfig": {
111-
return <NetPyNESimConfig model={"simConfig"}/>
121+
case 'simConfig': {
122+
return <NetPyNESimConfig model="simConfig"/>;
112123
}
113-
case "analysis": {
114-
return <NetPyNEPlots model={"simConfig.analysis"}/>
124+
case 'analysis': {
125+
return <NetPyNEPlots model="simConfig.analysis"/>;
115126
}
116127
}
117128
}

webapp/components/layout/actions.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,74 @@ export const ADD_WIDGET = 'ADD_WIDGET';
88
export const ADD_WIDGETS = 'ADD_WIDGETS';
99
export const RESET_LAYOUT = 'RESET_LAYOUT';
1010
export const DESTROY_WIDGET = 'DESTROY_WIDGET';
11-
export const ADD_PLOT_TO_EXISTING_WIDGET = 'ADD_PLOT_TO_EXISTING_WIDGET'
11+
export const ADD_PLOT_TO_EXISTING_WIDGET = 'ADD_PLOT_TO_EXISTING_WIDGET';
1212

13-
14-
export const newWidget = ({ path, component, panelName, ...others }) => ({
13+
export const newWidget = ({
14+
path, component, panelName, ...others
15+
}) => ({
1516
type: ADD_WIDGET,
1617
data: {
1718
id: path,
1819
instancePath: path,
19-
component: component,
20+
component,
2021
name: path,
2122
status: WidgetStatus.ACTIVE,
22-
panelName: panelName,
23-
...others
24-
}
23+
panelName,
24+
...others,
25+
},
2526
});
2627

27-
export const addWidget = widget => ({
28+
export const addWidget = (widget) => ({
2829
type: ADD_WIDGET,
29-
data: widget
30+
data: widget,
3031
});
3132

32-
export const addWidgets = widgets => ({
33+
export const addWidgets = (widgets) => ({
3334
type: ADD_WIDGETS,
34-
data: widgets
35+
data: widgets,
3536
});
3637

37-
export const setWidgets = widgets => ({
38+
export const setWidgets = (widgets) => ({
3839
type: SET_WIDGETS,
39-
data: widgets
40+
data: widgets,
4041
});
4142

42-
export const updateWidget = (newConf => ({
43+
export const updateWidget = ((newConf) => ({
4344
type: UPDATE_WIDGET,
44-
data: newConf
45-
}))
45+
data: newConf,
46+
}));
4647

47-
export const setLayout = (newLayout => ({
48+
export const setLayout = ((newLayout) => ({
4849
type: SET_LAYOUT,
49-
data: newLayout
50-
}))
50+
data: newLayout,
51+
}));
5152

52-
export const minimizeWidget = id => ({
53+
export const minimizeWidget = (id) => ({
5354
type: UPDATE_WIDGET,
5455
data: {
5556
id,
56-
status: WidgetStatus.MINIMIZED
57-
}
57+
status: WidgetStatus.MINIMIZED,
58+
},
5859

5960
});
6061

61-
export const maximizeWidget = id => ({
62+
export const maximizeWidget = (id) => ({
6263
type: UPDATE_WIDGET,
6364
data: {
6465
id,
65-
status: WidgetStatus.MAXIMIZED
66-
}
66+
status: WidgetStatus.MAXIMIZED,
67+
},
6768
});
68-
export const activateWidget = id => ({
69+
export const activateWidget = (id) => ({
6970
type: ACTIVATE_WIDGET,
70-
data: { id }
71+
data: { id },
7172

7273
});
7374

74-
export const destroyWidget = id => ({
75+
export const destroyWidget = (id) => ({
7576
type: DESTROY_WIDGET,
76-
data: { id }
77+
data: { id },
7778

7879
});
7980

80-
export const resetLayout = { type: RESET_LAYOUT, };
81+
export const resetLayout = { type: RESET_LAYOUT };

0 commit comments

Comments
 (0)