dataObject([dims [, dtype=’uint8’[, continuous = 0][, data = valueOrSequence]]]) -> constructor to get a new dataObject.
The itom.dataObject represents a multidimensional array of fixed-size items with corresponding meta information (units, axes descriptions, scalings, tags, protocol...). Recently the following data types (dtype) are supported:
Arrays can also be constructed using some of the static pre-initialization methods ‘zeros’, ‘ones’, ‘rand’ or ‘randN’ (refer to the See Also section below).
Parameters: | dims : {sequence of integers}, optional
dtype : {str}, optional
continuous : {int}, optional
data : {str}, optional
|
---|
Notes
The itom.dataObject is a direct wrapper for the underlying C++ class dataObject. This array class mainly is based on the class Mat of the computer vision library (OpenCV).
In order to handle huge matrices, the data object can divide one array into chunks in memory. Each subpart (called matrix-plane) is two-dimensional and covers data of the last two dimensions. In c++-context each of these matrix-planes is of type cv::Mat_<type> and can be used with every operator given by the openCV-framework (version 2.3.1 or higher).
The dimensions of the matrix are structured descending. So if we assume to have a n-dimensional matrix A, where each dimension has its size s_i, the dimensions order is n, .., z, y, x and the corresponding sizes of A are [s_n, s_(n-1), s_(n-2), ..., s_y, s_x].
In order to make the data object compatible to continuously organized data structures, like numpy-arrays, it is also possible to have all matrix-planes in one data-block in memory (not recommended for huge matrices). Nevertheless, the indicated data structure with the two-dimensional sub-matrix-planes is still existing. The data organization is equal to the one of openCV, hence, two-dimensional matrices are stored row-by-row (C-style)...
In addition to OpenCV, itom.dataObject supports complex valued data types for all operators and methods.
Warning ‘uint32’ is not fully openCV-compatible and hence causes instability!
Deep Copy, Shallow Copy and ROI
It is possible to set a n-dimensional region of interest (ROI) to each matrix, the virtual dimensions, which will be delivered if the user asks for the matrix size. To avoid copy operations where possible a simple =_Operator will also make a shallow copy of the object. Shallow copies share the same data (elements and meta data) with the original object, hence manipulations of one object will affect the original object and all shallow copies.
The opposite a deep copy of a dataObject (by sourceObject.copy()) creates a complete mew matrix with own meta data object.
Example:
#Create an object
dObj = dataObject([5, 10, 10], 'int8')
# Make a shallow copy
dObjShallow = dObj
# Make a shallow copy on ROI
dObjROI = dObj[1, :, :]
# Set the value of element [1, 0, 0] to 0
dObj[1, 0, 0] = 0
# Make a deep copy of the dObjROI
dObjROICopy = dObjROI.copy()
# Set the value of dObjROICopy element [0, 0, 0] to 127 without effecting other objects
dObjROICopy[0, 0, 0] = 127
Constructor
The function dataObject([dims [, dtype=’uint8’[, continuous = 0][, data = valueOrSequence]]]) creates a new itom-dataObject filled with undefined data. If no parameters are given, an uninitilized DataObject (dims = 0, no sizes) is created.
As second possibility you can also use the copy-constructor ‘dataObject(AnyArray)’, where AnyArray must be any array-like structure which is parsable by the numpy-interface.
This method calculates the abs value of each element in source and writes the result to the output object.In case of floating point or real object, the type of the output will not change. For complex valuesthe type is changes to the corresponding floating type value.
Returns: | res : {dataObject}
|
---|
Appends a line of text to the protocol string of this data object. If this data object has got a region of interest defined, the rectangle of the ROI is automatically appended to newLine. The protocol string ends with a newline character.
Address the content of the protocol by obj.tags[“protocol”]. The protocol is contained in the ordinary tag dictionary of this data object under the key ‘protocol’.
Parameters: | newLine : {str}
|
---|
Every plane (spanned by the last two axes) is transposed and every element is replaced by its complex conjugate value.
Raises: | TypeError : :
|
---|
See also
If this data object has a complex type, the tranposed data object is returned where every element is complex conjugated. For data objects with more than two dimensions the tranposition is done plane-wise, hence, only the last two dimensions are permutated.
Returns: | out : {dataObject}
|
---|---|
Raises: | TypeError : :
|
See also
For every data object, it is possible to define a region of interest such that subsequent commands only refer to this subpart. However, if values within the region of interest (ROI) are changed, this also affects the original data object due to the shallow copy principal of python. Use this command to adjust the current size and position of this region of interest by passing an offset list, that contains integer numbers with twice the size than the number of dimensions.
Example:
d = dataObject([5,4])
droi = d
droi.adjustROI([-2,0,-1,-1])
Now droi is a region of interest of the original data object whose first value is equal to d[2,1] and its size is (3,2)
Parameters: | offsetList : {list of integers}
|
---|
See also
This method calculates the argument value of each element in source and writes the result to the output object.This object must be of complex type (complex128 or complex64). The output value will be float type (float64 or float32).
Returns: | res : {dataObject}
|
---|
Converts this data object to a new data object with another type, given by the string newTypestring (e.g. ‘uint8’). The converted data object is a deep copy of this object if the new type does not correspond to the current type, else a shallow copy of this object is returned.
Parameters: | typestring : {str}
|
---|---|
Returns: | c : {dataObject}
|
Notes
This method mainly uses the method convertTo of OpenCV.
Every value of this dataObject is replaced by its complex-conjugate value.
Raises: | TypeError : :
|
---|
See also
Returns: | out : {dataObject}
|
---|---|
Raises: | TypeError : :
|
See also
Parameters: | regionOnly : {bool}, optional
|
---|---|
Returns: | cpy : {dataObject}
|
Notes
When calling this method, the complete content of the dataObject is printed to the standard output stream.
Checks whether a tag with the given key exists in the tag dictionary and if so deletes it.
Parameters: | key : {str}
|
---|---|
Returns: | success : {bool}:
|
Parameters: | obj : {dataObject}
|
---|---|
Returns: | c : {dataObject}
|
Checks whether a tag with the given key exists in tag dictionary of this data object and returns True if such a tag exists, else False.
Parameters: | key : {str}
|
---|---|
Returns: | result : {bool}
|
Static method for creating a two-dimensional, square, eye-matrix of type itom.dataObject.
Parameters: | size : {int},
dtype : {str}, optional
|
---|---|
Returns: | I : {dataObject} of shape (size,size)
|
Every data object can have an arbitrary number of tags stored in the tag dictionary. This method returns the number of different tags, where the protocol is also one tag with the key ‘protocol’.
Returns: | length : {int}:
|
---|
This method extracts the imaginary part of each element in source and writes the result to the output object.This object must be of complex type (complex128 or complex64). The output value will be float type (float64 or float32).
Returns: | res : {dataObject}
|
---|
A region of interest (ROI) of a data object is defined by the two values per axis. The first element always indicates the size between the real border of the data object and the region of interest on the left / top ... side and the second value the margin of the right / bottom ... side.
This method returns a tuple with two elements: The first is a list with the original sizes of this data object, the second is a list with the offsets from the original data object to the first value in the current region of interest
If no region of interest is set (hence: full region of interest), the first list corresponds to the one returned by size(), the second list is a zero-vector.
See also
Per default a dataObject with more than two dimensions allocates separated chunks of memory for every plane, where a plane is always the matrix given by the last two dimensions. This separated storage usually allows allocating more memory for huge for instance three dimensional matrices. However, in order to generate a dataObject that is directly compatible to Numpy or other C-style matrix structures, the entire allocated memory must be in one block, that is called continuous. If you create a Numpy array from a dataObject that is not continuous, this function is implicitely called in order to firstly make the dataObject continuous before passing to Numpy.
Returns: | obj : {dataObject}
|
---|
Notes
if this dataObject already is continuous, a simple shallow copy is returned
Parameters: | obj : {dataObject}
|
---|---|
Returns: | c : {dataObject}
|
Returns the normalized version of this data object, where the values lie in the range [minValue,maxValue]. Additionally it is also possible to convert the resulting data object to another type (given by the parameter typestring). As default no type conversion is executed.
Parameters: | minValue : {double}
maxValue : {double}
typestring : {String}
|
---|---|
Returns: | normalized : {dataObject}
|
Static method for creating a new n-dimensional itom.dataObject with given number of dimensions and dtype, filled with ones.
Parameters: | dims : {integer list}
dtype : {str}, optional
continuous : {int}, optional
|
---|---|
Returns: | I : {dataObject} of shape (size,size)
|
Notes
For color-types (rgba32) every item / cell will be white: [r=255 g=255 b=255 a=255].
Static method to create a new itom.dataObject filled with uniform distributed random numbers. In case of an integer type, the uniform noise is from min<ObjectType>(inclusiv) to max<ObjectType>(inclusiv). For floating point types, the noise is between 0(inclusiv) and 1(exclusiv).
Parameters: | dims : {integer list}
dtype : {str}, optional
continuous : {int}, optional
|
---|---|
Returns: | out : {dataObject}
|
See also
Static method to create a new itom.dataObject filled with gaussian distributed random numbers. In case of an integer type, the gausian noise mean value is (max+min)/2.0 and the standard deviation is (max-min/)6.0 to max. For floating point types, the noise mean value is 0 and the standard deviation is 1.0/3.0.
Parameters: | dims : {integer list}
dtype : {str}, optional
continuous : {int}, optional
|
---|---|
Returns: | out : {dataObject}
|
See also
This method extracts the real part of each element in source and writes the result to the output object.This object must be of complex type (complex128 or complex64). The output value will be float type (float64 or float32).
Returns: | res : {dataObject}
|
---|
Notes
Not implemented yet.
Each axis in the data object can get a specific axisDescription string (e.g. mm). Use this method to set the axisDescription of one specific axis.
Parameters: | axisNum : {int}
axisDescription : {str}
|
---|---|
Raises: | Runtime error : :
|
See also
Each axis in the data object can get a specific scale value, described in axisUnits per pixel. Use this method to set the scale of one specific axis. The value of each pixel in its physical unit is the (px-Coordinate - axisOffset) * axisScale
Parameters: | axisNum : {int}
axisOffset : {double}
|
---|---|
Raises: | Runtime error : :
|
See also
Each axis in the data object can get a specific scale value, described in axisUnits per pixel. Use this method to set the scale of one specific axis.
Parameters: | axisNum : {int}
axisScale : {double}
|
---|---|
Raises: | Runtime error : :
|
See also
Each axis in the data object can get a specific unit string (e.g. mm). Use this method to set the unit of one specific axis.
Parameters: | axisNum : {int}
axisUnit : {str}
|
---|---|
Raises: | Runtime error : :
|
See also
Sets the value of an existing tag (defined by key) in the tag dictionary to the string or double tagvalue or adds a new item with key.
Parameters: | key : {str}
tagvalue : {str or double}
|
---|
Notes
Do NOT use ‘special character’ within the tag key because they are not XML-save.
Parameters: | index : {int}, optional
|
---|---|
Returns: | A tuple containing the sizes of all dimensions or one single size value if ‘index’ is indicated. : |
See also
Notes
For a more consistent syntax with respect to numpy arrays, the same result is obtained by the attribute shape. Please use the attribute shape for future implementations since this method is marked as deprecated.
This method removes every dimension with size equal to 1. Take care, that none of the last two dimensions is considered by this squeeze-command.
Returns: | squeezed : {dataObject}
|
---|
Notes
The returned squeezed data object is a shallow copy of the original data object and hence changes in its values will also change the original data set. This method is equal to numpy.squeeze
The destination data object has the same size than this data object and the real type given by destinationType. The pixel-wise conversion is done using the formula: gray = 0.299 * red + 0.587 * green + 0.114 * blue. Parameters ———– destinationType : {str}
Type string indicating the new real type (‘uint8’,...’float32’,’float64’ - no complex)
Returns: | dataObj : {dataObject}
|
---|
This method returns a nested list with all values of this data object. The recursion level of this nested list corresponds to the number of dimensions. The outer list corresponds to the first dimension.
Returns: | y : {list}
|
---|
Return a new data object with the same data type than this object and where every plane (data spanned by the last two dimensions) is transposed respectively such that the last two axes are permuted.
Returns: | out : {dataObject}
|
---|
Static method for creating a new n-dimensional itom.dataObject with given number of dimensions and dtype, filled with zeros.
Parameters: | dims : {integer list}
dtype : {str}, optional
continuous : {int}, optional
|
---|---|
Returns: | I : {dataObject} of shape (size,size)
|
Notes
For color-types (rgba32) every item / cell will be black and transparent: [r=0 g=0 b=0 a=0].
tuple containing the axis descriptions {str}.
This attribute gives access to the internal axis descriptions expressed as a tuple of strings. The tuple has the same length than the number of dimensions of this data object.
You can either assign a new tuple with the same length or change single values using tuple indexing.
See also
Notes
read / write
tuple containing the axis offsets [px].
This attribute gives access to the internal axis offsets [px] expressed as a tuple of double values. The i-th value in the tuple corresponds to the pixel-offset of the i-th axis. Either assign a new tuple with the same length than the number of dimensions or change single values using tuple indexing.
Definition: Physical unit = (px-Coordinate - offset)* scale
See also
Notes
read / write
tuple containing the axis scales [unit/px].
This attribute gives access to the internal axis scales [unit/px] expressed as a tuple of double values. The i-th value in the tuple corresponds to the scaling factor of the i-th axis. Either assign a new tuple with the same length than the number of dimensions or change single values using tuple indexing.
Definition: Physical unit = (px-Coordinate - offset)* scale
See also
Notes
read / write
tuple containing the axis units {str}.
This attribute gives access to the internal axis units expressed as a tuple of strings. The tuple has the same length than the number of dimensions of this data object.
You can either assign a new tuple with the same length or change single values using tuple indexing.
See also
Notes
read / write
base object
true if matrix is continuously organized, else false.
If true, the whole matrix is allocated in one huge block in memory, hence, this data object can be transformed into a numpy representation (npDataObject) without reallocating memory.
Notes
read-only
number of dimensions of this data object
Notes
read-only property, this property is readable both by the attributes ndim and dims.
get type string of data in this data object
This type string has one of these values: ‘uint8’, ‘int8’, ‘uint16’, ‘int16’, ‘uint32’, ‘int32’, ‘float32’, ‘float64’, ‘complex64’, ‘complex128’, ‘rgba32’
Notes
This attribute is read-only
return dictionary with all meta information of this dataObject
Returns a new dictionary with the following meta information:
Notes
Adding or changing values to / in the dictionary does not change the meta information of the dataObject. Use the corresponding setters like setTag... instead.
number of dimensions of this data object
Notes
read-only property, this property is readable both by the attributes ndim and dims.
tuple with the sizes of each dimension / axis of this data object.
See also
Notes
In difference to the shape attribute of numpy arrays, no new shape tuple can be assigned to this value (used to ‘reshape’ the array). Read-only.
tag dictionary of this data object.
This attribute returns a dict_proxy object of the tag dictionary of this data object. This object is read-only. However you can assign an entire new dictionary to this attribute that fully replaces the old tag dictionary. The tag dictionary can contain arbitrary pairs of key -> value where value is either a string or a double value.
Special tags are the key ‘protocol’ that contains the newline-separated protocol string of the data object (see: addToProtocol()) or the key ‘title’ that can for instance be used as title in any plots.
You can add single elements using the method setTag(key,value) or you can delete tags using deleteTag(key).
Do NOT use ‘special character’ within the tag key because they are not XML-save.
Notes
read-only / write only for fully new dictionary
get/set the values within the ROI as a one-dimensional tuple.
This method gets or sets the values within the ROI. If this attribute is called by means of a getter, a tuple is returned which is created by iterating through the values of the data object (row-wise). In the same way of iterating, the values are set to the data object if you provide a tuple of the size of the data object or its ROI, respectively.
Example:
b = dataObject[1,1:10,1,1].value
# or for the first value
b = dataObject[1,1:10,1,1].value[0]
# The elements of the tuple are adressed with b[idx].
value unit description.
Attribute to read or write the unit description string of the values in this data object.
Notes
read / write
value offset [default: 0.0].
This attribute gives the offset of each value in the data object. This value is always 0.0.
Notes
This attribute is read only
value scale [default: 0.0].
This attribute gives the scaling factor of each value in the data object. This value is always 1.0.
Notes
This attribute is read only
value unit.
Attribute to read or write the unit string of the values in this data object.
Notes
read / write
Access the 3x3 rotational matrix in the dataObject tagspace
This attribute gives access to the xyRotationalMatrix in the metaData-Tagspace. The getter method retuns a 3x3-Array deep copied from the internal matrix, Implemented to offer compability to x3p format.
Notes
{3x3 array of doubles} : ReadWrite