コード例 #1
0
    def get_voxel_time_series(self, x, y, z, var=0, mode=0):
        """
        Retrieve for a given voxel (x,y,z) the entire timeline.

        :param x: int coordinate
        :param y: int coordinate
        :param z: int coordinate

        :return: A complex dictionary with information about current voxel.
                The main part will be a vector with all the values over time from the x,y,z coordinates.
        """

        if self.region_mapping_volume is None:
            raise exceptions.TVBException("Invalid method called for TS without Volume Mapping!")

        volume_rm = self.region_mapping_volume
        x, y, z = preprocess_space_parameters(x, y, z, volume_rm.length_1d, volume_rm.length_2d, volume_rm.length_3d)
        idx_slices = slice(x, x + 1), slice(y, y + 1), slice(z, z + 1)

        idx = int(volume_rm.get_data('array_data', idx_slices))

        time_length = self.read_data_shape()[0]
        voxel_slices = prepare_time_slice(time_length), slice(var, var + 1), slice(idx, idx + 1), slice(mode, mode + 1)
        label = volume_rm.connectivity.region_labels[idx]

        background, back_min, back_max = None, None, None
        if idx < 0:
            back_min, back_max = self.get_min_max_values()
            background = numpy.ones((time_length, 1)) * self.out_of_range(back_min)
            label = 'background'

        result = postprocess_voxel_ts(self, voxel_slices, background, back_min, back_max, label)
        return result
コード例 #2
0
    def get_volume_view(self, from_idx, to_idx, x_plane, y_plane, z_plane,
                        **kwargs):
        """
        Retrieve 3 slices through the Volume TS, at the given X, y and Z coordinates, and in time [from_idx .. to_idx].

        :param from_idx: int This will be the limit on the first dimension (time)
        :param to_idx: int Also limit on the first Dimension (time)
        :param x_plane: int coordinate
        :param y_plane: int coordinate
        :param z_plane: int coordinate

        :return: An array of 3 Matrices 2D, each containing the values to display in planes xy, yz and xy.
        """

        overall_shape = self.data.shape
        from_idx, to_idx, time = preprocess_time_parameters(
            from_idx, to_idx, overall_shape[0])
        x_plane, y_plane, z_plane = preprocess_space_parameters(
            x_plane, y_plane, z_plane, overall_shape[1], overall_shape[2],
            overall_shape[3])

        slices = slice(from_idx, to_idx), slice(overall_shape[1]), slice(
            overall_shape[2]), slice(z_plane, z_plane + 1)
        slicex = self.read_data_slice(slices)[:, :, :, 0].tolist()

        slices = slice(from_idx, to_idx), slice(x_plane, x_plane + 1), slice(
            overall_shape[2]), slice(overall_shape[3])
        slicey = self.read_data_slice(slices)[:, 0, :, :][..., ::-1].tolist()

        slices = slice(from_idx, to_idx), slice(overall_shape[1]), slice(
            y_plane, y_plane + 1), slice(overall_shape[3])
        slicez = self.read_data_slice(slices)[:, :, 0, :][..., ::-1].tolist()

        return [slicex, slicey, slicez]
コード例 #3
0
    def get_mapped_array_volume_view(self,
                                     mapped_array,
                                     x_plane,
                                     y_plane,
                                     z_plane,
                                     mapped_array_slice=None,
                                     **kwargs):
        x_plane, y_plane, z_plane = preprocess_space_parameters(
            x_plane, y_plane, z_plane, self.length_1d, self.length_2d,
            self.length_3d)
        slice_x, slice_y, slice_z = self.get_volume_slice(
            x_plane, y_plane, z_plane)

        if mapped_array_slice:
            matrix_slice = parse_slice(mapped_array_slice)
            measure = mapped_array.get_data('array_data', matrix_slice)
        else:
            measure = mapped_array.get_data('array_data')

        if measure.shape != (self.connectivity.number_of_regions, ):
            raise ValueError('cannot project measure on the space')

        result_x = measure[slice_x]
        result_y = measure[slice_y]
        result_z = measure[slice_z]
        # Voxels outside the brain are -1. The indexing above is incorrect for those voxels as it
        # associates the values of the last region measure[-1] to them.
        # Here we replace those values with an out of scale value.
        result_x[slice_x == -1] = measure.min() - 1
        result_y[slice_y == -1] = measure.min() - 1
        result_z[slice_z == -1] = measure.min() - 1

        return [[result_x.tolist()], [result_y.tolist()], [result_z.tolist()]]
