diff options
author | Edoardo Pasca <edo.paskino@gmail.com> | 2018-04-17 15:35:20 +0100 |
---|---|---|
committer | Edoardo Pasca <edo.paskino@gmail.com> | 2018-04-17 15:35:20 +0100 |
commit | 5dd99ea14fc1bd2b81770a8e605e6e988fc68b27 (patch) | |
tree | 6476b110d345cc3e1fbcc6db93f9f8b681b8fa6f /Wrappers/Python | |
parent | 60afbd4ea94b2383f20b3368f69b4996d6343870 (diff) | |
download | framework-5dd99ea14fc1bd2b81770a8e605e6e988fc68b27.tar.gz framework-5dd99ea14fc1bd2b81770a8e605e6e988fc68b27.tar.bz2 framework-5dd99ea14fc1bd2b81770a8e605e6e988fc68b27.tar.xz framework-5dd99ea14fc1bd2b81770a8e605e6e988fc68b27.zip |
few fixes cleaning the simple_demo_ccpi
Diffstat (limited to 'Wrappers/Python')
-rw-r--r-- | Wrappers/Python/ccpi/framework.py | 11 | ||||
-rwxr-xr-x | Wrappers/Python/ccpi/optimisation/ops.py | 23 |
2 files changed, 32 insertions, 2 deletions
diff --git a/Wrappers/Python/ccpi/framework.py b/Wrappers/Python/ccpi/framework.py index ed8bac6..9ccc22d 100644 --- a/Wrappers/Python/ccpi/framework.py +++ b/Wrappers/Python/ccpi/framework.py @@ -96,7 +96,14 @@ class ImageGeometry: self.center_y, self.center_z, self.channels) - + def __str__ (self): + repres = "" + repres += "Number of channels: {0}\n".format(self.channels) + repres += "voxel_num : x{0},y{1},z{2}\n".format(self.voxel_num_x, self.voxel_num_y, self.voxel_num_z) + repres += "voxel_size : x{0},y{1},z{2}\n".format(self.voxel_size_x, self.voxel_size_y, self.voxel_size_z) + repres += "center : x{0},y{1},z{2}\n".format(self.center_x, self.center_y, self.center_z) + return repres + class AcquisitionGeometry: @@ -168,7 +175,7 @@ class AcquisitionGeometry: def __str__ (self): repres = "" repres += "Number of dimensions: {0}\n".format(self.dimension) - repres += "angles: {0}\n".format(len(self.angles)) + repres += "angles: {0}\n".format(self.angles) repres += "voxel_num : h{0},v{1}\n".format(self.pixel_num_h, self.pixel_num_v) repres += "voxel size: h{0},v{1}\n".format(self.pixel_size_h, self.pixel_size_v) repres += "geometry type: {0}\n".format(self.geom_type) diff --git a/Wrappers/Python/ccpi/optimisation/ops.py b/Wrappers/Python/ccpi/optimisation/ops.py index 6460986..993f2de 100755 --- a/Wrappers/Python/ccpi/optimisation/ops.py +++ b/Wrappers/Python/ccpi/optimisation/ops.py @@ -157,3 +157,26 @@ def PowerMethodNonsquare(op,numiters): s[it] = (x1*x0).sum() / (x0*x0).sum() x0 = (1.0/x1norm)*x1 return numpy.sqrt(s[-1]), numpy.sqrt(s), x0 + +class LinearOperatorMatrix(Operator): + def __init__(self,A): + self.A = A + self.s1 = None # Largest singular value, initially unknown + super(LinearOperatorMatrix, self).__init__() + + def direct(self,x): + return DataContainer(numpy.dot(self.A,x.as_array())) + + def adjoint(self,x): + return DataContainer(numpy.dot(self.A.transpose(),x.as_array())) + + def size(self): + return self.A.shape + + def get_max_sing_val(self): + # If unknown, compute and store. If known, simply return it. + if self.s1 is None: + self.s1 = svds(self.A,1,return_singular_vectors=False)[0] + return self.s1 + else: + return self.s1 |