Skip to content

Commit

Permalink
Exclude CharPyLS for Python 3.11
Browse files Browse the repository at this point in the history
- does not compile
  • Loading branch information
mrbean-bremen committed Apr 22, 2023
1 parent 27ef8f4 commit 2a89d64
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/merge-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
python -m pip uninstall -y pillow
- name: Install and test jpeg_ls
if: ${{ matrix.python-version != '3.12-dev' }}
if: ${{ matrix.python-version != '3.11' && matrix.python-version != '3.12-dev'}}
run: |
python -m pip install --upgrade cython
python -m pip install git+https://github.com/Who8MyLunch/CharPyLS
Expand All @@ -101,7 +101,7 @@ jobs:
pytest ${{ matrix.pytest-args }} pydicom/tests/test_pylibjpeg.py
- name: Test all pixel handling
if: ${{ matrix.python-version != '3.12-dev' }}
if: ${{ matrix.python-version != '3.11' && matrix.python-version != '3.12-dev'}}
run: |
python -m pip install pillow python-gdcm
python -m pip install git+https://github.com/Who8MyLunch/CharPyLS
Expand Down
5 changes: 3 additions & 2 deletions doc/old/image_data_handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ handled by the given packages:

+-------------------------------------------------------------+-------+-------------+----------+-----------------+-----------------+
| Transfer Syntax | NumPy | | NumPy + | | NumPy +| | NumPy + | | NumPy + |
+------------------------------------+------------------------+ | | JPEG-LS | | GDCM | | Pillow | | pylibjpeg |
| Name | UID | | | | | |
+------------------------------------+------------------------+ | | JPEG-LS\ | | GDCM | | Pillow | | pylibjpeg |
| Name | UID | | :sup:`7` | | | |
+====================================+========================+=======+=============+==========+=================+=================+
| Explicit VR Little Endian | 1.2.840.10008.1.2.1 | |chk| | |chk| | |chk| | |chk| | |chk| |
+------------------------------------+------------------------+-------+-------------+----------+-----------------+-----------------+
Expand Down Expand Up @@ -92,6 +92,7 @@ handled by the given packages:
| :sup:`4` *with the pylibjpeg-rle plugin and using the* :meth:`~pydicom.dataset.Dataset.decompress` *method, 4-5x faster than default*
| :sup:`5` *with the pylibjpeg-libjpeg plugin*
| :sup:`6` *with the pylibjpeg-openjpeg plugin*
| :sup:`7` *only up to Python 3.10*
Usage
.....
Expand Down
1 change: 1 addition & 0 deletions doc/release_notes/v2.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ Pydicom Internals
-----------------
* In test suites, renamed 'setup' and 'teardown' methods, deprecated starting
in pytest 7.2
* Do not try to use `CharPyLS` with Python > 3.10 (:issue:`1788`)
41 changes: 41 additions & 0 deletions pydicom/tests/test_dataelem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,3 +1149,44 @@ def test_elem_description_deprecated():
)
with pytest.warns(DeprecationWarning, match=msg):
assert elem.description() == "Patient's Name"


def test_seg():
import numpy as np
import pydicom

orig = pydicom.dcmread(r"c:\dev\DICOM Data\pydicom\986\T1.dcm")
over = pydicom.dcmread(r"c:\dev\DICOM Data\pydicom\986\seg.dcm")

# rows_orig = orig[0x00280010].value
# cols_orig = orig[0x00280011].value
rows_orig = over[0x00280010].value
cols_orig = over[0x00280011].value

# segmented
im_data_over = over.pixel_array - 4203
# binarize segmented
im_data_over = np.where(im_data_over > 0, 1, 0)
im_data_over = im_data_over.astype('uint16')
from pydicom.pixel_data_handlers import pack_bits
im_data_over_bytes = pack_bits(im_data_over)
descrip = 'segmentation'

# Overlay fields
# filling in only Type 1 (mandatory) fields
orig.add_new([0x6000, 0x0010], 'US', rows_orig) # Overlay Rows
orig.add_new([0x6000, 0x0011], 'US', cols_orig) # Overlay Columns
orig.add_new([0x6000, 0x0015], 'US', 1) # Overlay number of frames
orig.add_new([0x6000, 0x0022], 'LO', descrip) # Overlay description
orig.add_new([0x6000, 0x0040], 'CS',
'G') # Overlay Type ('R','G'), ROI or Graphics
orig.add_new([0x6000, 0x0050], 'SS', [1, 1]) # Overlay Origin
orig.add_new([0x6000, 0x0051], 'US', 1) # Image Frame Origin
orig.add_new([0x6000, 0x0100], 'US',
1) # Overlay Bits Allocated, mandatory fixed value = 1!!
orig.add_new([0x6000, 0x0102], 'US',
0) # Overlay Bit Position, mandatory fixed value = 0!!
orig.add_new([0x6000, 0x1001], 'CS', 'MASK') # Overlay Activation Layer
orig.add_new([0x6000, 0x3000], 'OW', im_data_over_bytes) # PixelData

orig.save_as(r"c:\dev\DICOM Data\pydicom\986\orig_with_overlay.dcm")

Check failure on line 1192 in pydicom/tests/test_dataelem.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W292)

pydicom/tests/test_dataelem.py:1192:73: W292 No newline at end of file
33 changes: 33 additions & 0 deletions pydicom/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2302,3 +2302,36 @@ def test_setattr_ignore(setattr_ignore):
with assert_no_warning():
getattr(ds, s, None)
setattr(ds, s, None)

from pydicom.dataelem import _private_vr_for_tag
from pydicom.valuerep import VR

def remove_invalid_ds(raw_elem, **kwargs):
if raw_elem.tag.is_private and raw_elem.value:
vr = _private_vr_for_tag(kwargs["ds"], raw_elem.tag)
if vr == VR.DS:
try:
raw_elem.value.decode("ascii")
except UnicodeDecodeError:
print(f"Removing invalid tag value for tag {raw_elem.tag}")
return RawDataElement(raw_elem.tag, "DS", 0, None, 0,
raw_elem.is_implicit_VR,
raw_elem.is_little_endian)
return raw_elem


def test_change_encoding():
ds = dcmread(r"c:\dev\DICOM Data\pydicom\1739\filename.dcm")
config.data_element_callback = remove_invalid_ds
config.data_element_callback_kwargs = {"ds": ds}
ds.decode()
ds['SpecificCharacterSet'].value = 'ISO_IR 192'
ds.save_as(r"c:\dev\DICOM Data\pydicom\1739\filename_utf8.dcm")

def test_enhanced_mr():
filename = r"c:\dev\DICOM Data\EnhancedMR\BRUKER_WG30_1_Mouse_cardio_Brain_Mouse__E17_P1\EnIm1.dcm"
ds = dcmread(filename)
positions = []
for item in ds.PerFrameFunctionalGroupSequence:
positions.append(item.PlanePositionSequence[0].ImagePositionPatient)
print(positions)

Check failure on line 2337 in pydicom/tests/test_dataset.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W292)

pydicom/tests/test_dataset.py:2337:21: W292 No newline at end of file

0 comments on commit 2a89d64

Please sign in to comment.