def launch(self, view_model): # type: (CrossCorrelateAdapterModel) -> [CrossCorrelationIndex] """ Launch algorithm and build results. Compute the node-pairwise cross-correlation of the source 4D TimeSeries represented by the index given as input. Return a CrossCorrelationIndex. Create a CrossCorrelationH5 that contains the cross-correlation sequences for all possible combinations of the nodes. See: http://www.scipy.org/doc/api_docs/SciPy.signal.signaltools.html#correlate :param time_series: the input time series index for which the correlation should be computed :returns: the cross correlation index for the given time series :rtype: `CrossCorrelationIndex` """ # --------- Prepare CrossCorrelationIndex and CrossCorrelationH5 objects for result ------------## cross_corr_index = CrossCorrelationIndex() cross_corr_h5_path = h5.path_for(self.storage_path, CrossCorrelationH5, cross_corr_index.gid) cross_corr_h5 = CrossCorrelationH5(cross_corr_h5_path) node_slice = [ slice(self.input_shape[0]), None, slice(self.input_shape[2]), slice(self.input_shape[3]) ] # ---------- Iterate over slices and compose final result ------------## small_ts = TimeSeries() with h5.h5_file_for_index(self.input_time_series_index) as ts_h5: small_ts.sample_period = ts_h5.sample_period.load() partial_cross_corr = None labels_ordering = ts_h5.labels_ordering.load() for var in range(self.input_shape[1]): node_slice[1] = slice(var, var + 1) small_ts.data = ts_h5.read_data_slice(tuple(node_slice)) partial_cross_corr = self._compute_cross_correlation( small_ts, ts_h5) cross_corr_h5.write_data_slice(partial_cross_corr) ts_array_metadata = cross_corr_h5.array_data.get_cached_metadata() cross_corr_h5.time.store(partial_cross_corr.time) cross_corr_labels_ordering = list(partial_cross_corr.labels_ordering) cross_corr_labels_ordering[1] = labels_ordering[2] cross_corr_labels_ordering[2] = labels_ordering[2] cross_corr_h5.labels_ordering.store( json.dumps(tuple(cross_corr_labels_ordering))) cross_corr_h5.source.store(uuid.UUID(self.input_time_series_index.gid)) cross_corr_h5.gid.store(uuid.UUID(cross_corr_index.gid)) cross_corr_index.source_gid = self.input_time_series_index.gid cross_corr_index.labels_ordering = cross_corr_h5.labels_ordering.load() cross_corr_index.type = type(cross_corr_index).__name__ cross_corr_index.array_data_min = ts_array_metadata.min cross_corr_index.array_data_max = ts_array_metadata.max cross_corr_index.array_data_mean = ts_array_metadata.mean cross_corr_h5.close() return cross_corr_index
def build(): time_series_index = time_series_index_factory() time_series = h5.load_from_index(time_series_index) data = numpy.random.random((10, 10, 10, 10, 10)) cross_correlation = temporal_correlations.CrossCorrelation(source=time_series, array_data=data) op = operation_factory() cross_correlation_index = CrossCorrelationIndex() cross_correlation_index.fk_from_operation = op.id cross_correlation_index.fill_from_has_traits(cross_correlation) cross_correlation_h5_path = h5.path_for_stored_index(cross_correlation_index) with CrossCorrelationH5(cross_correlation_h5_path) as f: f.store(cross_correlation) cross_correlation_index = dao.store_entity(cross_correlation_index) return cross_correlation_index
def launch(self, view_model): # type: (CrossCorrelateAdapterModel) -> [CrossCorrelationIndex] """ Launch algorithm and build results. Compute the node-pairwise cross-correlation of the source 4D TimeSeries represented by the index given as input. Return a CrossCorrelationIndex. Create a CrossCorrelationH5 that contains the cross-correlation sequences for all possible combinations of the nodes. See: http://www.scipy.org/doc/api_docs/SciPy.signal.signaltools.html#correlate :param view_model: the ViewModel keeping the algorithm inputs :return: the cross correlation index for the given time series :rtype: `CrossCorrelationIndex` """ # --------- Prepare CrossCorrelationIndex and CrossCorrelationH5 objects for result ------------## cross_corr_index = CrossCorrelationIndex() cross_corr_h5_path = h5.path_for(self.storage_path, CrossCorrelationH5, cross_corr_index.gid) cross_corr_h5 = CrossCorrelationH5(cross_corr_h5_path) node_slice = [slice(self.input_shape[0]), None, slice(self.input_shape[2]), slice(self.input_shape[3])] # ---------- Iterate over slices and compose final result ------------## small_ts = TimeSeries() with h5.h5_file_for_index(self.input_time_series_index) as ts_h5: small_ts.sample_period = ts_h5.sample_period.load() small_ts.sample_period_unit = ts_h5.sample_period_unit.load() partial_cross_corr = None for var in range(self.input_shape[1]): node_slice[1] = slice(var, var + 1) small_ts.data = ts_h5.read_data_slice(tuple(node_slice)) partial_cross_corr = self._compute_cross_correlation(small_ts, ts_h5) cross_corr_h5.write_data_slice(partial_cross_corr) partial_cross_corr.source.gid = view_model.time_series partial_cross_corr.gid = uuid.UUID(cross_corr_index.gid) cross_corr_index.fill_from_has_traits(partial_cross_corr) self.fill_index_from_h5(cross_corr_index, cross_corr_h5) cross_corr_h5.store(partial_cross_corr, scalars_only=True) cross_corr_h5.close() return cross_corr_index