Skip to content

Commit

Permalink
Merge pull request #12 from Australian-Imaging-Service/fix-dicom-write
Browse files Browse the repository at this point in the history
Fixed up caching, so that different header values are cached separately
  • Loading branch information
tclose authored Sep 27, 2024
2 parents d9218a4 + 69b2617 commit 0264f09
Show file tree
Hide file tree
Showing 18 changed files with 211,826 additions and 7,616 deletions.
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

0 comments on commit 0264f09

Please sign in to comment.