def compute_2d_view(matrix, slice_s): """ Create a 2d view of the matrix using the suggested slice If the given slice is invalid or fails to produce a 2d array the default is used which selects the first 2 dimensions. If the matrix is complex the real part is shown :param slice_s: a string representation of a slice :return: (a 2d array, the slice used to make it, is_default_returned) """ default = (slice(None), slice(None)) + tuple(0 for _ in range(matrix.ndim - 2)) # [:,:,0,0,0,0 etc] try: if slice_s is not None: matrix_slice = parse_slice(slice_s) else: matrix_slice = slice(None) m = matrix[matrix_slice] if m.ndim > 2: # the slice did not produce a 2d array, treat as error raise ValueError(str(matrix.shape)) except (IndexError, ValueError): # if the slice could not be parsed or it failed to produce a 2d array matrix_slice = default slice_used = slice_str(matrix_slice) return matrix[matrix_slice].astype(float), slice_used, matrix_slice == default
def compute_2d_view(matrix, slice_s): """ Create a 2d view of the matrix using the suggested slice If the given slice is invalid or fails to produce a 2d array the default is used which selects the first 2 dimensions. If the matrix is complex the real part is shown :param slice_s: a string representation of a slice :return: (a 2d array, the slice used to make it, is_default_returned) """ default = (slice(None), slice(None)) + tuple( 0 for _ in range(matrix.ndim - 2)) # [:,:,0,0,0,0 etc] try: if slice_s is not None: matrix_slice = parse_slice(slice_s) else: matrix_slice = slice(None) m = matrix[matrix_slice] if m.ndim > 2: # the slice did not produce a 2d array, treat as error raise ValueError(str(matrix.shape)) except ( IndexError, ValueError ): # if the slice could not be parsed or it failed to produce a 2d array matrix_slice = default slice_used = slice_str(matrix_slice) return matrix[matrix_slice].astype( float), slice_used, matrix_slice == default
def _compute_measure_params(self, region_mapping_volume, measure, data_slice): # prepare the url that will project the measure onto the region volume map metadata = measure.get_metadata('array_data') min_value, max_value = metadata[measure.METADATA_ARRAY_MIN], metadata[measure.METADATA_ARRAY_MAX] measure_shape = measure.get_data_shape('array_data') if not data_slice: data_slice = self.get_default_slice(measure_shape, region_mapping_volume.connectivity.number_of_regions) data_slice = slice_str(data_slice) datatype_kwargs = json.dumps({'mapped_array': measure.gid}) url_volume_data = ABCDisplayer.paths2url(region_mapping_volume, "get_mapped_array_volume_view") url_volume_data += '/' + datatype_kwargs + '?mapped_array_slice=' + data_slice + ';' return dict( minValue=min_value, maxValue=max_value, urlVolumeData=url_volume_data, measureShape=slice_str(measure_shape), measureSlice=data_slice)