def fill_from_has_traits(self, datatype): # type: (Connectivity) -> None super(ConnectivityIndex, self).fill_from_has_traits(datatype) self.number_of_regions = datatype.number_of_regions self.number_of_connections = datatype.number_of_connections self.undirected = datatype.undirected self.weights_min, self.weights_max, self.weights_mean = from_ndarray( datatype.weights) self.tract_lengths_min, self.tract_lengths_max, self.tract_lengths_mean = from_ndarray( datatype.tract_lengths)
def fill_from_has_traits(self, datatype): # type: (RegionMapping) -> None super(RegionMappingIndex, self).fill_from_has_traits(datatype) self.array_data_min, self.array_data_max, self.array_data_mean = from_ndarray( datatype.array_data) self.fk_surface_gid = datatype.surface.gid.hex self.fk_connectivity_gid = datatype.connectivity.gid.hex
def fill_from_has_traits(self, datatype): # type: (StructuralMRI) -> None super(StructuralMRIIndex, self).fill_from_has_traits(datatype) self.weighting = datatype.weighting self.array_data_min, self.array_data_max, self.array_data_mean = from_ndarray( datatype.array_data) self.volume_gid = datatype.volume.gid.hex
def fill_from_has_traits(self, datatype): # type: (CrossCorrelation) -> None super(CrossCorrelationIndex, self).fill_from_has_traits(datatype) self.array_data_min, self.array_data_max, self.array_data_mean = from_ndarray(datatype.array_data) self.labels_ordering = json.dumps(datatype.labels_ordering) self.subtype = datatype.__class__.__name__ self.source_gid = datatype.source.gid.hex
def fill_from_has_traits(self, datatype): # type: (Fcd) -> None super(FcdIndex, self).fill_from_has_traits(datatype) self.array_data_min, self.array_data_max, self.array_data_mean = from_ndarray( datatype.array_data) self.labels_ordering = json.dumps(datatype.labels_ordering) self.source_gid = datatype.source.gid.hex
def fill_from_has_traits(self, datatype): # type: (Covariance) -> None super(CovarianceIndex, self).fill_from_has_traits(datatype) self.subtype = datatype.__class__.__name__ self.array_data_min, self.array_data_max, self.array_data_mean = from_ndarray( datatype.array_data) self.source_gid = datatype.source.gid.hex
def fill_from_has_traits(self, datatype): # type: (ConnectivityMeasure) -> None super(ConnectivityMeasureIndex, self).fill_from_has_traits(datatype) self.subtype = datatype.__class__.__name__ self.array_data_min, self.array_data_max, self.array_data_mean = from_ndarray( datatype.data_array) self.connectivity_gid = datatype.connectivity.gid.hex
def fill_from_has_traits(self, datatype): # type: (CoherenceSpectrum) -> None super(CoherenceSpectrumIndex, self).fill_from_has_traits(datatype) self.nfft = datatype.nfft self.frequencies_min, self.frequencies_max, _ = from_ndarray( datatype.frequency) self.fk_source_gid = datatype.source.gid.hex
def fill_from_has_traits(self, datatype): super(DataTypeMatrix, self).fill_from_has_traits(datatype) self.subtype = datatype.__class__.__name__ if hasattr(datatype, "array_data"): self.array_data_min, self.array_data_max, self.array_data_mean = from_ndarray( datatype.array_data) self.shape = json.dumps(datatype.array_data.shape) self.ndim = len(datatype.array_data.shape)
def fill_from_has_traits(self, datatype): # type: (CorrelationCoefficients) -> None super(CorrelationCoefficientsIndex, self).fill_from_has_traits(datatype) self.subtype = datatype.__class__.__name__ self.labels_ordering = datatype.labels_ordering self.array_data_min, self.array_data_max, self.array_data_mean = from_ndarray( datatype.data_array) self.source_gid = datatype.source.gid.hex
def launch(self, view_model): """ Launch algorithm and build results. """ # --------- Prepare a WaveletCoefficients object for result ----------## frequencies_array = numpy.array([]) if self.algorithm.frequencies is not None: frequencies_array = self.algorithm.frequencies.to_array() time_series_h5 = h5.h5_file_for_index(self.input_time_series_index) assert isinstance(time_series_h5, TimeSeriesH5) wavelet_index = WaveletCoefficientsIndex() dest_path = h5.path_for(self.storage_path, WaveletCoefficientsH5, wavelet_index.gid) wavelet_h5 = WaveletCoefficientsH5(path=dest_path) wavelet_h5.gid.store(uuid.UUID(wavelet_index.gid)) wavelet_h5.source.store(time_series_h5.gid.load()) wavelet_h5.mother.store(self.algorithm.mother) wavelet_h5.q_ratio.store(self.algorithm.q_ratio) wavelet_h5.sample_period.store(self.algorithm.sample_period) wavelet_h5.frequencies.store(frequencies_array) wavelet_h5.normalisation.store(self.algorithm.normalisation) # ------------- NOTE: Assumes 4D, Simulator timeSeries. --------------## node_slice = [ slice(self.input_shape[0]), slice(self.input_shape[1]), None, slice(self.input_shape[3]) ] # ---------- Iterate over slices and compose final result ------------## small_ts = TimeSeries() small_ts.sample_period = time_series_h5.sample_period.load() small_ts.sample_period_unit = time_series_h5.sample_period_unit.load() for node in range(self.input_shape[2]): node_slice[2] = slice(node, node + 1) small_ts.data = time_series_h5.read_data_slice(tuple(node_slice)) self.algorithm.time_series = small_ts partial_wavelet = self.algorithm.evaluate() wavelet_h5.write_data_slice(partial_wavelet) wavelet_h5.close() time_series_h5.close() wavelet_index.fk_source_gid = self.input_time_series_index.gid wavelet_index.mother = self.algorithm.mother wavelet_index.normalisation = self.algorithm.normalisation wavelet_index.q_ratio = self.algorithm.q_ratio wavelet_index.sample_period = self.algorithm.sample_period wavelet_index.number_of_scales = frequencies_array.shape[0] wavelet_index.frequencies_min, wavelet_index.frequencies_max, _ = from_ndarray( frequencies_array) return wavelet_index
def fill_from_has_traits(self, datatype): # type: (WaveletCoefficients) -> None super(WaveletCoefficientsIndex, self).fill_from_has_traits(datatype) self.mother = datatype.mother self.normalisation = datatype.normalisation self.q_ratio = datatype.q_ratio self.sample_period = datatype.sample_period self.number_of_scales = datatype.frequencies.shape[0] self.frequencies_min, self.frequencies_max, _ = from_ndarray(datatype.frequencies) self.source_gid = datatype.source.gid.hex
def fill_from_has_traits(self, datatype): super(DataTypeMatrix, self).fill_from_has_traits(datatype) self.subtype = datatype.__class__.__name__ if hasattr(datatype, "array_data"): self.array_has_complex = numpy.iscomplex(datatype.array_data).any().item() if not self.array_has_complex: self.array_data_min, self.array_data_max, self.array_data_mean = from_ndarray(datatype.array_data) self.array_is_finite = numpy.isfinite(datatype.array_data).all().item() self.shape = json.dumps(datatype.array_data.shape) self.ndim = len(datatype.array_data.shape)
def fill_from_has_traits(self, datatype): # type: (LocalConnectivity) -> None super(LocalConnectivityIndex, self).fill_from_has_traits(datatype) I, J, V = scipy.sparse.find(datatype.matrix) self.matrix_non_zero_min, self.matrix_non_zero_max, self.matrix_non_zero_mean = from_ndarray( V) self.fk_surface_gid = datatype.surface.gid.hex
def launch(self, view_model): # type: (ConnectivityMeasureImporterModel) -> [ConnectivityMeasureIndex] """ Execute import operations: """ try: data = self.read_matlab_data(view_model.data_file, view_model.dataset_name) measurement_count, node_count = data.shape connectivity_index = self.load_entity_by_gid( view_model.connectivity.hex) if node_count != connectivity_index.number_of_regions: raise LaunchException( 'The measurements are for %s nodes but the selected connectivity' ' contains %s nodes' % (node_count, connectivity_index.number_of_regions)) measures = [] for i in range(measurement_count): cm_idx = ConnectivityMeasureIndex() cm_idx.type = ConnectivityMeasureIndex.__name__ cm_idx.connectivity_gid = connectivity_index.gid cm_data = data[i, :] cm_idx.array_data_ndim = cm_data.ndim cm_idx.ndim = cm_data.ndim cm_idx.array_data_min, cm_idx.array_data_max, cm_idx.array_data_mean = from_ndarray( cm_data) cm_h5_path = h5.path_for(self.storage_path, ConnectivityMeasureH5, cm_idx.gid) with ConnectivityMeasureH5(cm_h5_path) as cm_h5: cm_h5.array_data.store(data[i, :]) cm_h5.connectivity.store(uuid.UUID(connectivity_index.gid)) cm_h5.gid.store(uuid.UUID(cm_idx.gid)) cm_idx.user_tag_2 = "nr.-%d" % (i + 1) cm_idx.user_tag_3 = "conn_%d" % node_count measures.append(cm_idx) return measures except ParseException as excep: logger = get_logger(__name__) logger.exception(excep) raise LaunchException(excep)