Overview of this package

This package’s purpose is to allow easy scripting using Starlink routines from Python. It sets up the necessary environmental variables inside the package (so you do not have to source Starlink before running Python), and ensures that Starlink is running in a scriptable mode where it will not prompt the user for input, and will write to a custom ADAM directory.

This package also attempts to provide a more pythonic interface to the commands, to provide easy access to the return values from Starlink commands (without using parget), and to not require shell escapes to be passed to the commands.

This package contains:

This package also includes convenience modules to make it easier to script the most popular (for EAO/JCMT users) Starlink packages from Python. These include integrated automatically generated help and call signatures for the commands:

We also include the following packages:

Each module is available as starlink.<modulename>. The commands are then available as starlink.<modulename>.<commandname>, and the help as help(starlink.<modulename>.<commandname>. Each command will return a Python object giving all of given and returned values from the Starlink command.

You can also see a convenient short listing of the available comamnds in the Starlink module and what they do by using the starlink.utilties.starhelp() command, like so:

>>> from starlink.utilities import starhelp
>>> from starlink import kappa
>>> starhelp(kappa)

These packages were autogenerated from a Starlink build, and you should ideally use versions generated from the same version of Starlink as you are running. If you are using a different version of the starlink-pywrapper package than your Starlink, then you may be missing some commands or some argument or keyword options to the commands present. However, most commands will probably work correctly. You can see which Starlink version the modules were generated from by using:

>>> help(starlink.kappa)

The top of this will mention the Starlink version the package was generated from.

Installation

You should normally install this package via pip with:

pip install starlink-pywrapper

This will also install the necessary python dependencies. The package depends on the starlink-pyhds package, which itself requires a Numpy installation (version>=1.13).

If you have the Astroy python package installed then you will also be able to use the starlink.utilities.get_ndf_fitshdr() command to return an Astropy FITS Header object of an NDF files FITS extension. This dependency will not be installed automatically by pip.

The source code lives at https://github.com/Starlink/starlink-pywrapper .

You can install from source by cloning this repo and running:

python setup.py install

You must also have a working Starlink installation, which can be downloaded from https://starlink.eao.hawaii.edu.

Commands that should be avoided

Some of the Starlink commands that are wrapped in this package should not be used, as they are either no longer necessary or will not work correctly. The following commands should normally be avoided.

parget

KAPPA’s parget command is used by Starlink to read values in from the $ADAMDIR/<commandname>.sf file created by Starlink commands. This does not need to be used with this wrapper, as all values are automatically returned to the user in a namedtuple object.

fitslist

KAPPA’s fitslist command only prints the FITS header values of an NDF to screen, therefore the returned object is not useful for scripting. It is possible to use the returnstdout=True keyword to get the values as a string, but instead we would recommend the following options:

  • If you only need a single FITS header value you can use starlink.kappa.fitsval() to read it.
  • If you need the whole header, then if you have Astropy python package installed on your computer you can use the :meth:`starlink.utilities.get_ndf_fitsheader method to return a astropy.io.fits.header.Header object. If you are not familiar with these objects, you can treat this much like a Python dictionary object.

Interactive usage

Many commands in Starlink have an interactive mode. This inclues both the basic mode where Starlink will prompt the user for needed values that weren’t passed on the command line, and more complex modes such as selecting positions from a displayed images. These interactive modes are not supported in this interface, as it was primarily designed for scripting.

Known Issues

1. When calling Starlink commands that are really Python scripts, such as starlink.smurf.jsasplit(), the module will not raise a proper error . Please ensure you can see the DEBUG info to identify problems. (This can be fixed if the scripts raise an exit code on error).