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, format_=None)[source]

Bases: TypeGroup

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

__abstractmethods__ = frozenset({})
__module__ = 'fastr.datatypes'
description: str = 'TypeGroup AnyFile\nAnyFile (AnyFile) is a group of consisting of all URLTypes known by fastr, currently:\n  - <URLType: NrrdImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <URLType: FilePrefix 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: ProvNFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <URLType: TifImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <URLType: TxtFile 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: MetaImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>'

Description of the DataType

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

Bases: TypeGroup

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

__abstractmethods__ = frozenset({})
__module__ = 'fastr.datatypes'
description: str = 'TypeGroup AnyType\nAnyType (AnyType) is a group of consisting of all DataTypes known by fastr, currently:\n  - <URLType: NrrdImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <URLType: FilePrefix class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <DataType: Deferred 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: JsonFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <DataType: Missing class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <ValueType: Int class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <URLType: ProvNFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <URLType: TifImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <URLType: TxtFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <ValueType: String class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <ValueType: UnsignedInt class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <ValueType: Boolean 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: MetaImageFile class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>\n  - <ValueType: Float class [\x1b[37m\x1b[42m\x1b[1mLoaded\x1b[0m]>'

Description of the DataType

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

Bases: BasePlugin

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

__abstractmethods__ = frozenset({'__init__'})
__annotations__ = {'description': <class 'str'>, 'filename': <class 'str'>, 'version': <class 'fastr.core.version.Version'>}
__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
abstract __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: str = ''

Description of the DataType

dot_extension = None
extension = None

Extension related to the Type

filename: str = '/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>              Missing                     :  <DataType: Missing>                   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]
property parsed_value

The parsed value of object instantiation of this DataType.

property 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

property 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.

property value

The value of object instantiation of this DataType.

version: Version = <Version: 1.0>

Version of the DataType definition

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

Bases: BaseDataType, Serializable

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

__abstractmethods__ = frozenset({'__init__'})
abstract __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

classmethod deserialize(doc, _=None)[source]

Classmethod that returns an object constructed based on the str/dict (or OrderedDict) representing the object

Parameters

doc (dict) – the state of the object to create

Return type

DataType

Returns

newly created object (of datatype indicated by the doc)

serialize()[source]

Method that returns a dict structure with the datatype the object.

Return type

dict

Returns

serialized representation of object

class fastr.datatypes.DataTypeManager[source]

Bases: BasePluginManager[Type[BaseDataType]]

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

__abstractmethods__ = frozenset({})
__args__ = None
__extra__ = None
__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'
__next_in_mro__

alias of object

__orig_bases__ = (fastr.abc.basepluginmanager.BasePluginManager[typing.Type[fastr.datatypes.BaseDataType]],)
__origin__ = None
__parameters__ = ()
__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__tree_hash__ = -9223366157312510165
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

Return type

Type[EnumType]

Returns

the newly created subclass of EnumType

Raises

FastrTypeError – if the options is not an iterable of str

property 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

Return type

Type[BaseDataType]

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

  • exists (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.

Return type

Optional[Type[BaseDataType]]

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 Resolving Datatypes 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 Resolving Datatypes 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

property 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

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

Bases: 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

property 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
property parsed_value

The value of object instantiation of this DataType.

property provenance
property target

Target object for this deferred.

Raises
property value

The value of object instantiation of this DataType.

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

Bases: 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: str = '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.'

Description of the DataType

options = frozenset({})
version: Version = <Version: 1.0>

Enums always have version 1.0

class fastr.datatypes.Missing(*args, **kwargs)[source]

Bases: DataType

Singleton DataType to annotate missing data

__abstractmethods__ = frozenset({})
__init__(_=None, __=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'
static __new__(cls, *args, **kwargs)[source]
value = 'MISSING'
class fastr.datatypes.TypeGroup(value=None, format_=None)[source]

Bases: 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: 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

property parsed_value

The parsed value of object instantiation of this DataType.

property 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: 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