dicom_parser
dicom_parser is deprecated and no longer maintained. Version 1.3.0 is the last release. It works with pydicom 2.1 to 3.x on Python 3.9 to 3.14, and it will get no further fixes. Everything it did is now covered by maintained tools. The guide below maps each feature to its replacement.
dicom_parser wrapped pydicom to return "pythonic" values from DICOM headers, and added Siemens-specific parsing: CSA headers, mosaics and diffusion vectors. Since it was written, pydicom 3, nibabel, csa_header and dcm2niix have come to cover all of it, with active maintainers and wider testing.
Replacing dicom_parser
| dicom_parser | Use instead |
|---|---|
Image, Header: reading a file, dict-like access by keyword or tag |
pydicom.dcmread and pydicom's Dataset |
| Parsed values (DS, IS, DA, TM, DT, PN) | pydicom: numbers are already float/int subclasses; dates and times with one config switch |
Header.keyword_contains, to_dict, to_dataframe |
Dataset.dir, Dataset.to_json_dict, a short pandas snippet |
Siemens private tags by keyword (B_value, MosaicRefAcqTimes, …) |
pydicom's Dataset.private_block |
CsaHeader, parse_ascconv |
csa_header (CsaHeader), or nibabel.nicom.ascconv.parse_ascconv |
Image.data (rescaling, Siemens mosaics, enhanced multi-frame) |
pydicom.pixels.apply_rescale; nibabel's DICOM wrappers |
affine, slice_normal, spatial_resolution, image_position |
nibabel's DICOM wrappers |
b_matrix, q_vector, b_vector, b_value |
nibabel's DICOM wrappers |
Series |
a few lines of pydicom, or dcm2niix for whole volumes |
detected_sequence, bids_path |
dcm2niix's BidsGuess; HeuDiConv, dcm2bids or BIDScoin for whole studies |
Verbose code strings ("MR" → "Magnetic Resonance") |
none: pydicom returns the codes |
Each replacement below was checked against dicom_parser's own test files.
Reading files and header values
import pydicom
pydicom.config.datetime_conversion = True # DA, TM and DT values become date/time objects
ds = pydicom.dcmread("image.dcm")
ds.ImagingFrequency # DS: already a float subclass
ds.InstanceNumber # IS: already an int subclass
ds.StudyDate # a datetime.date subclass
ds.PatientName.family_name # PN components
ds.get("MissingKeyword", "default")
ds[0x0018, 0x0050].value # access by tag
ds.dir("echo") # keywords containing "echo"
ds.to_json_dict() # the whole header as a dict
Age strings such as "027Y" stay strings in pydicom. To get years:
AGE_UNITS_PER_YEAR = {"Y": 1, "M": 12, "W": 52.1429, "D": 365.2422}
age_in_years = float(ds.PatientAge[:-1]) / AGE_UNITS_PER_YEAR[ds.PatientAge[-1]]
For a table of the header, like Header.to_dataframe:
import pandas as pd
header_table = pd.DataFrame(
[(str(element.tag), element.keyword, element.VR, element.VM, element.value) for element in ds],
columns=["Tag", "Keyword", "VR", "VM", "Value"],
).set_index("Tag")
Siemens private tags
pydicom knows the Siemens private dictionary, so private elements come back typed:
block = ds.private_block(0x0019, "SIEMENS MR HEADER")
block[0x0A].value # NumberOfImagesInMosaic
block[0x0C].value # B_value
block[0x0E].value # DiffusionGradientDirection
block[0x28].value # BandwidthPerPixelPhaseEncode
block[0x29].value # MosaicRefAcqTimes (slice timing, ms)
The B matrix (block[0x27]) is stored as its 6 upper-triangle values. To get the 3×3 matrix:
import numpy as np
upper_triangle = np.asarray(block[0x27].value, dtype=float)
b_matrix = upper_triangle[[0, 1, 2, 1, 3, 4, 2, 4, 5]].reshape(3, 3)
Siemens CSA headers
dicom_parser's CSA parser now lives on as csa_header, and gives the same result. The only change is that each
tag's index field is gone (csa_header 2.0 dropped it):
from csa_header import CsaHeader # pip install "csa_header>=2.0.1"
image_csa = CsaHeader(ds[0x0029, 0x1010].value).read()
series_csa = CsaHeader(ds[0x0029, 0x1020].value).read()
image_csa["B_value"]["value"]
protocol = series_csa["MrPhoenixProtocol"]["value"] # the parsed ASCCONV protocol
protocol["sDiffusion"]["lDiffDirections"]
To parse ASCCONV text yourself, parse_ascconv has the same signature and output in csa_header
(csa_header.ascii.ascconv) and in nibabel (nibabel.nicom.ascconv).
Pixel data, mosaics and multi-frame images
from pydicom.pixels import apply_rescale
pixels = apply_rescale(ds.pixel_array, ds) # applies RescaleSlope and RescaleIntercept
For Siemens mosaics and enhanced multi-frame images, nibabel unpacks and scales the data, and returns geometry that matches it:
from nibabel.nicom import dicomwrappers
wrapper = dicomwrappers.wrapper_from_file("image.dcm")
volume = wrapper.get_data() # a mosaic unpacked to 3D; a multi-frame image sorted into N-D
wrapper.affine # voxel indices to patient coordinates (DICOM LPS, mm)
wrapper.voxel_sizes
wrapper.slice_normal
wrapper.image_position
nibabel orders the axes differently from dicom_parser, so the arrays are transposed and flipped relative to
Image.data. The voxels are the same, and nibabel's affine matches nibabel's axes.
Diffusion
For Siemens DWI, nibabel's wrapper gives the same voxel-space values dicom_parser computed:
dwi = dicomwrappers.wrapper_from_file("dwi.dcm")
dwi.b_matrix # voxel space, as Image.voxel_space_b_matrix
dwi.q_vector
dwi.b_vector
dwi.b_value # as Image.voxel_space_b_value
Series
from pathlib import Path
import numpy as np
import pydicom
from pydicom.misc import is_dicom
from pydicom.pixels import apply_rescale
paths = [path for path in Path("series_directory").rglob("*") if path.is_file() and is_dicom(path)]
datasets = sorted((pydicom.dcmread(path) for path in paths), key=lambda dataset: dataset.InstanceNumber)
volume = np.stack([apply_rescale(dataset.pixel_array, dataset) for dataset in datasets], axis=-1)
echo_times = {dataset.EchoTime for dataset in datasets}
is_dicom finds DICOM files by content, as Series(path, mime=True) did, without libmagic. To turn a series into a
NIfTI volume with correct geometry, use dcm2niix.
Sequence detection and BIDS names
dcm2niix writes a JSON sidecar next to each volume (dcm2niix -b y …). Its BidsGuess field gives the BIDS data
type and entities, e.g. ["func", "_acq-epfid2p2m2_dir-AP_run-11_bold"], or ["discard", …] for a localizer. To
organise a whole study into BIDS, use HeuDiConv, dcm2bids or BIDScoin. All three let you write the
rules that dicom_parser hard-coded.
Verbose code strings
dicom_parser expanded some code strings (Modality, PatientPosition, PatientSex, ScanningSequence,
SequenceVariant), e.g. "HFS" to "Head First-Supine". pydicom returns the codes themselves. If you need the long
forms, the tables are in src/dicom_parser/utils/code_strings/ (MIT
licensed).
Known problems in dicom_parser's results
Comparing dicom_parser with the replacements on its own test files found these errors. If your results depend on any of them, re-check them with the tools above.
Image.affineon Siemens mosaics disagrees with dcm2niix's conversion by up to 283 mm for the same voxel. Its slice normal points the opposite way, and the affine does not follow the axis flips thatImage.dataapplies to the mosaic. nibabel's affine for the same file agrees with dcm2niix.spatial_resolution, and thereforeaffine, take the slice size fromSliceThicknessrather than from the spacing between slices, so they are wrong when slices have gaps (#84).Header.n_diffusion_directionsalways returnsNone.Header.phase_encoding_directiondisagrees with dcm2niix for row (left–right) phase encoding:i-where dcm2niix givesi.
Installing the last release
pip install dicom_parser
Version 1.3.0 supports pydicom 2.1 to 3.x and Python 3.9 to 3.14. It warns on import that the package is deprecated. The documentation site still describes the full API.
Credits
Written by Zvi Baratz during his PhD at Tel Aviv University, with contributions from
@GalKepler, @matthew-brett,
@taleinat, @Aharonyn,
@jstorrs, @LilianYou and
@juliam98. The CSA header parsing builds on nibabel's nicom module, and continues
in csa_header. To cite dicom_parser, use its Zenodo record.
Metadata
Release files for dicom-parser 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dicom_parser-1.3.0.tar.gz | 106.5 kB | Without provenance | Details for dicom_parser-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dicom_parser-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for dicom_parser-1.3.0-py3-none-any.whl |
Total release size: 210.8 kB
Release files / dicom_parser-1.3.0.tar.gz
| Download URL | dicom_parser-1.3.0.tar.gz |
|---|---|
| Size | 106.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
47b364de2f7c80d94c2942cd1d3f93209d901e79d1bc14e8720029f8c5fa0728
|
|
BLAKE2b-256 checksum How to use checksums |
6246b3c4bfcb213f5cdc1d5ee992e3605b12148c2b5839cc131d58b41fab11d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / dicom_parser-1.3.0-py3-none-any.whl
| Download URL | dicom_parser-1.3.0-py3-none-any.whl |
|---|---|
| Size | 104.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a97b93dee4791980d57a007819a09d93b49a07d60d005222796a814272794ac6
|
|
BLAKE2b-256 checksum How to use checksums |
8491093e41dca0751e4d40a543b36d56661069ae29d68a330e84ca0763e98d07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for dicom-parser 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.