Skip to content

Commit

Permalink
Merge pull request #9 from ZviBaratz/unhashable
Browse files Browse the repository at this point in the history
Multiple values return type
  • Loading branch information
ZviBaratz committed Nov 10, 2020
2 parents d55e2aa + 80d6c55 commit c4c4791
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[run]
omit = *tests*
.tox/
.tox/**
venv/**
setup.py

Expand Down
2 changes: 1 addition & 1 deletion dicom_parser/data_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def parse_value(self, value):

def parse_values(self):
if self.value_multiplicity > 1:
return [self.parse_value(value) for value in self.raw.value]
return tuple(self.parse_value(value) for value in self.raw.value)
return self.parse_value(self.raw.value)

def to_dict(self) -> dict:
Expand Down
1 change: 1 addition & 0 deletions dicom_parser/messages.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DATA_READ_FAILURE = (
"Failed to read image data with the following exception:\n{exception}"
)
EMPTY_SERIES_DIRECTORY = "Could not locate any files within the provided series directory!"
8 changes: 3 additions & 5 deletions dicom_parser/series.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
Definition of the Series class, representing a collection of Image instances
ordered by the header's InstanceNumber data element.
Definition of the :class:`Series` class.
"""

import numpy as np

from dicom_parser.image import Image
from dicom_parser.messages import EMPTY_SERIES_DIRECTORY
from dicom_parser.utils.peek import peek
from pathlib import Path
from types import GeneratorType
Expand Down Expand Up @@ -119,9 +119,7 @@ def get_dcm_paths(self) -> GeneratorType:

_, dcm_paths = peek(self.path.rglob("*.dcm"))
if not dcm_paths:
raise FileNotFoundError(
"Could not locate any .dcm files within the provided series directory!"
)
raise FileNotFoundError(EMPTY_SERIES_DIRECTORY)
return dcm_paths

def get_images(self) -> tuple:
Expand Down
2 changes: 1 addition & 1 deletion dicom_parser/utils/sequence_detector/sequence_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def check_definition(self, definition, values: dict) -> bool:
# definition standards.
if values:
values = {
key: set(value) if isinstance(value, list) else {value}
key: set(value) if isinstance(value, tuple) else {value}
for key, value in values.items()
}
else:
Expand Down
82 changes: 44 additions & 38 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,76 +1,82 @@
Release Notes
=============

0.1.4
-----

* Changed the return type of data elements with a value multiplicity greater
than 1 from `list` to `tuple`.

0.1.3
-----

* Changed Code String (CS) parsing to return verbose value or set of values
using the :mod:`~dicom_parser.utils.code_strings` module. This feature can
be disabled by setting the :class:`~dicom_parser.parser.Parser`'s
:attr:`~dicom_parser.parser.Parser.verbose_code_strings` attribute to *False*.
* Changed Code String (CS) parsing to return verbose value or set of values
using the :mod:`~dicom_parser.utils.code_strings` module. This feature can
be disabled by setting the :class:`~dicom_parser.parser.Parser`'s
:attr:`~dicom_parser.parser.Parser.verbose_code_strings` attribute to *False*.

* Added warnings for invalid pixel arrays and invalid Code String (CS) values.
* Added warnings for invalid pixel arrays and invalid Code String (CS) values.

* Updated the :mod:`~dicom_parser.utils.sequence_detector.sequences` module
to work with verbose Code String (CS) data element values and renamed known MR
sequences.
* Updated the :mod:`~dicom_parser.utils.sequence_detector.sequences` module
to work with verbose Code String (CS) data element values and renamed known MR
sequences.

* Refactored the :class:`~dicom_parser.parser.Parser` class to a bit to
improve readability.
* Refactored the :class:`~dicom_parser.parser.Parser` class to a bit to
improve readability.

* Fixed CSA header bug for headers with a duplicate *"### ASCCONV END ###"*
pattern.
* Fixed CSA header bug for headers with a duplicate *"### ASCCONV END ###"*
pattern.

* Created the :class:`~dicom_parser.data_element.DataElement` class as a wrapper
around pydicom_\'s :class:`~pydicom.dataelem.DataElement` to support some
custom functionality and provide better integration with django_dicom_.
* Created the :class:`~dicom_parser.data_element.DataElement` class as a wrapper
around pydicom_\'s :class:`~pydicom.dataelem.DataElement` to support some
custom functionality and provide better integration with django_dicom_.


0.1.2
-----

* Improved private tags definition so that the
:class:`~dicom_parser.header.Header` model's
:meth:`~dicom_parser.header.Header.get` method will work using the
private tag's keyword.
* Improved private tags definition so that the
:class:`~dicom_parser.header.Header` model's
:meth:`~dicom_parser.header.Header.get` method will work using the
private tag's keyword.

* Added support for calling :meth:`len` over a :class:`~dicom_parser.series.Series`
instance to return the number of images in it.
* Added support for calling :meth:`len` over a :class:`~dicom_parser.series.Series`
instance to return the number of images in it.

* Added support for querying header information from a
:class:`~dicom_parser.series.Series` instance using the
:meth:`~dicom_parser.series.Series.get` method or the indexing operator
([]) using a :obj:`str` or a :obj:`tuple`.
* Added support for querying header information from a
:class:`~dicom_parser.series.Series` instance using the
:meth:`~dicom_parser.series.Series.get` method or the indexing operator
([]) using a :obj:`str` or a :obj:`tuple`.

* Added support for indexing the :class:`~dicom_parser.image.Image` instances
from a :class:`~dicom_parser.series.Series` using an :obj:`int` or :obj:`slice`.
* Added support for indexing the :class:`~dicom_parser.image.Image` instances
from a :class:`~dicom_parser.series.Series` using an :obj:`int` or :obj:`slice`.


0.1.1
-----

* Improved support for accessing `CSA headers`_.
* Improved support for accessing `CSA headers`_.

* Added auto-decoding for `Siemens mosaic`_ encoded data (applies to data
extraction in both :class:`~dicom_parser.image.Image` and
:class:`~dicom_parser.series.Series` instances).
* Added auto-decoding for `Siemens mosaic`_ encoded data (applies to data
extraction in both :class:`~dicom_parser.image.Image` and
:class:`~dicom_parser.series.Series` instances).

* The decoding method also changes the orientation of the stacked arrays
to match the product of conversion to NIfTI_ using dcm2niix_.
* The decoding method also changes the orientation of the stacked arrays
to match the product of conversion to NIfTI_ using dcm2niix_.


0.1.0
-----

First release!

* Type correction based on `value-representation (VR)`_.
* Type correction based on `value-representation (VR)`_.

* Simple :class:`~dicom_parser.series.Series` class for reading DICOM
series directories.
* Simple :class:`~dicom_parser.series.Series` class for reading DICOM
series directories.

* Basic support for reading `CSA headers`_ using the
:class:`~dicom_parser.utils.siemens.csa.header.CsaHeader` class.
* Basic support for reading `CSA headers`_ using the
:class:`~dicom_parser.utils.siemens.csa.header.CsaHeader` class.


.. _CSA Headers: https://nipy.org/nibabel/dicom/siemens_csa.html
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ coverage~=5.0
coverage-badge~=1.0
doc8~=0.8
flake8~=3.7
ipython~=7.15
ipython~=7.19
pytest~=5.3
sphinx~=2.4
sphinx-rtd-theme~=0.4
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name="dicom_parser",
version="0.1.3",
version="0.1.4",
packages=find_packages(),
include_package_data=True,
license="AGPLv3",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def test_get_raw_value_with_invalid_key_raises_key_error(self):
def test_get_parsed_value(self):
expected_study_date = TEST_STUDY_FIELDS["date"]
study_date = self.header.get_parsed_value("StudyDate")
expected_pixel_spacing = [
expected_pixel_spacing = tuple(
float(value) for value in self.header.get_raw_value("PixelSpacing")
]
)
pixel_spacing = self.header.get_parsed_value("PixelSpacing")
self.assertEqual(study_date, expected_study_date)
self.assertEqual(pixel_spacing, expected_pixel_spacing)
Expand Down

0 comments on commit c4c4791

Please sign in to comment.