Python Interace

In order to build the python interface, you nee to check out the repository

python/source

in particular, the python package lives in

python/source/kepler

Currently, this requires Python 3.9.x and gcc 10.2.1 on Fedora Linux 33 and requires current NumPy 1.19.5 or 1.20.2 and later, and matplotlib 3.3 or better. (Numpy has been fixed to compile KEPLER for Versions 1.11 through 1.19.x and Version 1.20.2 and better.) Ideally, when you import the package, all dependencies should be compiled automatically, however, you need to make sure you us the same directory paths. (…)

Kepler can now be run as a Python module and development is on the way to improve the interface. All plot types from Mongo are available in Python/matplotlib, however, the plotting is somewhat slower.

Installing the Python Module

This has only been tested for Fedora Linux 22+ so far. Current work and update of this page is based on Fedora 33. First, you need to get a current version of Python, most easy to install locally. As of the time of this writing, this is Version 3.9.2. Earlier versions may have bugs and some parts do not work.

First start to make a non-optimised compile to check whether you have all pre-requisites (libraries, header files) installed on your system:

# using bash
export py=3.9.2
wget https://www.python.org/ftp/python/${py}/Python-${py}.tar.xz
cd
tar -xvJf Python-${py}.tar.xz
cd Python-${py}
./configure --prefix=$HOME/Python
make -j

Note

the make -j command may give you some message of components in python it did not build because of missing dependencies. You should try to find them all to build a complete python install, otherwise some key components may not be build. Specifically, pip3 has happened to be missing in some of the installations I attempted.

Find and install missing dependencies, re-compile until all works.

When this is accomplished, compile and install the full version

make clean
./configure --prefix=$HOME/Python --enable-optimizations --enable-shared
make install

Then, I change my ~/.bashrc to file to include

export PYTHON=${HOME}/Python
export PATH=$PYTHON/bin:$PATH
export MANPATH=$PYTHON/man:$MANPATH
export PYTHONPATH=${PYTHONPATH}:${PYTHON}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${PYTHON}/lib

and open a new bash shell. Now, you want to install a phledora of python packages,

pip3 install -U pip
pip3 install -U wheel
pip3 install -U  --force-reinstall numpy scipy ipython[notebook] psutil pyyaml six matplotlib py-cpuinfo

You will need to install numpy 1.20.2 or higher (as of this writing version 1.19.5 also works, but 1.20.0 and 1.20.1 do not), which you may have to check out from the development page and compile/install your self. (Numpy developers kindly, repeatedly, included bug fixes to f2py to make KEPLER work, for 1.11, and most recent for 1.20.2.)

By default, it appears current numpy does not create a link for f2py3 by defaul, so we need to make this by hand:

cd
cd Python/bin
ln -s f2py f2py3

If you now create a kepler.code.Kepler object, in an ideal world, this should automatically compile the necessary binary libraries tuned for your computer all from scratch.

Note

Please let me know of any problems, their solutions, and possible updates for this documentation

You can also manually build the KEPLER module in Python, e.g., IPython

from kepler.code import make
make()

to start over fresh, or to remove all old binary and build files, use

from kepler.code import clean
clean()

Updating your Python Install

A useful scrtip that I run every now and then to update python is

#!/usr/bin/bash
pip3 install --upgrade pip
pip3 freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs pip3 install -U
pip3 check

You should coupy this into a file, e.g., update_python and make executable.