Skip to content

Commit

Permalink
#173 poc nwb jupyter widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
filippomc committed Jun 10, 2020
1 parent 7a8b4e1 commit d4f8ac7
Show file tree
Hide file tree
Showing 9 changed files with 5,558 additions and 7,105 deletions.
55 changes: 40 additions & 15 deletions nwb_explorer/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,60 @@ def createNotebook(filename):
f.close()






def get_model_interpreter(runtime_project) -> NWBModelInterpreter:
return get_model_interpreter_from_variable(runtime_project.model.variables[0])
def get_model_interpreter(clientId, projectId) -> NWBModelInterpreter:
data_manager = DataManagerHelper.getDataManager()
geppetto_project = data_manager.getGeppettoProjectById(projectId)
geppetto_manager = GeppettoManager.get_instance(clientId)
runtime_project = geppetto_manager.get_runtime_project(geppetto_project)
model_interpreter = get_model_interpreter_from_variable(runtime_project.model.variables[0])
return model_interpreter


class NWBController: # pytest: no cover

@get('/api/image', {'Content-type': 'image/png', 'Cache-Control': 'max-age=600'})
def image(handler: IPythonHandler, name: str, interface: str, projectId: str = '0', index: str = '0') -> str:
def image(handler: IPythonHandler, name: str, interface: str, projectId: str = '0', index: str = '0', clientId=None) -> str:
if not any([name, interface, projectId]):
return "Bad request"

manager = GeppettoManager()

dataManager = DataManagerHelper.getDataManager()
project = dataManager.getGeppettoProjectById(project_id=int(projectId))
model_interpreter = get_model_interpreter(clientId, projectId)

project = manager.get_runtime_project(project)
model_interpreter = get_model_interpreter(project)
nwb_reader = model_interpreter.nwb_reader
return model_interpreter.nwb_reader.get_image(name=name, interface=interface, index=index)

return nwb_reader.get_image(name=name, interface=interface, index=index)
def get_model(self, clientId, projectId):
data_manager = DataManagerHelper.getDataManager()
geppetto_project = data_manager.getGeppettoProjectById(projectId)
geppetto_manager = GeppettoManager.get_instance(clientId)
runtime_project = geppetto_manager.get_runtime_project(geppetto_project)
model_interpreter = get_model_interpreter(runtime_project)
return model_interpreter

@get('/notebook')
def new_notebook(handler: IPythonHandler, path):
if not os.path.exists(path):
logging.info("Creating notebook {}".format(path))
createNotebook(path)
handler.redirect('notebooks/' + path)

@get('/nwbwidget')
def get_nwb_widget(handler: IPythonHandler, path='', projectId: str = '0', clientId=None):
from ipywidgets.embed import embed_snippet, html_template
from nwbwidgets import nwb2widget

model_interpreter = get_model_interpreter(clientId, projectId)
nwbfile = model_interpreter.get_nwbfile()

widget = nwb2widget(nwbfile.acquisition)

snippet = embed_snippet([widget])

values = {
'title': '',
'snippet': snippet,
}

template = html_template


return template.format(**values)

2 changes: 2 additions & 0 deletions webapp/actions/flexlayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export const newWidget = ({ path, component, panelName }) => ({
}
});

export const showNWBWidget = path => (newWidget({ path, component: 'NWBWidget', panelName: 'bottomPanel' }));

export const updateWidget = (newConf => ({
type: UPDATE_WIDGET,
data: newConf
Expand Down
5 changes: 5 additions & 0 deletions webapp/components/NWBListViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class NWBListViewer extends Component {
this.showPlot = this.props.showPlot ? this.props.showPlot : () => console.debug('showPlot not defined in ' + typeof this);
this.addToPlot = props.addToPlot ? props.addToPlot : () => console.debug('addToPlot not defined in ' + typeof this);
this.showImageSeries = props.showImg ? props.showImg : () => console.debug('showImg not defined in ' + typeof this);
this.showNWBWidget = props.showNWBWidget ? props.showNWBWidget : () => console.debug('showNWBWidget not defined in ' + typeof this);
this.updateDetailsWidget = this.props.updateDetailsWidget ? this.props.updateDetailsWidget : () => console.debug('updateDetailsWidget not defined in ' + typeof this);
this.modelSettings = {};
this.state = { update: 0 }
Expand Down Expand Up @@ -60,6 +61,10 @@ export default class NWBListViewer extends Component {
this.showPlot({ path, color });
}

clickShowNWBWidget ({ path }) {
this.showNWBWidget(path);
}

clickShowImg ({ path }) {
this.showImageSeries({ path });
}
Expand Down
8 changes: 8 additions & 0 deletions webapp/components/WidgetFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ export default class WidgetFactory{

return getConsole();

}
case "NWBWidget": {

return <iframe
src={`/nwbwidget?path=${widgetConfig.path}&projectId=${window.Project.getId()}&clientId=${GEPPETTO.MessageSocket.getClientID()}`}
style={{ width: '100%', flex: 1 }}
/>;

}
}
}
Expand Down
10 changes: 10 additions & 0 deletions webapp/components/configuration/listViewerConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ const conf = [
tooltip: "Plot image series"
},
},
{
id: "nwbwidget",
customComponent: IconComponent,
configuration: {
icon: "eye",
action: "clickShowNWBWidget",
label: "NWB widget",
tooltip: "Show as NWB widget",
}
},
{
id: "addToPlot",
customComponent: AddToPlotComponent,
Expand Down
3 changes: 2 additions & 1 deletion webapp/components/reduxconnect/NWBListViewerContainer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import NWBListViewer from '../NWBListViewer';
import { showPlot, showImageSeries, updateDetailsWidget, addToPlot } from '../../actions/flexlayout';
import { showPlot, showImageSeries, updateDetailsWidget, addToPlot, showNWBWidget } from '../../actions/flexlayout';

const mapStateToProps = state => ({ modelSettings: state.nwbfile.modelSettings });

Expand All @@ -9,6 +9,7 @@ const mapDispatchToProps = dispatch => ({
showImg: instanceDescriptor => dispatch(showImageSeries(instanceDescriptor)),
addToPlot: instanceDescriptor => dispatch(addToPlot(instanceDescriptor)),
updateDetailsWidget: path => dispatch(updateDetailsWidget(path)),
showNWBWidget: path => dispatch(showNWBWidget(path)),
});

export default connect(mapStateToProps, mapDispatchToProps)(NWBListViewer);
Loading

0 comments on commit d4f8ac7

Please sign in to comment.