Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed up caching, so that different header values are cached separately #12

Merged
merged 3 commits into from
Sep 27, 2024
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
12 changes: 10 additions & 2 deletions medimages4tests/dummy/dicom/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from copy import copy, deepcopy
import pydicom.dataset
import pydicom.datadict
from medimages4tests.utils import invalid_path_chars_re
from medimages4tests.cache_dir import base_cache_dir

cache_dir = base_cache_dir / "dummy" / "dicom"
Expand All @@ -27,11 +28,12 @@ def default_dicom_dir(file_loc: str):


def generate_dicom(
cache_path: Path,
cache_dir: Path,
num_vols: int,
constant_hdr: dict,
collated_data: dict,
varying_hdr: dict,
header_vals: ty.Dict[str, ty.Any],
):
"""Generates a dummy DICOM dataset for a test fixture

Expand All @@ -54,7 +56,13 @@ def generate_dicom(
Dicom dataset
"""

cache_path = Path(cache_path)
cache_dir = Path(cache_dir)
if header_vals:
header_str = "__".join(f"{k}_{v}" for k, v in sorted(header_vals.items()))
header_str = invalid_path_chars_re.sub("_", header_str)
else:
header_str = "_"
cache_path = cache_dir / header_str
# Check for non-empty cache directory, and return it if present
if cache_path.exists() and len(
[p for p in cache_path.iterdir() if not p.name.startswith(".")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from copy import copy
from medimages4tests.dummy.dicom.base import (
generate_dicom, default_dicom_dir, evolve_header
)
Expand All @@ -7,8 +6,7 @@
def get_image(out_dir=default_dicom_dir(__file__), **kwargs):
hdr = evolve_header(constant_hdr, **kwargs)
return generate_dicom(out_dir, num_vols, hdr,
collated_data, varying_hdr)

collated_data, varying_hdr, kwargs)


num_vols = 531
Expand Down
Loading
Loading