def quick_launch_an_operation(tvb_client_instance, project_gid, datatype_gid): """ This is intended to simulate the following behavior: - in GUI the user has the possibility to view all algorithms that can run over a certain datatype - he chooses a datatype and all these algorithms are displayed - then, he selects an algorithm The data that should be sent to the server: - the selected datatype_gid - the index of the selected algorithm """ algo_dto_list = tvb_client_instance.get_operations_for_datatype(datatype_gid) algo_dto_index = 0 # Supposing that algo_dt_index and time_series_gid are sent from the client-side operation_gid = tvb_client.quick_launch_operation(project_gid, algo_dto_list[algo_dto_index], datatype_gid) monitor_operation(tvb_client, operation_gid)
def fire_simulation_example(tvb_client_instance): logger.info("Requesting projects for logged user") projects_of_user = tvb_client_instance.get_project_list() assert len(projects_of_user) > 0 logger.info("TVB has {} projects for this user".format( len(projects_of_user))) project_gid = projects_of_user[0].gid logger.info("Requesting datatypes from project {}...".format(project_gid)) data_in_project = tvb_client_instance.get_data_in_project(project_gid) logger.info("We have {} datatypes".format(len(data_in_project))) logger.info("Requesting operations from project {}...".format(project_gid)) ops_in_project, _ = tvb_client_instance.get_operations_in_project( project_gid, 1) logger.info("Displayname of the first operation is: {}".format( ops_in_project[0].displayname)) connectivity_gid = None datatypes_type = [] for datatype in data_in_project: datatypes_type.append(datatype.type) if datatype.type == ConnectivityIndex().display_type: connectivity_gid = datatype.gid logger.info("The datatypes in project are: {}".format(datatypes_type)) if connectivity_gid: logger.info("Preparing the simulator...") simulator = SimulatorAdapterModel() simulator.connectivity = connectivity_gid simulator.simulation_length = 100 logger.info("Starting the simulation...") operation_gid = tvb_client_instance.fire_simulation( project_gid, simulator) logger.info("Monitoring the simulation operation...") monitor_operation(tvb_client_instance, operation_gid) logger.info("Requesting the results of the simulation...") simulation_results = tvb_client_instance.get_operation_results( operation_gid) datatype_names = [] for datatype in simulation_results: datatype_names.append(datatype.name) logger.info("The resulted datatype are: {}".format(datatype_names)) time_series_gid = simulation_results[1].gid logger.info("Download the time series file...") time_series_path = tvb_client_instance.retrieve_datatype( time_series_gid, tvb_client_instance.temp_folder) logger.info( "The time series file location is: {}".format(time_series_path)) logger.info("Requesting algorithms to run on time series...") algos = tvb_client_instance.get_operations_for_datatype( time_series_gid) algo_names = [algo.displayname for algo in algos] logger.info("Possible algorithms are {}".format(algo_names)) logger.info("Launch Fourier Analyzer...") fourier_model = FFTAdapterModel() fourier_model.time_series = time_series_gid fourier_model.window_function = 'hamming' operation_gid = tvb_client_instance.launch_operation( project_gid, FourierAdapter, fourier_model) logger.info( "Fourier Analyzer operation has launched with gid {}".format( operation_gid)) logger.info("Download the connectivity file...") connectivity_path = tvb_client_instance.retrieve_datatype( connectivity_gid, tvb_client_instance.temp_folder) logger.info( "The connectivity file location is: {}".format(connectivity_path)) logger.info("Loading an entire Connectivity datatype in memory...") connectivity = tvb_client_instance.load_datatype_from_file( connectivity_path) logger.info("Info on current Connectivity: {}".format( connectivity.summary_info())) logger.info( "Loading a chuck from the time series H5 file, as this can be very large..." ) with TimeSeriesH5(time_series_path) as time_series_h5: data_shape = time_series_h5.read_data_shape() chunk = time_series_h5.read_data_slice( tuple([ slice(20), slice(data_shape[1]), slice(data_shape[2]), slice(data_shape[3]) ])) assert chunk.shape[0] == 20 assert chunk.shape[1] == data_shape[1] assert chunk.shape[2] == data_shape[2] assert chunk.shape[3] == data_shape[3] return project_gid, time_series_gid
def launch_operation_examples(tvb_client_instance): logger.info("Requesting projects for logged user") projects_of_user = tvb_client_instance.get_project_list() assert len(projects_of_user) > 0 logger.info("TVB has {} projects for this user".format(len(projects_of_user))) project_gid = projects_of_user[0].gid # --- Launch operations to import a Connectivity, a Surface and a RegionMapping --- logger.info("Importing a connectivity from ZIP...") zip_connectivity_importer_model = ZIPConnectivityImporterModel() zip_connectivity_importer_model.uploaded = compute_tvb_data_path('connectivity', 'connectivity_96.zip') zip_connectivity_importer_model.normalization = 'region' operation_gid = tvb_client_instance.launch_operation(project_gid, ZIPConnectivityImporter, zip_connectivity_importer_model) monitor_operation(tvb_client_instance, operation_gid) logger.info("Get the result of connectivity import...") connectivity_dto = tvb_client_instance.get_operation_results(operation_gid)[0] logger.info("Importing a surface from ZIP...") zip_surface_importer_model = ZIPSurfaceImporterModel() zip_surface_importer_model.uploaded = compute_tvb_data_path('surfaceData', 'cortex_16384.zip') zip_surface_importer_model.surface_type = CORTICAL zip_surface_importer_model.should_center = False operation_gid = tvb_client_instance.launch_operation(project_gid, ZIPSurfaceImporter, zip_surface_importer_model) monitor_operation(tvb_client_instance, operation_gid) logger.info("Get the result of surface import...") surface_dto = tvb_client_instance.get_operation_results(operation_gid)[0] logger.info("Importing a region mapping...") rm_importer_model = RegionMappingImporterModel() rm_importer_model.mapping_file = compute_tvb_data_path('regionMapping', 'regionMapping_16k_76.txt') rm_importer_model.connectivity = connectivity_dto.gid rm_importer_model.surface = surface_dto.gid operation_gid = tvb_client_instance.launch_operation(project_gid, RegionMappingImporter, rm_importer_model) monitor_operation(tvb_client_instance, operation_gid) logger.info("Get the result of region mapping import...") region_mapping_dto = tvb_client_instance.get_operation_results(operation_gid)[0] # --- Load the region mapping together with references information in 3 different ways --- logger.info("1.Download and load the region mapping with all its references...") region_mapping_complete = tvb_client_instance.load_datatype_with_full_references(region_mapping_dto.gid, tvb_client_instance.temp_folder) logger.info("1.This region mapping is linked to a connectivity with GID={} and number_of_regions={}".format( region_mapping_complete.connectivity.gid, region_mapping_complete.connectivity.number_of_regions)) logger.info("2.Download and load the region mapping with only GIDs for its references...") region_mapping_with_links = tvb_client_instance.load_datatype_with_links(region_mapping_dto.gid, tvb_client_instance.temp_folder) logger.info("2.This region mapping is linked to a connectivity with GID={}".format( region_mapping_with_links.connectivity.gid)) logger.info("3.Only download the region mapping on client machine...") region_mapping_path = tvb_client_instance.retrieve_datatype(region_mapping_dto.gid, tvb_client_instance.temp_folder) logger.info("3.Load the region mapping that was already downloaded on client machine...") local_region_mapping_with_links = tvb_client_instance.load_datatype_from_file(region_mapping_path) logger.info("3.This region mapping is linked to a connectivity with GID={}".format( local_region_mapping_with_links.connectivity.gid)) # --- Launch operation to run a Degree Analyzer over the Connectivity --- bct_model = BaseBCTModel() bct_model.connectivity = connectivity_dto.gid operation_gid = tvb_client_instance.launch_operation(project_gid, Degree, bct_model) monitor_operation(tvb_client_instance, operation_gid) logger.info("Get the result of BCT...") bct_dto = tvb_client_instance.get_operation_results(operation_gid)[0] logger.info("The resulted BCT has GID={}".format(bct_dto.gid))
assert len(projects_of_user) > 0 logger.info("TVB has {} projects for this user".format( len(projects_of_user))) project_gid = projects_of_user[0].gid # --- Launch operations to import a Connectivity, a Surface and a RegionMapping --- logger.info("Importing a connectivity from ZIP...") zip_connectivity_importer_model = ZIPConnectivityImporterModel() zip_connectivity_importer_model.uploaded = compute_tvb_data_path( 'connectivity', 'connectivity_96.zip') zip_connectivity_importer_model.normalization = 'region' operation_gid = tvb_client.launch_operation( project_gid, ZIPConnectivityImporter, zip_connectivity_importer_model) monitor_operation(tvb_client, operation_gid) logger.info("Get the result of connectivity import...") connectivity_dto = tvb_client.get_operation_results(operation_gid)[0] logger.info("Importing a surface from ZIP...") zip_surface_importer_model = ZIPSurfaceImporterModel() zip_surface_importer_model.uploaded = compute_tvb_data_path( 'surfaceData', 'cortex_16384.zip') zip_surface_importer_model.surface_type = CORTICAL zip_surface_importer_model.should_center = False operation_gid = tvb_client.launch_operation(project_gid, ZIPSurfaceImporter, zip_surface_importer_model) monitor_operation(tvb_client, operation_gid)