Contain and manipulate a DICOM Element.
Examples
While its possible to create a new DataElement
directly and add it to a Dataset
:
>>> from pydicom import Dataset >>> elem = DataElement(0x00100010, 'PN', 'CITIZEN^Joan') >>> ds = Dataset() >>> ds.add(elem)
Its far more convenient to use a Dataset
to add a new DataElement
, as the VR and tag are determined automatically from the DICOM dictionary:
>>> ds = Dataset() >>> ds.PatientName = 'CITIZEN^Joan'
Empty DataElement objects (e.g. with VM = 0) show an empty string as value for text VRs and None for non-text (binary) VRs:
>>> ds = Dataset() >>> ds.PatientName = None >>> ds.PatientName ''
>>> ds.BitsAllocated = None >>> ds.BitsAllocated
>>> str(ds.BitsAllocated) 'None'
For string display, this is the maximum width of the description field (default 35
).
Indicates whether the length field for the element was 0xFFFFFFFFL
(ie undefined).
For string display, elements with values containing data which is longer than this value will display "array of # bytes"
(default 16
).
For string display, include the element’s VR just before it’s value (default True
).
The element’s tag.
The mode used to validate the element’s value. See Settings.writing_validation_mode
for more information.
The element’s Value Representation.
Create a new DataElement
.
tag (int | str | tuple[int, int]) – The DICOM (group, element) tag in any form accepted by Tag()
such as 'PatientName'
, (0x10, 0x10)
, 0x00100010
, etc.
VR (str) – The 2 character DICOM value representation (see DICOM Standard, Part 5, Section 6.2).
value (Any) –
The value of the data element, the allowed type depends on the VR and includes:
file_value_tell (int, optional) – The byte offset to the start of the encoded element value.
is_undefined_length (bool, optional) – Used internally to store whether the length field for this element was 0xFFFFFFFF
, i.e. ‘undefined length’. Default is False
.
already_converted (bool, optional) – Used to determine whether or not the element’s value requires conversion to a value with VM > 1. Default is False
.
validation_mode (int, optional) – Defines if values are validated and how validation errors are handled.
Methods
Attributes
Return the value multiplicity of the element as int
.
Changed in version 3.0: SQ elements now always return a VM of 1
.
Clears the value, e.g. sets it to the configured empty value.
See empty_value_for_VR()
.
Return the value for an empty element.
See empty_value_for_VR()
for more information.
The value this data element is assigned on decoding if it is empty.
str or None
Return a DataElement
from a DICOM JSON Model attribute object.
dataset_class (dataset.Dataset derived class) – The class object to use for SQ element items.
tag (str) – The data element’s tag as uppercase hex.
vr (str) – The data element’s value representation (VR).
value (str or list[None | str | int | float | bytes | dict]) – The data element’s value(s).
value_key (str or None) – The attribute name for value, should be one of: {"Value", "InlineBinary", "BulkDataURI"}
. If the element’s VM is 0
and none of the keys are used then will be None
.
bulk_data_uri_handler (callable or None) – Callable function that accepts either the tag, vr and “BulkDataURI” value or just the “BulkDataURI” value of the JSON representation of a data element and returns the actual value of that data element (retrieved via DICOMweb WADO-RS). If no bulk_data_uri_handler is specified (default) then the corresponding element will have an “empty” value such as ""
, b""
or None
depending on the vr (i.e. the Value Multiplicity will be 0).
Return True
if the element’s value is a io.BufferedIOBase
instance, False
otherwise.
Return True
if the element has no value.
Return True
if the element’s tag is private.
Added in version 2.1.
Return the element’s retired status as bool
.
For officially registered DICOM Data Elements this will be True
if the retired status as given in the DICOM Standard, Part 6, Table 6-1 is ‘RET’. For private or unknown elements this will always be False
.
Return the element’s keyword (if known) as str
.
For officially registered DICOM Data Elements this will be the Keyword as given in Table 6-1. For private or unknown elements this will return an empty string ''
.
Return the DICOM dictionary name for the element as str
.
For officially registered DICOM Data Elements this will be the Name as given in Table 6-1.
For private elements known to pydicom this will be the Name in the format '[name]'
.
For unknown private elements this will be 'Private tag data'
.
Otherwise returns an empty string ''
.
Return a str
representation of the element’s value.
Return a JSON representation of the DataElement
.
bulk_data_threshold (int, optional) – Size of base64 encoded data element above which a value will be provided in form of a “BulkDataURI” rather than “InlineBinary”. Ignored if no bulk_data_element_handler is given.
bulk_data_element_handler (callable, optional) – Callable that accepts a bulk :class`data element <pydicom.dataelem.DataElement>` and returns the “BulkDataURI” as a str
for retrieving the value of the data element via DICOMweb WADO-RS.
dump_handler (callable, optional) – Callable function that accepts a dict
of {str: Any}
and returns the serialized (dumped) JSON str
(by default uses json.dumps()
).
Mapping representing a JSON encoded data element
Return a dictionary representation of the DataElement
conforming to the DICOM JSON Model as described in the DICOM Standard, Part 18, Annex F.
bulk_data_element_handler (callable or None) – Callable that accepts a bulk :class`data element <pydicom.dataelem.DataElement>` and returns the “BulkDataURI” as a str
for retrieving the value of the data element via DICOMweb WADO-RS.
bulk_data_threshold (int) – Size of base64 encoded data element above which a value will be provided in form of a “BulkDataURI” rather than “InlineBinary”. Ignored if no bulk_data_element_handler is given.
Mapping representing a JSON encoded data element as {str: Any}
.
Validate the current value against the DICOM standard. See validate_value()
for details.
Get or set the element’s value.
val (Any) – The value to use to set the element’s value, should be an appropriate type for the VR. The value will be validated in accordance with the element’s validation_mode
.
The element’s value.
Any
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4