Skip to content

Commit

Permalink
Merged in feature/RAM-3186_writing_to_lazy_stacks (pull request #319)
Browse files Browse the repository at this point in the history
RAM-3186 Allow writing to lazy dicom stacks

Approved-by: Randy Taylor
  • Loading branch information
jrkerns committed Dec 22, 2023
2 parents d47d996 + ec01909 commit 003e44f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
Changelog
=========

v 3.19.0
--------

Core
^^^^

* The efficient DICOM stack introduced in the last version did not allow for writing images back to the stack
(e.g. when manipulating the image). Images can now be written back to efficient stacks.

v 3.18.0
--------

Expand Down
5 changes: 5 additions & 0 deletions pylinac/core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,11 @@ def metadata(self) -> pydicom.FileDataset:
def __getitem__(self, item: int) -> DicomImage:
return DicomImage(self._image_path_keys[item], dtype=self.dtype)

def __setitem__(self, key: int, value: DicomImage):
"""Save the passed image to disk in place of the current image."""
current_path = self._image_path_keys[key]
value.save(current_path)

def __len__(self):
return len(self._image_path_keys)

Expand Down
10 changes: 10 additions & 0 deletions tests_basic/core/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,16 @@ def test_mixed_studies(self):
with self.assertRaises(ValueError):
DicomImageStack.from_zip(mixed_study_zip)

def test_writing_back_to_lazy_stack(self):
dstack_lazy = LazyDicomImageStack.from_zip(self.stack_location)
original_offset = np.copy(dstack_lazy[0].array) + 50
for idx, img in enumerate(dstack_lazy):
img.array += 50
dstack_lazy[idx] = img
manipulated_offset = np.copy(dstack_lazy[0].array)
# assert that writing back to the stack works
assert_array_almost_equal(manipulated_offset, original_offset)


class TestGamma2D(TestCase):
def test_perfect_match_is_0(self):
Expand Down

0 comments on commit 003e44f

Please sign in to comment.