def __init__(self, parent_app, imageseries, path_external_file=None, pixel_mask=None, foreign_time_window_controller=None, id='tiff_image_series'): super().__init__(id=id, figure={}, config={'displayModeBar': False}) self.parent_app = parent_app self.imageseries = imageseries self.pixel_mask = pixel_mask self.parent_files_path = Path(self.parent_app.server.config['DATA_PATH']).parent if foreign_time_window_controller is not None: self.time_window_controller = foreign_time_window_controller else: self.time_window_controller = None # Set controller if foreign_time_window_controller is None: tmin = get_timeseries_mint(imageseries) tmax = get_timeseries_maxt(imageseries) # self.time_window_controller = StartAndDurationController(tmax, tmin) else: self.time_window_controller = foreign_time_window_controller # Make figure component if path_external_file is not None: self.tiff = TiffFile(path_external_file) self.n_samples = len(self.tiff.pages) self.page = self.tiff.pages[0] self.n_y, self.n_x = page.shape # Read first frame self.image = imread(path_external_file, key=0) else: self.image = [] self.tiff = None self.out_fig = go.Figure( data=go.Heatmap( z=self.image, colorscale='gray', showscale=False, ), ) self.out_fig.update_layout( xaxis=go.layout.XAxis(showticklabels=False, ticks=""), yaxis=go.layout.YAxis(showticklabels=False, ticks=""), margin=dict( l=0, r=0, b=10, t=0, pad=0 ), height=380, ) self.figure = self.out_fig
def test_get_timeseries_mint(self): mint = get_timeseries_mint(self.ts) assert (mint == 0)
def __init__(self, nwb): super().__init__() self.nwb = nwb self.show_spikes = False self.btn_spike_times = widgets.Button(description='Show spike times', button_style='') self.btn_spike_times.on_click(self.spikes_viewer) # Start time and duration controller self.tmin = get_timeseries_mint( nwb.processing['ophys'].data_interfaces['fluorescence']. roi_response_series['roi_response_series']) self.tmax = get_timeseries_maxt( nwb.processing['ophys'].data_interfaces['fluorescence']. roi_response_series['roi_response_series']) self.time_window_controller = StartAndDurationController( tmin=self.tmin, tmax=self.tmax, start=0, duration=5, ) # Electrophys single trace self.electrical = SingleTracePlotlyWidget( timeseries=nwb.processing['ecephys']. data_interfaces['filtered_membrane_voltage'], foreign_time_window_controller=self.time_window_controller, ) self.electrical.out_fig.update_layout( title=None, showlegend=False, xaxis_title=None, yaxis_title='Volts', width=840, height=230, margin=dict(l=60, r=200, t=8, b=20), # yaxis={"position": 0, "anchor": "free"}, yaxis={ "range": [ min(self.electrical.out_fig.data[0].y), max(self.electrical.out_fig.data[0].y) ], "autorange": False }, xaxis={ "showticklabels": False, "ticks": "", "range": [ min(self.electrical.out_fig.data[0].x), max(self.electrical.out_fig.data[0].x) ], "autorange": False }) # Fluorescence single trace self.fluorescence = SingleTracePlotlyWidget( timeseries=nwb.processing['ophys'].data_interfaces['fluorescence']. roi_response_series['roi_response_series'], foreign_time_window_controller=self.time_window_controller, ) self.fluorescence.out_fig.update_layout( title=None, showlegend=False, width=840, height=230, margin=dict(l=60, r=200, t=8, b=20), yaxis_title='dF/F', yaxis={ "range": [ min(self.fluorescence.out_fig.data[0].y), max(self.fluorescence.out_fig.data[0].y) ], "autorange": False }, xaxis={ "range": [ min(self.fluorescence.out_fig.data[0].x), max(self.fluorescence.out_fig.data[0].x) ], "autorange": False, "constrain": "domain", "anchor": "free" }) # Two photon imaging self.photon_series = ImageSeriesWidget( imageseries=nwb.acquisition['raw_ophys'], foreign_time_window_controller=self.time_window_controller, ) self.photon_series.out_fig.update_layout( showlegend=False, margin=dict(l=30, r=5, t=65, b=65), ) # Frame controller self.frame_controller = widgets.FloatSlider( value=0, step=1 / self.nwb.acquisition['raw_ophys'].rate, min=self.time_window_controller.value[0], max=self.time_window_controller.value[1], description='Frame: ', style={'description_width': '55px'}, continuous_update=False, readout=False, orientation='horizontal', layout=Layout(width='645px'), ) # Add line traces marking Image frame point self.frame_point = go.Scatter(x=[0, 0], y=[-1000, 1000]) self.electrical.out_fig.add_trace(self.frame_point) self.fluorescence.out_fig.add_trace(self.frame_point) # Updates frame point self.frame_controller.observe(self.update_frame_point) # Updates list of valid spike times at each change in time range self.time_window_controller.observe(self.updated_time_range) # Layout hbox_header = widgets.HBox( [self.btn_spike_times, self.time_window_controller]) vbox_widgets = widgets.VBox([self.electrical, self.fluorescence]) hbox_widgets = widgets.HBox([vbox_widgets, self.photon_series]) self.children = [hbox_header, self.frame_controller, hbox_widgets] self.update_spike_traces()
def test_get_timeseries_mint(self): assert get_timeseries_mint(self.ts_rate) == 0 assert get_timeseries_mint(self.ts_timestamps) == 1
def __init__( self, position: Position, foreign_time_window_controller: StartAndDurationController = None, ): super().__init__() self.position = position joint_keys = list(position.spatial_series.keys()) self.joint_colors = [] for (joint, c) in zip(joint_keys, DEFAULT_PLOTLY_COLORS): self.joint_colors.append(c) self.spatial_series = position.spatial_series[joint_keys[0]] if foreign_time_window_controller is None: self.time_window_controller = StartAndDurationController( tmax=get_timeseries_maxt(self.spatial_series), tmin=get_timeseries_mint(self.spatial_series), start=0, duration=5, ) show_time_controller = True else: show_time_controller = False self.time_window_controller = foreign_time_window_controller frame_ind = timeseries_time_to_ind( self.spatial_series, self.time_window_controller.value[0]) self.sample_period = 1 / list( self.position.spatial_series.values())[0].rate self.play = Play( value=0, min=0, max=int(self.time_window_controller.duration.value / self.sample_period), step=1, interval=self.sample_period * 1000, ) joint_colors = [ to_hex(np.array(unlabel_rgb(x)) / 255) for x in DEFAULT_PLOTLY_COLORS ] self.joint_keys = POSITION_KEYS self.joint_colors = [ joint_colors[0], # l_wrist joint_colors[1], # l_elbow joint_colors[2], # l_shoulder joint_colors[9], # neck joint_colors[4], # nose joint_colors[3], # l_ear joint_colors[5], # r_ear joint_colors[4], # nose joint_colors[9], # neck joint_colors[6], # r_shoulder joint_colors[7], # r_elbow joint_colors[8], # r_wrist ] self.skeleton_labels = [ "L_Wrist", "L_Elbow", "L_Shoulder", "Neck", "Nose", "L_Ear", "R_Ear", "Nose", "Neck", "R_Shoulder", "R_Elbow", "R_Wrist", ] self.fig = (go.FigureWidget() ) # animation_duration=int(1/spatial_series.rate*1000) self.plot_skeleton(frame_ind) self.updated_time_range({"new": None}) # Updates list of valid spike times at each change in time range self.time_window_controller.observe(self.updated_time_range) self.play.observe(self.animate_scatter_chart) if show_time_controller: self.children = [self.time_window_controller, self.fig, self.play] else: self.children = [self.fig, self.play]
def render_dashboard(self): io = pynwb.NWBHDF5IO(self.path_nwb, 'r') self.nwb = io.read() self.controller_tmax = get_timeseries_maxt( self.nwb.processing['ophys'].data_interfaces['fluorescence']. roi_response_series['roi_response_series']) self.controller_tmin = get_timeseries_mint( self.nwb.processing['ophys'].data_interfaces['fluorescence']. roi_response_series['roi_response_series']) # Create traces figure self.traces = make_subplots(rows=3, cols=1, row_heights=[0.4, 0.2, 0.4], shared_xaxes=False, vertical_spacing=0.02) # Electrophysiology self.ecephys_trace = self.nwb.processing['ecephys'].data_interfaces[ 'filtered_membrane_voltage'] self.traces.add_trace(go.Scattergl( x=[0], y=[0], line={ "color": "#151733", "width": 1 }, mode='lines', ), row=1, col=1) # Optophysiology self.ophys_trace = self.nwb.processing['ophys'].data_interfaces[ 'fluorescence'].roi_response_series['roi_response_series'] self.traces.add_trace(go.Scattergl(x=[0], y=[0], line={ "color": "#151733", "width": 1 }, mode='lines'), row=3, col=1) # Layout self.traces.update_layout(height=400, showlegend=False, title=None, paper_bgcolor='rgba(0, 0, 0, 0)', plot_bgcolor='rgba(0, 0, 0, 0)', margin=dict(l=60, r=20, t=8, b=20), shapes=[{ 'type': 'line', 'x0': 10, 'x1': 10, 'xref': 'x', 'y0': -1000, 'y1': 1000, 'yref': 'paper', 'line': { 'width': 4, 'color': 'rgb(30, 30, 30)' } }]) self.traces.update_xaxes(patch={ 'showgrid': False, 'visible': False, }) self.traces.update_xaxes(patch={ 'visible': True, 'showline': True, 'linecolor': 'rgb(0, 0, 0)', 'title_text': 'time [s]' }, row=3, col=1) self.traces.update_yaxes( patch={ 'showgrid': False, 'visible': True, 'showline': True, 'linecolor': 'rgb(0, 0, 0)' }) self.traces.update_yaxes(patch={ "title": { "text": "Ephys [V]", "font": { "color": "#151733", "size": 16 } } }, row=1, col=1) self.traces.update_yaxes(patch={ "title": { "text": "dF/F", "font": { "color": "#151733", "size": 16 } } }, row=3, col=1) self.traces.update_yaxes(patch={ "title": { "text": "Spikes", "font": { "color": "#151733", 'size': 16 } }, "showticklabels": True, "ticks": "outside", "tickcolor": "white", "color": "white", }, row=2, col=1) # Two photon imaging self.photon_series = TiffImageSeriesComponent( id='figure_photon_series', parent_app=self.parent_app, imageseries=self.nwb.acquisition['raw_ophys'], path_external_file=None, pixel_mask=self.nwb.processing['ophys']. data_interfaces['image_segmentation']. plane_segmentations['plane_segmentation'].pixel_mask[:], foreign_time_window_controller=self.controller_time, ) self.photon_series.graph.out_fig.update_layout( showlegend=False, margin=dict(l=10, r=10, t=70, b=70), # width=300, height=300, )