Skip to content

Commit f11d893

Browse files
committed
Only evaluate necessary transforms.
Dict evaulation is not lazy: previously, this code evaluated all allowable transforms before picking the appropriate one. This is now fixed by breaking it down into the rotation transfrom, then passing the result to one function from a dict of flip transform functions.
1 parent 5ff43e0 commit f11d893

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

microscope/devices.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,15 @@ def _process_data(self, data):
685685
rot = self._transform[2]
686686

687687
# Choose appropriate transform based on (flips, rot).
688-
return {(0, 0): numpy.rot90(data, rot),
689-
(0, 1): numpy.flipud(numpy.rot90(data, rot)),
690-
(1, 0): numpy.fliplr(numpy.rot90(data, rot)),
691-
(1, 1): numpy.fliplr(numpy.flipud(numpy.rot90(data, rot)))
692-
}[flips]
693-
688+
# Do rotation
689+
data = numpy.rot90(data, rot)
690+
# Flip
691+
data = {(0, 0): lambda d: d,
692+
(0, 1): numpy.flipud,
693+
(1, 0): numpy.fliplr,
694+
(1, 1): lambda d: numpy.fliplr(numpy.flipud(d))
695+
}[flips](data)
696+
return super()._process_data(data)
694697

695698
def set_readout_mode(self, description):
696699
"""Set the readout mode and _readout_transform."""

0 commit comments

Comments
 (0)