More...
Convert Casacore objects to/from Python (using Boost.Python)
See below for an overview of the classes in this module.
Intended use:
Public interface
Review Status
- Test programs:
- tConvert
Prerequisite
Synopsis
Converters contains functions to convert the important Casacore objects to/from Python using the Boost.Python package. Converters for the following Casacore classes exist:
-
Scalars of basic data types like Bool, Int, Float, Complex.
-
casacore::String and std::string.
-
casacore::Vector and std::vector of any type which can be converted from a Python scalar, list, tuple, or 1-dim array. They are converted back to a Python list.
-
Record which is converted to/from a Python dict.
-
ValueHolder which is converted to/from the appropriate Python type. A ValueHolder is a class which can hold various value types:
-
Scalar of any basic data type.
-
Record.
-
N-dim Array of any basic data type. A casacore::Array can be constructed from Python types like tuple, list, and numpy array A Py_None object results in an empty array. The conversion back is done to a numpy array. An empty array is returned as an empty numpy array.
Because Casacore arrays are in Fortran order and numpy arrays (preferably) in C order, the axes are reversed during conversion.
A 1-dim Array<String>
object is converted to a list, while a higher dimensioned Array<String> object is converted to/from a dict containing the shape and the values as a list. However, conversion from a numpy string array is supported.
A ValueHolder is for instance used by the Table System to be able to get or put data in a column of any type. It can be used by any Python binding to convert arrays. Class ValueHolder has functions to get or set the array.
-
casacore::IPosition which can be converted from a Python scalar, list, tuple, or 1-dim array. It is converted back to a Python list. An IPosition object represents an array shape or position, so its values are reversed because of the different ordening of Casacore and Python arrays.
-
Exceptions, which are mapped to a Python
RuntimeError
exception. Only the casacore::IterError
exception is mapped to a Python StopIteration
exception.
The converts from Python to C++ can handle some special numpy objects. Such objects can also be contained in sequences or dicts.
-
Elements in a numpy array are called array scalars. They do not have a python type such as
int
, but instead a type as numpy.int32
. The converters can handle such types and convert them correctly to a scalar.
-
A numpy scalar array (e.g.
array(1.0)
is a somewhat peculiar numpy object. It has an empty shape and cannot be indexed. It is handled correctly by the from converters and handled as a scalar value.
-
An empty numpy object (e.g.
array([])
) is handled as a None value.
◆ PycArrayCheck()
Bool casacore::python::PycArrayCheck |
( |
PyObject * |
obj_ptr | ) |
|
A class to convert an Array to/from Python objects.
Intended use:
Public interface
Synopsis
Check if the PyObject is an array object.