Fork me on GitHub
IDLSave - a python module to read IDL 'save' files

News!

The IDLSave code is now in scipy.io! At the moment, it is only available through the svn version of SciPy, but it should be included in future stable releases (from 0.9.0 onwards). To use the version in scipy.io, you can use from scipy.io.idl import readsav and then use readsav as you would use idlsave.read.

At this time, the standalone idlsave package on this page will be maintained in parallel with the scipy.io.idl version.

Introduction

IDLSave is a pure python module to import variables from IDL 'save' files (e.g. .sav) into python, and does not require IDL to work. It has a very simple command-line interface, and converts all IDL variables to python types. Arrays are converted to Numpy arrays, and Structures are converted to Numpy record arrays.

Download the latest version
(0.9.7, released 18 August 2010)

This program is distributed with permission from ITT Visual Information Systems. To report bugs and request features, please use the issue tracker. To contact me directly, please use thomas dot robitaille [at] gmail dot com.

To follow the development and get a copy of the latest development code, visit the GitHub pages.
Changes
Installation

To install, simply run python setup.py install inside the IDLSave-x.x.x directory. Alternatively, IDLSave can be installed using easy_install idlsave if you have setuptools installed.

The only dependency for IDLSave is Numpy (1.3.0 or later)

Quick start

The following example demonstrates how to read a .sav file into python. This is done using the idlsave.read method, which returns an IDLSaveFile instance. The variables are then accessible as attributes to the IDLSaveFile instance. Variable names are not case-sensitive. For structures (i.e. recarrays), variable names can be access either lower or upper case, but not mixed-case.
Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import idlsave

>>> s = idlsave.read('varsandstructs.sav')
--------------------------------------------------
Date: Tue Sep 22 11:15:11 2009
User: johndoe
Host: hal9000
--------------------------------------------------
Format: 9
Architecture: x86_64
Operating System: linux
IDL Version: 7.0
--------------------------------------------------
Successfully read 11 records of which:
 - 7 are of type VARIABLE
 - 1 are of type TIMESTAMP
 - 1 are of type NOTICE
 - 1 are of type VERSION
--------------------------------------------------
Available variables:
 - nan [<type 'numpy.ndarray'>]
 - nstruct [<class 'numpy.core.records.recarray'>]
 - floatarray [<type 'numpy.ndarray'>]
 - astruct [<class 'numpy.core.records.recarray'>]
 - journalver [<type 'int'>]
 - stringarray [<type 'numpy.ndarray'>]
 - zstruct [<class 'numpy.core.records.recarray'>]
--------------------------------------------------

>>> s.journalver
800

>>> s.floatarray
array([[  0.00000000e+00,   1.00000000e+00,   2.00000000e+00, ...,
          9.70000000e+01,   9.80000000e+01,   9.90000000e+01],
       [  1.00000000e+02,   1.01000000e+02,   1.02000000e+02, ...,
          1.97000000e+02,   1.98000000e+02,   1.99000000e+02],
       [  2.00000000e+02,   2.01000000e+02,   2.02000000e+02, ...,
          2.97000000e+02,   2.98000000e+02,   2.99000000e+02],
       ..., 
       [  9.70000000e+03,   9.70100000e+03,   9.70200000e+03, ...,
          9.79700000e+03,   9.79800000e+03,   9.79900000e+03],
       [  9.80000000e+03,   9.80100000e+03,   9.80200000e+03, ...,
          9.89700000e+03,   9.89800000e+03,   9.89900000e+03],
       [  9.90000000e+03,   9.90100000e+03,   9.90200000e+03, ...,
          9.99700000e+03,   9.99800000e+03,   9.99900000e+03]], dtype=float32)
          
>>> s.nstruct
rec.array([ (array([[  0.00000000e+00,   1.00000000e+00,   2.00000000e+00, ...,
          9.70000000e+01,   9.80000000e+01,   9.90000000e+01],
       [  1.00000000e+02,   1.01000000e+02,   1.02000000e+02, ...,
          1.97000000e+02,   1.98000000e+02,   1.99000000e+02],
       [  2.00000000e+02,   2.01000000e+02,   2.02000000e+02, ...,
          2.97000000e+02,   2.98000000e+02,   2.99000000e+02],
       ..., 
       [  9.70000000e+03,   9.70100000e+03,   9.70200000e+03, ...,
          9.79700000e+03,   9.79800000e+03,   9.79900000e+03],
       [  9.80000000e+03,   9.80100000e+03,   9.80200000e+03, ...,
          9.89700000e+03,   9.89800000e+03,   9.89900000e+03],
       [  9.90000000e+03,   9.90100000e+03,   9.90200000e+03, ...,
          9.99700000e+03,   9.99800000e+03,   9.99900000e+03]], dtype=float32), 
          array([[a, a, a, ..., a, a, a],
       [a, a, a, ..., a, a, a],
       [a, a, a, ..., a, a, a],
       ..., 
       [a, a, a, ..., a, a, a],
       [a, a, a, ..., a, a, a],
       [a, a, a, ..., a, a, a]], dtype=object), 'named structure')], 
      dtype=[(('floatarray', 'FLOATARRAY'), '|O8'), 
             (('stringarray', 'STRINGARRAY'), '|O8'),
             (('comment', 'COMMENT'), '|O8')])
             
>>> s.nstruct.stringarray
array([ [[a a a ..., a a a]
 [a a a ..., a a a]
 [a a a ..., a a a]
 ..., 
 [a a a ..., a a a]
 [a a a ..., a a a]
 [a a a ..., a a a]]], dtype=object)