Exemplo n.º 1
0
    def import_region_mapping(user, project, import_file_path, surface_gid, connectivity_gid, same_process=True):

        view_model = RegionMappingImporterModel()
        view_model.mapping_file = import_file_path
        view_model.surface = surface_gid
        view_model.connectivity = connectivity_gid
        TestFactory.launch_importer(RegionMappingImporter, view_model, user, project, same_process)

        return TestFactory._assert_one_more_datatype(project, RegionMappingIndex)
Exemplo n.º 2
0
def import_surface_rm(project_id, conn_gid):
    # Import surface and region mapping from tvb_data berlin subjects (68 regions)
    rm_file = try_get_absolute_path("tvb_data", "berlinSubjects/DH_20120806/DH_20120806_RegionMapping.txt")
    surface_zip_file = try_get_absolute_path("tvb_data", "berlinSubjects/DH_20120806/DH_20120806_Surface_Cortex.zip")

    surface_importer = ABCAdapter.build_adapter_from_class(ZIPSurfaceImporter)
    surface_imp_model = ZIPSurfaceImporterModel()
    surface_imp_model.uploaded = surface_zip_file
    surface_imp_operation = fire_operation(project_id, surface_importer, surface_imp_model)
    surface_imp_operation = wait_to_finish(surface_imp_operation)

    surface_gid = dao.get_results_for_operation(surface_imp_operation.id)[0].gid
    rm_importer = ABCAdapter.build_adapter_from_class(RegionMappingImporter)
    rm_imp_model = RegionMappingImporterModel()
    rm_imp_model.mapping_file = rm_file
    rm_imp_model.surface = surface_gid
    rm_imp_model.connectivity = conn_gid
    rm_import_operation = fire_operation(project_id, rm_importer, rm_imp_model)
    wait_to_finish(rm_import_operation)
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
    logger.info("Requesting the result of the surface uploading...")
    surface_result = tvb_client.get_operation_results(operation_gid)[0]

    logger.info("Downloading the connectivity from server...")
    connectivity_path = tvb_client.retrieve_datatype(connectivity_result.gid, TvbProfile.current.TVB_TEMP_FOLDER)

    logger.info("Downloading the surface from server...")
    surface_path = tvb_client.retrieve_datatype(surface_result.gid, TvbProfile.current.TVB_TEMP_FOLDER)

    logger.info("Preparing a region mapping H5 file using the downloaded connectivity and surface...")
    rm_view_model = RegionMappingImporterModel()
    rm_text_path = os.path.join(os.path.dirname(tvb_data.__file__), 'regionMapping', 'regionMapping_16k_76.txt')
    rm_view_model.mapping_file = rm_text_path
    conn_db = dao.get_datatype_by_gid(connectivity_result.gid).gid
    rm_view_model.connectivity = UUID(conn_db)
    surface_db = dao.get_datatype_by_gid(surface_result.gid).gid
    rm_view_model.surface = UUID(surface_db)

    logger.info("Launching region mapping upload operation...")
    operation_gid = tvb_client.launch_operation(project_gid, RegionMappingImporter, rm_view_model)

    while True:
        status = tvb_client.get_operation_status(operation_gid)
        if status in [STATUS_FINISHED, STATUS_CANCELED, STATUS_ERROR]:
            break
        time.sleep(5)
    logger.info("The region mapping uploading has finished with status: {}".format(status))
    os.remove(connectivity_path)
    os.remove(surface_path)
Exemplo n.º 5
0
        '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)

    logger.info("Get the result of surface import...")
    surface_dto = tvb_client.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.launch_operation(project_gid,
                                                RegionMappingImporter,
                                                rm_importer_model)
    monitor_operation(tvb_client, operation_gid)

    logger.info("Get the result of region mapping import...")
    region_mapping_dto = tvb_client.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.load_datatype_with_full_references(
        region_mapping_dto.gid, tvb_client.temp_folder)