def launch(self, data_file, dataset_name, structure_path='', transpose=False, slice=None, sampling_rate=1000, start_time=0, tstype=None, tstype_parameters=None): try: data = read_nested_mat_file(data_file, dataset_name, structure_path) if transpose: data = data.T if slice: data = data[parse_slice(slice)] ts = self.ts_builder[tstype](self, data, **tstype_parameters) ts.start_time = start_time ts.sample_period = 1.0 / sampling_rate ts.sample_period_unit = 's' ts.write_time_slice(numpy.r_[:data.shape[0]] * ts.sample_period) # we expect empirical data shape to be time, channel. # But tvb expects time, state, channel, mode. Introduce those dimensions ts.write_data_slice(data[:, numpy.newaxis, :, numpy.newaxis]) ts.close_file() return ts except ParseException as ex: self.log.exception(ex) raise LaunchException(ex)
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