Formats¶
Formats model different data sources (file formats).
All formats extend the BaseFormat class, guaranteeing basic functionality of checking files, loading scan pixeldata and metadata.
The BaseFormat Class¶
-
class
pyseus.formats.BaseFormat¶ Defines the interface for format classes.
-
classmethod
can_handle(path)¶ Return True if the format class can handle the file at path, otherwise return False.
Custom formats have to override this function.
-
flip(direction)¶ Flip the currently loaded pixeldata.
-
get_metadata(keys=None)¶ Return metadata items specified in keys.
If keys is empty, returns standard metadata items.
-
get_orientation()¶ Return the default image orientation, if available.
-
get_pixeldata(slice_=-1)¶ Return pixeldata of current scan. By default, the entire 3D pixeldata is returned. If slice_ is set, a 2D array of pixeldata[slice_] is returned.
-
get_scale()¶ Return the actual size of a pixel in mm, if available.
-
get_scan_metadata(scan)¶ Collect and return the metadata from the scan scan.
Custom formats have to override either this function and get_scan_pixeldata or reimplement load_scan.
-
get_scan_pixeldata(scan)¶ Collect and return the pixeldata from the scan scan.
Custom formats have to override either this function and get_scan_metadata or reimplement load_scan.
-
get_scan_thumbnail(scan)¶ Return the pixeldata to use for a scan thumbnail.
-
get_spacing(reset=False)¶ Return the pixel spacing, if available.
This is used for calculation of the pixel aspect ratio; the value has to be stored in self.pixel_spacing to be adjusted on rotation.
-
get_units()¶ Return units associated with the loaded values, if available.
-
load(path)¶ Attempt to load the file at path. Return True on success or throw an exception.
-
load_scan(scan)¶ Load pixeldata and metadata from the scan with the ID scan. Set self.scan to the scan ID on success or throw an exception. Uses get_scan_pixeldata and get_scan_metadata.
Custom formats have to override either this function or get_scan_pixeldata and get_scan_metadata.
-
meta_keymap= None¶ Maps common metadata keys to format specific keys.
-
metadata= None¶ Dictionary list of the metadata of the current scan.
-
path= None¶ The path to the currently loaded.
-
pixel_spacing= None¶ The pixel spacing metadata adjusted for rotation.
-
pixeldata= None¶ 3D array of the pixeldata of the current scan.
-
rotate(axis)¶ Rotate the currently loaded pixeldata in 3D.
-
scan= None¶ The ID of the currently loaded scan.
-
scan_count()¶ Return the number of scans in the current dataset.
-
scans= None¶ List of loaded scan IDs.
-
slice_count()¶ Return the number of slices in the current scan.
-
classmethod
Built-in Formats¶
-
class
pyseus.formats.Raw¶ Class modeling raw data arrays as datasets.
Supports python lists, tuples and numpy arrays. Metadata, pixelspacing, scale, units and orientation are not supported.
-
class
pyseus.formats.NumPy¶ Class modeling NumPy datasets.
Supports arrays or pickeled objects in .npy-files. Metadata, pixelspacing, scale, units and orientation are not supported.
-
class
pyseus.formats.H5¶ Class modeling DICOM datasets.
Supports .h5-files in HDF5 format. Supports metadata, pixelspacing, scale, units and orientation using attributes with DICOM or NIfTI standard keywords.
-
class
pyseus.formats.DICOM¶ Class modeling DICOM datasets.
Supports multiple .dcm-files in standard directory structure; DICOMDIR files are not supported. Supports metadata, pixelspacing, scale, units and orientation.
-
class
pyseus.formats.NIfTI¶ Class modeling NIfTI datasets.
Supports single file .nii-files according to the NIfTI-1 and NIfTI-2 standard. Supports metadata, pixelspacing, scale, units and orientation.
Custom Formats¶
Just extend the BaseFormat class and add the format class to the PySeus.formats list.