Example #1
0
def write(path: Path) -> None:
    # read methods up to start of tag enum values
    lines: List[str] = []
    with open(path, "r") as f:
        for line in f.readlines():
            lines.append(line)
            if line.strip() == MARKER:
                break

    # write tag enum values
    with open(path, "w") as f:
        f.writelines(lines)
        for tag, v in DicomDictionary.items():
            keyword = v[-1]
            if keyword:
                f.write(f"    {keyword} = {tag}\n")
Example #2
0
# mean the AGPL-3.0+.

# You should have received a copy of the Apache-2.0 along with this
# program. If not, see <http://www.apache.org/licenses/LICENSE-2.0>.

from copy import deepcopy

import numpy as np

from pydicom import Dataset
from pydicom.datadict import DicomDictionary

from ...libutils import get_imports
IMPORTS = get_imports(globals())

DICOM_NAMES = [item[-1] for _, item in DicomDictionary.items()]


def convert_nparray_and_set_key_value_in_dataset(dataset, key, value):
    if isinstance(value, np.ndarray):
        value = value.tolist()

    setattr(dataset, key, value)


def dicom_dataset_from_dict(input_dict: dict, template_ds=None):
    """Create a pydicom DICOM object from a dictionary"""
    if template_ds is None:
        dataset = Dataset()
    else:
        dataset = deepcopy(template_ds)