Code Duplication    Length = 51-52 lines in 3 locations

savu/core/iterative_plugin_runner.py 1 location

@@ 375-426 (lines=52) @@
372
        self.end_plugin._finalise_datasets()
373
        self.end_plugin._finalise_plugin_datasets()
374
375
    def _finalise_iterated_datasets(self):
376
        '''
377
        Inspect the two Data objects that are used to contain the input and
378
        output data for iterations over the course of the iterative processing
379
        (input/output depending on which particular iteration was being done).
380
381
        Mark one of them as the "final dataset" to be added to the output
382
        NeXuS file, and mark the other as "obsolete/to be removed".
383
384
        The decision between which one is kept and which one is removed
385
        depends on which Data object contains the OUTPUT of the very last
386
        iteration.
387
388
        For an odd number of iterations, this is the "original" Data object.
389
        For an even number of iteration, this is the "clone" Data object.
390
        '''
391
        for s1, s2 in self._ip_data_dict['iterating'].items():
392
            name = s1.get_name()
393
            name = name if 'itr_clone' not in name else s2.get_name()
394
            final_dataset = s1 if s1 in self.end_plugin.parameters['out_datasets'] else s2
395
            obsolete = s1 if s1 is not final_dataset else s2
396
            obsolete.remove = True
397
398
            # switch names if necessary
399
            if final_dataset.get_name() != name:
400
                # If this is true, then the output dataset of the last
401
                # iteration is the clone Data object (hence, the mismatched
402
                # names).
403
                #
404
                # So then:
405
                # - obsolete = original
406
                # - final_dataset = clone
407
                #
408
                # which means that the CLONED dataset needs to be set in the
409
                # Experiment object (self.exp) as the "out data", but under
410
                # the name of the ORIGINAL dataset.
411
                # And also, the ORIGINAL dataset is set in the Experiment
412
                # object, but under the name of the CLONED/OBSOLETE dataset
413
                temp = obsolete
414
                self.exp.index['out_data'][name] = final_dataset
415
                self.exp.index['out_data'][s2.get_name()] = temp
416
                # One last thing to do in this case is to set the "name"
417
                # inside the Data object that final_result is set to.
418
                #
419
                # This is because, in this case, the CLONED dataset is in
420
                # final_result, and the "name" within the Data object will
421
                # be some value like "itr_0".
422
                #
423
                # However, the name within the Data object needs to be the
424
                # name of the ORIGINAL Data object in order for the creation
425
                # of the output NeXuS file to work.
426
                final_dataset._set_name(name)
427
428
    def set_alternating_datasets(self):
429
        d1 = self.end_plugin.parameters['out_datasets'][0]

savu/plugins/driver/cpu_iterative_plugin.py 1 location

@@ 248-299 (lines=52) @@
245
        '''
246
        self._ip_complete = True
247
248
    def __finalise_datasets(self):
249
        '''
250
        Inspect the two Data objects that are used to contain the input and
251
        output data for iterations over the course of the iterative processing
252
        (input/output depending on which particular iteration was being done).
253
254
        Mark one of them as the "final dataset" to be added to the output
255
        NeXuS file, and mark the other as "obsolete/to be removed".
256
257
        The decision between which one is kept and which one is removed
258
        depends on which Data object contains the OUTPUT of the very last
259
        iteration.
260
261
        For an odd number of iterations, this is the "original" Data object.
262
        For an even number of iteration, this is the "clone" Data object.
263
        '''
264
        for s1, s2 in self._ip_data_dict['iterating'].items():
265
            name = s1.get_name()
266
            name = name if 'itr_clone' not in name else s2.get_name()
267
            final_dataset = s1 if s1 in self.parameters['out_datasets'] else s2
268
            obsolete = s1 if s1 is not final_dataset else s2
269
            obsolete.remove = True
270
271
            # switch names if necessary
272
            if final_dataset.get_name() != name:
273
                # If this is true, then the output dataset of the last
274
                # iteration is the clone Data object (hence, the mismatched
275
                # names).
276
                #
277
                # So then:
278
                # - obsolete = original
279
                # - final_dataset = clone
280
                #
281
                # which means that the CLONED dataset needs to be set in the
282
                # Experiment object (self.exp) as the "out data", but under
283
                # the name of the ORIGINAL dataset.
284
                # And also, the ORIGINAL dataset is set in the Experiment
285
                # object, but under the name of the CLONED/OBSOLETE dataset
286
                temp = obsolete
287
                self.exp.index['out_data'][name] = final_dataset
288
                self.exp.index['out_data'][s2.get_name()] = temp
289
                # One last thing to do in this case is to set the "name"
290
                # inside the Data object that final_result is set to.
291
                #
292
                # This is because, in this case, the CLONED dataset is in
293
                # final_result, and the "name" within the Data object will
294
                # be some value like "itr_0".
295
                #
296
                # However, the name within the Data object needs to be the
297
                # name of the ORIGINAL Data object in order for the creation
298
                # of the output NeXuS file to work.
299
                final_dataset._set_name(name)
300
301
    def __set_original_datasets(self):
302
        '''

savu/plugins/driver/iterative_plugin.py 1 location

@@ 166-216 (lines=51) @@
163
    def get_iteration(self):
164
        return self._ip_iteration
165
166
    def __finalise_datasets(self):
167
        '''
168
        Inspect the two Data objects that are used to contain the input and
169
        output data for iterations over the course of the iterative processing
170
        (input/output depending on which particular iteration was being done).
171
172
        Mark one of them as the "final dataset" to be added to the output
173
        NeXuS file, and mark the other as "to be removed".
174
175
        The decision between which one is kept and which one is removed
176
        depends on which Data object contains the OUTPUT of the very last
177
        iteration.
178
179
        For an odd number of iterations, this is the "original" Data object.
180
        For an even number of iteration, this is the "clone" Data object.
181
        '''
182
        for s1, s2 in self._ip_data_dict['iterating'].items():
183
            name = s1.get_name()
184
            name = name if 'itr_clone' not in name else s2.get_name()
185
            final_dataset = s1 if s1 in self.parameters['out_datasets'] else s2
186
            obsolete = s1 if s1 is not final_dataset else s2
187
            obsolete.remove = True
188
            # switch names if necessary
189
            if final_dataset.get_name() != name:
190
                # If this is true, then the output dataset of the last
191
                # iteration is the clone Data object (hence, the mismatched
192
                # names).
193
                #
194
                # So then:
195
                # - obsolete = original
196
                # - final_dataset = clone
197
                #
198
                # which means that the CLONED dataset needs to be set in the
199
                # Experiment object (self.exp) as the "out data", but under
200
                # the name of the ORIGINAL dataset.
201
                # And also, the ORIGINAL dataset is set in the Experiment
202
                # object, but under the name of the CLONED/OBSOLETE dataset
203
                temp = obsolete
204
                self.exp.index['out_data'][name] = final_dataset
205
                self.exp.index['out_data'][s2.get_name()] = temp
206
                # One last thing to do in this case is to set the "name"
207
                # inside the Data object that final_result is set to.
208
                #
209
                # This is because, in this case, the CLONED dataset is in
210
                # final_result, and the "name" within the Data object will
211
                # be some value like "itr_0".
212
                #
213
                # However, the name within the Data object needs to be the
214
                # name of the ORIGINAL Data object in order for the creation
215
                # of the output NeXuS file to work.
216
                final_dataset._set_name(name)
217
218
    def set_processing_complete(self):
219
        self._ip_complete = True