| @@ 44-97 (lines=54) @@ | ||
| 41 | def nOutput_datasets(self): |
|
| 42 | return 1 |
|
| 43 | ||
| 44 | def setup(self): |
|
| 45 | in_dataset, out_dataset = self.get_datasets() |
|
| 46 | ||
| 47 | #=================== populate output dataset ========================== |
|
| 48 | # Due to the reduction in dimensions, the out_dataset will have |
|
| 49 | # different axis_labels, patterns and shape to the in_dataset and |
|
| 50 | # these will need to be defined. |
|
| 51 | # For more information about the syntax used here see: |
|
| 52 | # http://savu.readthedocs.io/en/latest/api_plugin/savu.data.data_structures.data_create |
|
| 53 | ||
| 54 | # AMEND THE PATTERNS: The output dataset will have one dimension less |
|
| 55 | # than the in_dataset, so remove the final slice dimension from any |
|
| 56 | # patterns you want to keep. |
|
| 57 | rm_dim = str(in_dataset[0].get_data_patterns() |
|
| 58 | ['SINOGRAM']['slice_dims'][-1]) |
|
| 59 | patterns = ['SINOGRAM.' + rm_dim, 'PROJECTION.' + rm_dim] |
|
| 60 | ||
| 61 | # AMEND THE AXIS LABELS: Find the dimensions to remove using their |
|
| 62 | # axis_labels to ensure the plugin is as generic as possible and will |
|
| 63 | # work for data in all orientations. |
|
| 64 | axis_labels = copy.copy(in_dataset[0].get_axis_labels()) |
|
| 65 | rm_labels = ['detector_x', 'detector_y'] |
|
| 66 | rm_dims = sorted([in_dataset[0].get_data_dimension_by_axis_label(a) |
|
| 67 | for a in rm_labels])[::-1] |
|
| 68 | for d in rm_dims: |
|
| 69 | del axis_labels[d] |
|
| 70 | # Add a new axis label to the list |
|
| 71 | axis_labels.append({'Q': 'Angstrom^-1'}) |
|
| 72 | ||
| 73 | # AMEND THE SHAPE: Remove the two unrequired dimensions from the |
|
| 74 | # original shape and add a new dimension shape. |
|
| 75 | shape = list(in_dataset[0].get_shape()) |
|
| 76 | for d in rm_dims: |
|
| 77 | del shape[d] |
|
| 78 | shape += (self.get_parameters('num_bins'),) |
|
| 79 | ||
| 80 | # populate the output dataset |
|
| 81 | out_dataset[0].create_dataset( |
|
| 82 | patterns={in_dataset[0]: patterns}, |
|
| 83 | axis_labels=axis_labels, |
|
| 84 | shape=tuple(shape)) |
|
| 85 | ||
| 86 | # ASSOCIATE AN EXTRA PATTERN WITH THE DATASET: SINOGRAM and PROJECTION |
|
| 87 | # patterns are already asssociated with the output dataset, but add |
|
| 88 | # another one. |
|
| 89 | spectrum = \ |
|
| 90 | {'core_dims': (-1,), 'slice_dims': tuple(range(len(shape)-1))} |
|
| 91 | out_dataset[0].add_pattern("SPECTRUM", **spectrum) |
|
| 92 | #====================================================================== |
|
| 93 | ||
| 94 | #================== populate plugin datasets ========================== |
|
| 95 | in_pData, out_pData = self.get_plugin_datasets() |
|
| 96 | in_pData[0].plugin_data_setup('DIFFRACTION', 'single') |
|
| 97 | out_pData[0].plugin_data_setup('SPECTRUM', 'single') |
|
| 98 | #====================================================================== |
|
| 99 | ||
| 100 | def pre_process(self): |
|
| @@ 97-140 (lines=44) @@ | ||
| 94 | ||
| 95 | self.add_axes_to_meta_data(axis, mData) |
|
| 96 | ||
| 97 | def setup(self): |
|
| 98 | in_dataset, out_dataset = self.get_datasets() |
|
| 99 | ||
| 100 | # AMEND THE PATTERNS: The output dataset will have one dimension less |
|
| 101 | # than the in_dataset, so remove the final slice dimension from any |
|
| 102 | # patterns you want to keep. |
|
| 103 | rm_dim = str(in_dataset[0].get_data_patterns() |
|
| 104 | ['SINOGRAM']['slice_dims'][-1]) |
|
| 105 | patterns = ['SINOGRAM.' + rm_dim, 'PROJECTION.' + rm_dim] |
|
| 106 | ||
| 107 | # AMEND THE AXIS LABELS: Find the dimensions to remove using their |
|
| 108 | # axis_labels to ensure the plugin is as generic as possible and will |
|
| 109 | # work for data in all orientations. |
|
| 110 | axis_labels = copy.copy(in_dataset[0].get_axis_labels()) |
|
| 111 | rm_labels = ['detector_x', 'detector_y'] |
|
| 112 | rm_dims = sorted([in_dataset[0].get_data_dimension_by_axis_label(a) |
|
| 113 | for a in rm_labels])[::-1] |
|
| 114 | for d in rm_dims: |
|
| 115 | del axis_labels[d] |
|
| 116 | # Add a new axis label to the list |
|
| 117 | axis_labels.append({'Q': 'Angstrom^-1'}) |
|
| 118 | ||
| 119 | # AMEND THE SHAPE: Remove the two unrequired dimensions from the |
|
| 120 | # original shape and add a new dimension shape. |
|
| 121 | shape = list(in_dataset[0].get_shape()) |
|
| 122 | for d in rm_dims: |
|
| 123 | del shape[d] |
|
| 124 | shape += (self.get_parameters('num_bins'),) |
|
| 125 | ||
| 126 | # populate the output dataset |
|
| 127 | out_dataset[0].create_dataset( |
|
| 128 | patterns={in_dataset[0]: patterns}, |
|
| 129 | axis_labels=axis_labels, |
|
| 130 | shape=tuple(shape)) |
|
| 131 | ||
| 132 | spectrum = \ |
|
| 133 | {'core_dims': (-1,), 'slice_dims': tuple(range(len(shape)-1))} |
|
| 134 | out_dataset[0].add_pattern("SPECTRUM", **spectrum) |
|
| 135 | # ===================================================================== |
|
| 136 | ||
| 137 | # ================== populate plugin datasets ========================= |
|
| 138 | in_pData, out_pData = self.get_plugin_datasets() |
|
| 139 | in_pData[0].plugin_data_setup('DIFFRACTION', 'single') |
|
| 140 | out_pData[0].plugin_data_setup('SPECTRUM', 'single') |
|
| 141 | # ===================================================================== |
|
| 142 | ||
| 143 | def get_max_frames(self): |
|