Skip to content

Commit e8bdc98

Browse files
author
David Miguel Susano Pinto
committed
Always 'import numpy as np' for consistency
1 parent 53f1856 commit e8bdc98

File tree

7 files changed

+38
-38
lines changed

7 files changed

+38
-38
lines changed

microscope/abc.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from threading import Thread
3333
from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple
3434

35-
import numpy
35+
import numpy as np
3636
import Pyro4
3737

3838
import microscope
@@ -853,13 +853,13 @@ def _process_data(self, data):
853853

854854
# Choose appropriate transform based on (flips, rot).
855855
# Do rotation
856-
data = numpy.rot90(data, rot)
856+
data = np.rot90(data, rot)
857857
# Flip
858858
data = {
859859
(0, 0): lambda d: d,
860-
(0, 1): numpy.flipud,
861-
(1, 0): numpy.fliplr,
862-
(1, 1): lambda d: numpy.fliplr(numpy.flipud(d)),
860+
(0, 1): np.flipud,
861+
(1, 0): np.fliplr,
862+
(1, 1): lambda d: np.fliplr(np.flipud(d)),
863863
}[flips](data)
864864
return super()._process_data(data)
865865

@@ -1064,15 +1064,15 @@ class DeformableMirror(TriggerTargetMixin, Device, metaclass=abc.ABCMeta):
10641064
@abc.abstractmethod
10651065
def __init__(self, **kwargs) -> None:
10661066
super().__init__(**kwargs)
1067-
self._patterns: Optional[numpy.ndarray] = None
1067+
self._patterns: Optional[np.ndarray] = None
10681068
self._pattern_idx: int = -1
10691069

10701070
@property
10711071
@abc.abstractmethod
10721072
def n_actuators(self) -> int:
10731073
raise NotImplementedError()
10741074

1075-
def _validate_patterns(self, patterns: numpy.ndarray) -> None:
1075+
def _validate_patterns(self, patterns: np.ndarray) -> None:
10761076
"""Validate the shape of a series of patterns.
10771077
10781078
Only validates the shape of the patterns, not if the values
@@ -1096,10 +1096,10 @@ def _validate_patterns(self, patterns: numpy.ndarray) -> None:
10961096
)
10971097

10981098
@abc.abstractmethod
1099-
def _do_apply_pattern(self, pattern: numpy.ndarray) -> None:
1099+
def _do_apply_pattern(self, pattern: np.ndarray) -> None:
11001100
raise NotImplementedError()
11011101

1102-
def apply_pattern(self, pattern: numpy.ndarray) -> None:
1102+
def apply_pattern(self, pattern: np.ndarray) -> None:
11031103
"""Apply this pattern.
11041104
11051105
Raises:
@@ -1118,7 +1118,7 @@ def apply_pattern(self, pattern: numpy.ndarray) -> None:
11181118
self._validate_patterns(pattern)
11191119
self._do_apply_pattern(pattern)
11201120

