Skip to content
Snippets Groups Projects
Commit 7f674955 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-882: Fix linting

parent ace8d1f3
No related branches found
No related tags found
1 merge request!4Added custom LofarDeviceProxy to enhance support for high-dimensional arrays in attribtues
Pipeline #36548 failed
......@@ -8,6 +8,7 @@ import numpy
from tango import DeviceProxy
from tango import ExtractAs
class LofarDeviceProxy(DeviceProxy):
"""A LOFAR-specific tango.DeviceProxy that provides
a richer experience."""
......@@ -20,10 +21,14 @@ class LofarDeviceProxy(DeviceProxy):
@lru_cache()
def get_attribute_shape(self, name):
# "format" property describes actual dimensions as a tuple (x, y, z, ...),
# so reshape the value accordingly.
"""Get the shape of the requested attribute, as a tuple."""
config = self.get_attribute_config(name)
if config.format and config.format[0] == "(":
# For >2D arrays, the "format" property describes actual
# the dimensions as a tuple (x, y, z, ...),
# so reshape the value accordingly.
shape = ast.literal_eval(config.format)
elif config.max_dim_y > 0:
# 2D array
......@@ -61,7 +66,9 @@ class LofarDeviceProxy(DeviceProxy):
value = numpy.array(value)
if value.shape != shape:
raise ValueError(f"Invalid shape. Given: {value.shape} Expected: {shape}")
raise ValueError(
f"Invalid shape. Given: {value.shape} Expected: {shape}"
)
if len(shape) > 2:
# >2D arrays collapse into 2D
......
......@@ -17,22 +17,12 @@ class MyDevice(Device):
access=AttrWriteType.READ_WRITE,
)
scalar = attribute(
dtype=bool,
access=AttrWriteType.READ_WRITE
)
scalar = attribute(dtype=bool, access=AttrWriteType.READ_WRITE)
spectrum = attribute(
dtype=(bool,),
max_dim_x=2,
access=AttrWriteType.READ_WRITE
)
spectrum = attribute(dtype=(bool,), max_dim_x=2, access=AttrWriteType.READ_WRITE)
image = attribute(
dtype=((bool,),),
max_dim_x=2,
max_dim_y=3,
access=AttrWriteType.READ_WRITE
dtype=((bool,),), max_dim_x=2, max_dim_y=3, access=AttrWriteType.READ_WRITE
)
def init_device(self):
......@@ -110,7 +100,6 @@ class LofarDeviceProxyTest(base.TestCase):
self.assertEqual((3, 2), value.shape)
self.assertEqual(numpy.bool_, type(value[0, 0]))
def test_write_image(self):
self.proxy.image = [[True, False]] * 3
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment