diff options
-rw-r--r-- | Wrappers/Python/ccpi/astra/astra_ops.py (renamed from Wrappers/Python/ccpi/reconstruction/astra_ops.py) | 22 | ||||
-rw-r--r-- | Wrappers/Python/ccpi/astra/astra_processors.py | 60 | ||||
-rw-r--r-- | Wrappers/Python/ccpi/framework.py | 241 | ||||
-rw-r--r-- | Wrappers/Python/ccpi/reconstruction/algs.py | 1 | ||||
-rw-r--r-- | Wrappers/Python/ccpi/reconstruction/ops.py | 10 | ||||
-rw-r--r-- | Wrappers/Python/wip/simple_demo.py | 16 | ||||
-rwxr-xr-x | Wrappers/Python/wip/simple_mc_demo.py | 9 |
7 files changed, 154 insertions, 205 deletions
diff --git a/Wrappers/Python/ccpi/reconstruction/astra_ops.py b/Wrappers/Python/ccpi/astra/astra_ops.py index 1346f22..c409529 100644 --- a/Wrappers/Python/ccpi/reconstruction/astra_ops.py +++ b/Wrappers/Python/ccpi/astra/astra_ops.py @@ -17,7 +17,7 @@ from ccpi.reconstruction.ops import Operator import numpy -from ccpi.framework import SinogramData, VolumeData +from ccpi.framework import AcquisitionData, ImageData from ccpi.reconstruction.ops import PowerMethodNonsquare from ccpi.astra.astra_processors import * @@ -44,13 +44,13 @@ class AstraProjectorSimple(Operator): self.s1 = None def direct(self, IM): - self.fp.setInput(IM) - out = self.fp.getOutput() + self.fp.set_input(IM) + out = self.fp.get_output() return out def adjoint(self, DATA): - self.bp.setInput(DATA) - out = self.bp.getOutput() + self.bp.set_input(DATA) + out = self.bp.get_output() return out #def delete(self): @@ -90,13 +90,13 @@ class AstraProjectorMC(Operator): self.s1 = 50 def direct(self, IM): - self.fp.setInput(IM) - out = self.fp.getOutput() + self.fp.set_input(IM) + out = self.fp.get_output() return out def adjoint(self, DATA): - self.bp.setInput(DATA) - out = self.bp.getOutput() + self.bp.set_input(DATA) + out = self.bp.get_output() return out #def delete(self): @@ -163,7 +163,7 @@ class AstraProjector(Operator): sinogram_id, DATA = astra.create_sino(IM.as_array(), self.proj_id) astra.data2d.delete(sinogram_id) astra.data2d.delete(self.proj_id) - return SinogramData(DATA) + return AcquisitionData(DATA) def adjoint(self, DATA): """Applying backprojection to DATA [2D or 3D]""" if numpy.ndim(DATA) == 3: @@ -180,7 +180,7 @@ class AstraProjector(Operator): self.proj_id) astra.data2d.delete(rec_id) astra.data2d.delete(self.proj_id) - return VolumeData(IM) + return ImageData(IM) def delete(self): astra.data2d.delete(self.proj_id) diff --git a/Wrappers/Python/ccpi/astra/astra_processors.py b/Wrappers/Python/ccpi/astra/astra_processors.py index f51aec9..bf6048b 100644 --- a/Wrappers/Python/ccpi/astra/astra_processors.py +++ b/Wrappers/Python/ccpi/astra/astra_processors.py @@ -1,17 +1,16 @@ -from ccpi.framework import DataSetProcessor, DataSet, VolumeData, SinogramData +from ccpi.framework import DataSetProcessor, ImageData, AcquisitionData from ccpi.astra.astra_utils import convert_geometry_to_astra import astra -import numpy class AstraForwardProjector(DataSetProcessor): '''AstraForwardProjector - Forward project VolumeDataSet to SinogramDataSet using ASTRA proj_id. + Forward project ImageData to AcquisitionData using ASTRA proj_id. - Input: VolumeDataSet + Input: ImageData Parameter: proj_id - Output: SinogramDataSet + Output: AcquisitionData ''' def __init__(self, @@ -50,7 +49,7 @@ class AstraForwardProjector(DataSetProcessor): else: NotImplemented - def checkInput(self, dataset): + def check_input(self, dataset): if dataset.number_of_dimensions == 3 or\ dataset.number_of_dimensions == 2: return True @@ -68,24 +67,24 @@ class AstraForwardProjector(DataSetProcessor): self.sinogram_geometry = sinogram_geometry def process(self): - IM = self.getInput() - DATA = SinogramData(geometry=self.sinogram_geometry) + IM = self.get_input() + DATA = AcquisitionData(geometry=self.sinogram_geometry) #sinogram_id, DATA = astra.create_sino( IM.as_array(), # self.proj_id) sinogram_id, DATA.array = astra.create_sino(IM.as_array(), self.proj_id) astra.data2d.delete(sinogram_id) - #return SinogramData(array=DATA, geometry=self.sinogram_geometry) + #return AcquisitionData(array=DATA, geometry=self.sinogram_geometry) return DATA class AstraBackProjector(DataSetProcessor): '''AstraBackProjector - Back project SinogramDataSet to VolumeDataSet using ASTRA proj_id. + Back project AcquisitionData to ImageData using ASTRA proj_id. - Input: SinogramDataSet + Input: AcquisitionData Parameter: proj_id - Output: VolumeDataSet + Output: ImageData ''' def __init__(self, @@ -124,7 +123,7 @@ class AstraBackProjector(DataSetProcessor): else: NotImplemented - def checkInput(self, dataset): + def check_input(self, dataset): if dataset.number_of_dimensions == 3 or dataset.number_of_dimensions == 2: return True else: @@ -141,8 +140,8 @@ class AstraBackProjector(DataSetProcessor): self.sinogram_geometry = sinogram_geometry def process(self): - DATA = self.getInput() - IM = VolumeData(geometry=self.volume_geometry) + DATA = self.get_input() + IM = ImageData(geometry=self.volume_geometry) rec_id, IM.array = astra.create_backprojection(DATA.as_array(), self.proj_id) astra.data2d.delete(rec_id) @@ -151,13 +150,13 @@ class AstraBackProjector(DataSetProcessor): class AstraForwardProjectorMC(AstraForwardProjector): '''AstraForwardProjector Multi channel - Forward project VolumeDataSet to SinogramDataSet using ASTRA proj_id. + Forward project ImageData to AcquisitionDataSet using ASTRA proj_id. - Input: VolumeDataSet + Input: ImageDataSet Parameter: proj_id - Output: SinogramDataSet + Output: AcquisitionData ''' - def checkInput(self, dataset): + def check_input(self, dataset): if dataset.number_of_dimensions == 2 or \ dataset.number_of_dimensions == 3 or \ dataset.number_of_dimensions == 4: @@ -166,9 +165,9 @@ class AstraForwardProjectorMC(AstraForwardProjector): raise ValueError("Expected input dimensions is 2 or 3, got {0}"\ .format(dataset.number_of_dimensions)) def process(self): - IM = self.getInput() - #create the output Sinogram - DATA = SinogramData(geometry=self.sinogram_geometry) + IM = self.get_input() + #create the output AcquisitionData + DATA = AcquisitionData(geometry=self.sinogram_geometry) for k in range(DATA.geometry.channels): sinogram_id, DATA.as_array()[k] = astra.create_sino(IM.as_array()[k], @@ -179,13 +178,13 @@ class AstraForwardProjectorMC(AstraForwardProjector): class AstraBackProjectorMC(AstraBackProjector): '''AstraBackProjector Multi channel - Back project SinogramDataSet to VolumeDataSet using ASTRA proj_id. + Back project AcquisitionData to ImageData using ASTRA proj_id. - Input: SinogramDataSet + Input: AcquisitionData Parameter: proj_id - Output: VolumeDataSet + Output: ImageData ''' - def checkInput(self, dataset): + def check_input(self, dataset): if dataset.number_of_dimensions == 2 or \ dataset.number_of_dimensions == 3 or \ dataset.number_of_dimensions == 4: @@ -194,12 +193,13 @@ class AstraBackProjectorMC(AstraBackProjector): raise ValueError("Expected input dimensions is 2 or 3, got {0}"\ .format(dataset.number_of_dimensions)) def process(self): - DATA = self.getInput() + DATA = self.get_input() - IM = VolumeData(geometry=self.volume_geometry) + IM = ImageData(geometry=self.volume_geometry) for k in range(IM.geometry.channels): - rec_id, IM.as_array()[k] = astra.create_backprojection(DATA.as_array()[k], - self.proj_id) + rec_id, IM.as_array()[k] = astra.create_backprojection( + DATA.as_array()[k], + self.proj_id) astra.data2d.delete(rec_id) return IM
\ No newline at end of file diff --git a/Wrappers/Python/ccpi/framework.py b/Wrappers/Python/ccpi/framework.py index 777ab1c..9b0cf54 100644 --- a/Wrappers/Python/ccpi/framework.py +++ b/Wrappers/Python/ccpi/framework.py @@ -138,67 +138,9 @@ class AcquisitionGeometry: self.channels = channels -class CCPiBaseClass(ABC): - def __init__(self, **kwargs): - self.acceptedInputKeywords = [] - self.pars = {} - self.debug = True - # add keyworded arguments as accepted input keywords and add to the - # parameters - for key, value in kwargs.items(): - self.acceptedInputKeywords.append(key) - #print ("key {0}".format(key)) - #self.setParameter(key.__name__=value) - self.setParameter(**{key:value}) - - def setParameter(self, **kwargs): - '''set named parameter for the reconstructor engine - - raises Exception if the named parameter is not recognized - - ''' - for key , value in kwargs.items(): - if key in self.acceptedInputKeywords: - self.pars[key] = value - else: - raise KeyError('Wrong parameter "{0}" for {1}'.format(key, - self.__class__.__name__ )) - # setParameter - def getParameter(self, key): - if type(key) is str: - if key in self.acceptedInputKeywords: - return self.pars[key] - else: - raise KeyError('Unrecongnised parameter: {0} '.format(key) ) - elif type(key) is list: - outpars = [] - for k in key: - outpars.append(self.getParameter(k)) - return outpars - else: - raise Exception('Unhandled input {0}' .format(str(type(key)))) - #getParameter - def getParameterMap(self, key): - if type(key) is str: - if key in self.acceptedInputKeywords: - return self.pars[key] - else: - raise KeyError('Unrecongnised parameter: {0} '.format(key) ) - elif type(key) is list: - outpars = {} - for k in key: - outpars[k] = self.getParameter(k) - return outpars - else: - raise Exception('Unhandled input {0}' .format(str(type(key)))) - #getParameter - - def log(self, msg): - if self.debug: - print ("{0}: {1}".format(self.__class__.__name__, msg)) -class DataSet(object): +class DataContainer(object): '''Generic class to hold data Data is currently held in a numpy arrays''' @@ -210,7 +152,7 @@ class DataSet(object): self.shape = numpy.shape(array) self.number_of_dimensions = len (self.shape) self.dimension_labels = {} - self.geometry = None # Only relevant for SinogramData and VolumeData + self.geometry = None # Only relevant for AcquisitionData and ImageData if dimension_labels is not None and \ len (dimension_labels) == self.number_of_dimensions: @@ -238,10 +180,10 @@ class DataSet(object): def as_array(self, dimensions=None): - '''Returns the DataSet as Numpy Array + '''Returns the DataContainer as Numpy Array Returns the pointer to the array if dimensions is not set. - If dimensions is set, it first creates a new DataSet with the subset + If dimensions is set, it first creates a new DataContainer with the subset and then it returns the pointer to the array''' if dimensions is not None: return self.subset(dimensions).as_array() @@ -249,7 +191,7 @@ class DataSet(object): def subset(self, dimensions=None, **kw): - '''Creates a DataSet containing a subset of self according to the + '''Creates a DataContainer containing a subset of self according to the labels in dimensions''' if dimensions is None: return self.array.copy() @@ -259,7 +201,7 @@ class DataSet(object): proceed = True unknown_key = '' # axis_order contains the order of the axis that the user wants - # in the output DataSet + # in the output DataContainer axis_order = [] if type(dimensions) == list: for dl in dimensions: @@ -325,12 +267,12 @@ class DataSet(object): numpy.shape(array))) self.array = array[:] - def checkDimensions(self, other): + def check_dimensions(self, other): return self.shape == other.shape def __add__(self, other): - if issubclass(type(other), DataSet): - if self.checkDimensions(other): + if issubclass(type(other), DataContainer): + if self.check_dimensions(other): out = self.as_array() + other.as_array() return type(self)(out, deep_copy=True, @@ -346,13 +288,13 @@ class DataSet(object): dimension_labels=self.dimension_labels, geometry=self.geometry) else: - raise TypeError('Cannot {0} DataSet with {1}'.format("add" , + raise TypeError('Cannot {0} DataContainer with {1}'.format("add" , type(other))) # __add__ def __sub__(self, other): - if issubclass(type(other), DataSet): - if self.checkDimensions(other): + if issubclass(type(other), DataContainer): + if self.check_dimensions(other): out = self.as_array() - other.as_array() return type(self)(out, deep_copy=True, @@ -367,7 +309,7 @@ class DataSet(object): dimension_labels=self.dimension_labels, geometry=self.geometry) else: - raise TypeError('Cannot {0} DataSet with {1}'.format("subtract" , + raise TypeError('Cannot {0} DataContainer with {1}'.format("subtract" , type(other))) # __sub__ def __truediv__(self,other): @@ -375,8 +317,8 @@ class DataSet(object): def __div__(self, other): print ("calling __div__") - if issubclass(type(other), DataSet): - if self.checkDimensions(other): + if issubclass(type(other), DataContainer): + if self.check_dimensions(other): out = self.as_array() / other.as_array() return type(self)(out, deep_copy=True, @@ -391,13 +333,13 @@ class DataSet(object): dimension_labels=self.dimension_labels, geometry=self.geometry) else: - raise TypeError('Cannot {0} DataSet with {1}'.format("divide" , + raise TypeError('Cannot {0} DataContainer with {1}'.format("divide" , type(other))) # __div__ def __pow__(self, other): - if issubclass(type(other), DataSet): - if self.checkDimensions(other): + if issubclass(type(other), DataContainer): + if self.check_dimensions(other): out = self.as_array() ** other.as_array() return type(self)(out, deep_copy=True, @@ -412,13 +354,13 @@ class DataSet(object): dimension_labels=self.dimension_labels, geometry=self.geometry) else: - raise TypeError('Cannot {0} DataSet with {1}'.format("power" , + raise TypeError('Cannot {0} DataContainer with {1}'.format("power" , type(other))) # __pow__ def __mul__(self, other): - if issubclass(type(other), DataSet): - if self.checkDimensions(other): + if issubclass(type(other), DataContainer): + if self.check_dimensions(other): out = self.as_array() * other.as_array() return type(self)(out, deep_copy=True, @@ -433,7 +375,7 @@ class DataSet(object): dimension_labels=self.dimension_labels, geometry=self.geometry) else: - raise TypeError('Cannot {0} DataSet with {1}'.format("multiply" , + raise TypeError('Cannot {0} DataContainer with {1}'.format("multiply" , type(other))) # __mul__ @@ -490,8 +432,8 @@ class DataSet(object): return type(self)(fother ** self.array , dimension_labels=self.dimension_labels, geometry=self.geometry) - elif issubclass(other, DataSet): - if self.checkDimensions(other): + elif issubclass(other, DataContainer): + if self.check_dimensions(other): return type(self)(other.as_array() ** self.array , dimension_labels=self.dimension_labels, geometry=self.geometry) @@ -541,8 +483,8 @@ class DataSet(object): -class VolumeData(DataSet): - '''DataSet for holding 2D or 3D dataset''' +class ImageData(DataContainer): + '''DataContainer for holding 2D or 3D DataContainer''' def __init__(self, array = None, deep_copy=True, @@ -580,24 +522,24 @@ class VolumeData(DataSet): 'horizontal_x'] array = numpy.zeros( shape , dtype=numpy.float32) - super(VolumeData, self).__init__(array, deep_copy, + super(ImageData, self).__init__(array, deep_copy, dim_labels, **kwargs) else: - raise ValueError('Please pass either a DataSet, ' +\ + raise ValueError('Please pass either a DataContainer, ' +\ 'a numpy array or a geometry') else: - if type(array) == DataSet: - # if the array is a DataSet get the info from there + if type(array) == DataContainer: + # if the array is a DataContainer get the info from there if not ( array.number_of_dimensions == 2 or \ array.number_of_dimensions == 3 or \ array.number_of_dimensions == 4): raise ValueError('Number of dimensions are not 2 or 3 or 4: {0}'\ .format(array.number_of_dimensions)) - #DataSet.__init__(self, array.as_array(), deep_copy, + #DataContainer.__init__(self, array.as_array(), deep_copy, # array.dimension_labels, **kwargs) - super(VolumeData, self).__init__(array.as_array(), deep_copy, + super(ImageData, self).__init__(array.as_array(), deep_copy, array.dimension_labels, **kwargs) elif type(array) == numpy.ndarray: if not ( array.ndim == 2 or array.ndim == 3 or array.ndim == 4 ): @@ -616,8 +558,8 @@ class VolumeData(DataSet): dimension_labels = ['horizontal_y' , 'horizontal_x'] - #DataSet.__init__(self, array, deep_copy, dimension_labels, **kwargs) - super(VolumeData, self).__init__(array, deep_copy, + #DataContainer.__init__(self, array, deep_copy, dimension_labels, **kwargs) + super(ImageData, self).__init__(array, deep_copy, dimension_labels, **kwargs) # load metadata from kwargs if present @@ -630,8 +572,8 @@ class VolumeData(DataSet): self.spacing = value -class SinogramData(DataSet): - '''DataSet for holding 2D or 3D sinogram''' +class AcquisitionData(DataContainer): + '''DataContainer for holding 2D or 3D sinogram''' def __init__(self, array = None, deep_copy=True, @@ -669,21 +611,21 @@ class SinogramData(DataSet): 'horizontal'] array = numpy.zeros( shape , dtype=numpy.float32) - super(SinogramData, self).__init__(array, deep_copy, + super(AcquisitionData, self).__init__(array, deep_copy, dim_labels, **kwargs) else: - if type(array) == DataSet: - # if the array is a DataSet get the info from there + if type(array) == DataContainer: + # if the array is a DataContainer get the info from there if not ( array.number_of_dimensions == 2 or \ array.number_of_dimensions == 3 or \ array.number_of_dimensions == 4): raise ValueError('Number of dimensions are not 2 or 3 or 4: {0}'\ .format(array.number_of_dimensions)) - #DataSet.__init__(self, array.as_array(), deep_copy, + #DataContainer.__init__(self, array.as_array(), deep_copy, # array.dimension_labels, **kwargs) - super(SinogramData, self).__init__(array.as_array(), deep_copy, + super(AcquisitionData, self).__init__(array.as_array(), deep_copy, array.dimension_labels, **kwargs) elif type(array) == numpy.ndarray: if not ( array.ndim == 2 or array.ndim == 3 or array.ndim == 4 ): @@ -702,16 +644,16 @@ class SinogramData(DataSet): dimension_labels = ['angle' , 'horizontal'] - #DataSet.__init__(self, array, deep_copy, dimension_labels, **kwargs) - super(SinogramData, self).__init__(array, deep_copy, + #DataContainer.__init__(self, array, deep_copy, dimension_labels, **kwargs) + super(AcquisitionData, self).__init__(array, deep_copy, dimension_labels, **kwargs) class DataSetProcessor(object): - '''Defines a generic DataSet processor + '''Defines a generic DataContainer processor - accepts DataSet as inputs and - outputs DataSet + accepts DataContainer as inputs and + outputs DataContainer additional attributes can be defined with __setattr__ ''' @@ -728,7 +670,7 @@ class DataSetProcessor(object): def __setattr__(self, name, value): if name == 'input': - self.setInput(value) + self.set_input(value) elif name in self.__dict__.keys(): self.__dict__[name] = value self.__dict__['mTime'] = datetime.now() @@ -736,23 +678,23 @@ class DataSetProcessor(object): raise KeyError('Attribute {0} not found'.format(name)) #pass - def setInput(self, dataset): - if issubclass(type(dataset), DataSet): - if self.checkInput(dataset): + def set_input(self, dataset): + if issubclass(type(dataset), DataContainer): + if self.check_input(dataset): self.__dict__['input'] = dataset else: raise TypeError("Input type mismatch: got {0} expecting {1}"\ - .format(type(dataset), DataSet)) + .format(type(dataset), DataContainer)) - def checkInput(self, dataset): - '''Checks parameters of the input DataSet + def check_input(self, dataset): + '''Checks parameters of the input DataContainer - Should raise an Error if the DataSet does not match expectation, e.g. - if the expected input DataSet is 3D and the Processor expects 2D. + Should raise an Error if the DataContainer does not match expectation, e.g. + if the expected input DataContainer is 3D and the Processor expects 2D. ''' - raise NotImplementedError('Implement basic checks for input DataSet') + raise NotImplementedError('Implement basic checks for input DataContainer') - def getOutput(self): + def get_output(self): if None in self.__dict__.values(): raise ValueError('Not all parameters have been passed') shouldRun = False @@ -769,21 +711,21 @@ class DataSetProcessor(object): self.runTime = datetime.now() return self.process() - def setInputProcessor(self, processor): + def set_input_processor(self, processor): if issubclass(type(processor), DataSetProcessor): self.__dict__['input'] = processor else: raise TypeError("Input type mismatch: got {0} expecting {1}"\ .format(type(processor), DataSetProcessor)) - def getInput(self): - '''returns the input DataSet + def get_input(self): + '''returns the input DataContainer It is useful in the case the user has provided a DataSetProcessor as input ''' if issubclass(type(self.input), DataSetProcessor): - dsi = self.input.getOutput() + dsi = self.input.get_output() else: dsi = self.input return dsi @@ -795,8 +737,8 @@ class DataSetProcessor23D(DataSetProcessor): '''Regularizers DataSetProcessor ''' - def checkInput(self, dataset): - '''Checks number of dimensions input DataSet + def check_input(self, dataset): + '''Checks number of dimensions input DataContainer Expected input is 2D or 3D ''' @@ -818,7 +760,7 @@ class AX(DataSetProcessor): a is a scalar - x a DataSet. + x a DataContainer. ''' def __init__(self): @@ -829,15 +771,15 @@ class AX(DataSetProcessor): #DataSetProcessor.__init__(self, **kwargs) super(AX, self).__init__(**kwargs) - def checkInput(self, dataset): + def check_input(self, dataset): return True def process(self): - dsi = self.getInput() + dsi = self.get_input() a = self.scalar - y = DataSet( a * dsi.as_array() , True, + y = DataContainer( a * dsi.as_array() , True, dimension_labels=dsi.dimension_labels ) #self.setParameter(output_dataset=y) return y @@ -848,7 +790,7 @@ class AX(DataSetProcessor): class PixelByPixelDataSetProcessor(DataSetProcessor): '''Example DataSetProcessor - This processor applies a python function to each pixel of the DataSet + This processor applies a python function to each pixel of the DataContainer f is a python function @@ -862,18 +804,18 @@ class PixelByPixelDataSetProcessor(DataSetProcessor): #DataSetProcessor.__init__(self, **kwargs) super(PixelByPixelDataSetProcessor, self).__init__(**kwargs) - def checkInput(self, dataset): + def check_input(self, dataset): return True def process(self): pyfunc = self.pyfunc - dsi = self.getInput() + dsi = self.get_input() eval_func = numpy.frompyfunc(pyfunc,1,1) - y = DataSet( eval_func( dsi.as_array() ) , True, + y = DataContainer( eval_func( dsi.as_array() ) , True, dimension_labels=dsi.dimension_labels ) return y @@ -890,7 +832,7 @@ if __name__ == '__main__': print("a refcount " , sys.getrefcount(a)) a = numpy.reshape(a, shape) print("a refcount " , sys.getrefcount(a)) - ds = DataSet(a, False, ['X', 'Y','Z' ,'W']) + ds = DataContainer(a, False, ['X', 'Y','Z' ,'W']) print("a refcount " , sys.getrefcount(a)) print ("ds label {0}".format(ds.dimension_labels)) subset = ['W' ,'X'] @@ -901,34 +843,34 @@ if __name__ == '__main__': c = ds.subset(['Z','W','X']) print("a refcount " , sys.getrefcount(a)) - # Create a VolumeData sharing the array with c - volume0 = VolumeData(c.as_array(), False, dimensions = c.dimension_labels) - volume1 = VolumeData(c, False) + # Create a ImageData sharing the array with c + volume0 = ImageData(c.as_array(), False, dimensions = c.dimension_labels) + volume1 = ImageData(c, False) print ("volume0 {0} volume1 {1}".format(id(volume0.array), id(volume1.array))) - # Create a VolumeData copying the array from c - volume2 = VolumeData(c.as_array(), dimensions = c.dimension_labels) - volume3 = VolumeData(c) + # Create a ImageData copying the array from c + volume2 = ImageData(c.as_array(), dimensions = c.dimension_labels) + volume3 = ImageData(c) print ("volume2 {0} volume3 {1}".format(id(volume2.array), id(volume3.array))) # single number DataSet - sn = DataSet(numpy.asarray([1])) + sn = DataContainer(numpy.asarray([1])) ax = AX() ax.scalar = 2 - ax.setInput(c) + ax.set_input(c) #ax.apply() print ("ax in {0} out {1}".format(c.as_array().flatten(), - ax.getOutput().as_array().flatten())) + ax.get_output().as_array().flatten())) axm = AX() axm.scalar = 0.5 - axm.setInput(c) + axm.set_input(c) #axm.apply() - print ("axm in {0} out {1}".format(c.as_array(), axm.getOutput().as_array())) + print ("axm in {0} out {1}".format(c.as_array(), axm.get_output().as_array())) # create a PixelByPixelDataSetProcessor @@ -936,20 +878,20 @@ if __name__ == '__main__': pyfunc = lambda x: -x if x > 20 else x clip = PixelByPixelDataSetProcessor() clip.pyfunc = pyfunc - clip.setInput(c) + clip.set_input(c) #clip.apply() - print ("clip in {0} out {1}".format(c.as_array(), clip.getOutput().as_array())) + print ("clip in {0} out {1}".format(c.as_array(), clip.get_output().as_array())) #dsp = DataSetProcessor() - #dsp.setInput(ds) + #dsp.set_input(ds) #dsp.input = a # pipeline chain = AX() chain.scalar = 0.5 - chain.setInputProcessor(ax) - print ("chain in {0} out {1}".format(ax.getOutput().as_array(), chain.getOutput().as_array())) + chain.set_input_processor(ax) + print ("chain in {0} out {1}".format(ax.get_output().as_array(), chain.get_output().as_array())) # testing arithmetic operations @@ -979,14 +921,14 @@ if __name__ == '__main__': s = [i for i in range(3 * 4 * 4)] s = numpy.reshape(numpy.asarray(s), (3,4,4)) - sino = SinogramData( s ) + sino = AcquisitionData( s ) shape = (4,3,2) a = [i for i in range(2*3*4)] a = numpy.asarray(a) a = numpy.reshape(a, shape) print (numpy.shape(a)) - ds = DataSet(a, True, ['X', 'Y','Z']) + ds = DataContainer(a, True, ['X', 'Y','Z']) # this means that I expect the X to be of length 2 , # y of length 3 and z of length 4 subset = ['Y' ,'Z'] @@ -1000,6 +942,7 @@ if __name__ == '__main__': print ("shape b 2,3? {0}".format(numpy.shape(b1.as_array()))) + # create VolumeData from geometry vgeometry = ImageGeometry(voxel_num_x=2, voxel_num_y=3, channels=2) vol = VolumeData(geometry=vgeometry) @@ -1007,6 +950,6 @@ if __name__ == '__main__': sgeometry = AcquisitionGeometry(dimension=2, angles=numpy.linspace(0, 180, num=20), geom_type='parallel', pixel_num_v=3, pixel_num_h=5 , channels=2) - sino = SinogramData(geometry=sgeometry) + sino = AcquisitionData(geometry=sgeometry) sino2 = sino.clone()
\ No newline at end of file diff --git a/Wrappers/Python/ccpi/reconstruction/algs.py b/Wrappers/Python/ccpi/reconstruction/algs.py index 088b36e..ec52fee 100644 --- a/Wrappers/Python/ccpi/reconstruction/algs.py +++ b/Wrappers/Python/ccpi/reconstruction/algs.py @@ -21,7 +21,6 @@ import numpy import time from ccpi.reconstruction.funcs import BaseFunction -from ccpi.framework import SinogramData, VolumeData def FISTA(x_init, f=None, g=None, opt=None): diff --git a/Wrappers/Python/ccpi/reconstruction/ops.py b/Wrappers/Python/ccpi/reconstruction/ops.py index c21ff06..d6f31eb 100644 --- a/Wrappers/Python/ccpi/reconstruction/ops.py +++ b/Wrappers/Python/ccpi/reconstruction/ops.py @@ -19,10 +19,10 @@ import numpy from scipy.sparse.linalg import svds -from ccpi.framework import DataSet, VolumeData, SinogramData, DataSetProcessor +from ccpi.framework import DataContainer # Maybe operators need to know what types they take as inputs/outputs -# to not just use generic DataSet +# to not just use generic DataContainer class Operator(object): @@ -60,10 +60,10 @@ class LinearOperatorMatrix(Operator): super(LinearOperatorMatrix, self).__init__() def direct(self,x): - return DataSet(numpy.dot(self.A,x.as_array())) + return DataContainer(numpy.dot(self.A,x.as_array())) def adjoint(self,x): - return DataSet(numpy.dot(self.A.transpose(),x.as_array())) + return DataContainer(numpy.dot(self.A.transpose(),x.as_array())) def size(self): return self.A.shape @@ -130,7 +130,7 @@ class FiniteDiff2D(Operator): def PowerMethodNonsquare(op,numiters): # Initialise random inputsize = op.size()[1] - x0 = DataSet(numpy.random.randn(inputsize[0],inputsize[1])) + x0 = DataContainer(numpy.random.randn(inputsize[0],inputsize[1])) s = numpy.zeros(numiters) # Loop for it in numpy.arange(numiters): diff --git a/Wrappers/Python/wip/simple_demo.py b/Wrappers/Python/wip/simple_demo.py index 1ca99f5..655b68d 100644 --- a/Wrappers/Python/wip/simple_demo.py +++ b/Wrappers/Python/wip/simple_demo.py @@ -1,10 +1,11 @@ #import sys #sys.path.append("..") -from ccpi.framework import VolumeData, ImageGeometry, AcquisitionGeometry -from ccpi.reconstruction.algs import * -from ccpi.reconstruction.funcs import Norm2sq, Norm1, TV2D -from ccpi.reconstruction.astra_ops import AstraProjectorSimple +from ccpi.framework import ImageData , VolumeGeometry, SinogramGeometry +from ccpi.reconstruction.algs import FISTA, FBPD, CGLS +from ccpi.reconstruction.funcs import Norm2sq, Norm1 +from ccpi.astra.astra_ops import AstraProjectorSimple +from ccpi.reconstruction.geoms import import numpy as np import matplotlib.pyplot as plt @@ -14,6 +15,7 @@ test_case = 1 # 1=parallel2D, 2=cone2D # Set up phantom N = 128 + vg = ImageGeometry(voxel_num_x=N,voxel_num_y=N) Phantom = VolumeData(geometry=vg) @@ -76,7 +78,7 @@ plt.show() f = Norm2sq(Aop,b,c=0.5) # Initial guess -x_init = VolumeData(np.zeros(x.shape),geometry=vg) +x_init = ImageData(np.zeros(x.shape),geometry=vg) # Run FISTA for least squares without regularization x_fista0, it0, timing0, criter0 = FISTA(x_init, f, None) @@ -146,7 +148,11 @@ fig = plt.figure() # projections row a=fig.add_subplot(rows,cols,current) a.set_title('phantom {0}'.format(np.shape(Phantom.as_array()))) +<<<<<<< HEAD +imgplot = plt.imshow(Phantom.as_array()) +======= imgplot = plt.imshow(Phantom.as_array(),vmin=clims[0],vmax=clims[1]) +>>>>>>> origin current = current + 1 a=fig.add_subplot(rows,cols,current) diff --git a/Wrappers/Python/wip/simple_mc_demo.py b/Wrappers/Python/wip/simple_mc_demo.py index 778aef6..bb74c09 100755 --- a/Wrappers/Python/wip/simple_mc_demo.py +++ b/Wrappers/Python/wip/simple_mc_demo.py @@ -1,10 +1,11 @@ #import sys #sys.path.append("..") -from ccpi.framework import VolumeData, SinogramData, ImageGeometry, AcquisitionGeometry +from ccpi.framework import ImageData, AcquisitionData, ImageGeometry, AcquisitionGeometry from ccpi.reconstruction.algs import FISTA from ccpi.reconstruction.funcs import Norm2sq, Norm1 -from ccpi.reconstruction.astra_ops import AstraProjectorMC +from ccpi.astra.astra_ops import AstraProjectorMC +from ccpi.reconstruction.geoms import VolumeGeometry, SinogramGeometry import numpy import matplotlib.pyplot as plt @@ -48,7 +49,7 @@ plt.show() #vg = ImageGeometry(N,N,None, 1,1,None,channels=numchannels) -#Phantom = VolumeData(x,geometry=vg) +#Phantom = ImageData(x,geometry=vg) # Set up measurement geometry angles_num = 20; # angles number @@ -106,7 +107,7 @@ plt.show() f = Norm2sq(Aop,b,c=0.5) # Initial guess -x_init = VolumeData(numpy.zeros(x.shape),geometry=vg) +x_init = ImageData(numpy.zeros(x.shape),geometry=vg) # FISTA options opt = {'tol': 1e-4, 'iter': 200} |