Skip to content

Commit 78fe9c8

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 66d295e commit 78fe9c8

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
@@ -698,11 +698,14 @@ def _process_data(self, data):
698698
rot = self._transform[2]
699699

700700
# Choose appropriate transform based on (flips, rot).
701-
data = {(0, 0): numpy.rot90(data, rot),
702-
(0, 1): numpy.flipud(numpy.rot90(data, rot)),
703-
(1, 0): numpy.fliplr(numpy.rot90(data, rot)),
704-
(1, 1): numpy.fliplr(numpy.flipud(numpy.rot90(data, rot)))
705-
}[flips]
701+
# Do rotation
702+
data = numpy.rot90(data, rot)
703+
# Flip
704+
data = {(0, 0): lambda d: d,
705+
(0, 1): numpy.flipud,
706+
(1, 0): numpy.fliplr,
707+
(1, 1): lambda d: numpy.fliplr(numpy.flipud(d))
708+
}[flips](data)
706709
return super()._process_data(data)
707710

708711
def set_readout_mode(self, description):

0 commit comments

Comments
 (0)