def launch(self, view_model): # type: (FCDAdapterModel) -> [FcdIndex, ConnectivityMeasureIndex] """ Launch algorithm and build results. :param view_model: the ViewModel keeping the algorithm inputs :return: the fcd index for the computed fcd matrix on the given time-series, with that sw and that sp """ with h5.h5_file_for_index(self.input_time_series_index) as ts_h5: [fcd, fcd_segmented, eigvect_dict, eigval_dict] = self._compute_fcd_matrix(ts_h5) connectivity_gid = ts_h5.connectivity.load() connectivity = self.load_traited_by_gid(connectivity_gid) result = [ ] # list to store: fcd index, fcd_segmented index (eventually), and connectivity measure indexes # Create an index for the computed fcd. fcd_index = FcdIndex() fcd_h5_path = h5.path_for(self.storage_path, FcdH5, fcd_index.gid) with FcdH5(fcd_h5_path) as fcd_h5: self._populate_fcd_h5(fcd_h5, fcd, fcd_index.gid, self.input_time_series_index.gid, view_model.sw, view_model.sp) self._populate_fcd_index(fcd_index, self.input_time_series_index.gid, fcd_h5) result.append(fcd_index) if np.amax(fcd_segmented) == 1.1: result_fcd_segmented_index = FcdIndex() result_fcd_segmented_h5_path = h5.path_for( self.storage_path, FcdH5, result_fcd_segmented_index.gid) with FcdH5( result_fcd_segmented_h5_path) as result_fcd_segmented_h5: self._populate_fcd_h5(result_fcd_segmented_h5, fcd_segmented, result_fcd_segmented_index.gid, self.input_time_series_index.gid, view_model.sw, view_model.sp) self._populate_fcd_index(result_fcd_segmented_index, self.input_time_series_index.gid, result_fcd_segmented_h5) result.append(result_fcd_segmented_index) for mode in eigvect_dict.keys(): for var in eigvect_dict[mode].keys(): for ep in eigvect_dict[mode][var].keys(): for eig in range(3): cm_data = eigvect_dict[mode][var][ep][eig] measure = ConnectivityMeasure() measure.connectivity = connectivity measure.array_data = cm_data measure.title = "Epoch # %d, eigenvalue = %s, variable = %s, " \ "mode = %s." % (ep, eigval_dict[mode][var][ep][eig], var, mode) cm_index = h5.store_complete(measure, self.storage_path) result.append(cm_index) return result
def launch(self, view_model): # type: (FCDAdapterModel) -> [FcdIndex] """ Launch algorithm and build results. :param time_series: the input time-series index for which fcd matrix should be computed :param sw: length of the sliding window :param sp: spanning time: distance between two consecutive sliding window :returns: the fcd index for the computed fcd matrix on the given time-series, with that sw and that sp :rtype: `FcdIndex`,`ConnectivityMeasureIndex` """ with h5.h5_file_for_index(self.input_time_series_index) as ts_h5: [fcd, fcd_segmented, eigvect_dict, eigval_dict] = self._compute_fcd_matrix(ts_h5) connectivity_gid = ts_h5.connectivity.load() result = [ ] # list to store: fcd index, fcd_segmented index (eventually), and connectivity measure indexes # Create an index for the computed fcd. fcd_index = FcdIndex() fcd_h5_path = h5.path_for(self.storage_path, FcdH5, fcd_index.gid) with FcdH5(fcd_h5_path) as fcd_h5: fcd_array_metadata = self._populate_fcd_h5( fcd_h5, fcd, fcd_index.gid, self.input_time_series_index.gid, view_model.sw, view_model.sp) self._populate_fcd_index(fcd_index, self.input_time_series_index.gid, fcd, fcd_array_metadata) result.append(fcd_index) if np.amax(fcd_segmented) == 1.1: result_fcd_segmented_index = FcdIndex() result_fcd_segmented_h5_path = h5.path_for( self.storage_path, FcdH5, result_fcd_segmented_index.gid) with FcdH5( result_fcd_segmented_h5_path) as result_fcd_segmented_h5: fcd_segmented_metadata = self._populate_fcd_h5( result_fcd_segmented_h5, fcd_segmented, result_fcd_segmented_index.gid, self.input_time_series_index.gid, view_model.sw, view_model.sp) self._populate_fcd_index(result_fcd_segmented_index, self.input_time_series_index.id, fcd_segmented, fcd_segmented_metadata) result.append(result_fcd_segmented_index) for mode in eigvect_dict.keys(): for var in eigvect_dict[mode].keys(): for ep in eigvect_dict[mode][var].keys(): for eig in range(3): cm_data = eigvect_dict[mode][var][ep][eig] cm_index = ConnectivityMeasureIndex() cm_index.type = ConnectivityMeasure.__name__ cm_index.fk_connectivity_gid = connectivity_gid.hex cm_index.title = "Epoch # %d, \n eigenvalue = %s,\n variable = %s,\n " \ "mode = %s." % (ep, eigval_dict[mode][var][ep][eig], var, mode) storage_path = h5.path_for(self.storage_path, ConnectivityMeasureH5, cm_index.gid) with ConnectivityMeasureH5(storage_path) as f: f.array_data.store(cm_data) f.connectivity.store(connectivity_gid) f.title.store(cm_index.title) cm_array_metadata = f.array_data.get_cached_metadata( ) cm_index.array_data_min = cm_array_metadata.min cm_index.array_data_max = cm_array_metadata.max cm_index.array_data_mean = cm_array_metadata.mean result.append(cm_index) return result