Generate pydicom datasets and data elements for use in testing
Project description
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.factory 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.factory 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dicomgenerator-0.9.0.tar.gz
.
File metadata
- Download URL: dicomgenerator-0.9.0.tar.gz
- Upload date:
- Size: 99.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.8.18 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ab7eec9865171b85951df7be35a9aa38b04ef8a1d97b4278116dd2a005158fe |
|
MD5 | 2202e864ed3ca00a21ab46f982aa05b0 |
|
BLAKE2b-256 | 6c803ef358b15c8482230c4c712e2fb5ca004e0657380cba6e36d507e87e6702 |
File details
Details for the file dicomgenerator-0.9.0-py3-none-any.whl
.
File metadata
- Download URL: dicomgenerator-0.9.0-py3-none-any.whl
- Upload date:
- Size: 101.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.8.18 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c04ad17286aacd5288143cff796902e05770cf5c449c88306076b4c761ac18d |
|
MD5 | ec248b4dc24ddadea86b3d44b0efd292 |
|
BLAKE2b-256 | 005015b0f9ee5acedfb6e841016ab246621ea230bf61185850aadaa4e25cb21a |