Skip to content

Utils

utils #

matching_instance_ids #

matching_instance_ids(archive_path: str, instance_ids: set[str]) -> set[str]

Return ids that sit under the extensionless archive path.

Source code in src/imgnet/download/utils.py
def matching_instance_ids(
    archive_path: str, instance_ids: set[str]
) -> set[str]:
    """Return ids that sit under the extensionless archive path."""
    archive_id = PurePosixPath(RemoteArchive.strip_extension(archive_path))
    return {
        instance_id
        for instance_id in instance_ids
        if _contains_subpath(instance_id, archive_id)
    }

archive_instance_ids #

archive_instance_ids(archive_path: str, inner_members: list[str]) -> list[str]

Map archive members to extensionless instance ids.

root/zip/archive.zip with member zip_test_file.nii.gz becomes root/zip/archive/zip_test_file.nii.gz. Listings that already start with the archive stem are joined onto the parent directory.

Source code in src/imgnet/download/utils.py
def archive_instance_ids(
    archive_path: str, inner_members: list[str]
) -> list[str]:
    """Map archive members to extensionless instance ids.

    ``root/zip/archive.zip`` with member ``zip_test_file.nii.gz`` becomes
    ``root/zip/archive/zip_test_file.nii.gz``. Listings that already start
    with the archive stem are joined onto the parent directory.
    """
    prefix = PurePosixPath(RemoteArchive.strip_extension(archive_path))
    stem = prefix.name
    parent = prefix.parent
    instance_ids: list[str] = []
    for member in inner_members:
        member_path = PurePosixPath(member)
        if member_path.parts and member_path.parts[0] == stem:
            instance_ids.append((parent / member_path).as_posix())
        else:
            instance_ids.append((prefix / member).as_posix())
    return instance_ids