Ejemplo n.º 1
0
def test_volume_calc(tmpdir):
    tmpdir = str(tmpdir)

    atlas = Atlas(source_custom_config())

    structures_file_path = atlas.get_structures_path()
    registration_config = source_custom_config()

    volumes_csv_path = os.path.join(tmpdir, "volumes.csv")
    calculate_volumes(
        registered_atlas_path,
        registered_hemispheres_path,
        structures_file_path,
        registration_config,
        volumes_csv_path,
    )

    volumes_validate = pd.read_csv(
        volumes_validate_path, sep=",", header=0, quotechar='"'
    )
    volumes_test = pd.read_csv(
        volumes_csv_path, sep=",", header=0, quotechar='"'
    )

    assert (volumes_validate == volumes_test).all().all()
Ejemplo n.º 2
0
def prep_registration(args):
    logging.info("Checking whether the atlas exists")
    _, atlas_files_exist = check_atlas_install()
    if not atlas_files_exist:
        logging.warning("Atlas does not exist, downloading.")
        if args.download_path is None:
            args.download_path = os.path.join(temp_dir_path, "atlas.tar.gz")
        atlas_download.main(args.atlas, args.install_path, args.download_path)
        amend_cfg(
            new_atlas_folder=args.install_path, atlas=args.atlas,
        )
    if args.registration_config is None:
        args.registration_config = source_files.source_custom_config()

    logging.debug("Making registration directory")
    ensure_directory_exists(args.registration_output_folder)

    logging.debug("Copying registration config to output directory")
    copy_registration_config(
        args.registration_config, args.registration_output_folder
    )

    additional_images_downsample = {}
    if args.downsample_images:
        for idx, images in enumerate(args.downsample_images):
            name = Path(images).name
            additional_images_downsample[name] = images

    return args, additional_images_downsample
Ejemplo n.º 3
0
def amend_cfg(new_atlas_folder=None, atlas=None):
    """
    Updates the registration config file to point to the correct atlas path
    :param new_atlas_folder:
    """
    print("Ensuring custom config file is correct")

    original_config = source_files.source_config()
    new_config = source_files.source_custom_config()
    if new_atlas_folder is not None:
        write_atlas_to_cfg(
            new_atlas_folder, atlas, original_config, new_config
        )
Ejemplo n.º 4
0
def check_atlas_install():
    """
    Checks whether the atlas directory exists, and whether it's empty or not.
    :return: Whether the directory exists, and whether the files also exist
    """
    dir_exists = False
    files_exist = False
    cfg_file_path = source_files.source_custom_config()
    if os.path.exists(cfg_file_path):
        config_obj = get_config_obj(cfg_file_path)
        atlas_conf = config_obj["atlas"]
        atlas_directory = atlas_conf["base_folder"]
        if os.path.exists(atlas_directory):
            dir_exists = True
            if not os.listdir(atlas_directory) == []:
                files_exist = True

    return dir_exists, files_exist
Ejemplo n.º 5
0
 def get_atlas_config(self):
     if self._atlas_config is None:
         self._atlas_config = source_custom_config()