Skip to content
Convert between AACGM and open closed field-line boundary coodinates
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Build Status Coverage Status Documentation Status DOI


ocbpy is a Python module that converts between AACGM coordinates and a magnetic coordinate system that adjusts latitude and local time relative to the Open Closed field line Boundary (OCB). This is particulary useful for statistical studies of the poles, where gridding relative to a fixed magnetic coordinate system would cause averaging of different physical regions, such as auroral and polar cap measurements. This coordinate system is described in:

  • Chisham, G. (2017), A new methodology for the development of high‐latitude ionospheric climatologies and empirical models, Journal of Geophysical Research: Space Physics, doi:10.1002/2016JA023235.

  • Full documentation

OCBs must be obtained from observations for this coordinate transformation. In the British Antarctic Survey's IMAGE Auroral Boundary data project from three auroral instruments provide northern hemisphere OCB locations for 3 May 2000 03:01:42 UT - 22 Aug 2002 00:01:28, though not all of the times included in these files contain high-quality estimations of the OCB. Recommended selection criteria are included as defaults in the OCBoundary class.

Currently, support is included for files from the following datasets:

These routines may be used as a guide to write routines for other datasets.

Python versions

This module has been tested on python version 2.7, 3.4 - 3.6. Local testing on 3.3 was also performed, but may not be supported in the next version.


The listed dependecies were tested with the following versions:

  • datetime
  • numpy (1.11.3, 1.12.1, 1.14.1)
  • logbook
  • setuptools (36.0.1)

Testing is performed using the python module, unittest


Installation is now available through pypi PyPI version

    $ pip install ocbpy

You may also checkout the repository and install it yourself:

    $ git clone git://;

Change directories into the repository folder and run the file. For a local install use the "--user" flag after "install".

    $ cd ocbpy/
    $ python install

To run the unit tests,

    $ python test


In iPython, run:

import numpy as np
import ocbpy

Then initialise an OCB class object. This uses the default IMAGE FUV file and will take a few minutes to load.

ocb = ocbpy.ocboundary.OCBoundary()
print ocb

The output should be as follows:

Open-Closed Boundary file: ~/ocbpy/ocbpy/boundaries/si13_north_circle
Source instrument: IMAGE
Open-Closed Boundary reference latitude: 74.0 degrees

219927 records from 2000-05-05 11:35:27 to 2002-08-22 00:01:28

YYYY-MM-DD HH:MM:SS NumSectors Phi_Centre R_Centre R  R_Err Area
2000-05-05 11:35:27 4 356.93 8.74 9.69 0.14 3.642e+06
2000-05-05 11:37:23 5 202.97 13.23 22.23 0.77 1.896e+07
2002-08-21 23:55:20 8 322.60 5.49 15.36 0.61 9.107e+06
2002-08-22 00:01:28 7 179.02 2.32 19.52 0.89 1.466e+07

Get the first good OCB record, which will be record index 27.

print ocb.rec_ind


Now plot the location of the OCB

First initialise the figure

import matplotlib.pyplot as plt
f = plt.figure()
ax = f.add_subplot(111, projection="polar")
ax.xaxis.set_ticks([0, 0.5*np.pi, np.pi, 1.5*np.pi])
ax.xaxis.set_ticklabels(["00:00", "06:00", "12:00 MLT", "18:00"])

Mark the location of the circle centre in AACGM coordinates

phi_cent_rad = np.radians(ocb.phi_cent[ocb.rec_ind])
ax.plot([phi_cent_rad], [ocb.r_cent[ocb.rec_ind]], "mx", ms=10, label="OCB Pole")

Calculate at plot the location of the OCB in AACGM coordinates

lon = np.arange(0.0, 2.0 * np.pi + 0.1, 0.1)
del_lon = lon - phi_cent_rad
lat = ocb.r_cent[ocb.rec_ind] * np.cos(del_lon) + np.sqrt(ocb.r[ocb.rec_ind]**2 - (ocb.r_cent[ocb.rec_ind] * np.sin(del_lon))**2)
ax.plot(lon, lat, "m-", linewidth=2, label="OCB")
ax.text(lon[35], lat[35]+1.5, "74$^\circ$", fontsize="medium", color="m")

Add reference labels for OCB coordinates

lon_clock = list()
lat_clock = list()

for ocb_mlt in np.arange(0.0, 24.0, 6.0):
    aa,oo = ocb.revert_coord(74.0, ocb_mlt)
    lon_clock.append(oo * np.pi / 12.0)
    lat_clock.append(90.0 - aa)

ax.plot(lon_clock, lat_clock, "m+")
ax.plot([lon_clock[0], lon_clock[2]], [lat_clock[0], lat_clock[2]], "-", color="lightpink", zorder=1)
ax.plot([lon_clock[1], lon_clock[3]], [lat_clock[1], lat_clock[3]], "-", color="lightpink", zorder=1)
ax.text(lon_clock[2]+.2, lat_clock[2]+1.0, "12:00",fontsize="medium",color="m")
ax.text(lon[35], olat[35]+1.5, "82$^\circ$", fontsize="medium", color="m")

Now add the location of a point in AACGM coordinates, calculate the location relative to the OCB, and output both coordinates in the legend

aacgm_lat = 85.0
aacgm_lon = np.pi
ocb_lat, ocb_mlt = ocb.normal_coord(aacgm_lat, aacgm_lon * 12.0 / np.pi)
plabel = "Point (MLT, lat)\nAACGM (12:00,85.0$^\circ$)\nOCB ({:.0f}:{:.0f},{:.1f}$^\circ$)".format(np.floor(ocb_mlt), (ocb_mlt - np.floor(ocb_mlt))*60.0, ocb_lat)

ax.plot([aacgm_lon], [90.0-aacgm_lat], "ko", ms=5, label=plabel)

ax.legend(loc=2, fontsize="small", title="{:}".format(ocb.dtime[ocb.rec_ind]), bbox_to_anchor=(-0.4,1.15))

The figure should now look like:

OCB Example
You can’t perform that action at this time.