GNU Astronomy Utilities


Next: , Previous: , Up: Gnuastro library   [Contents][Index]


12.3.31 Python interface (python.h)

Python is a high-level interpreted programming language that is used by some for data analysis. Python itself is written in C, which is the same language that Gnuastro is written in. Hence Gnuastro’s library can be directly used in Python wrappers. The functions in this section provide some low-level features to simplify the creation of Python modules that may want to use Gnuastro’s advanced and powerful features directly. To see why Gnuastro was written in C, please see Why C programming language?.

The Gnuastro Python Package is built using CPython. This entails using Python wrappers around currently existing Gnuastro library functions to build Python Extension Modules. It also makes use of the NumPy C-API for dealing with data arrays. Writing an interface between these and Gnuastro can be simplified using the functions below. Since many of these functions depend on the Gnuastro Library itself, it is more convenient to package them with the Library to facilitate the work of Python package. These functions will be expanding as Gnuastro’s own Python module (pyGnuastro) grows.

The Python interface of Gnuastro’s library is built and installed by default if a Python 3.0.0 or greater with NumPy is found in $PATH. Users may disable this interface with the --without-python option to ./configure when they installed Gnuastro, see Gnuastro configure options. If you have problems in a Python virtual env, see Optional dependencies.

Because Python is an optional dependency of Gnuastro, the following functions may not be available on some systems. To check if the installed Gnuastro library was compiled with the following functions, you can use the GAL_CONFIG_HAVE_PYTHON macro which is defined in gnuastro/config.h, see Configuration information (config.h).

Function:
int
gal_python_type_to_numpy (uint8_t type)

Returns the NumPy datatype corresponding to a certain Gnuastro type, see Library data types (type.h).

Function:
uint8_t
gal_python_type_from_numpy (int type)

Returns Gnuastro’s numerical datatype that corresponds to the input NumPy type. For Gnuastro’s recognized data types, see Library data types (type.h).


Next: Unit conversion library (units.h), Previous: Git wrappers (git.h), Up: Gnuastro library   [Contents][Index]