datatypes Package

datatypes Package

The datatypes module holds all DataTypes generated by fastr and all the base classes for these datatypes.

class fastr.datatypes.AnyFile(value=None)[source]

Bases: fastr.datatypes.TypeGroup

Special Datatype in fastr that is a TypeGroup with all known DataTypes as its members.

__abstractmethods__ = frozenset()
__module__ = 'fastr.datatypes'
description = 'TypeGroup AnyFile\nAnyFile (AnyFile) is a group of consisting of all URLTypes known by fastr, currently:\n - <URLType: FilePrefix class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: NrrdImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: MetaImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: NiftiImageFileUncompressed class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: Directory class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: ProvNFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: JsonFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: AnalyzeImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: NiftiImageFileCompressed class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: TxtFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: TifImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>'
class fastr.datatypes.AnyType(value=None)[source]

Bases: fastr.datatypes.TypeGroup

Special Datatype in fastr that is a TypeGroup with all known DataTypes as its members.

__abstractmethods__ = frozenset()
__module__ = 'fastr.datatypes'
description = 'TypeGroup AnyType\nAnyType (AnyType) is a group of consisting of all DataTypes known by fastr, currently:\n - <URLType: FilePrefix class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: TifImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <ValueType: Boolean class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <ValueType: String class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: NrrdImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: MetaImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: NiftiImageFileUncompressed class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <ValueType: Float class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: Directory class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: ProvNFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: JsonFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: AnalyzeImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <ValueType: Int class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <DataType: Deferred class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: NiftiImageFileCompressed class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <URLType: TxtFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n - <ValueType: UnsignedInt class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>'
class fastr.datatypes.BaseDataType(value=None, format_=None)[source]

Bases: fastr.abc.baseplugin.BasePlugin

The base class for all datatypes in the fastr type system.

__abstractmethods__ = frozenset({'__init__'})
__eq__(other)[source]

Test the equality of two DataType objects

Parameters:other (DataType) – the object to compare against
Returns:flag indicating equality
Return type:bool
__getstate__()[source]
__hash__ = None
__init__(value=None, format_=None)[source]

The BaseDataType constructor.

Parameters:
  • value – value to assign to the new BaseDataType object
  • format – the format used for the ValueType
Returns:

new BaseDataType object

Raises:

FastrNotImplementedError – if id, name, version or description is None

__module__ = 'fastr.datatypes'
__ne__(other)[source]

Test if two objects are not equal. This is by default done by negating the __eq__ operator

Parameters:other (DataType) – the object to compare against
Returns:flag indicating equality
Return type:bool
__reduce_ex__(*args, **kwargs)[source]

helper for pickle

__repr__()[source]

Returns string representation of the BaseDataType

Returns:string represenation
Return type:str
__setstate__(state)[source]
__str__()[source]

Returns the string version of the BaseDataType

Returns:string version
Return type:str
checksum()[source]

Generate a checksum for the value of this DataType

Returns:the checksum of the value
Return type:str
description = ''

Description of the DataType

dot_extension = None
extension = None

Extension related to the Type

filename = '/home/docs/checkouts/readthedocs.org/user_builds/fastr/envs/stable/lib/python3.6/site-packages/fastr/datatypes/__init__.py'
fullid = 'fastr://types/BaseDataType'
id = 'BaseDataType'
classmethod isinstance(value)[source]

Indicate whether value is an instance for this DataType.

Returns:the flag indicating the value is of this DataType
Return type:bool
name = 'BaseDataType'
parent = DataTypeManager AnalyzeImageFile : <URLType: AnalyzeImageFile> AnyFile : <TypeGroup: AnyFile> AnyType : <TypeGroup: AnyType> Boolean : <ValueType: Boolean> Deferred : <DataType: Deferred> Directory : <URLType: Directory> FilePrefix : <URLType: FilePrefix> Float : <ValueType: Float> ITKImageFile : <TypeGroup: ITKImageFile> Int : <ValueType: Int> JsonFile : <URLType: JsonFile> MetaImageFile : <URLType: MetaImageFile> NiftiImageFile : <TypeGroup: NiftiImageFile> NiftiImageFileCompressed : <URLType: NiftiImageFileCompressed> NiftiImageFileUncompressed : <URLType: NiftiImageFileUncompressed> NrrdImageFile : <URLType: NrrdImageFile> Number : <TypeGroup: Number> ProvNFile : <URLType: ProvNFile> String : <ValueType: String> TifImageFile : <URLType: TifImageFile> TxtFile : <URLType: TxtFile> UnsignedInt : <ValueType: UnsignedInt> [source]
parsed_value

The parsed value of object instantiation of this DataType.

raw_value

The raw value of object instantiation of this DataType. For datatypes that override value (like Deferred) this is the way to access the _value field.

classmethod test()[source]

Define the test for the BasePluginManager. Make sure we are not one of the base classes

valid

