Skip to content

Commit cfff4a5

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 a74fd0d commit cfff4a5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

microscope/devices.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,14 @@ def _process_data(self, data):
692692
rot = self._transform[2]
693693

694694
# Choose appropriate transform based on (flips, rot).
695-
data = {(0, 0): numpy.rot90(data, rot),
696-
(0, 1): numpy.flipud(numpy.rot90(data, rot)),
697-
(1, 0): numpy.fliplr(numpy.rot90(data, rot)),
698-
(1, 1): numpy.fliplr(numpy.flipud(numpy.rot90(data, rot)))
699-
}[flips]
695+
# Do rotation
696+
data = numpy.rot90(data, rot)
697+
# Flip
698+
data = {(0, 0): lambda d: d,
699+
(0, 1): numpy.flipud,
700+
(1, 0): numpy.fliplr,
701+
(1, 1): lambda d: numpy.fliplr(numpy.flipud(d))
702+
}[flips](data)
700703
return super()._process_data(data)
701704

702705
def set_readout_mode(self, description):

0 commit comments

Comments
 (0)