How to ... Install OrbFit 5.0 on macOS

How to ... Install OrbFit 5.0 on macOS

OrbFit is a software package used to determine the orbits of asteroids written by the OrbFit Consortium. But it’s very sparsely documented, and can be a little tricky to install, never-mind learning how to use it.

Here’s my guide to getting it to successfully install on my mac (macOS Sierra).

A Conda Environment with a Lovely Fortran Compiler

Anaconda/Miniconda are going to greatly reduce the headache of having to install OrbFit, so make sure you have one or the other installed on your mac. There are plenty of tutorials just a google away, the Anaconda docs are excellent and I even wrote up my own guide and tutorial here.

Once you have .*Conda installed, go ahead and create a new environment within which to install Orbfit. I’m calling mine orbfit5.0 in case I want install an older/newer version of OrbFit at any point.

$ conda create -n orbfit5.0

Fetching package metadata ...............
Solving package specifications:
Package plan for installation in environment /Users/Dave/anaconda/envs/orbfit5.0:

Proceed ([y]/n)? y

# To activate this environment, use:

# > source activate orbfit5.0

#

# To deactivate this environment, use:

# > source deactivate orbfit5.0

Now activate your new environment:

$ source activate orbfit5.0

As OrbFit is written in Fortran you will need a suitable compiler to install the code. Go ahead and install one into your environment:

$ conda install -c uvcdat gfortran

Fetching package metadata .................
Solving package specifications: .

Package plan for installation in environment /Users/Dave/anaconda/envs/orbfit5.0:

The following NEW packages will be INSTALLED:

    cloog:    0.18.0-0
    gfortran: 4.9.3-1  uvcdat
    gmp:      6.1.0-0
    isl:      0.15-0
    mpc:      1.0.3-0
    mpfr:     3.1.5-0

Proceed ([y]/n)? y

Typing gfortran -v reveals that I’ve just installed the gcc v4.9.3 version of the compiler. Yours maybe a more recent version.

Download

The next thing to do is download the Orbfit distribution. You can find the latest distribution here:

http://adams.dm.unipi.it/orbfit/OrbFit/

As of writing this tutorial, OrbFit v5.0.5 was the latest version, and you can download the compressed version of that distribution from here. Unpack the code somewhere sensible.

mkdir ~/Orbfit5.0
mv ~/Downloads/OrbFit5.0.5.tar.gz ~/Orbfit5.0
cd ~/Orbfit5.0
tar -xvf OrbFit5.0.5.tar.gz

Install

Configure and Make OrbFit

Once unpacked, jump into the directory, wherever you’ve placed it (let’s assume it’s on your desktop):

$ cd ~/Orbfit5.0

Configure make to perform an optimised compile with gfortran:

$ ./config -O gfortran

Next we have to tweak the Make flags so the compiler knows where to find the conda library files. Open the file ./src/make.flags and change the line FFLAGS= -O3 -I../include to FFLAGS= -O3 -I../include -Wl,-rpath,${CONDA_PREFIX}/lib.

Now you can compile the code:

$ make

If at any point in this stage you slip-up or something goes wrong, try a make clean and begin again from the start of the configure and make processed.

At this point you either want the add Orbfit’s ./bin directory to your path. Open your ~/.bashrc, or equivalent file for your shell, and append:

# ORBFIT
export PATH="$PATH:$HOME/Orbfit5.0/bin"

Building a JPL Ephemerides Binary

Before you can use any of the OrbFit programs we need to generate a binary JPL ephemeris file for your machine. To do this first connect to the JPL FTP site via the command-line or your favourite FTP client. The server URL is:

ftp://ssd.jpl.nasa.gov

and the directory you want to download is /pub/eph/planets/ascii/de413

Once downloaded, copy the contents of this directory into src/jpleph:

