From d4f8ac7ebb7b5495ca19d280ece0ef295f2cb910 Mon Sep 17 00:00:00 2001 From: Filippo Ledda Date: Wed, 10 Jun 2020 21:44:30 +0200 Subject: [PATCH] #173 poc nwb jupyter widgets --- nwb_explorer/api.py | 55 +- webapp/actions/flexlayout.js | 2 + webapp/components/NWBListViewer.js | 5 + webapp/components/WidgetFactory.js | 8 + .../configuration/listViewerConfiguration.js | 10 + .../reduxconnect/NWBListViewerContainer.js | 3 +- webapp/package-lock.json | 12570 +++++++--------- webapp/reducers/general.js | 2 +- webapp/webpack.config.dev.js | 8 + 9 files changed, 5558 insertions(+), 7105 deletions(-) diff --git a/nwb_explorer/api.py b/nwb_explorer/api.py index de2236c..c9483f9 100644 --- a/nwb_explorer/api.py +++ b/nwb_explorer/api.py @@ -44,31 +44,33 @@ 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): @@ -76,3 +78,26 @@ def new_notebook(handler: IPythonHandler, 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) + \ No newline at end of file diff --git a/webapp/actions/flexlayout.js b/webapp/actions/flexlayout.js index 59b7b56..e7a91b4 100644 --- a/webapp/actions/flexlayout.js +++ b/webapp/actions/flexlayout.js @@ -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 diff --git a/webapp/components/NWBListViewer.js b/webapp/components/NWBListViewer.js index ac36850..c9974d8 100644 --- a/webapp/components/NWBListViewer.js +++ b/webapp/components/NWBListViewer.js @@ -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 } @@ -60,6 +61,10 @@ export default class NWBListViewer extends Component { this.showPlot({ path, color }); } + clickShowNWBWidget ({ path }) { + this.showNWBWidget(path); + } + clickShowImg ({ path }) { this.showImageSeries({ path }); } diff --git a/webapp/components/WidgetFactory.js b/webapp/components/WidgetFactory.js index f6b63c5..62a8fa8 100644 --- a/webapp/components/WidgetFactory.js +++ b/webapp/components/WidgetFactory.js @@ -80,6 +80,14 @@ export default class WidgetFactory{ return getConsole(); + } + case "NWBWidget": { + + return