/usr/lib/python2.7/dist-packages/PyTango/tango_numpy.py is in python-pytango 8.1.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | # ------------------------------------------------------------------------------
# This file is part of PyTango (http://www.tinyurl.com/PyTango)
#
# Copyright 2006-2012 CELLS / ALBA Synchrotron, Bellaterra, Spain
# Copyright 2013-2014 European Synchrotron Radiation Facility, Grenoble, France
#
# Distributed under the terms of the GNU Lesser General Public License,
# either version 3 of the License, or (at your option) any later version.
# See LICENSE.txt for more info.
# ------------------------------------------------------------------------------
"""
This is an internal PyTango module.
"""
__all__ = [ "NumpyType", "numpy_type", "numpy_spectrum", "numpy_image" ]
__docformat__ = "restructuredtext"
from ._PyTango import Except
from ._PyTango import constants
from .attribute_proxy import AttributeProxy
import collections
def _numpy_invalid(*args, **kwds):
Except.throw_exception(
"PyTango_InvalidConversion",
"There's no registered conversor to numpy.",
"NumpyType.tango_to_numpy"
)
def _define_numpy():
if not constants.NUMPY_SUPPORT:
return None, _numpy_invalid, _numpy_invalid, _numpy_invalid
try:
import numpy
import operator
ArgType = _PyTango.CmdArgType
AttributeInfo = _PyTango.AttributeInfo
Attribute = _PyTango.Attribute
class NumpyType(object):
DevShort = numpy.int16
DevLong = numpy.int32
DevDouble = numpy.float64
DevFloat = numpy.float32
DevBoolean = numpy.bool8
DevUShort = numpy.uint16
DevULong = numpy.uint32
DevUChar = numpy.ubyte
DevLong64 = numpy.int64
DevULong64 = numpy.uint64
mapping = {
ArgType.DevShort: DevShort,
ArgType.DevLong: DevLong,
ArgType.DevDouble: DevDouble,
ArgType.DevFloat: DevFloat,
ArgType.DevBoolean: DevBoolean,
ArgType.DevUShort: DevUShort,
ArgType.DevULong: DevULong,
ArgType.DevUChar: DevUChar,
ArgType.DevLong64: DevLong64,
ArgType.DevULong: DevULong64,
}
@staticmethod
def tango_to_numpy(param):
if isinstance(param, ArgType):
tg_type = param
if isinstance(param, AttributeInfo): # or AttributeInfoEx
tg_type = param.data_type
elif isinstance(param, Attribute):
tg_type = param.get_data_type()
elif isinstance(param, AttributeProxy):
tg_type = param.get_config().data_type
else:
tg_type = param
try:
return NumpyType.mapping[tg_type]
except Exception:
_numpy_invalid()
@staticmethod
def spectrum(tg_type, dim_x):
"""
numpy_spectrum(self, tg_type, dim_x, dim_y) -> numpy.array
numpy_spectrum(self, tg_type, sequence) -> numpy.array
Get a square numpy array to be used with PyTango.
One version gets dim_x and creates an object with
this size. The other version expects any sequence to
convert.
Parameters:
- tg_type : (ArgType): The tango type. For convenience, it
can also extract this information from an
Attribute, AttributeInfo or AttributeProxy
object.
- dim_x : (int)
- sequence:
"""
np_type = NumpyType.tango_to_numpy(tg_type)
if isinstance(dim_x, collections.Sequence):
return numpy.array(dim_x, dtype=np_type)
else:
return numpy.ndarray(shape=(dim_x,), dtype=np_type)
@staticmethod
def image(tg_type, dim_x, dim_y=None):
"""
numpy_image(self, tg_type, dim_x, dim_y) -> numpy.array
numpy_image(self, tg_type, sequence) -> numpy.array
Get a square numpy array to be used with PyTango.
One version gets dim_x and dim_y and creates an object with
this size. The other version expects a square sequence of
sequences to convert.
Parameters:
- tg_type : (ArgType): The tango type. For convenience, it
can also extract this information from an
Attribute, AttributeInfo or AttributeProxy
object.
- dim_x : (int)
- dim_y : (int)
- sequence:
"""
np_type = NumpyType.tango_to_numpy(tg_type)
if dim_y is None:
return numpy.array(dim_x, dtype=np_type)
else:
return numpy.ndarray(shape=(dim_y,dim_x,), dtype=np_type)
return NumpyType, NumpyType.spectrum, \
NumpyType.image, NumpyType.tango_to_numpy
except Exception:
return None, _numpy_invalid, _numpy_invalid, _numpy_invalid
NumpyType, numpy_spectrum, numpy_image, numpy_type = _define_numpy()
|