Welcome to the Harris Geospatial product documentation center. Here you will find reference guides, help documents, and product libraries.

Harris Geospatial / Docs Center / Using IDL / IDL IPython Notebook Kernel


IDL IPython Notebook Kernel

IDL IPython Notebook Kernel

The IDL IPython Kernel provides the necessary hooks for an IPython (Jupyter) notebook to run IDL code.


First, install IDL and set up the Python Bridge. Make sure that <IDL_DIR>/lib/bridges is on the Python path so that Python can find the idl_kernel.py script. You can test this using the following Python command:

>>> from idl_kernel import *

IDL should start up with no errors. If you encounter errors, see Python Bridge for troubleshooting.

Then install IPython using the instructions for your platform:

For example, if you are using the Anaconda python package, you can install IPython using the following commands:

conda update conda
conda install jupyter

Once IPython (Jupyter) has been installed, you need to install the IDL kernel. The IDL kernel can be found in:


Depending upon your platform, this file should be installed into one of the following directories.


To install for all users:




To install for a single user:



To install for all users:


Note: For all platforms, be sure to create a directory named kernels with a subdirectory named IDL and copy the kernel.json file into that directory.

Environment Variable

Instead of copying the kernel.json file, you can define an environment variable:

JUPYTER_PATH = <IDL_DIR>/lib/bridges/kernels/IDL/kernel.json

where <IDL_DIR> should be changed to your IDL installation directory.


Once installed, a type of notebook will be available called IDL.

Start the IPython (Jupyter) notebook interface using the following command from a command shell:

jupyter notebook

Your default web browser should start and should load the main notebook web page, called the "dashboard". On the right-hand side, under the "New" drop-down button, you should see a menu item for both "Python" and "IDL". Choose IDL to start a new IDL notebook.

A new web browser window or tab should appear, containing the IDL notebook. After the IDL kernel has started, you can start entering IDL commands. All code inside this notebook will be treated as IDL code. To execute IDL commands, type the command into a notebook cell and then press <Shift>+<Return>.

You can enter either single commands or multiple commands within a cell. If you enter multiple commands, then the notebook will send each line to IDL as a separate command (although see the Multi-line section below). Any text output from IDL (including error messages) will appear in the "output" cell below the command cell.

You can also enter any "executive" commands such as .RESET or .COMPILE. Note that some commands such as .EDIT will not do anything.

Any graphics created by the notebook will appear inline by default. This includes graphics generated by direct graphics, object graphics (using IDLgrBuffer), and function graphics.

IDL widgets will appear in a separate window, not embedded in the notebook.

Controlling Graphics Output

By default, any graphics created by IDL will be inline (embedded) within the IDL notebook. You can change this behavior by using the %inline and %window magic commands.

For example:

In [0]: %window
In [1]: p = PLOT('r',/TEST) ; display in a separate window
In [2]: %inline
In [3]: p = PLOT('g',/TEST) ; display inline in the browser

HTML Output

Normally, all IDL output will be sent to the browser as raw unformatted text. Any HTML commands or special escape characters will be ignored and displayed as just text. However, if your IDL output begins with the characters <HTML> then the output for that line will be sent to the browser as HTML.

For example:

In [0]:
s1 = '<html>Here is some <B>BOLD</B> and <i>italic</i> HTML.<br>'
s2 = 'Go to the <a href="https://www.google.com/search?q=idl%20documentation%20center" target="_blank">IDL Documentation Center</a>.'
print, s1 + s2

The IDL notebook displays:

Here is some BOLD and italic HTML.

Go to the IDL Documentation Center.

Here, we display an image using the BUFFER keyword to WRITE_PNG, and base-64 encoding using the IDL_BASE64 function:

In [0]:
lam = Lambda(n,m:Reform(Congrid(255*Randomu(seed,n,n),n*m,n*m),1,n*m,n*m))
WRITE_PNG, '', [lam(15,10),lam(15,10),lam(15,10)], BUFFER=b
img = IDL_BASE64(b)
print,'<html><img src="data:image/png;base64,'+img+'"/></html>'

The IDL notebook displays:

Note: You can also use the %%HTML magic command to include HTML. See Magic Commands below for details.

Multi-line IDL Blocks

By default the IDL notebook executes each line within a cell as a single command.

If you use the IDL continuation character "$" then the notebook will automatically concatenate these lines together and execute it as a single command (see the Examples below).

If the last line in a cell is an END statement, then the IDL notebook will assume that you have a multi-line block of commands. In this case the notebook will compile the entire block as one unit. This allows you to dynamically compile functions and procedures. In addition, if the cell contains a $MAIN program then the notebook will issue a .RUN command to execute the block.

For example, if you wanted to use a FOR BEGIN/END loop with an IF/THEN block, you could do the following:

In [0]:
for i=1,6 do begin
  if i gt 3 then begin
    print, i

As another example, we create a function and then use it later:

In [0]:
  RETURN, X^3 + (X - 1.0)^2 + 3.0
In [1]:
PRINT, QROMB('cubic', 0.0, 3.0)

The IDL notebook displays:


We could also combine both cells into a single cell with an END as the last line and the IDL notebook will compile the code and then execute it:

In [0]:
  RETURN, X^3 + (X - 1.0)^2 + 3.0
PRINT, QROMB('cubic', 0.0, 3.0)

Note: When using a multi-line block, the entire cell is executed as a single command. If you create any graphics within that block, only the last graphic will be displayed (unless !MAGIC has been used to turn off embedding).

Magic Commands

You can also use special "magic" commands at the top of a cell to control behavior. Commands that begin with "%" are single line commands, where the rest of the cell is ignored. Commands that begin with "%%" are multi-line commands.

The following commands are available by default:

Magic Command



Render the cell contents as a block of HTML



Execute the cell contents as a block of Python code. The ">>>" is a shorthand form.


%config property

%config property=value

Set various configuration properties. Using %config by itself will print out a list of available properties, while using %config property will print out the current value.


Switch to inline (embedded) mode for IDL graphics


Print out a list of all available magic commands.


Switch to separate windows for IDL graphics

The magic commands are designed to be extensible. To add your own magic commands, see the idl_magic.py file within the <IDL_DIR>/lib/bridges directory.



In the IDL notebook, enter the following commands. Be sure to press <Shift>+<Return> to execute the commands within a cell.

In [0]:
; Create and use IDL variables
arr = Randomu(seed, 1000)
HELP, arr
Out [0]:
ARR             FLOAT     = Array[1000]
In [1]:
PRINT, MAX(arr), MIN(arr), MEAN(arr)
Out [1]:
0.999996   0.00185713     0.503354
In [2]:
theory = SIN(2.0*[0:199]*!PI/25.0)*EXP(-0.02*[0:199])
; You can use the $ continuation character.
p = PLOT(theory, "r4D-", YTITLE='Resistance ($\Omega$)', $ 
TITLE="Circuit Resistance", DIM=[450,400], MARGIN=0.2)
p.SYM_COLOR = "blue"
Out [2]:

For more examples open the <IDL_DIR>/lib/bridges/IPythonTests.ipynb notebook within the IDL kernel.


  • If the "jupyter notebook" command fails, make sure that you have installed the latest version of IPython (Jupyter) using the installation instructions.
  • If IDL does not appear as a choice in the "New" notebook list, make sure you have copied the kernel.json file into one of the installation directories given above. Make sure that the JSON file is located inside a directory named kernels/IDL.
  • If IPython finds the IDL kernel but is unable to start IDL, make sure you have set up the appropriate Python bridge system variables. See the Python Bridge page for details.

Version History




Add support for multi-line blocks.
Add support for magic commands.

See Also

Python Bridge, IDL to Python, Python to IDL

© 2017 Exelis Visual Information Solutions, Inc. |  Legal
My Account    |    Buy    |    Contact Us