dicomgenerator
Generate pydicom datasets and data elements for use in testing.
- Free software: MIT license
- Status: Alpha. Tests run but there are loose ends
Features
- Extends factory-boy factories to produce pydicom Datasets and DicomElements
- Generate valid DICOM values for person name, time, date, and UID
- Create json-based editable templates from any dicom file
- quick_dataset(): single-line pydicom dataset init
Installation
Install with pip::
pip install dicomgenerator
Usage
Quick dataset
I have found this quite useful in testing:
from dicomgenerator.generators import quick_dataset
ds = quick_dataset(PatientName='Jane', StudyDescription='Test')
# >>> ds.PatientName -> 'Jane'
# >>> ds.StudyDescription -> 'Test'
Generating a dataset
Generate a realistic CT dataset
from dicomgenerator.templates import CTDatasetFactory
# Generate from template
>>> CTDatasetFactory().PatientName -> 'van Haarlem^Anouk' # generated random name
>>> CTDatasetFactory().PatientName -> 'Loreal^Casper' # generated random name
# Overwrite arbitrary DICOM elements
ds.CTDatasetFactory(PatientSex='M', PatientName='Smith^Harry')
>>> ds.PatientName -> 'Smith^Harry'
>>> ds.PatientSex -> 'M'
# generated UIDs and dates are valid DICOM
>>> CTDatasetFactory().StudyTime -> '130624.929'
>>> CTDatasetFactory().StudyDate -> '20110508'
>>> CTDatasetFactory().StudyInstanceUID -> '1.2.826.0.1.3680'
Generating a data element
# import
from dicomgenerator.templates import DataElementFactory
# Creating a DICOM data element by name will give a realistic value and correct VR
>>> DataElementFactory(tag='PatientName').value -> "van Ooyen^Fiene"
>>> DataElementFactory(tag='PatientName').VR -> 'PN'
# You can also give DICOM tags as hex
>>> DataElementFactory(tag=0x00100010).value -> "Weil^Jack"
# Dates, times and UIDs all work.
>>> DataElementFactory(tag="AcquisitionTime").value -> '184146.928'
>>> DataElementFactory(tag="PatientBirthDate").value -> '20120511'
>>> DataElementFactory(tag="SeriesInstanceUID").value -> '1.2.826.0.1.3680'
In reproducible tests
You can set the random seed in factory-boy like this:
from factory import random
def test_one:
"""The random patient name in this test will always be the same"""
random.reseed_random('any string you want')
assert element = DataElementFactory(tag='PatientName').value == "van Ooyen^Fiene"
Command Line Interface
You can convert a DICOM file to AnnotatedDataset via the commandline. by default this will write an annotated dataset to the same folder, appending_template.json
$ dicomgen convert to-json /tmp/dicom_file
$ ls
dicom_file dicom_file_template.json
For options, use
$ dicomgen convert to-json --help
Credits
This package was originally created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
Metadata
Release files for dicomgenerator 0.13.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 |
|---|---|---|---|---|
| dicomgenerator-0.13.0.tar.gz | 99.3 kB | Without provenance | Details for dicomgenerator-0.13.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dicomgenerator-0.13.0-py3-none-any.whl | Python 3 | none | any | Details for dicomgenerator-0.13.0-py3-none-any.whl |
Total release size: 201.8 kB
Release files / dicomgenerator-0.13.0.tar.gz
| Download URL | dicomgenerator-0.13.0.tar.gz |
|---|---|
| Size | 99.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f5f4156d3ff690877d71d35931870b162cde61f9663b68d0adc540f6482b761
|
|
BLAKE2b-256 checksum How to use checksums |
62631ab988527e75ac4cd8c2765b7d33970214919caeea846f1eccbcad521ef1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / dicomgenerator-0.13.0-py3-none-any.whl
| Download URL | dicomgenerator-0.13.0-py3-none-any.whl |
|---|---|
| Size | 102.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e7fe680592fbd1e3299e7e6791239da032b5e60cdcb6091b740cbf940938e37
|
|
BLAKE2b-256 checksum How to use checksums |
02f68c1a7a68e45b0f0ac04e61c80966f3016278882267ae6106a0b9763d5d18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for dicomgenerator 0.13.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.