Archives API Reference — imagedata 1.3.0 documentation

# Archives API Reference

## Module imagedata.archives.abstractarchive

Abstract class for image archives.

Defines generic functions.

class `imagedata.archives.abstractarchive.` `AbstractArchive`(name, description, authors, version, url, _mimetypes)

  Abstract base class definition for imagedata archive plugins. Plugins must be a subclass of AbstractPlugin and must define the atttributes set in __init__() and the following methods:

  __init__() method use_query() method getnames() method basename() method open() method getmembers() method to_localfile() method read() method write() method

  abstract `add_localfile`(local_file, filename)

    Add a local file to the archive.

    Parameters

      - local_file – named local file

      - filename – filename in the archive

    Returns

      filehandle to file in the archive

  property `authors`

    Plugin authors

    Multi-line string naming the author(s) of the plugin.

  abstract `basename`(filehandle)

    Basename of file.

    Examples

    if archive.basename(filehandle) == “DICOMDIR”:

    Parameters

      filehandle – reference to member object

  abstract `close`()

    Close archive.

  property `description`

    Plugin description

    Single line string describing the image format.

  abstract `getmembers`(files=None)

    Get the members of the archive.

    Returns

      The members of the archive as an OrderedDict of member objects.

        The keys are the member names as given by getnames().

  abstract `getnames`(files=None)

    Get name list of the members.

    Returns

      The members as a list of their names.

        It has the same order as the members of the archive.

  abstract `is_file`(filehandle)

    Determine whether the named file is a single file.

  property `mimetypes`

    MIME types supporte by this plugin.

    List of strings.

  property `name`

    Plugin name

    Single word string describing the image format. Typical names: dicom, nifti, itk.

  abstract `open`(filehandle, mode='rb')

    Open file.

    Returns

      a member object for member given its filehandle.

  abstract `to_localfile`(filehandle)

    Access a member object through a local file.

  property `transport`

    Underlying transport plugin

  property `url`

    Plugin URL

    URL string to the site of the plugin or the author(s).

  abstract `use_query`()

    Do the plugin need the ?query part of the url?

  property `version`

    Plugin version

    String giving the plugin version. Version scheme: 1.0.0

  abstract `writedata`(filename, data)

    Write data to a named file in the archive.

    Parameters

      - filename – named file in the archive

      - data – data to write

exception `imagedata.archives.abstractarchive.` `NoOtherInstance`

exception `imagedata.archives.abstractarchive.` `WriteMultipleArchives`

## Module imagedata.archives.filesystemarchive

Read/Write local image files

class `imagedata.archives.filesystemarchive.` `FilesystemArchive`(transport=None, url=None, mode='r', read_directory_only=True, opts=None)

  Read/write local files.

  `add_localfile`(local_file, filename)

    Add a local file to the archive.

    Parameters

      - local_file – named local file

      - filename – filename in the archive

    Returns

      filehandle to file in the archive

  `basename`(filehandle)

    Basename of file.

    Examples

    if archive.basename(filehandle) == “DICOMDIR”:

    Parameters

      filehandle – reference to member object

  `close`()

    Close function.

  `getmembers`(files=None)

    Get the members of the archive.

    Returns

      The members of the archive as a list of member objects.

        The list has the same order as the members in the archive.

  `getnames`(files=None)

    Get name list of the members.

    Returns

      The members as a list of their names.

        It has the same order as the members of the archive.

  `is_file`(filehandle)

    Determine whether the named file is a single file.

  `open`(filehandle, mode='rb')

    Open file.

    Returns

      a member object for member with filehandle.

  `to_localfile`(filehandle)

    Access a member object through a local file.

  property `transport`

    Underlying transport plugin

  `use_query`()

    Do the plugin need the ?query part of the url?

  `writedata`(filename, data)

    Write data to a named file in the archive.

    Parameters

      - filename – named file in the archive

      - data – data to write

exception `imagedata.archives.filesystemarchive.` `NoSuchFile`

exception `imagedata.archives.filesystemarchive.` `ReadOnlyError`

exception `imagedata.archives.filesystemarchive.` `WriteOnFile`

## Module imagedata.archives.zipfilearchive

Read/Write image files from a zipfile

class `imagedata.archives.zipfilearchive.` `WriteFileIO`(archive, filename, localfile)

  Local object making sure the new file is written to zip archive before closing.

  `close`()

    Close file, copy it to archive, then delete local file.

class `imagedata.archives.zipfilearchive.` `ZipfileArchive`(transport=None, url=None, mode='r', read_directory_only=False, opts=None)

  Read/write image files from a zipfile.

  `add_localfile`(local_file, filename)

    Add a local file to the archive.

    Parameters

      - local_file – named local file

      - filename – filename in the archive

    Returns

      filehandle to file in the archive

  `basename`(filehandle)

    Basename of file.

    Examples

    if archive.basename(filehandle) == “DICOMDIR”:

    Parameters

      filehandle – reference to member object

  `close`()

    Close zip file.

  `getmembers`(files=None)

    Get the members of the archive.

    Returns

      The members of the archive as a list of member objects.

        The list has the same order as the members in the archive.

  `getnames`(files=None)

    Get name list of the members.

    Returns

      The members as a list of their names.

        It has the same order as the members of the archive.

  `is_file`(filehandle)

    Determine whether the named file is a single file.

  `open`(filehandle, mode='rb')

    Open file.

    Returns

      A member object for member with filehandle.

    Extract the member object to local file space. This is necessary to allow the seek() operation on open files.

  `to_localfile`(filehandle)

    Access a member object through a local file.

  property `transport`

    Underlying transport plugin

  `use_query`()

    Do the plugin need the ?query part of the url?

  `writedata`(filename, data)

    Write data to a named file in the archive.

    Parameters

      - filename – named file in the archive

      - data – data to write