summaryrefslogtreecommitdiffstats
path: root/python/astra
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2015-12-01 12:27:44 +0100
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2015-12-01 12:27:44 +0100
commitfff0e6dba508744f540bcf5efff76f676fe7af48 (patch)
tree5f33544e7d79b59501a5dd63a4922722eed8a98b /python/astra
parent0d5947a0e8e7d6f86c7591a96d877dfe14b187e4 (diff)
parentdcfd15335549fa8e3e56260791cc4510331f7be6 (diff)
downloadastra-fff0e6dba508744f540bcf5efff76f676fe7af48.tar.gz
astra-fff0e6dba508744f540bcf5efff76f676fe7af48.tar.bz2
astra-fff0e6dba508744f540bcf5efff76f676fe7af48.tar.xz
astra-fff0e6dba508744f540bcf5efff76f676fe7af48.zip
Merge branch 'master' into python-plugins
Conflicts: python/astra/utils.pyx
Diffstat (limited to 'python/astra')
-rw-r--r--python/astra/PyIncludes.pxd2
-rw-r--r--python/astra/algorithm_c.pyx4
-rw-r--r--python/astra/log_c.pyx8
-rw-r--r--python/astra/optomo.py18
-rw-r--r--python/astra/projector3d_c.pyx10
-rw-r--r--python/astra/projector_c.pyx10
-rw-r--r--python/astra/utils.pyx7
7 files changed, 45 insertions, 14 deletions
diff --git a/python/astra/PyIncludes.pxd b/python/astra/PyIncludes.pxd
index a099c31..77346b0 100644
--- a/python/astra/PyIncludes.pxd
+++ b/python/astra/PyIncludes.pxd
@@ -145,7 +145,7 @@ cdef extern from "astra/Float32ProjectionData2D.h" namespace "astra":
cdef extern from "astra/Algorithm.h" namespace "astra":
cdef cppclass CAlgorithm:
bool initialize(Config)
- void run(int)
+ void run(int) nogil
bool isInitialized()
cdef extern from "astra/ReconstructionAlgorithm2D.h" namespace "astra":
diff --git a/python/astra/algorithm_c.pyx b/python/astra/algorithm_c.pyx
index 966d3d7..3231c1f 100644
--- a/python/astra/algorithm_c.pyx
+++ b/python/astra/algorithm_c.pyx
@@ -73,7 +73,9 @@ cdef CAlgorithm * getAlg(i) except NULL:
def run(i, iterations=0):
cdef CAlgorithm * alg = getAlg(i)
- alg.run(iterations)
+ cdef int its = iterations
+ with nogil:
+ alg.run(its)
def get_res_norm(i):
diff --git a/python/astra/log_c.pyx b/python/astra/log_c.pyx
index f16329f..55c63e6 100644
--- a/python/astra/log_c.pyx
+++ b/python/astra/log_c.pyx
@@ -53,19 +53,19 @@ cdef extern from "astra/Logging.h" namespace "astra::CLogger":
def log_debug(sfile, sline, message):
cstr = list(map(six.b,(sfile,message)))
- debug(cstr[0],sline,cstr[1])
+ debug(cstr[0],sline,"%s",<char*>cstr[1])
def log_info(sfile, sline, message):
cstr = list(map(six.b,(sfile,message)))
- info(cstr[0],sline,cstr[1])
+ info(cstr[0],sline,"%s",<char*>cstr[1])
def log_warn(sfile, sline, message):
cstr = list(map(six.b,(sfile,message)))
- warn(cstr[0],sline,cstr[1])
+ warn(cstr[0],sline,"%s",<char*>cstr[1])
def log_error(sfile, sline, message):
cstr = list(map(six.b,(sfile,message)))
- error(cstr[0],sline,cstr[1])
+ error(cstr[0],sline,"%s",<char*>cstr[1])
def log_enable():
enable()
diff --git a/python/astra/optomo.py b/python/astra/optomo.py
index 0108674..4a64150 100644
--- a/python/astra/optomo.py
+++ b/python/astra/optomo.py
@@ -86,7 +86,15 @@ class OpTomo(scipy.sparse.linalg.LinearOperator):
self.proj_id = proj_id
- self.T = OpTomoTranspose(self)
+ self.transposeOpTomo = OpTomoTranspose(self)
+ try:
+ self.T = self.transposeOpTomo
+ except AttributeError:
+ # Scipy >= 0.16 defines self.T using self._transpose()
+ pass
+
+ def _transpose(self):
+ return self.transposeOpTomo
def __checkArray(self, arr, shp):
if len(arr.shape)==1:
@@ -189,6 +197,11 @@ class OpTomoTranspose(scipy.sparse.linalg.LinearOperator):
self.parent = parent
self.dtype = np.float32
self.shape = (parent.shape[1], parent.shape[0])
+ try:
+ self.T = self.parent
+ except AttributeError:
+ # Scipy >= 0.16 defines self.T using self._transpose()
+ pass
def _matvec(self, s):
return self.parent.rmatvec(s)
@@ -196,6 +209,9 @@ class OpTomoTranspose(scipy.sparse.linalg.LinearOperator):
def rmatvec(self, v):
return self.parent.matvec(v)
+ def _transpose(self):
+ return self.parent
+
def __mul__(self,s):
# Catch the case of a backprojection of 2D/3D data
if isinstance(s, np.ndarray) and s.shape==self.parent.sshape:
diff --git a/python/astra/projector3d_c.pyx b/python/astra/projector3d_c.pyx
index 8b978d7..aec9cde 100644
--- a/python/astra/projector3d_c.pyx
+++ b/python/astra/projector3d_c.pyx
@@ -87,12 +87,18 @@ cdef CProjector3D * getObject(i) except NULL:
def projection_geometry(i):
cdef CProjector3D * proj = getObject(i)
- return utils.configToDict(proj.getProjectionGeometry().getConfiguration())
+ cdef Config * cfg = proj.getProjectionGeometry().getConfiguration()
+ dct = utils.configToDict(cfg)
+ del cfg
+ return dct
def volume_geometry(i):
cdef CProjector3D * proj = getObject(i)
- return utils.configToDict(proj.getVolumeGeometry().getConfiguration())
+ cdef Config * cfg = proj.getVolumeGeometry().getConfiguration()
+ dct = utils.configToDict(cfg)
+ del cfg
+ return dct
def weights_single_ray(i, projection_index, detector_index):
diff --git a/python/astra/projector_c.pyx b/python/astra/projector_c.pyx
index 9aa868e..77c64a4 100644
--- a/python/astra/projector_c.pyx
+++ b/python/astra/projector_c.pyx
@@ -91,12 +91,18 @@ cdef CProjector2D * getObject(i) except NULL:
def projection_geometry(i):
cdef CProjector2D * proj = getObject(i)
- return utils.configToDict(proj.getProjectionGeometry().getConfiguration())
+ cdef Config * cfg = proj.getProjectionGeometry().getConfiguration()
+ dct = utils.configToDict(cfg)
+ del cfg
+ return dct
def volume_geometry(i):
cdef CProjector2D * proj = getObject(i)
- return utils.configToDict(proj.getVolumeGeometry().getConfiguration())
+ cdef Config * cfg = proj.getVolumeGeometry().getConfiguration()
+ dct = utils.configToDict(cfg)
+ del cfg
+ return dct
def weights_single_ray(i, projection_index, detector_index):
diff --git a/python/astra/utils.pyx b/python/astra/utils.pyx
index 9d2e9ab..9871ac6 100644
--- a/python/astra/utils.pyx
+++ b/python/astra/utils.pyx
@@ -99,7 +99,8 @@ cdef void readDict(XMLNode root, _dc):
if val.size == 0:
break
listbase = root.addChildNode(item)
- data = <double*>np.PyArray_DATA(np.ascontiguousarray(val,dtype=np.float64))
+ contig_data = np.ascontiguousarray(val,dtype=np.float64)
+ data = <double*>np.PyArray_DATA(contig_data)
if val.ndim == 2:
listbase.setContent(data, val.shape[1], val.shape[0], False)
elif val.ndim == 1:
@@ -135,7 +136,8 @@ cdef void readOptions(XMLNode node, dc):
break
listbase = node.addChildNode(six.b('Option'))
listbase.addAttribute(< string > six.b('key'), < string > item)
- data = <double*>np.PyArray_DATA(np.ascontiguousarray(val,dtype=np.float64))
+ contig_data = np.ascontiguousarray(val,dtype=np.float64)
+ data = <double*>np.PyArray_DATA(contig_data)
if val.ndim == 2:
listbase.setContent(data, val.shape[1], val.shape[0], False)
elif val.ndim == 1:
@@ -147,4 +149,3 @@ cdef void readOptions(XMLNode node, dc):
cdef configToDict(Config *cfg):
return XMLNode2dict(cfg.self)
-