コード例 #1
0
def make_electrode_table():
    table = ElectrodeTable()
    dev1 = Device('dev1')  # noqa: F405
    group = ElectrodeGroup('tetrode1', 'tetrode description', 'tetrode location', dev1)  # noqa: F405
    table.add_row(id=1, x=1.0, y=2.0, z=3.0, imp=-1.0, location='CA1', filtering='none',
                  group=group, group_name='tetrode1')
    table.add_row(id=2, x=1.0, y=2.0, z=3.0, imp=-2.0, location='CA1', filtering='none',
                  group=group, group_name='tetrode1')
    table.add_row(id=3, x=1.0, y=2.0, z=3.0, imp=-3.0, location='CA1', filtering='none',
                  group=group, group_name='tetrode1')
    table.add_row(id=4, x=1.0, y=2.0, z=3.0, imp=-4.0, location='CA1', filtering='none',
                  group=group, group_name='tetrode1')
    return table
コード例 #2
0
ファイル: test_file.py プロジェクト: vrhaynes/pynwb
    def test_set_electrode_table(self):
        table = ElectrodeTable()
        dev1 = self.nwbfile.create_device('dev1')
        group = self.nwbfile.create_electrode_group('tetrode1', 'tetrode description', 'tetrode location', dev1)
        table.add_row(x=1.0, y=2.0, z=3.0, imp=-1.0, location='CA1', filtering='none', group=group,
                      group_name='tetrode1')
        table.add_row(x=1.0, y=2.0, z=3.0, imp=-2.0, location='CA1', filtering='none', group=group,
                      group_name='tetrode1')
        table.add_row(x=1.0, y=2.0, z=3.0, imp=-3.0, location='CA1', filtering='none', group=group,
                      group_name='tetrode1')
        table.add_row(x=1.0, y=2.0, z=3.0, imp=-4.0, location='CA1', filtering='none', group=group,
                      group_name='tetrode1')
        self.nwbfile.set_electrode_table(table)

        self.assertIs(self.nwbfile.electrodes, table)
        self.assertIs(table.parent, self.nwbfile)
コード例 #3
0
    def update_response(self, electrodes: ElectrodeTable,
                        pre_alignment_window: Iterable[float],
                        post_alignment_window: Iterable[float],
                        event_name: str):
        """
        Visualize the electrode grid with on-click selection of channels in one-to-one relationship to units.

        Parameters
        ----------
        electrodes: ElectrodeTable
            Electrodes Table of an NWBFile.
        pre_alignment_window : Iterable[float]
            Array-like of the form [start, end] flipped with respect to the value of the alignment time,
            in units seconds. E.g., pre_alignment_window = [0.1, 0.5] with alignment_times = [1.2, 2.3, 3.4]
            will calculate spiking activity over the windows [[0.7, 1.1], [1.8, 2.2], [2.9, 3.3]] respectively.
        post_alignment_window : Iterable[float]
            Array-like of the form [start, end] with respect to the value of the alignment time, in units seconds.
            E.g., post_alignment_window = [0.1, 0.5] with alignment_times = [1.2, 2.3, 3.4]
            will calculate spiking activity over the windows [[1.3, 1.7], [2.4, 2.8], [3.5, 3.9]] respectively.
        event_name : str
            Name of event from trials table to align to.
        """
        unit_ids = electrodes.get_ancestor("NWBFile").units.id.data[:]
        n_channels = len(self.scatter.marker.size)

        nwbfile = electrodes.get_ancestor("NWBFile")
        responses = calculate_all_responses(
            units=nwbfile.units,
            trials=nwbfile.trials,
            pre_alignment_window=pre_alignment_window,
            post_alignment_window=post_alignment_window,
            event_name=event_name)
        channel_response = np.array([np.nan] * n_channels)
        channel_response[unit_ids] = responses

        self.scatter.marker.cmax = max(responses[~np.isnan(responses)],
                                       default=0)
        self.scatter.marker.cmin = min(responses[~np.isnan(responses)],
                                       default=0)
        self.scatter.marker.color = channel_response

        self.scatter.text = [
            f"Channel ID: {channel_id} <br> Responsitivity: {round(response, 2)}"
            for channel_id, response in zip(electrodes.id.data[:],
                                            channel_response)
        ]
コード例 #4
0
    def __init__(self, electrodes: ElectrodeTable,
                 pre_alignment_window: Iterable[float],
                 post_alignment_window: Iterable[float], event_name: str):
        """
        Visualize the electrode grid with on-click selection of channels in one-to-one relationship to units.

        Parameters
        ----------
        electrodes: ElectrodeTable
            Electrodes Table of an NWBFile.
        pre_alignment_window : Iterable[float]
            Array-like of the form [start, end] flipped with respect to the value of the alignment time,
            in units seconds. E.g., pre_alignment_window = [0.1, 0.5] with alignment_times = [1.2, 2.3, 3.4]
            will calculate spiking activity over the windows [[0.7, 1.1], [1.8, 2.2], [2.9, 3.3]] respectively.
        post_alignment_window : Iterable[float]
            Array-like of the form [start, end] with respect to the value of the alignment time, in units seconds.
            E.g., post_alignment_window = [0.1, 0.5] with alignment_times = [1.2, 2.3, 3.4]
            will calculate spiking activity over the windows [[1.3, 1.7], [2.4, 2.8], [3.5, 3.9]] respectively.
        event_name : str
            Name of event from trials table to align to.
        """
        super().__init__()
        x = electrodes["rel_x"].data[:]
        y = electrodes["rel_y"].data[:]
        n_channels = len(x)

        nwbfile = electrodes.get_ancestor("NWBFile")
        unit_ids = nwbfile.units.id.data[:]

        responses = calculate_all_responses(
            units=nwbfile.units,
            trials=nwbfile.trials,
            pre_alignment_window=pre_alignment_window,
            post_alignment_window=post_alignment_window,
            event_name=event_name)
        valid_unit_responses = responses[~np.isnan(responses)]
        channel_response = np.array([np.nan] * n_channels)
        channel_response[unit_ids] = responses

        self.fig = go.FigureWidget([
            go.Scatter(
                x=x,
                y=y,
                mode="markers",
                text=[
                    f"Channel ID: {channel_id} <br> Responsitivity: {round(response, 2)}"
                    for channel_id, response in zip(electrodes.id.data[:],
                                                    channel_response)
                ],
                marker=dict(colorbar=dict(title="Responsitivity"),
                            cmax=max(valid_unit_responses, default=0),
                            cmin=min(valid_unit_responses, default=0),
                            color=channel_response,
                            colorscale="Viridis"),
            )
        ])
        self.scatter = self.fig.data[0]
        s = np.array([ELECTRODE_SIZE] * n_channels)
        s[unit_ids] = DETECTED_SIZE
        s[unit_ids[0]] = SELECTED_SIZE
        self.scatter.marker.size = s

        self.scatter.on_click(self.update_point)
        self.fig.layout.hovermode = "closest"
        self.fig.update_layout(title=dict(text="electrode grid",
                                          xanchor="center",
                                          yanchor="top",
                                          y=0.9,
                                          x=0.5,
                                          font=dict(family="monospace",
                                                    size=14)),
                               autosize=False,
                               width=420,
                               height=640,
                               xaxis=dict(showline=False,
                                          showticklabels=False,
                                          ticks=""),
                               yaxis=dict(showline=False,
                                          showticklabels=False,
                                          ticks=""))

        self.children = [self.fig]