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)
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
def test_happy_flow(self): assert 0 == TestFactory.get_entity_count(self.test_project, ConnectivityMeasureIndex()) self._import('mantini_networks.mat') assert 6 == TestFactory.get_entity_count(self.test_project, ConnectivityMeasureIndex())