コード例 #4
0
 def get_volume_view(self, x_plane, y_plane, z_plane, **kwargs):
     # Work with space inside Volume:
     x_plane, y_plane, z_plane = preprocess_space_parameters(
         x_plane, y_plane, z_plane, self.length_1d, self.length_2d,
         self.length_3d)
     slice_x, slice_y, slice_z = self.get_volume_slice(
         x_plane, y_plane, z_plane)
     return [[slice_x.tolist()], [slice_y.tolist()], [slice_z.tolist()]]
コード例 #5
0
    def get_volume_view(self,
                        from_idx,
                        to_idx,
                        x_plane,
                        y_plane,
                        z_plane,
                        var=0,
                        mode=0):
        """
        Retrieve 3 slices through the Volume TS, at the given X, y and Z coordinates, and in time [from_idx .. to_idx].

        :param from_idx: int This will be the limit on the first dimension (time)
        :param to_idx: int Also limit on the first Dimension (time)
        :param x_plane: int coordinate
        :param y_plane: int coordinate
        :param z_plane: int coordinate

        :return: An array of 3 Matrices 2D, each containing the values to display in planes xy, yz and xy.
        """

        if self.region_mapping_volume is None:
            raise exceptions.TVBException(
                "Invalid method called for TS without Volume Mapping!")

        volume_rm = self.region_mapping_volume

        # Work with space inside Volume:
        x_plane, y_plane, z_plane = preprocess_space_parameters(
            x_plane, y_plane, z_plane, volume_rm.length_1d,
            volume_rm.length_2d, volume_rm.length_3d)

        slice_x, slice_y, slice_z = self.region_mapping_volume.get_volume_slice(
            x_plane, y_plane, z_plane)

        # Read from the current TS:
        from_idx, to_idx, current_time_length = preprocess_time_parameters(
            from_idx, to_idx,
            self.read_data_shape()[0])
        no_of_regions = self.read_data_shape()[2]
        time_slices = slice(from_idx, to_idx), slice(
            var, var + 1), slice(no_of_regions), slice(mode, mode + 1)

        min_signal = self.get_min_max_values()[0]
        regions_ts = self.read_data_slice(time_slices)[:, 0, :, 0]
        regions_ts = numpy.hstack(
            (regions_ts, numpy.ones(
                (current_time_length, 1)) * self.out_of_range(min_signal)))

        # Index from TS with the space mapping:
        result_x, result_y, result_z = [], [], []

        for i in range(0, current_time_length):
            result_x.append(regions_ts[i][slice_x].tolist())
            result_y.append(regions_ts[i][slice_y].tolist())
            result_z.append(regions_ts[i][slice_z].tolist())

        return [result_x, result_y, result_z]
コード例 #6
0
 def get_voxel_region(self, x_plane, y_plane, z_plane):
     x_plane, y_plane, z_plane = preprocess_space_parameters(
         x_plane, y_plane, z_plane, self.length_1d, self.length_2d,
         self.length_3d)
     slices = slice(x_plane, x_plane + 1), slice(y_plane,
                                                 y_plane + 1), slice(
                                                     z_plane, z_plane + 1)
     voxel = self.read_data_slice(slices)[0, 0, 0]
     if voxel != -1:
         return self.connectivity.region_labels[int(voxel)]
     else:
         return 'background'
コード例 #7
0
ファイル: time_series.py プロジェクト: virati/tvb-library
    def get_voxel_time_series(self, x, y, z, **kwargs):
        """
        Retrieve for a given voxel (x,y,z) the entire timeline.

        :param x: int coordinate
        :param y: int coordinate
        :param z: int coordinate

        :return: A complex dictionary with information about current voxel.
                The main part will be a vector with all the values over time from the x,y,z coordinates.
        """

        overall_shape = self.read_data_shape()
        x, y, z = preprocess_space_parameters(x, y, z, overall_shape[1], overall_shape[2], overall_shape[3])

        slices = prepare_time_slice(overall_shape[0]), slice(x, x + 1), slice(y, y + 1), slice(z, z + 1)

        result = postprocess_voxel_ts(self, slices)
        return result