1121-
def queue_patterns(self, patterns: numpy.ndarray) -> None:
1121+
def queue_patterns(self, patterns: np.ndarray) -> None:
11221122
"""Send values to the mirror.
11231123
11241124
Args:

microscope/gui.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import threading
3838
from typing import Dict, List, Optional, Sequence
3939

40-
import numpy
40+
import numpy as np
4141
import Pyro4
4242
from qtpy import QtCore, QtGui, QtWidgets
4343

@@ -136,7 +136,7 @@ def put(self, *args, **kwargs):
136136
class _Imager(QtCore.QObject):
137137
"""Helper for CameraWidget handling the internals of the camera trigger."""
138138

139-
imageAcquired = QtCore.Signal(numpy.ndarray)
139+
imageAcquired = QtCore.Signal(np.ndarray)
140140

141141
def __init__(self, camera: microscope.abc.Camera) -> None:
142142
super().__init__()
@@ -187,7 +187,7 @@ def __init__(self, device: microscope.abc.Camera, *args, **kwargs) -> None:
187187

188188
self._view = QtWidgets.QLabel(parent=self)
189189
self.displayData(
190-
numpy.zeros(self._device.get_sensor_shape(), dtype=numpy.uint8)
190+
np.zeros(self._device.get_sensor_shape(), dtype=np.uint8)
191191
)
192192

193193
self._enable_check = QtWidgets.QCheckBox("Enabled", parent=self)
@@ -232,10 +232,10 @@ def updateEnableState(self) -> None:
232232
self._snap_button.setEnabled(self._device.get_is_enabled())
233233
self._exposure_box.setEnabled(self._device.get_is_enabled())
234234

235-
def displayData(self, data: numpy.ndarray) -> None:
235+
def displayData(self, data: np.ndarray) -> None:
236236
np_to_qt = {
237-
numpy.dtype("uint8"): QtGui.QImage.Format_Grayscale8,
238-
numpy.dtype("uint16"): QtGui.QImage.Format_Grayscale16,
237+
np.dtype("uint8"): QtGui.QImage.Format_Grayscale8,
238+
np.dtype("uint16"): QtGui.QImage.Format_Grayscale16,
239239
}
240240
qt_img = QtGui.QImage(
241241
data.tobytes(), *data.shape, np_to_qt[data.dtype]
@@ -257,7 +257,7 @@ def __init__(
257257
super().__init__(*args, **kwargs)
258258
self._device = device
259259

260-
self._pattern = numpy.ndarray(shape=(self._device.n_actuators))
260+
self._pattern = np.ndarray(shape=(self._device.n_actuators))
261261
self._actuators: List[QtWidgets.QSlider] = []
262262
for i in range(self._device.n_actuators):
263263
actuator = QtWidgets.QSlider(QtCore.Qt.Horizontal, parent=self)

microscope/mirror/alpao.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import ctypes
2121
import warnings
2222

23-
import numpy
23+
import numpy as np
2424

2525
import microscope
2626
import microscope.abc
@@ -55,7 +55,7 @@ class AlpaoDeformableMirror(microscope.abc.DeformableMirror):
5555
]
5656

5757
@staticmethod
58-
def _normalize_patterns(patterns: numpy.ndarray) -> numpy.ndarray:
58+
def _normalize_patterns(patterns: np.ndarray) -> np.ndarray:
5959
"""
6060
Alpao SDK expects values in the [-1 1] range, so we normalize
6161
them from the [0 1] range we expect in our interface.
@@ -124,7 +124,7 @@ def trigger_mode(self) -> microscope.TriggerMode:
124124
def trigger_type(self) -> microscope.TriggerType:
125125
return self._trigger_type
126126

127-
def _do_apply_pattern(self, pattern: numpy.ndarray) -> None:
127+
def _do_apply_pattern(self, pattern: np.ndarray) -> None:
128128
pattern = self._normalize_patterns(pattern)
129129
data_pointer = pattern.ctypes.data_as(asdk.Scalar_p)
130130
status = asdk.Send(self._dm, data_pointer)
@@ -157,14 +157,14 @@ def set_trigger(self, ttype, tmode):
157157
self._raise_if_error(status)
158158
self._trigger_type = ttype
159159

160-
def queue_patterns(self, patterns: numpy.ndarray) -> None:
160+
def queue_patterns(self, patterns: np.ndarray) -> None:
161161
if self._trigger_type == microscope.TriggerType.SOFTWARE:
162162
super().queue_patterns(patterns)
163163
return
164164

165165
self._validate_patterns(patterns)
166166
patterns = self._normalize_patterns(patterns)
167-
patterns = numpy.atleast_2d(patterns)
167+
patterns = np.atleast_2d(patterns)
168168
n_patterns: int = patterns.shape[0]
169169

170170
# The Alpao SDK seems to only support the trigger mode start. It

microscope/mirror/bmc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import os
2525
import warnings
2626

27-
import numpy
27+
import numpy as np
2828

2929
import microscope
3030
import microscope._utils
@@ -62,7 +62,7 @@ def __init__(self, serial_number: str, **kwargs) -> None:
6262
def n_actuators(self) -> int:
6363
return self._dm.ActCount
6464

65-
def _do_apply_pattern(self, pattern: numpy.ndarray) -> None:
65+
def _do_apply_pattern(self, pattern: np.ndarray) -> None:
6666
data_pointer = pattern.ctypes.data_as(ctypes.POINTER(ctypes.c_double))
6767
status = BMC.SetArray(self._dm, data_pointer, None)
6868
if status:

microscope/mirror/mirao52e.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import ctypes
4343
from typing import Callable
4444

45-
import numpy
45+
import numpy as np
4646

4747
import microscope
4848
import microscope._utils
@@ -82,15 +82,15 @@ def n_actuators(self) -> int:
8282
return mro.NB_COMMAND_VALUES
8383

8484
@staticmethod
85-
def _normalize_patterns(patterns: numpy.ndarray) -> numpy.ndarray:
85+
def _normalize_patterns(patterns: np.ndarray) -> np.ndarray:
8686
"""
8787
mirao52e SDK expects values in the [-1 1] range, so we normalize
8888
them from the [0 1] range we expect in our interface.
8989
"""
9090
patterns = (patterns * 2) - 1
9191
return patterns
9292

