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

Please note!

IDLSave has now been merged in to Scipy and is available from Scipy 0.9.0 onwards. To use the version in scipy.io, import the read function with from scipy.io.idl import readsav and then use readsav as you would use idlsave.read.

Unless any bugs are discovered, there will be no more standalone releases of IDLSave, and future development will take place in Scipy. IDLSave 1.0.0 matches the version in Scipy 0.10.1.

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 standalone version
(1.0.0, released 1 August 2012)

This program is distributed with permission from ITT Visual Information Systems. To report bugs, you can use the issue tracker. However, if possible, please consider switching to using scipy.io.readsav and report bugs and feature requests via the Scipy 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 pip install idlsave if you have pip 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)