| Conditions | 7 |
| Total Lines | 60 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # Copyright 2014 Diamond Light Source Ltd. |
||
| 68 | def setup(self): |
||
| 69 | in_dataset, out_dataset = self.get_datasets() |
||
| 70 | in_pData, out_pData = self.get_plugin_datasets() |
||
| 71 | in_pData[0].plugin_data_setup('PROJECTION', 'single') |
||
| 72 | det_y = in_dataset[0].get_data_dimension_by_axis_label('detector_y') |
||
| 73 | det_x = in_dataset[0].get_data_dimension_by_axis_label('detector_x') |
||
| 74 | |||
| 75 | self.shape = list(in_dataset[0].get_shape()) |
||
| 76 | self.core_dims = in_pData[0].get_core_dimensions() |
||
| 77 | img_dims = self.get_in_datasets()[0].get_shape() |
||
| 78 | |||
| 79 | if self.parameters['mode'] == 'absolute': |
||
| 80 | sizeX = self.parameters['sizeX'] |
||
| 81 | sizeY = self.parameters['sizeY'] |
||
| 82 | if sizeX > 0: |
||
| 83 | xslice = slice(self.shape[det_x] / 2 - sizeX / 2, |
||
| 84 | self.shape[det_x] / 2 + sizeX / 2 + sizeX % 2) |
||
| 85 | self.shape[det_x] = 2 * (sizeX / 2) + sizeX % 2 |
||
| 86 | else: |
||
| 87 | xslice = slice(0, self.shape[det_x]) |
||
| 88 | if sizeY > 0: |
||
| 89 | yslice = slice(self.shape[det_y] / 2 - sizeY / 2, |
||
| 90 | self.shape[det_y] / 2 + sizeY / 2 + sizeY % 2) |
||
| 91 | self.shape[det_y] = 2 * (sizeY / 2) + sizeY % 2 |
||
| 92 | else: |
||
| 93 | yslice = slice(0, self.shape[det_y]) |
||
| 94 | self.new_slice = [yslice, xslice] |
||
| 95 | elif self.parameters['mode'] == 'relative': |
||
| 96 | cropX = self.parameters['cropX'] |
||
| 97 | cropY = self.parameters['cropY'] |
||
| 98 | self.new_slice = [slice(cropY, img_dims[det_y] - cropY), |
||
| 99 | slice(cropX, img_dims[det_x] - cropX)] |
||
| 100 | self.shape[det_x] -= 2 * cropX |
||
| 101 | self.shape[det_y] -= 2 * cropY |
||
| 102 | elif self.parameters['mode'] == 'automatic': |
||
| 103 | print(in_dataset[0].get_name()) |
||
| 104 | print(in_dataset[0].meta_data.get_dictionary().keys()) |
||
| 105 | for key, value in in_dataset[0].meta_data.get_dictionary().iteritems(): |
||
| 106 | print (key, value) |
||
| 107 | |||
| 108 | #print(in_dataset[0].meta_data.get('indices2crop')) |
||
| 109 | # getting indices to crop the data |
||
| 110 | #sample_data[int(indices2crop[2]):int(indices2crop[3]),int(indices2crop[0]):int(indices2crop[1])] |
||
| 111 | #indices2crop = in_dataset[0].meta_data.get('indices2crop') |
||
| 112 | #shapeX = int(indices2crop[1]-indices2crop[0]) |
||
| 113 | #shapeY = int(indices2crop[3]-indices2crop[2]) |
||
| 114 | #self.new_slice = [slice(indices2crop[0], indices2crop[1]), |
||
| 115 | # slice(indices2crop[2], indices2crop[3])] |
||
| 116 | #self.new_slice = [slice(indices2crop[2], indices2crop[3]), |
||
| 117 | # slice(indices2crop[0], indices2crop[1])] |
||
| 118 | #print(shapeX, shapeY) |
||
| 119 | #self.shape[det_x] = shapeX |
||
| 120 | #self.shape[det_y] = shapeY |
||
| 121 | #print(img_dims[det_x], img_dims[det_y]) |
||
| 122 | self.new_slice = (None, None) |
||
| 123 | |||
| 124 | out_dataset[0].create_dataset(patterns=in_dataset[0], |
||
| 125 | axis_labels=in_dataset[0], |
||
| 126 | shape=tuple(self.shape)) |
||
| 127 | out_pData[0].plugin_data_setup('PROJECTION', 'single') |
||
| 128 |