pydicom.dataset.FileDataset¶
- class pydicom.dataset.FileDataset(filename_or_obj: str | bytes | PathLike | BinaryIO | DicomFileLike, dataset: Dataset | MutableMapping[BaseTag, DataElement | RawDataElement], preamble: bytes | None = None, file_meta: FileMetaDataset | None = None, is_implicit_VR: bool = True, is_little_endian: bool = True)[source]¶
An extension of
Dataset
to make reading and writing to file-like easier.- preamble¶
The optional DICOM preamble prepended to the
FileDataset
, if available.
- file_meta¶
The Dataset’s file meta information as a
FileMetaDataset
, if available (None
if not present). Consists of group0x0002
elements.- Type:
FileMetaDataset or None
- filename¶
The filename that the
FileDataset
was read from (if read from file) orNone
if the filename is not available (if read from aio.BytesIO
or similar).- Type:
str or None
- fileobj_type¶
The object type of the file-like the
FileDataset
was read from.
- is_little_endian¶
True
if the dataset encoding is little endian byte ordering,False
otherwise.- Type:
- timestamp¶
The modification time of the file the
FileDataset
was read from,None
if the modification time is not available.- Type:
float or None
- __init__(filename_or_obj: str | bytes | PathLike | BinaryIO | DicomFileLike, dataset: Dataset | MutableMapping[BaseTag, DataElement | RawDataElement], preamble: bytes | None = None, file_meta: FileMetaDataset | None = None, is_implicit_VR: bool = True, is_little_endian: bool = True) None [source]¶
Initialize a
FileDataset
read from a DICOM file.- Parameters:
filename_or_obj (str or PathLike or BytesIO or None) – Full path and filename to the file, memory buffer object, or
None
if is aio.BytesIO
.dataset (Dataset or dict) – Some form of dictionary, usually a
Dataset
returned fromdcmread()
.preamble (bytes or str, optional) – The 128-byte DICOM preamble.
file_meta (FileMetaDataset, optional) – The file meta
FileMetaDataset
, such as the one returned byread_file_meta_info()
, or an emptyFileMetaDataset
if no file meta information is in the file.is_implicit_VR (bool, optional) –
True
(default) if implicit VR transfer syntax used;False
if explicit VR.is_little_endian (bool) –
True
(default) if little-endian transfer syntax used;False
if big-endian.
Methods
__init__
(filename_or_obj, dataset[, ...])Initialize a
FileDataset
read from a DICOM file.add
(data_element)Add an element to the
Dataset
.add_new
(tag, VR, value)Create a new element and add it to the
Dataset
.add_new_private
(private_creator, group, ...)Create a new private element and add it to the
Dataset
.clear
()Delete all the elements from the
Dataset
.compress
(transfer_syntax_uid[, arr, ...])Compress and update an uncompressed dataset in-place with the resulting encapsulated pixel data.
convert_pixel_data
([handler_name])Convert pixel data to a
numpy.ndarray
internally.copy
()Return a shallow copy of the dataset.
data_element
(name)Return the element corresponding to the element keyword name.
decode
()Apply character set decoding to the elements in the
Dataset
.decompress
([handler_name])Decompresses Pixel Data and modifies the
Dataset
in-place.dir
(*filters)Return an alphabetical list of element keywords in the
Dataset
.elements
()Yield the top-level elements of the
Dataset
.ensure_file_meta
()Create an empty
Dataset.file_meta
if none exists.fix_meta_info
([enforce_standard])Ensure the file meta info exists and has the correct values for transfer syntax and media storage UIDs.
formatted_lines
([element_format, ...])Iterate through the
Dataset
yielding formattedstr
for each element.from_json
(json_dataset[, bulk_data_uri_handler])Return a
Dataset
from a DICOM JSON Model object.get
(key[, default])Simulate
dict.get()
to handle element tags and keywords.get_item
(key)Return the raw data element if possible.
get_private_item
(group, element_offset, ...)Return the data element for the given private tag group.
group_dataset
(group)Return a
Dataset
containing only elements of a certain group.items
()Return the
Dataset
items to simulatedict.items()
.iterall
()Iterate through the
Dataset
, yielding all the elements.keys
()Return the
Dataset
keys to simulatedict.keys()
.overlay_array
(group)Return the Overlay Data in group as a
numpy.ndarray
.pop
(key, *args)Emulate
dict.pop()
with support for tags and keywords.popitem
()Emulate
dict.popitem()
.private_block
(group, private_creator[, create])Return the block for the given tag group and private_creator.
private_creators
(group)Return a list of private creator names in the given group.
remove_private_tags
()Remove all private elements from the
Dataset
.save_as
(filename[, write_like_original])Write the
Dataset
to filename.set_original_encoding
(is_implicit_vr, ...)Set the values for the original transfer syntax and encoding.
setdefault
(key[, default])Emulate
dict.setdefault()
with support for tags and keywords.to_json
([bulk_data_threshold, ...])Return a JSON representation of the
Dataset
.to_json_dict
([bulk_data_threshold, ...])Return a dictionary representation of the
Dataset
conforming to the DICOM JSON Model as described in the DICOM Standard, Part 18, Annex F.top
()Return a
str
representation of the top level elements.trait_names
()Return a
list
of valid names for auto-completion code.update
(d)Extend
dict.update()
to handle DICOM tags and keywords.values
()Return the
Dataset
values to simulatedict.values()
.walk
(callback[, recursive])Iterate through the
Dataset's
elements and run callback on each.waveform_array
(index)Return an
ndarray
for the multiplex group at index in the (5400,0100) Waveform Sequence.Attributes
default_element_format
default_sequence_element_format
indent_chars
is_original_encoding
Return
True
if the encoding to be used for writing is set and is the same as that used to originally encode theDataset
.original_character_set
Return the original character set encoding for a dataset decoded from a file or buffer.
original_encoding
Return the original encoding used for a dataset decoded from a file or buffer.
pixel_array
Return the pixel data as a
numpy.ndarray
.read_encoding
read_implicit_vr
Get the VR method used by the original encoding of the dataset.
read_little_endian
Get the endianness used by the original encoding of the dataset.