A boolean flag that indicates weather or not the value assigned to this DataType is valid. This property is generally overwritten by implementation of specific DataTypes.

value

The value of object instantiation of this DataType.

version = <Version: 1.0>

Version of the DataType definition

class fastr.datatypes.DataType(value=None, format_=None)[source]

Bases: fastr.datatypes.BaseDataType

This class is the base class for all DataTypes that can hold a value.

__abstractmethods__ = frozenset({'__init__'})
__init__(value=None, format_=None)[source]

The DataType constructor.

Parameters:
  • value – value to assign to the new DataType object
  • format – the format used for the ValueType
Returns:

new DataType object

__module__ = 'fastr.datatypes'
action(name)[source]

This function can be overwritten by subclasses to implement certain action that should be performed. For example, the Directory DataType has an action ensure. This method makes sure the Directory exists. A Tool can indicate an action that should be called for an Output which will be called before execution.

Parameters:name (str) – name of the action to execute
Returns:None
class fastr.datatypes.DataTypeManager[source]

Bases: fastr.abc.basepluginmanager.BasePluginManager

The DataTypeManager hold a mapping of all DataTypes in the fast system and can create new DataTypes from files/data structures.

__abstractmethods__ = frozenset()
__init__()[source]

The DataTypeManager constructor will create a new DataTypeManager and populate it with all DataTypes it can find in the paths set in config.types_path.

Returns:the created DataTypeManager
__keytransform__(key)[source]

Key transformation for this mapping. The key transformation allows indexing by both the DataType name as well as the DataType it self.

Parameters:key (fastr.datatypes.BaseDataType or str) – The name of the requested datatype or the datatype itself
Returns:The requested datatype
__module__ = 'fastr.datatypes'
create_enumtype(type_id, options, name=None)[source]

Create a python class based on an XML file. This function return a completely functional python class based on the contents of a DataType XML file.

Such a class will be of type EnumType.

Parameters:
  • type_id (str) – the id of the new class
  • options (iterable) – an iterable of options, each option should be str
Returns:

the newly created subclass of EnumType

Raises:

FastrTypeError – if the options is not an iterable of str

fullid

The fullid of the datatype manager

get_type(name)[source]

Read a type given a typename. This will scan all directories in types_path and attempt to load the newest version of the DataType.

Parameters:name (str) – Name of the datatype that should be imported in the system
Returns:the datatype with the requested name, or None if datatype is not found

Note

If type is already in TypeManager it will not load anything and return the already loaded version.

guess_type(value, exists=True, options=None, preferred=None)[source]

Guess the DataType based on a value str.

Parameters:
  • value (str) – the value to guess the type for
  • options (TypeGroup, DataType or tuple of DataTypes) – The options that are allowed to be guessed from
  • extists (bool) – Indicate the value exists (if file) and can be checked for validity, if false skip validity check
  • preferred (iterable) – An iterable of preferred types in case multiple types match.
Returns:

The resulting DataType or None if no match was found

Raises:

FastrTypeError – if the options argument is of the wrong type

The function will first create a list of all candidate DataTypes. Subsequently, it will check for each candidate if the value would valid. If there are multiple matches, the config value for preferred types is consulted to break the ties. If non of the DataTypes are in the preferred types list, a somewhat random DataType will be picked as the most optimal result.

has_type(name)[source]

Check if the datatype with requested name exists

Parameters:name (str) – the name of the requested datatype
Returns:flag indicating if the datatype exists
Return type:bool
static isdatatype(item)[source]

Check if item is a valid datatype for the fastr system.

Parameters:item – item to check
Returns:flag indicating if the item is a fastr datatype
Return type:bool
match_types(*args, **kwargs)[source]

Find the match between a list of DataTypes/TypeGroups, see resolve-datatype for details

Parameters:
  • args – A list of DataType/TypeGroup objects to match
  • kwargs – A ‘preferred’ keyword argument can be used to indicate a list of DataTypes to prefer in case of ties (first has precedence over later in list)
Returns:

The best DataType match, or None if no match is possible.

Raises:

FastrTypeError – if not all args are subclasses of BaseDataType

match_types_any(*args)[source]

Find the match between a list of DataTypes/TypeGroups, see resolve-datatype for details

Parameters:args – A list of DataType/TypeGroup objects to match
Returns:A set with all DataTypes that match.
Return type:set
Raises:FastrTypeError – if not all args are subclasses of BaseDataType
plugin_class

The PluginClass of the items of the BasePluginManager

poll_datatype(filename)[source]

Poll an xml file to see if there is a definition of a datatype in it.

Parameters:filename (str) – path of the file to poll
Returns:tuple with (id, version, basetype) if a datatype is found or (None, None, None) if no datatype is found
populate()[source]

Populate Manager. After scanning for DataTypes, create the AnyType and set the preferred types

preferred_types
class fastr.datatypes.Deferred(value=None, format_=None)[source]

Bases: fastr.datatypes.DataType

