Skip to content
Snippets Groups Projects

Added custom LofarDeviceProxy to enhance support for high-dimensional arrays in attribtues

Merged Jan David Mol requested to merge reshape-highdim-arrays into main
All threads resolved!
Compare and Show latest version
6 files
+ 48
33
Compare changes
  • Side-by-side
  • Inline
Files
6
@@ -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
Loading