summaryrefslogtreecommitdiffstats
path: root/python/astra/data2d.py
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <wjp@usecode.org>2015-04-14 14:54:38 +0200
committerWillem Jan Palenstijn <wjp@usecode.org>2015-04-14 14:54:38 +0200
commitd24877997bfe77e7177e3208328d99e1f99ac6b9 (patch)
tree58a86e22618775acfb5e761201727eec558c9200 /python/astra/data2d.py
parent306b3b5613ccb039122d38e8deb1e0ecc9e43403 (diff)
parent1b32573046f33050b9300324e6c74e10abb6caaf (diff)
downloadastra-d24877997bfe77e7177e3208328d99e1f99ac6b9.tar.gz
astra-d24877997bfe77e7177e3208328d99e1f99ac6b9.tar.bz2
astra-d24877997bfe77e7177e3208328d99e1f99ac6b9.tar.xz
astra-d24877997bfe77e7177e3208328d99e1f99ac6b9.zip
Merge pull request #51 from dmpelt/python-link
Add 'link' feature to Python (for 2D and 3D data)
Diffstat (limited to 'python/astra/data2d.py')
-rw-r--r--python/astra/data2d.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/python/astra/data2d.py b/python/astra/data2d.py
index 8c4be03..f119f05 100644
--- a/python/astra/data2d.py
+++ b/python/astra/data2d.py
@@ -24,6 +24,7 @@
#
#-----------------------------------------------------------------------
from . import data2d_c as d
+import numpy as np
def clear():
"""Clear all 2D data objects."""
@@ -52,6 +53,26 @@ def create(datatype, geometry, data=None):
"""
return d.create(datatype,geometry,data)
+def link(datatype, geometry, data):
+ """Link a 2D numpy array with the toolbox.
+
+ :param datatype: Data object type, '-vol' or '-sino'.
+ :type datatype: :class:`string`
+ :param geometry: Volume or projection geometry.
+ :type geometry: :class:`dict`
+ :param data: Numpy array to link
+ :type data: :class:`numpy.ndarray`
+ :returns: :class:`int` -- the ID of the constructed object.
+
+ """
+ if not isinstance(data,np.ndarray):
+ raise ValueError("Input should be a numpy array")
+ if not data.dtype==np.float32:
+ raise ValueError("Numpy array should be float32")
+ if not (data.flags['C_CONTIGUOUS'] and data.flags['ALIGNED']):
+ raise ValueError("Numpy array should be C_CONTIGUOUS and ALIGNED")
+ return d.create(datatype,geometry,data,True)
+
def store(i, data):
"""Fill existing 2D object with data.