$ cp de413/* src/jpleph/

And now combine these ascii files into one binary file:

$ cd src/jpleph/
$ cat header.413 ascp1900.413 ascp1925.413 ascp1950.413 ascp1975.413 ascp2000.413 ascp2025.413 | ./asc2eph.x

If successful you will see something like this:

...
1713 EPHEMERIS RECORDS WRITTEN. LAST JED = 2469808.50
STOP OK

and a non-zero sized JPLEPH file containing the combined JPL ephemerides:

$ ls -l JPLEPH
-rw-r--r--@ 1 Dave admin 13966960 7 Sep 15:10 JPLEPH

Move this file into Orbfit’s lib directory:

$ mv JPLEPH ../../lib/jpleph

Test the Install

The final task is to test your install. To do so make a directory somewhere called orbfit-workspace and change into it:

$ mkdir ~/Desktop/orbfit-workspace
$ cd ~/Desktop/orbfit-workspace

Now download the Lowell Observatory astorb flavour of orbital elements from here and uncompress.

wget ftp://ftp.lowell.edu/pub/elgb/astorb.dat.gz
gunzip astorb.dat.gz

Finally grab my template options file and dummy observation files from this gist (click on the ‘Download ZIP’ button). Now you should have 3 files in your workspace:

$ ls
astorb.dat
dummy.obs
orbfit-template-run-options.oop

Run the command orbfit.x and then give orbfit-template-run-options as the run name. You should see something like this:

$ orbfit.x
 Run name =
orbfit-template-run-options
 Run name = orbfit-template-run-options
 JPL planetary ephemerides DE413
 number of perturbers =            0
 binary ephemerides file= CPV
 perturbing asteroids used: none
 ngr_opt =  F
 No .rwo file, reading .obs and/or .rad files.
 input_obs:            1  obs in ./dummy.obs
 Using .rwo file, but checking .obs,.rad for update.
 input_obs:            1  obs from  ./dummy.rwo
 input_obs:           1  obs from  ./dummy.obs
 There are no updates in .obs or .rad files.
Scanning file "astorb.dat" (format: BA2)
        Semimajor axis     =  3.1166357900000001E+00 au
        Eccentricity       =   0.115222750000000
        Inclination        =  12.5288100000000 deg
        Long. of node      = 148.0323380000000 deg
        Arg. of pericenter = 357.0506910000000 deg
        Mean anomaly       =  39.3705710000000 deg
Scanning file "astorb.dat" (format: BA2)
        Semimajor axis     =  3.1166357900000001E+00 au
        Eccentricity       =   0.115222750000000
        Inclination        =  12.5288100000000 deg
        Long. of node      = 148.0323380000000 deg
        Arg. of pericenter = 357.0506910000000 deg
        Mean anomaly       =  39.3705710000000 deg
 ORBFIT: propagation of orbital elements
  write_elems: ndim.ne.nd        32767           6
  write_elems: ndim.ne.nd        32767           6
 ORBFIT: generating ephemerides

and you will find an ephemeris file has been created called orbfit-template-run-options.oep containing the following:

Ephemeris for object 1999
     Origin of orbital elements: read from file "astorb.dat" at record 1999


                                     Equatorial coordinates                                                    App. motion
    Date      Hour      MJD            RA            DEC       Mag   Delta     R     SolEl  Phase Glat    RA*cosDE       DEC
             (UTC)     (UTC)        h  m  s        d  '  "            (au)    (au)   (deg)  (deg) (deg)   arcsec/s    arcsec/s
 =========== ====== ============  =============  ============ ===== ======= ======= ====== ====== =====  ==========  ==========
 12 Jun 2017  0.000 57916.000000   10 34 12.030  +14 59  6.76  16.5  2.9078  2.7977  -73.7   20.4  55.9  1.1476E-02 -3.8280E-03

Ephemeris for object 1999
     Origin of orbital elements: read from file "astorb.dat" at record 1999


                                     Equatorial coordinates                                                    App. motion
    Date      Hour      MJD            RA            DEC       Mag   Delta     R     SolEl  Phase Glat    RA*cosDE       DEC
             (UTC)     (UTC)        h  m  s        d  '  "            (au)    (au)   (deg)  (deg) (deg)   arcsec/s    arcsec/s
 =========== ====== ============  =============  ============ ===== ======= ======= ====== ====== =====  ==========  ==========
 12 Jun 2017  0.000 57916.000000   10 34 12.030  +14 59  6.76  16.5  2.9078  2.7977  -73.7   20.4  55.9  1.1476E-02 -3.8280E-03

Job done. Coffee time.

If you want some more details on the Orbfit options see here.