summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjakobsj <jakobsj@users.noreply.github.com>2018-02-27 11:45:44 +0000
committerEdoardo Pasca <edo.paskino@gmail.com>2018-02-27 11:45:44 +0000
commit959bca9887a1d2608aaa6bfcb3f5568115990602 (patch)
tree33995e5f9e3b2264fab60899ae1f1e14cbe0f1fc
parent7058cd5eb3d5f3f2a0a57d981411cd6707fe2d6b (diff)
downloadframework-959bca9887a1d2608aaa6bfcb3f5568115990602.tar.gz
framework-959bca9887a1d2608aaa6bfcb3f5568115990602.tar.bz2
framework-959bca9887a1d2608aaa6bfcb3f5568115990602.tar.xz
framework-959bca9887a1d2608aaa6bfcb3f5568115990602.zip
Simple demo fix (#11)
* Added simple demo and removed DataSet in sum() * Adds methods for #9, simple demo working, type/error checks still missing.
-rw-r--r--Wrappers/Python/ccpi/framework.py21
-rw-r--r--Wrappers/Python/test/simple_demo.py82
2 files changed, 101 insertions, 2 deletions
diff --git a/Wrappers/Python/ccpi/framework.py b/Wrappers/Python/ccpi/framework.py
index fc1aa21..b9dd964 100644
--- a/Wrappers/Python/ccpi/framework.py
+++ b/Wrappers/Python/ccpi/framework.py
@@ -310,6 +310,24 @@ class DataSet(object):
# return self.callFieldMath(operation, None, self.mask, self.maskOnValue)
# __abs__
+ def abs(self):
+ out = numpy.abs(self.as_array() )
+ return DataSet(out,
+ deep_copy=True,
+ dimension_labels=self.dimension_labels)
+
+ def maximum(self,otherscalar):
+ out = numpy.maximum(self.as_array(),otherscalar)
+ return DataSet(out,
+ deep_copy=True,
+ dimension_labels=self.dimension_labels)
+
+ def sign(self):
+ out = numpy.sign(self.as_array() )
+ return DataSet(out,
+ deep_copy=True,
+ dimension_labels=self.dimension_labels)
+
# reverse operand
def __radd__(self, other):
return self + other
@@ -344,8 +362,7 @@ class DataSet(object):
# __rpow__
def sum(self):
- return DataSet(self.as_array().sum(),
- dimension_labels=self.dimension_labels)
+ return self.as_array().sum()
# in-place arithmetic operators:
# (+=, -=, *=, /= , //=,
diff --git a/Wrappers/Python/test/simple_demo.py b/Wrappers/Python/test/simple_demo.py
new file mode 100644
index 0000000..4b7e89e
--- /dev/null
+++ b/Wrappers/Python/test/simple_demo.py
@@ -0,0 +1,82 @@
+
+import sys
+
+sys.path.append("..")
+
+from ccpi.framework import *
+from ccpi.reconstruction.algs import *
+from ccpi.reconstruction.funcs import *
+from ccpi.reconstruction.ops import *
+from ccpi.reconstruction.astra_ops import *
+
+import numpy as np
+import matplotlib.pyplot as plt
+
+# Set up phantom
+N = 128
+
+x = np.zeros((N,N))
+x[round(N/4):round(3*N/4),round(N/4):round(3*N/4)] = 1.0
+x[round(N/8):round(7*N/8),round(3*N/8):round(5*N/8)] = 2.0
+
+plt.imshow(x)
+plt.show()
+
+#vg = VolumeGeometry(grid=(N,N), domain=((-N/2,N/2),(-N/2,N/2)))
+
+#Phantom = VolumeData(x,geometry=vg)
+Phantom = VolumeData(x)
+
+# Set up measurement geometry
+angles_num = 20; # angles number
+angles = np.linspace(0,np.pi,angles_num,endpoint=False)
+
+det_w = 1.0
+det_num = N
+
+SourceOrig = 500
+OrigDetec = 0
+
+# Set up ASTRA projector
+#Aop = AstraProjector(vg, angles, N,'gpu')
+#Aop = AstraProjector(det_w, det_num, angles, projtype='parallel',device='gpu')
+
+Aop = AstraProjector(det_w, det_num, SourceOrig,
+ OrigDetec, angles,
+ N,'fanbeam','gpu')
+
+
+# Try forward and backprojection
+b = Aop.direct(Phantom)
+out2 = Aop.adjoint(b)
+
+plt.imshow(b.array)
+plt.show()
+
+plt.imshow(out2.array)
+plt.show()
+
+# Create least squares object instance with projector and data.
+f = Norm2sq(Aop,b,c=0.5)
+
+# Initial guess
+x_init = VolumeData(np.zeros(x.shape))
+
+# Run FISTA for least squares without regularization
+x_fista0, it0, timing0, criter0 = FISTA(x_init, f, None)
+
+plt.imshow(x_fista0.array)
+plt.show()
+
+# Now least squares plus 1-norm regularization
+lam = 0.1
+g0 = Norm1(lam)
+
+# Run FISTA for least squares plus 1-norm function.
+x_fista1, it1, timing1, criter1 = FISTA(x_init, f, g0)
+
+plt.imshow(x_fista1.array)
+plt.show()
+
+# Delete projector
+#Aop.delete()