summaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/astra/functions.py6
-rw-r--r--python/astra/log_c.pyx21
-rw-r--r--python/astra/matrix_c.pyx7
-rw-r--r--python/astra/optomo.py10
-rw-r--r--python/astra/projector3d_c.pyx10
-rw-r--r--python/astra/projector_c.pyx10
-rw-r--r--python/astra/utils.pyx11
-rw-r--r--python/docSRC/operator.rst4
8 files changed, 59 insertions, 20 deletions
diff --git a/python/astra/functions.py b/python/astra/functions.py
index b826b86..e38b5bc 100644
--- a/python/astra/functions.py
+++ b/python/astra/functions.py
@@ -32,7 +32,11 @@
from . import creators as ac
import numpy as np
-from six.moves import range
+try:
+ from six.moves import range
+except ImportError:
+ # six 1.3.0
+ from six.moves import xrange as range
from . import data2d
from . import data3d
diff --git a/python/astra/log_c.pyx b/python/astra/log_c.pyx
index 969cc06..f16329f 100644
--- a/python/astra/log_c.pyx
+++ b/python/astra/log_c.pyx
@@ -52,16 +52,20 @@ cdef extern from "astra/Logging.h" namespace "astra::CLogger":
void setFormatScreen(const char *fmt)
def log_debug(sfile, sline, message):
- debug(six.b(sfile),sline,six.b(message))
+ cstr = list(map(six.b,(sfile,message)))
+ debug(cstr[0],sline,cstr[1])
def log_info(sfile, sline, message):
- info(six.b(sfile),sline,six.b(message))
+ cstr = list(map(six.b,(sfile,message)))
+ info(cstr[0],sline,cstr[1])
def log_warn(sfile, sline, message):
- warn(six.b(sfile),sline,six.b(message))
+ cstr = list(map(six.b,(sfile,message)))
+ warn(cstr[0],sline,cstr[1])
def log_error(sfile, sline, message):
- error(six.b(sfile),sline,six.b(message))
+ cstr = list(map(six.b,(sfile,message)))
+ error(cstr[0],sline,cstr[1])
def log_enable():
enable()
@@ -82,10 +86,12 @@ def log_disableFile():
disableFile()
def log_setFormatFile(fmt):
- setFormatFile(six.b(fmt))
+ cstr = six.b(fmt)
+ setFormatFile(cstr)
def log_setFormatScreen(fmt):
- setFormatScreen(six.b(fmt))
+ cstr = six.b(fmt)
+ setFormatScreen(cstr)
enumList = [LOG_DEBUG,LOG_INFO,LOG_WARN,LOG_ERROR]
@@ -93,4 +99,5 @@ def log_setOutputScreen(fd, level):
setOutputScreen(fd, enumList[level])
def log_setOutputFile(filename, level):
- setOutputFile(six.b(filename), enumList[level]) \ No newline at end of file
+ cstr = six.b(filename)
+ setOutputFile(cstr, enumList[level])
diff --git a/python/astra/matrix_c.pyx b/python/astra/matrix_c.pyx
index b0d8bc4..d099a75 100644
--- a/python/astra/matrix_c.pyx
+++ b/python/astra/matrix_c.pyx
@@ -27,7 +27,12 @@
# distutils: libraries = astra
import six
-from six.moves import range
+try:
+ from six.moves import range
+except ImportError:
+ # six 1.3.0
+ from six.moves import xrange as range
+
import numpy as np
import scipy.sparse as ss
diff --git a/python/astra/optomo.py b/python/astra/optomo.py
index 0c37353..0108674 100644
--- a/python/astra/optomo.py
+++ b/python/astra/optomo.py
@@ -32,7 +32,13 @@ from . import creators
from . import algorithm
from . import functions
import numpy as np
-from six.moves import range, reduce
+from six.moves import reduce
+try:
+ from six.moves import range
+except ImportError:
+ # six 1.3.0
+ from six.moves import xrange as range
+
import operator
import scipy.sparse.linalg
@@ -158,7 +164,7 @@ class OpTomo(scipy.sparse.linalg.LinearOperator):
:param extraOptions: Extra options to use during reconstruction (i.e. for cfg['option']).
:type extraOptions: :class:`dict`
"""
- self.__checkArray(s, self.sshape)
+ s = self.__checkArray(s, self.sshape)
sid = self.data_mod.link('-sino',self.pg,s)
v = np.zeros(self.vshape,dtype=np.float32)
vid = self.data_mod.link('-vol',self.vg,v)
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 ddb37aa..260c308 100644
--- a/python/astra/utils.pyx
+++ b/python/astra/utils.pyx
@@ -95,7 +95,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:
@@ -129,7 +130,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:
@@ -202,7 +204,10 @@ cdef XMLNode2dict(XMLNode node):
while it != nodes.end():
subnode = deref(it)
if castString(subnode.getName())=="Option":
- opts[castString(subnode.getAttribute('key'))] = stringToPythonValue(subnode.getAttribute('value'))
+ if subnode.hasAttribute('value'):
+ opts[castString(subnode.getAttribute('key'))] = stringToPythonValue(subnode.getAttribute('value'))
+ else:
+ opts[castString(subnode.getAttribute('key'))] = stringToPythonValue(subnode.getContent())
else:
dct[castString(subnode.getName())] = stringToPythonValue(subnode.getContent())
inc(it)
diff --git a/python/docSRC/operator.rst b/python/docSRC/operator.rst
index f5369fa..fe500ba 100644
--- a/python/docSRC/operator.rst
+++ b/python/docSRC/operator.rst
@@ -1,7 +1,7 @@
-OpTomo class: the :mod:`operator` module
+OpTomo class: the :mod:`optomo` module
==============================================
-.. automodule:: astra.operator
+.. automodule:: astra.optomo
:members:
:undoc-members:
:show-inheritance: