Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/physiotwin4d/data_download_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def DownloadCHOPValve4DData(dirname: Union[str, Path]) -> Path: # noqa: N802
data_dir = Path(dirname)
for subdir_name, asset_name in DataDownloadTools.CHOP_VALVE4D_ASSETS.items():
target_dir = data_dir / subdir_name
if DataDownloadTools._CHOPValve4DSubdirIsPopulated(subdir_name, target_dir):
if DataDownloadTools._CHOPValve4DSubdirIsPopulated(target_dir):
continue
url = DataDownloadTools.CHOP_VALVE4D_RELEASE_URL + asset_name
DataDownloadTools._DownloadAndExtractZip(url, target_dir)
Expand All @@ -254,7 +254,7 @@ def DownloadCHOPValve4DData(dirname: Union[str, Path]) -> Path: # noqa: N802

@staticmethod
def _CHOPValve4DSubdirIsPopulated( # noqa: N802
subdir_name: str, target_dir: Path
target_dir: Path,
) -> bool:
"""Return True when ``target_dir`` already has subdir_name's expected files.

Expand All @@ -266,6 +266,7 @@ def _CHOPValve4DSubdirIsPopulated( # noqa: N802
"""
if not target_dir.is_dir():
return False
subdir_name = target_dir.name
if subdir_name == "CT":
has_ct_volume = any(
(target_dir / filename).is_file()
Expand Down Expand Up @@ -293,7 +294,7 @@ def _DownloadAndExtractZip(url: str, target_dir: Path) -> None: # noqa: N802
raise RuntimeError(f"Downloaded archive is empty: {url}")

with zipfile.ZipFile(archive_file) as archive:
archive.extractall(target_dir)
archive.extractall(target_dir.parent)

@staticmethod
def VerifyCHOPValve4DData(dirname: Union[str, Path]) -> bool: # noqa: N802
Expand All @@ -304,13 +305,11 @@ def VerifyCHOPValve4DData(dirname: Union[str, Path]) -> bool: # noqa: N802
experiments.
"""
data_dir = Path(dirname)
has_ct = DataDownloadTools._CHOPValve4DSubdirIsPopulated("CT", data_dir / "CT")
has_ct = DataDownloadTools._CHOPValve4DSubdirIsPopulated(data_dir / "CT")
has_alterra = DataDownloadTools._CHOPValve4DSubdirIsPopulated(
"Alterra", data_dir / "Alterra"
)
has_tpv25 = DataDownloadTools._CHOPValve4DSubdirIsPopulated(
"TPV25", data_dir / "TPV25"
data_dir / "Alterra"
)
has_tpv25 = DataDownloadTools._CHOPValve4DSubdirIsPopulated(data_dir / "TPV25")
return has_ct or (has_alterra and has_tpv25)

@staticmethod
Expand Down
8 changes: 5 additions & 3 deletions tests/test_download_heart_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def make_archive(subdir_name: str, member_name: str, content: bytes) -> Path:
for subdir_name, asset_name in DataDownloadTools.CHOP_VALVE4D_ASSETS.items():
url = DataDownloadTools.CHOP_VALVE4D_RELEASE_URL + asset_name
urls_to_archives[url] = make_archive(
subdir_name, f"{subdir_name}.txt", f"# {subdir_name}\n".encode()
subdir_name,
f"{subdir_name}/{subdir_name}.txt",
f"# {subdir_name}\n".encode(),
)

def fake_urlopen(url: str, timeout: float) -> object:
Expand Down Expand Up @@ -274,9 +276,9 @@ def make_archive(subdir_name: str, member_name: str, content: bytes) -> Path:
urls_to_archives = {}
for subdir_name, asset_name in DataDownloadTools.CHOP_VALVE4D_ASSETS.items():
url = DataDownloadTools.CHOP_VALVE4D_RELEASE_URL + asset_name
member_name = "RVOT28-Dias.mha" if subdir_name == "CT" else "frame_0000.vtk"
leaf = "RVOT28-Dias.mha" if subdir_name == "CT" else "frame_0000.vtk"
urls_to_archives[url] = make_archive(
subdir_name, member_name, f"# {subdir_name}\n".encode()
subdir_name, f"{subdir_name}/{leaf}", f"# {subdir_name}\n".encode()
)

def fake_urlopen(url: str, timeout: float) -> object:
Expand Down
Loading