One of the major features of IDL 8.5 is the two-way bridge between IDL and Python. This allows Python functionality to be accessed from IDL (Python has a lot of libraries for things that fall outside of the standard scientific routines found in IDL) as well as accessing IDL functionality from Python (call legacy IDL code).

The IDL-Python bridge works with either Python 2 or 3 (whew, I’m still on Python 2!).

It is possible to use any of the vast array of libraries available for Python from IDL. For example, we can use one of the interpolation methods in SciPy just by importing it:

IDL> interpol = python.import('scipy.interpolate')

Now, create some data in IDL to interpolate:

IDL> lat = randomu(seed, 20) + 40.0
IDL> lon = randomu(seed, 20) - 100.0
IDL> values = randomu(seed, 20)

Now, create the interpolation function with those values:

IDL> rbfi = interpol->Rbf(lat, lon, values)

Finally, call the interpolation routine on with the locations we need values for:

IDL> print, rbfi([40.5], [-99.5])
0.37419477

To make this side of the bridge even easier from the IDL command line, there is a special Python mode that can be entered simply by entering >>>:

IDL> >>>
>>> import numpy
>>>
IDL>

Enter a blank line to get back to IDL.

From Python, use the idlpy package access IDL:

>>> from idlpy import IDL
>>> x = IDL.findgen(10)
>>> print x
[ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9.]

The Python bridge docs are online, check them out for more details.

One of the most exciting aspects of the IDL-Python bridge is the IDL Jupyter notebook kernel, which I will discuss next week.