Version 0.2.7
Copyright (c) 2008-2017, Anthony Smith
(NB: since pIDLy was written, IDL has developed a two-way Python Bridge. I recommend trying that first.)
This module has been written to enable an IDL session to be controlled from within Python. I was inspired by pyIDL, which looks great but which I couldn't manage to install. So I wrote my own.
pIDLy works by launching an IDL session as a child application and then passing data between Python and the IDL shell. It's not particularly fast, so not suitable for applications which require huge amounts of data to be passed around with ease. But it should be fine for most applications.
pIDLy requires NumPy, SciPy and Pexpect, but these will (hopefully!) be installed automatically if you follow the instructions below. You also need IDL, of course.
Contributions welcome!
- Requirements
- Installation
- Usage
- Further information
- Known bugs/issues
- To do
- Release history
The following are required, but should be installed automatically if you follow the installation instructions below:
Also required:
This version tested on
- Mac OS X with IDL 7.1.1 and Python 3.4.1
- Mac OS X with IDL 7.1.1 and Python 2.7.5
- Type "pip install pidly"
If that fails:
- Download https://raw.github.com/pypa/pip/master/contrib/get-pip.py
- run it (type "python get-pip.py")
- Type "pip install pidly"
- Initiate::
>>> import pidly >>> idl = pidly.IDL()
- Or::
- idl = pidly.IDL('/path/to/idl')
- Or::
- idl = pidly.IDL('/path/to/gdl', idl_prompt='GDL> ')
- Execute commands::
>>> idl('x = total([1, 1], /int)')
- Retrieve values::
>>> print idl.x 2
- Or (slightly faster)::
>>> print idl.ev('x') 2
- Evaluate expressions::
>>> print idl.ev('x ^ 2') 4
- Use cache (IDL save) to handle large arrays::
>>> idl('x=[1,2,3,4,5,6]') >>> print(idl.ev('x', use_cache=True)) [1 2 3 4 5 6]
- Transfer a list of IDL variables, using cache::
>>> idl('y=[1,2,3,4,5,6]') >>> xy = idl.ev_list(['x','y'], use_cache=True) >>> print(sorted(xy.keys())) ['x', 'y'] >>> print(xy['x']) [1 2 3 4 5 6]
- Assign value from Python expression::
>>> idl.x = 2 + 2 >>> print idl.x 4
- Or::
>>> idl('x', 2 + 2) >>> print idl.x 4
- Perform IDL function on Python expression(s)::
>>> idl.reform(range(4), 2, 2) array([[0, 1], [2, 3]])
- Or (slightly faster)::
>>> idl.func('reform', range(4), 2, 2) array([[0, 1], [2, 3]])
- With keywords (/L64 -> L64=True or L64=1):
>>> idl.histogram(range(4), binsize=3, L64=True) array([3, 1], dtype=int64)
- IDL procedure with Python argument(s)::
>>> idl.pro('plot', range(10), range(10), xstyle=True, ystyle=True)
- Interactive mode::
>>> idl.interact() IDL> print, x 4 IDL> ^D >>>
- Close::
>>> idl.close()
pIDLy supports the transfer of
- ints, longs, ...
- floats, doubles, ...
- strings
- arrays of the above types, with arbitrary size and shape
- dictionaries <-> structures & lists of dicts <-> arrays of structures but with certain limitations on transfer from Python to IDL
- NB if getting Syntax Errors when passing large arrays to IDL, try using::
>>> idl = pidly.IDL(long_delay=0.05) # default is 0.02.
Further information is available
- from the Python Package Index
- from the GitHub repository
- from the author: [email protected]
- Python variables cannot be used as "output" parameters for IDL procedures and functions; use idl('my_procedure, output_parameter') to run the procedure then idl.output_parameter to retrieve the output.
- If Python is force-killed when IDL is running, IDL will persist and run wild
- Restrictive limits on size of Python dictionaries to send to IDL structures
- Slow transferring large Python arrays to IDL, e.g., 20,000 doubles in 12-15s
- IPython on Aquamacs: prints input in interactive mode
- Aquamacs: interactive mode has very small input buffer (253 bytes?)
- idl.f(..., idl.g(...)) doesn't work (pidly_tmp conflict)
- Test on Windows
- Complex numbers
- Raise exceptions (e.g., for unsupported types)
- Passing special characters in strings (t, n etc)
- Add use_cache option to transfer data using IDL save (with thanks to Fmajor)
- Python3 compatible version (with thanks to Alexander Heger)
- Better behaviour when IDL is no longer alive
- Works with GDL
- Fixed bug with keyword arguments in functions
- Added pro() method for IDL procedures with Python arguments
- Improved garbage collection (using weakref and atexit)
- IDL Errors: launches interactive after '% Stop' or '% Execution Halted'
- If IDL pauses (waiting for input?), KeyboardInterrupt -> interactive mode
- Fixed bugs with NumPy array input
- Fixed problems with double precision float transfer
- Fixed problem with spaces in strings in structures/dictionaries
- Added test() function for full tests
- Added NaN and Inf support
- Fixed bug, where IDL would run wild when IPython closed
- Added keyword parameters in calls to IDL functions
- Added support for Python bool type
- Structures can be transferred from IDL to Python as dictionaries
- Dictionaries can be transferred from Python to IDL as structures. But:
- lists of dictionaries must be explicitly and consistently typed
- the dictionary, or each dictionary in the list, must be short enough to fit into a single command for IDL
- long lists of dictionaries are likely to be slow from Python to IDL, as assignment takes place one dictionary at a time
- Now gives "live" output while waiting for the IDL prompt
- Fixed bug related to long IDL 'help' output
- String arrays with arbitrary spaces now work
- Added support for unsigned integers
- Fixed bug with byte/int8
- Added easy access to IDL variables and functions (__getattr__ and __setattr__)
- Performance improvement:
- 5-100 times faster, tranferring from Python to IDL
- ~1.5x faster, transferring from IDL to Python
- Renamed Session class to IDL
- Removed timeout limit
- Fixed typo in license
- README and LICENSE files
- Wrapper on Pexpect, with conversions between IDL data and NumPy arrays
- Handles arbitrarily sized and shaped arrays of strings, ints and floats