diff options
author | Edoardo Pasca <edo.paskino@gmail.com> | 2018-03-07 14:37:19 +0000 |
---|---|---|
committer | Edoardo Pasca <edo.paskino@gmail.com> | 2018-03-07 14:37:19 +0000 |
commit | c8aea54ea281f5990d5ce2966fff30db48e87716 (patch) | |
tree | 320d125e185d27ab50714fda034537968a30d174 /Wrappers/Python | |
parent | 00781c2c2b1f51bed23db8878f628d72b296ac0c (diff) | |
download | framework-c8aea54ea281f5990d5ce2966fff30db48e87716.tar.gz framework-c8aea54ea281f5990d5ce2966fff30db48e87716.tar.bz2 framework-c8aea54ea281f5990d5ce2966fff30db48e87716.tar.xz framework-c8aea54ea281f5990d5ce2966fff30db48e87716.zip |
bugfix in subset, initialize processor with variables
Diffstat (limited to 'Wrappers/Python')
-rw-r--r-- | Wrappers/Python/ccpi/framework.py | 42 | ||||
-rwxr-xr-x | Wrappers/Python/ccpi/processors.py | 14 |
2 files changed, 43 insertions, 13 deletions
diff --git a/Wrappers/Python/ccpi/framework.py b/Wrappers/Python/ccpi/framework.py index 5ac17ee..754e0ee 100644 --- a/Wrappers/Python/ccpi/framework.py +++ b/Wrappers/Python/ccpi/framework.py @@ -141,8 +141,9 @@ class DataSet(object): if dimensions is not None: return self.subset(dimensions).as_array() return self.array - - def subset(self, dimensions=None): + + + def subset(self, dimensions=None, **kw): '''Creates a DataSet containing a subset of self according to the labels in dimensions''' if dimensions is None: @@ -164,7 +165,7 @@ class DataSet(object): else: axis_order.append(find_key(self.dimension_labels, dl)) if not proceed: - raise KeyError('Unknown key specified {0}'.format(dl)) + raise KeyError('Subset error: Unknown key specified {0}'.format(dl)) # slice away the unwanted data from the array unwanted_dimensions = self.dimension_labels.copy() @@ -176,13 +177,21 @@ class DataSet(object): #print ("left_dimensions {0}".format(left_dimensions)) #new_shape = [self.shape[ax] for ax in axis_order] #print ("new_shape {0}".format(new_shape)) - command = "self.array" + command = "self.array[" for i in range(self.number_of_dimensions): if self.dimension_labels[i] in unwanted_dimensions.values(): - command = command + "[0]" + value = 0 + for k,v in kw.items(): + if k == self.dimension_labels[i]: + value = v + + command = command + str(value) else: - command = command + "[:]" - #print ("command {0}".format(command)) + command = command + ":" + if i < self.number_of_dimensions -1: + command = command + ',' + command = command + ']' + cleaned = eval(command) # cleaned has collapsed dimensions in the same order of # self.array, but we want it in the order stated in the @@ -413,7 +422,7 @@ class DataSet(object): repres += "Number of dimensions: {0}\n".format(self.number_of_dimensions) repres += "Shape: {0}\n".format(self.shape) repres += "Axis labels: {0}\n".format(self.dimension_labels) - repres += "Representation: {0}\n".format(self.array) + repres += "Representation: \n{0}\n".format(self.array) return repres @@ -772,5 +781,22 @@ if __name__ == '__main__': s = numpy.reshape(numpy.asarray(s), (3,4,4)) sino = SinogramData( 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']) + # this means that I expect the X to be of length 2 , + # y of length 3 and z of length 4 + subset = ['Y' ,'Z'] + b0 = ds.subset( subset ) + print ("shape b 3,2? {0}".format(numpy.shape(b0.as_array()))) + # expectation on b is that it is + # 3x2 cut at z = 0 + + subset = ['X' ,'Y'] + b1 = ds.subset( subset , Z=1) + print ("shape b 2,3? {0}".format(numpy.shape(b1.as_array())))
\ No newline at end of file diff --git a/Wrappers/Python/ccpi/processors.py b/Wrappers/Python/ccpi/processors.py index 09e7229..c509a4e 100755 --- a/Wrappers/Python/ccpi/processors.py +++ b/Wrappers/Python/ccpi/processors.py @@ -32,19 +32,23 @@ class Normalizer(DataSetProcessor): Input: SinogramDataSet
Parameter: 2D projection with flat field (or stack)
2D projection with dark field (or stack)
- Output: SinogramDataSet
+ Output: SinogramDataSetn
'''
- def __init__(self):
+ def __init__(self, flat_field = None, dark_field = None, tolerance = 1e-5):
kwargs = {
- 'flat_field' :None,
- 'dark_field' :None,
+ 'flat_field' : None,
+ 'dark_field' : None,
# very small number. Used when there is a division by zero
- 'tolerance' : 1e-5
+ 'tolerance' : tolerance
}
#DataSetProcessor.__init__(self, **kwargs)
super(Normalizer, self).__init__(**kwargs)
+ if not flat_field is None:
+ self.setFlatField(flat_field)
+ if not dark_field is None:
+ self.setDarkField(dark_field)
def checkInput(self, dataset):
if dataset.number_of_dimensions == 3:
|