dicomgenerator


Namedicomgenerator JSON
Version 0.9.0 PyPI version JSON
download
home_pagehttps://github.com/sjoerdk/dicomgenerator
SummaryGenerate pydicom datasets and data elements for use in testing
upload_time2024-09-19 15:07:32
maintainerNone
docs_urlNone
authorsjoerdk
requires_python<4.0,>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dicomgenerator


[![CI](https://github.com/sjoerdk/dicomgenerator/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/sjoerdk/dicomgenerator/actions/workflows/build.yml?query=branch%3Amaster)
[![PyPI](https://img.shields.io/pypi/v/dicomgenerator)](https://pypi.org/project/dicomgenerator/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/dicomgenerator)](https://pypi.org/project/dicomgenerator/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)

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](https://factoryboy.readthedocs.io) factories to produce [pydicom](https://github.com/pydicom/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:

```python
    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

```python 
    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

```python
    # 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](https://factoryboy.readthedocs.io) like this:

```python
    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](https://github.com/audreyr/cookiecutter) and the [audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage) project template.
 

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sjoerdk/dicomgenerator",
    "name": "dicomgenerator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "sjoerdk",
    "author_email": "sjoerd.kerkstra@radboudumc.nl",
    "download_url": "https://files.pythonhosted.org/packages/6c/80/3ef358b15c8482230c4c712e2fb5ca004e0657380cba6e36d507e87e6702/dicomgenerator-0.9.0.tar.gz",
    "platform": null,
    "description": "# dicomgenerator\n\n\n[![CI](https://github.com/sjoerdk/dicomgenerator/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/sjoerdk/dicomgenerator/actions/workflows/build.yml?query=branch%3Amaster)\n[![PyPI](https://img.shields.io/pypi/v/dicomgenerator)](https://pypi.org/project/dicomgenerator/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/dicomgenerator)](https://pypi.org/project/dicomgenerator/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n\nGenerate pydicom datasets and data elements for use in testing.\n\n* Free software: MIT license\n* Status: Alpha. Tests run but there are loose ends\n\nFeatures\n--------\n* Extends [factory-boy](https://factoryboy.readthedocs.io) factories to produce [pydicom](https://github.com/pydicom/pydicom) Datasets and DicomElements \n* Generate valid DICOM values for person name, time, date, and UID\n* Create json-based editable templates from any dicom file\n* quick_dataset(): single-line pydicom dataset init\n\n## Installation\n\n\nInstall with pip::\n\n    pip install dicomgenerator\n\n\n## Usage\n### Quick dataset\nI have found this quite useful in testing:\n\n```python\n    from dicomgenerator.generators import quick_dataset\n    ds = quick_dataset(PatientName='Jane', StudyDescription='Test')\n\n    # >>> ds.PatientName -> 'Jane'     \n    # >>> ds.StudyDescription -> 'Test'\n```\n\n\n### Generating a dataset\nGenerate a realistic CT dataset\n\n```python \n    from dicomgenerator.factory import CTDatasetFactory\n\n    # Generate from template\n    >>> CTDatasetFactory().PatientName -> 'van Haarlem^Anouk'  #  generated random name\n    >>> CTDatasetFactory().PatientName -> 'Loreal^Casper'      #  generated random name\n\n    # Overwrite arbitrary DICOM elements\n    ds.CTDatasetFactory(PatientSex='M', PatientName='Smith^Harry')\n    >>> ds.PatientName -> 'Smith^Harry'\n    >>> ds.PatientSex  -> 'M'\n\n    # generated UIDs and dates are valid DICOM\n    >>> CTDatasetFactory().StudyTime        -> '130624.929'\n    >>> CTDatasetFactory().StudyDate        -> '20110508'\n    >>> CTDatasetFactory().StudyInstanceUID -> '1.2.826.0.1.3680'\n```\n\n\n## Generating a data element\n\n```python\n    # import\n    from dicomgenerator.factory import DataElementFactory\n\n    # Creating a DICOM data element by name will give a realistic value and correct VR\n    >>> DataElementFactory(tag='PatientName').value -> \"van Ooyen^Fiene\"\n    >>> DataElementFactory(tag='PatientName').VR -> 'PN'\n\n    # You can also give DICOM tags as hex\n    >>> DataElementFactory(tag=0x00100010).value -> \"Weil^Jack\"\n\n    # Dates, times and UIDs all work.\n    >>> DataElementFactory(tag=\"AcquisitionTime\").value   -> '184146.928'\n    >>> DataElementFactory(tag=\"PatientBirthDate\").value  -> '20120511'\n    >>> DataElementFactory(tag=\"SeriesInstanceUID\").value -> '1.2.826.0.1.3680'\n```\n\n### In reproducible tests\nYou can set the random seed in [factory-boy](https://factoryboy.readthedocs.io) like this:\n\n```python\n    from factory import random\n\n    def test_one:\n        \"\"\"The random patient name in this test will always be the same\"\"\"\n        random.reseed_random('any string you want')\n        assert element = DataElementFactory(tag='PatientName').value == \"van Ooyen^Fiene\"\n```\n\n### Command Line Interface\nYou 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`\n\n```\n$ dicomgen convert to-json /tmp/dicom_file\n$ ls\ndicom_file  dicom_file_template.json\n```\n\nFor options, use\n```\n$ dicomgen convert to-json --help\n```\n\n\n## Credits\n\nThis package was originally created with [Cookiecutter](https://github.com/audreyr/cookiecutter) and the [audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage) project template.\n \n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Generate pydicom datasets and data elements for use in testing",
    "version": "0.9.0",
    "project_urls": {
        "Homepage": "https://github.com/sjoerdk/dicomgenerator",
        "Repository": "https://github.com/sjoerdk/dicomgenerator"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "005015b0f9ee5acedfb6e841016ab246621ea230bf61185850aadaa4e25cb21a",
                "md5": "ec248b4dc24ddadea86b3d44b0efd292",
                "sha256": "4c04ad17286aacd5288143cff796902e05770cf5c449c88306076b4c761ac18d"
            },
            "downloads": -1,
            "filename": "dicomgenerator-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ec248b4dc24ddadea86b3d44b0efd292",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 101254,
            "upload_time": "2024-09-19T15:07:31",
            "upload_time_iso_8601": "2024-09-19T15:07:31.068337Z",
            "url": "https://files.pythonhosted.org/packages/00/50/15b0f9ee5acedfb6e841016ab246621ea230bf61185850aadaa4e25cb21a/dicomgenerator-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6c803ef358b15c8482230c4c712e2fb5ca004e0657380cba6e36d507e87e6702",
                "md5": "2202e864ed3ca00a21ab46f982aa05b0",
                "sha256": "5ab7eec9865171b85951df7be35a9aa38b04ef8a1d97b4278116dd2a005158fe"
            },
            "downloads": -1,
            "filename": "dicomgenerator-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2202e864ed3ca00a21ab46f982aa05b0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 99644,
            "upload_time": "2024-09-19T15:07:32",
            "upload_time_iso_8601": "2024-09-19T15:07:32.300760Z",
            "url": "https://files.pythonhosted.org/packages/6c/80/3ef358b15c8482230c4c712e2fb5ca004e0657380cba6e36d507e87e6702/dicomgenerator-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-19 15:07:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sjoerdk",
    "github_project": "dicomgenerator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dicomgenerator"
}
        
Elapsed time: 0.36788s