93-
def _do_apply_pattern(self, pattern: numpy.ndarray) -> None:
93+
def _do_apply_pattern(self, pattern: np.ndarray) -> None:
9494
pattern = self._normalize_patterns(pattern)
9595
command = pattern.ctypes.data_as(mro.Command)
9696
if not mro.applyCommand(command, mro.FALSE, self._status):

microscope/testsuite/hardware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import time
2424

25-
import numpy
25+
import numpy as np
2626

2727

2828
def test_mirror_actuators(dm, time_interval=0.5):
@@ -34,7 +34,7 @@ def test_mirror_actuators(dm, time_interval=0.5):
3434
actuator.
3535
"""
3636
base_value = 0.5
37-
data = numpy.full((dm.n_actuators), base_value)
37+
data = np.full((dm.n_actuators), base_value)
3838
dm.apply_pattern(data)
3939

4040
time.sleep(time_interval)

microscope/testsuite/test_devices.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import unittest.mock
4040
from queue import Queue
4141

42-
import numpy
42+
import numpy as np
4343

4444
import microscope
4545
import microscope.testsuite.devices as dummies
@@ -280,7 +280,7 @@ class DeformableMirrorTests(DeviceTests):
280280
"""
281281

282282
def assertCurrentPattern(self, expected_pattern, msg=""):
283-
numpy.testing.assert_array_equal(
283+
np.testing.assert_array_equal(
284284
self.fake.get_current_pattern(), expected_pattern, msg
285285
)
286286

@@ -290,39 +290,39 @@ def test_get_number_of_actuators(self):
290290
self.assertEqual(self.device.n_actuators, self.planned_n_actuators)
291291

292292
def test_applying_pattern(self):
293-
pattern = numpy.full((self.planned_n_actuators,), 0.2)
293+
pattern = np.full((self.planned_n_actuators,), 0.2)
294294
self.device.apply_pattern(pattern)
295295
self.assertCurrentPattern(pattern)
296296

297297
def test_out_of_range_pattern(self):
298298
# While we expect values in the [0 1] range, we should not
299299
# actually be checking for that.
300-
pattern = numpy.zeros((self.planned_n_actuators,))
300+
pattern = np.zeros((self.planned_n_actuators,))
301301
for v in [-1000, -1, 0, 1, 3]:
302302
pattern[:] = v
303303
self.device.apply_pattern(pattern)
304304
self.assertCurrentPattern(pattern)
305305

306306
def test_software_triggering(self):
307307
n_patterns = 5
308-
patterns = numpy.random.rand(n_patterns, self.planned_n_actuators)
308+
patterns = np.random.rand(n_patterns, self.planned_n_actuators)
309309
self.device.queue_patterns(patterns)
310310
for i in range(n_patterns):
311311
self.device.next_pattern()
312312
self.assertCurrentPattern(patterns[i])
313313

314314
def test_validate_pattern_too_long(self):
315-
patterns = numpy.zeros((self.planned_n_actuators + 1))
315+
patterns = np.zeros((self.planned_n_actuators + 1))
316316
with self.assertRaisesRegex(Exception, "length of second dimension"):
317317
self.device.apply_pattern(patterns)
318318

319319
def test_validate_pattern_swapped_dimensions(self):
320-
patterns = numpy.zeros((self.planned_n_actuators, 1))
320+
patterns = np.zeros((self.planned_n_actuators, 1))
321321
with self.assertRaisesRegex(Exception, "length of second dimension"):
322322
self.device.apply_pattern(patterns)
323323

324324
def test_validate_pattern_with_extra_dimension(self):
325-
patterns = numpy.zeros((2, 1, self.planned_n_actuators))
325+
patterns = np.zeros((2, 1, self.planned_n_actuators))
326326
with self.assertRaisesRegex(
327327
Exception, "dimensions \\(must be 1 or 2\\)"
328328
):
@@ -444,7 +444,7 @@ def test_non_square_patterns_shape(self):
444444

445445
class TestStageAwareCamera(unittest.TestCase, CameraTests):
446446
def setUp(self):
447-
image = numpy.full((3000, 1500, 1), 42, dtype=numpy.uint8)
447+
image = np.full((3000, 1500, 1), 42, dtype=np.uint8)
448448
self.sensor_shape = (128, 128)
449449
self.stage = simulators.SimulatedStage(
450450
{

0 commit comments

Comments
 (0)