__abstractmethods__ = frozenset()
__getstate__()[source]
__init__(value=None, format_=None)[source]

The Deferred constructor.

Parameters:
  • value – value to assign to the new DataType object
  • format – This is ignore but here for compatibility
Returns:

new Deferred object

__module__ = 'fastr.datatypes'
__repr__()[source]

Returns string representation of the BaseDataType

Returns:string represenation
Return type:str
__setstate__(state)[source]
checksum()[source]

Generate a checksum for the value of this DataType

Returns:the checksum of the value
Return type:str
job
classmethod lookup(value)[source]

Look up the deferred target and return that object

Param:

value

Returns:

The value the deferred points to

Return type:

DataType

Raises:
parsed_value

The value of object instantiation of this DataType.

provenance
target

Target object for this deferred.

Raises:
value

The value of object instantiation of this DataType.

class fastr.datatypes.EnumType(value=None, format_=None)[source]

Bases: fastr.datatypes.DataType

The EnumType is the base for DataTypes that can have a value which is an option from a predefined set of possibilities (similar to an enum type in many programming languages).

__abstractmethods__ = frozenset()
__init__(value=None, format_=None)[source]

The EnumType constructor.

Parameters:
  • value – value to assign to the new EnumType object
  • format – the format used for the ValueType
Returns:

new EnumType object

Raises:

FastrDataTypeNotInstantiableError – if not subclassed

__module__ = 'fastr.datatypes'
__reduce_ex__(*args, **kwargs)[source]

helper for pickle

description = 'EnumType (EnumType) is a enumerate type with options:\n\n\nEnumType can take the value of any of the option, but any other value is considered invalid.'
options = frozenset()
version = <Version: 1.0>

Enums always have version 1.0

class fastr.datatypes.TypeGroup(value=None)[source]

Bases: fastr.datatypes.BaseDataType

The TypeGroup is a special DataType that does not hold a value of its own but is used to group a number of DataTypes. For example ITK has a list of supported file formats that all tools build on ITK support. A group can be used to conveniently specify this in multiple Tools that use the same set DataTypes.

__abstractmethods__ = frozenset({'_members'})
__init__(value=None)[source]

Dummy constructor. TypeGroups are not instantiable and cannot hold a value of its own.

Raises:FastrDataTypeNotInstantiableError – if called
__module__ = 'fastr.datatypes'
static __new__(cls, value=None, format_=None)[source]

Instantiate a TypeGroup. This will for match the value to the best matching type and instantiate that. Not that the returned object will not be of type TypeGroup but one of the TypeGroup members.

classmethod isinstance(value)[source]

Indicate whether value is an instance for this DataType.

Returns:the flag indicating the value is of this DataType
Return type:bool
members

A descriptor that can act like a property for a class.

preference

A descriptor that can act like a property for a class.

class fastr.datatypes.URLType(value=None, format_=None)[source]

Bases: fastr.datatypes.DataType

The URLType is the base for DataTypes that point to a resource somewhere else (typically a filesystem). The true value is actually the resource referenced by the value in this object.

__abstractmethods__ = frozenset()
__eq__(other)[source]

Test the equality of two DataType objects

Parameters:other (URLType) – the object to compare against
Returns:flag indicating equality
Return type:bool
__hash__ = None
__init__(value=None, format_=None)[source]

The URLType constructor

Parameters:
  • value – value to assign to the new URLType
  • format – the format used for the ValueType
Returns:

new URLType object

__module__ = 'fastr.datatypes'
checksum()[source]

Return the checksum of this URL type

Returns:checksum string
Return type:str
classmethod content(inval, outval=None)[source]

Give the contents of a URLType, this is generally useful for filetypes that consists of multiple files (e.g. AnalyzeImageFile, DICOM). The value will indicate the main file, and the contents function can determine all files that form a single data value.

Parameters:
  • inval – a value to figure out contents for this type
  • outval – the place where the copy should point to
Returns:

a list of all files part of the value (e.g. header and data file)

Return type:

list

parsed_value

The parsed value of object instantiation of this DataType.

valid

A boolean flag that indicates weather or not the value assigned to this DataType is valid. This property is generally overwritten by implementation of specific DataTypes.

class fastr.datatypes.ValueType(value=None, format_=None)[source]

Bases: fastr.datatypes.DataType

The ValueType is the base for DataTypes that hold simple values (not an EnumType and not a file/URL). The values is generally represented by a string.

__abstractmethods__ = frozenset()
__init__(value=None, format_=None)[source]

The ValueType constructor

Parameters:
  • value – value to assign to the new ValueType
  • format – the format used for the ValueType
Returns:

new ValueType object

__module__ = 'fastr.datatypes'
fastr.datatypes.fastr_isinstance(obj, datatype)[source]

Check if an object is of a specific datatype.

Parameters:
  • obj – Object to inspect
  • datatype (tuple, BaseDataType) – The datatype(s) to check
Returns:

flag indicating object is of datatype

Return type:

bool